/* Generated by Cython 0.21.2 */

#define PY_SSIZE_T_CLEAN
#ifndef CYTHON_USE_PYLONG_INTERNALS
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 0
#else
#include "pyconfig.h"
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 1
#else
#define CYTHON_USE_PYLONG_INTERNALS 0
#endif
#endif
#endif
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
    #error Cython requires Python 2.6+ or Python 3.2+.
#else
#define CYTHON_ABI "0_21_2"
#include <stddef.h>
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
#define CYTHON_COMPILING_IN_PYPY 1
#define CYTHON_COMPILING_IN_CPYTHON 0
#else
#define CYTHON_COMPILING_IN_PYPY 0
#define CYTHON_COMPILING_IN_CPYTHON 1
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600
#define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyClass_Type
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyType_Type
#endif
#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#if PY_VERSION_HEX < 0x030400a1 && !defined(Py_TPFLAGS_HAVE_FINALIZE)
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ? \
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
#else
  #define CYTHON_PEP393_ENABLED 0
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
  #define __Pyx_PyFrozenSet_Size(s)         PyObject_Size(s)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ? \
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
  #define __Pyx_PyFrozenSet_Size(s)         PySet_Size(s)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  /* Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and
   a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is
   a quiet NaN. */
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif
#ifdef __cplusplus
template<typename T>
void __Pyx_call_destructor(T* x) {
    x->~T();
}
#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_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(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 "stdint.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "zlib.h"
#include "htslib/kstring.h"
#include "htslib/hfile.h"
#include "htslib/bgzf.h"
#include "htslib/hts.h"
#include "htslib/sam.h"
#include "pysam_stream.h"
#include "htslib/faidx.h"
#include "htslib/tbx.h"
#include "htslib_util.h"
#include "samfile_util.h"
#include "math.h"
#include "pythread.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif

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

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


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

static PyObject *__pyx_m;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;


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

/*--- Type declarations ---*/
struct __pyx_obj_5pysam_6cfaidx_FastaFile;
struct __pyx_obj_5pysam_6cfaidx_FastqProxy;
struct __pyx_obj_5pysam_6cfaidx_FastqFile;
struct __pyx_obj_5pysam_6cfaidx_Fastafile;
struct __pyx_obj_5pysam_6cfaidx_Fastqfile;
struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment;
struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile;
struct __pyx_obj_5pysam_14calignmentfile_PileupColumn;
struct __pyx_obj_5pysam_14calignmentfile_PileupRead;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRow;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection;
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn;
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion;
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs;
struct __pyx_obj_5pysam_14calignmentfile_IndexedReads;
struct __pyx_obj_10pysamstats__StatBinned;
struct __pyx_obj_10pysamstats__CoverageBinned;
struct __pyx_obj_10pysamstats__CoverageExtBinned;
struct __pyx_obj_10pysamstats__MapqBinned;
struct __pyx_obj_10pysamstats__AlignmentBinned;
struct __pyx_obj_10pysamstats__TlenBinned;
struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc;
struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default;
struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom;
struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom;
struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten;
struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr;
struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__;
struct __pyx_t_5pysam_14calignmentfile___iterdata;
typedef struct __pyx_t_5pysam_14calignmentfile___iterdata __pyx_t_5pysam_14calignmentfile___iterdata;
struct __pyx_opt_args_5pysam_14calignmentfile_14AlignedSegment_setTag;
struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData;

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

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

/* "pysam/calignmentfile.pxd":179
 *     cdef char * getSequence( self )
 *     cdef setMask(self, mask)
 *     cdef setupIteratorData(self,             # <<<<<<<<<<<<<<
 *                            int tid,
 *                            int start,
 */
struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData {
  int __pyx_n;
  int multiple_iterators;
};
struct __pyx_opt_args_10pysamstats__rec_coverage;
struct __pyx_opt_args_10pysamstats__rec_coverage_pad;
struct __pyx_opt_args_10pysamstats__rec_coverage_strand;
struct __pyx_opt_args_10pysamstats__rec_coverage_strand_pad;
struct __pyx_opt_args_10pysamstats__rec_coverage_ext;
struct __pyx_opt_args_10pysamstats__rec_coverage_ext_pad;
struct __pyx_opt_args_10pysamstats__rec_coverage_ext_strand;
struct __pyx_opt_args_10pysamstats__rec_coverage_ext_strand_pad;
struct __pyx_opt_args_10pysamstats__rec_variation;
struct __pyx_opt_args_10pysamstats__rec_variation_pad;
struct __pyx_t_10pysamstats__CountPpStrand;
struct __pyx_opt_args_10pysamstats__rec_variation_strand;
struct __pyx_opt_args_10pysamstats__rec_variation_strand_pad;
struct __pyx_opt_args_10pysamstats__rec_tlen;
struct __pyx_opt_args_10pysamstats__rec_tlen_pad;
struct __pyx_opt_args_10pysamstats__rec_tlen_strand;
struct __pyx_opt_args_10pysamstats__rec_tlen_strand_pad;
struct __pyx_opt_args_10pysamstats__rec_mapq;
struct __pyx_opt_args_10pysamstats__rec_mapq_pad;
struct __pyx_opt_args_10pysamstats__rec_mapq_strand;
struct __pyx_opt_args_10pysamstats__rec_mapq_strand_pad;
struct __pyx_opt_args_10pysamstats__rec_baseq;
struct __pyx_opt_args_10pysamstats__rec_baseq_pad;
struct __pyx_opt_args_10pysamstats__rec_baseq_strand;
struct __pyx_opt_args_10pysamstats__rec_baseq_strand_pad;
struct __pyx_opt_args_10pysamstats__rec_baseq_ext;
struct __pyx_opt_args_10pysamstats__rec_baseq_ext_pad;
struct __pyx_opt_args_10pysamstats__rec_baseq_ext_strand;
struct __pyx_opt_args_10pysamstats__rec_baseq_ext_strand_pad;

/* "pysamstats.pyx":90
 * 
 * 
 * cpdef dict _rec_coverage(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                          PileupColumn col, bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_coverage {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":128
 * 
 * 
 * cpdef dict _rec_coverage_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                              bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */
struct __pyx_opt_args_10pysamstats__rec_coverage_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":196
 * 
 * 
 * cpdef dict _rec_coverage_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                 PileupColumn col, bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_coverage_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":252
 * 
 * 
 * cpdef dict _rec_coverage_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                     bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */
struct __pyx_opt_args_10pysamstats__rec_coverage_strand_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":328
 * 
 * 
 * cpdef dict _rec_coverage_ext(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                              bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_coverage_ext {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":401
 * 
 * 
 * cpdef dict _rec_coverage_ext_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                  bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */
struct __pyx_opt_args_10pysamstats__rec_coverage_ext_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":492
 * 
 * 
 * cpdef dict _rec_coverage_ext_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                     PileupColumn col, bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_coverage_ext_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":629
 * 
 * 
 * cpdef dict _rec_coverage_ext_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                         bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */
struct __pyx_opt_args_10pysamstats__rec_coverage_ext_strand_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":735
 * 
 * 
 * cpdef dict _rec_variation(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                           PileupColumn col, bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_variation {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":851
 * 
 * 
 * cpdef dict _rec_variation_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                               bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */
struct __pyx_opt_args_10pysamstats__rec_variation_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":970
 * 
 * 
 * cdef struct _CountPpStrand:             # <<<<<<<<<<<<<<
 *     int all, pp, fwd, rev, pp_fwd, pp_rev
 * 
 */
struct __pyx_t_10pysamstats__CountPpStrand {
  int all;
  int pp;
  int fwd;
  int rev;
  int pp_fwd;
  int pp_rev;
};

/* "pysamstats.pyx":993
 * 
 * 
 * cpdef dict _rec_variation_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                  PileupColumn col, bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_variation_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1083
 * 
 * 
 * cpdef dict _rec_variation_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                      bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */
struct __pyx_opt_args_10pysamstats__rec_variation_strand_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1179
 * 
 * 
 * cpdef dict _rec_tlen(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                      bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_tlen {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1299
 * 
 * 
 * cpdef dict _rec_tlen_pad(FastaFile fafile, chrom, pos, bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
struct __pyx_opt_args_10pysamstats__rec_tlen_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1394
 * 
 * 
 * cpdef dict _rec_tlen_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                             bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_tlen_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1638
 * 
 * 
 * cpdef dict _rec_tlen_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                 bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */
struct __pyx_opt_args_10pysamstats__rec_tlen_strand_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1734
 * 
 * 
 * cpdef dict _rec_mapq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                      bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_mapq {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1807
 * 
 * 
 * cpdef dict _rec_mapq_pad(FastaFile fafile, chrom, pos, bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
struct __pyx_opt_args_10pysamstats__rec_mapq_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1898
 * 
 * 
 * cpdef dict _rec_mapq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                             bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_mapq_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":2060
 * 
 * 
 * cpdef dict _rec_mapq_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                 bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */
struct __pyx_opt_args_10pysamstats__rec_mapq_strand_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":2149
 * 
 * 
 * cpdef dict _rec_baseq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                       bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_baseq {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":2208
 * 
 * 
 * cpdef dict _rec_baseq_pad(FastaFile fafile, chrom, pos, bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
struct __pyx_opt_args_10pysamstats__rec_baseq_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":2283
 * 
 * 
 * cpdef dict _rec_baseq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                              bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_baseq_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":2394
 * 
 * 
 * cpdef dict _rec_baseq_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                  bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */
struct __pyx_opt_args_10pysamstats__rec_baseq_strand_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":2481
 * 
 * 
 * cpdef dict _rec_baseq_ext(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                           PileupColumn col, bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_baseq_ext {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":2580
 * 
 * 
 * cpdef dict _rec_baseq_ext_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                               bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */
struct __pyx_opt_args_10pysamstats__rec_baseq_ext_pad {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":2693
 * 
 * 
 * cpdef dict _rec_baseq_ext_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                  PileupColumn col, bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats__rec_baseq_ext_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":2891
 * 
 * 
 * cpdef dict _rec_baseq_ext_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                      bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */
struct __pyx_opt_args_10pysamstats__rec_baseq_ext_strand_pad {
  int __pyx_n;
  int one_based;
};

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


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


/* "pysam/cfaidx.pxd":25
 * 
 * 
 * cdef class FastqFile:             # <<<<<<<<<<<<<<
 *     cdef object _filename
 *     cdef gzFile fastqfile
 */
struct __pyx_obj_5pysam_6cfaidx_FastqFile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_6cfaidx_FastqFile *__pyx_vtab;
  PyObject *_filename;
  gzFile fastqfile;
  kseq_t *entry;
};


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


/* "pysam/cfaidx.pxd":38
 *     pass
 * 
 * cdef class Fastqfile(FastqFile):             # <<<<<<<<<<<<<<
 *     pass
 */
struct __pyx_obj_5pysam_6cfaidx_Fastqfile {
  struct __pyx_obj_5pysam_6cfaidx_FastqFile __pyx_base;
};


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


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


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


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


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


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


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


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


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


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


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


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


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


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


/* "pysamstats.pyx":3133
 * 
 * 
 * cdef class _StatBinned(object):             # <<<<<<<<<<<<<<
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):
 */
struct __pyx_obj_10pysamstats__StatBinned {
  PyObject_HEAD
  struct __pyx_vtabstruct_10pysamstats__StatBinned *__pyx_vtab;
};


/* "pysamstats.pyx":3142
 * 
 * 
 * cdef class _CoverageBinned(_StatBinned):             # <<<<<<<<<<<<<<
 * 
 *     cdef int reads_all, reads_pp
 */
struct __pyx_obj_10pysamstats__CoverageBinned {
  struct __pyx_obj_10pysamstats__StatBinned __pyx_base;
  int reads_all;
  int reads_pp;
};


/* "pysamstats.pyx":3246
 * 
 * 
 * cdef class _CoverageExtBinned(_StatBinned):             # <<<<<<<<<<<<<<
 * 
 *     cdef int reads_all, reads_pp, reads_mate_unmapped, reads_mate_other_chr, \
 */
struct __pyx_obj_10pysamstats__CoverageExtBinned {
  struct __pyx_obj_10pysamstats__StatBinned __pyx_base;
  int reads_all;
  int reads_pp;
  int reads_mate_unmapped;
  int reads_mate_other_chr;
  int reads_mate_same_strand;
  int reads_faceaway;
  int reads_softclipped;
  int reads_duplicate;
};


/* "pysamstats.pyx":3380
 * 
 * 
 * cdef class _MapqBinned(_StatBinned):             # <<<<<<<<<<<<<<
 * 
 *     cdef int reads_all, reads_mapq0
 */
struct __pyx_obj_10pysamstats__MapqBinned {
  struct __pyx_obj_10pysamstats__StatBinned __pyx_base;
  int reads_all;
  int reads_mapq0;
  uint64_t mapq;
  uint64_t mapq_squared_sum;
};


/* "pysamstats.pyx":3486
 * 
 * 
 * cdef class _AlignmentBinned(_StatBinned):             # <<<<<<<<<<<<<<
 * 
 *     cdef int reads_all, M, I, D, N, S, H, P, EQ, X
 */
struct __pyx_obj_10pysamstats__AlignmentBinned {
  struct __pyx_obj_10pysamstats__StatBinned __pyx_base;
  int reads_all;
  int M;
  int I;
  int D;
  int N;
  int S;
  int H;
  int P;
  int EQ;
  int X;
};


/* "pysamstats.pyx":3606
 * 
 * 
 * cdef class _TlenBinned(_StatBinned):             # <<<<<<<<<<<<<<
 * 
 *     cdef int reads_all
 */
struct __pyx_obj_10pysamstats__TlenBinned {
  struct __pyx_obj_10pysamstats__StatBinned __pyx_base;
  int reads_all;
  int reads_pp;
  int64_t tlen_sum;
  int64_t tlen_pp_sum;
  int64_t tlen_squared_sum;
  int64_t tlen_pp_squared_sum;
};


/* "pysamstats.pyx":2970
 * 
 * 
 * def stat_coverage_gc(alignmentfile, fafile, chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                      one_based=False, truncate=False, pad=False, max_depth=8000,
 *                      window_size=300, window_offset=None, **kwargs):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc {
  PyObject_HEAD
  PyObject *__pyx_v_window_offset;
  PyObject *__pyx_v_window_size;
};


/* "pysamstats.pyx":3693
 * 
 * 
 * def _iter_pileup_default(frec, alignmentfile, fafile=None,             # <<<<<<<<<<<<<<
 *                          chrom=None, start=None, end=None,
 *                          one_based=False, truncate=False,
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default {
  PyObject_HEAD
  PyObject *__pyx_v_alignmentfile;
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_fafile;
  PyObject *__pyx_v_frec;
  PyObject *__pyx_v_it;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_max_depth;
  PyObject *__pyx_v_one_based;
  PyObject *__pyx_v_start;
  PyObject *__pyx_v_truncate;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":3729
 * 
 * 
 * def _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile, chrom, start=None,             # <<<<<<<<<<<<<<
 *                               end=None, one_based=False, truncate=False,
 *                               max_depth=8000, **kwargs):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom {
  PyObject_HEAD
  PyObject *__pyx_v_alignmentfile;
  PyObject *__pyx_v_chrom;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col;
  int __pyx_v_curpos;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_fafile;
  PyObject *__pyx_v_fpad;
  PyObject *__pyx_v_frec;
  PyObject *__pyx_v_it;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_max_depth;
  PyObject *__pyx_v_one_based;
  PyObject *__pyx_v_start;
  PyObject *__pyx_v_truncate;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":3783
 * 
 * 
 * def _iter_binned_chrom(_StatBinned stat, AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                        chrom, start=None, end=None, one_based=False,
 *                        int window_size=300, int window_offset=150, **kwargs):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom {
  PyObject_HEAD
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile;
  bam1_t *__pyx_v_b;
  int __pyx_v_bin_end;
  int __pyx_v_bin_start;
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_end;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile;
  int __pyx_v_has_coord;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_it;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  PyObject *__pyx_v_pos;
  PyObject *__pyx_v_rec;
  int __pyx_v_rend;
  int __pyx_v_rstart;
  int __pyx_v_rtid;
  PyObject *__pyx_v_start;
  struct __pyx_obj_10pysamstats__StatBinned *__pyx_v_stat;
  int __pyx_v_window_offset;
  int __pyx_v_window_size;
};


/* "pysamstats.pyx":4109
 * 
 * 
 * def flatten(recs, *fields):             # <<<<<<<<<<<<<<
 *     """Convert a record (dict) iterator to a row (tuple) iterator.
 * 
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten {
  PyObject_HEAD
  PyObject *__pyx_v_getter;
  PyObject *__pyx_v_recs;
};


/* "pysamstats.pyx":4129
 * 
 *     getter = itemgetter(*fields)
 *     it = (getter(rec) for rec in recs)             # <<<<<<<<<<<<<<
 *     return it
 * 
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr {
  PyObject_HEAD
  struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten *__pyx_outer_scope;
  PyObject *__pyx_v_rec;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":4171
 *             raise Exception('statistics type not found: %r' % stats_type)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         recs = self.stats_function(*self.args, **self.kwargs)
 *         fields = tuple(self.fields)
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ {
  PyObject_HEAD
  PyObject *__pyx_v_fields;
  PyObject *__pyx_v_recs;
  PyObject *__pyx_v_row;
  PyObject *__pyx_v_rows;
  PyObject *__pyx_v_self;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};



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

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


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

struct __pyx_vtabstruct_5pysam_6cfaidx_FastqFile {
  kseq_t *(*getCurrent)(struct __pyx_obj_5pysam_6cfaidx_FastqFile *);
  int (*cnext)(struct __pyx_obj_5pysam_6cfaidx_FastqFile *);
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_FastqFile *__pyx_vtabptr_5pysam_6cfaidx_FastqFile;


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

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


/* "pysam/cfaidx.pxd":38
 *     pass
 * 
 * cdef class Fastqfile(FastqFile):             # <<<<<<<<<<<<<<
 *     pass
 */

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


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

struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignedSegment {
  PyObject *(*setTag)(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_14calignmentfile_14AlignedSegment_setTag *__pyx_optional_args);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignedSegment *__pyx_vtabptr_5pysam_14calignmentfile_AlignedSegment;


/* "pysam/calignmentfile.pxd":74
 *     cpdef setTag( self, tag, value, value_type = ?, replace = ? )
 * 
 * cdef class AlignmentFile:             # <<<<<<<<<<<<<<
 * 
 *     cdef object _filename
 */

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


/* "pysam/calignmentfile.pxd":134
 *     cdef int owns_samfile
 * 
 * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef hts_itr_t * iter
 *     cdef bam1_t * getCurrent( self )
 */

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


/* "pysam/calignmentfile.pxd":139
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowHead(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int max_rows
 *     cdef int current_row
 */

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


/* "pysam/calignmentfile.pxd":145
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam1_t * getCurrent( self )
 *     cdef int cnext(self)
 */

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


/* "pysam/calignmentfile.pxd":153
 *     cdef IteratorRowRegion rowiter
 * 
 * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int current_pos
 *     cdef positions
 */

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


/* "pysam/calignmentfile.pxd":160
 *     cdef BGZF * fp
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 * 
 *     # result of the last plbuf_push
 */

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


/* "pysam/calignmentfile.pxd":188
 *     cdef _free_pileup_iter(self)
 * 
 * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
 *     cdef int start
 *     cdef int end
 */

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


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

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


/* "pysamstats.pyx":3133
 * 
 * 
 * cdef class _StatBinned(object):             # <<<<<<<<<<<<<<
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):
 */

struct __pyx_vtabstruct_10pysamstats__StatBinned {
  PyObject *(*rec)(struct __pyx_obj_10pysamstats__StatBinned *, PyObject *, PyObject *, PyObject *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *);
  PyObject *(*recv)(struct __pyx_obj_10pysamstats__StatBinned *, bam1_t *);
};
static struct __pyx_vtabstruct_10pysamstats__StatBinned *__pyx_vtabptr_10pysamstats__StatBinned;


/* "pysamstats.pyx":3142
 * 
 * 
 * cdef class _CoverageBinned(_StatBinned):             # <<<<<<<<<<<<<<
 * 
 *     cdef int reads_all, reads_pp
 */

struct __pyx_vtabstruct_10pysamstats__CoverageBinned {
  struct __pyx_vtabstruct_10pysamstats__StatBinned __pyx_base;
};
static struct __pyx_vtabstruct_10pysamstats__CoverageBinned *__pyx_vtabptr_10pysamstats__CoverageBinned;


/* "pysamstats.pyx":3246
 * 
 * 
 * cdef class _CoverageExtBinned(_StatBinned):             # <<<<<<<<<<<<<<
 * 
 *     cdef int reads_all, reads_pp, reads_mate_unmapped, reads_mate_other_chr, \
 */

struct __pyx_vtabstruct_10pysamstats__CoverageExtBinned {
  struct __pyx_vtabstruct_10pysamstats__StatBinned __pyx_base;
};
static struct __pyx_vtabstruct_10pysamstats__CoverageExtBinned *__pyx_vtabptr_10pysamstats__CoverageExtBinned;


/* "pysamstats.pyx":3380
 * 
 * 
 * cdef class _MapqBinned(_StatBinned):             # <<<<<<<<<<<<<<
 * 
 *     cdef int reads_all, reads_mapq0
 */

struct __pyx_vtabstruct_10pysamstats__MapqBinned {
  struct __pyx_vtabstruct_10pysamstats__StatBinned __pyx_base;
};
static struct __pyx_vtabstruct_10pysamstats__MapqBinned *__pyx_vtabptr_10pysamstats__MapqBinned;


/* "pysamstats.pyx":3486
 * 
 * 
 * cdef class _AlignmentBinned(_StatBinned):             # <<<<<<<<<<<<<<
 * 
 *     cdef int reads_all, M, I, D, N, S, H, P, EQ, X
 */

struct __pyx_vtabstruct_10pysamstats__AlignmentBinned {
  struct __pyx_vtabstruct_10pysamstats__StatBinned __pyx_base;
};
static struct __pyx_vtabstruct_10pysamstats__AlignmentBinned *__pyx_vtabptr_10pysamstats__AlignmentBinned;


/* "pysamstats.pyx":3606
 * 
 * 
 * cdef class _TlenBinned(_StatBinned):             # <<<<<<<<<<<<<<
 * 
 *     cdef int reads_all
 */

struct __pyx_vtabstruct_10pysamstats__TlenBinned {
  struct __pyx_vtabstruct_10pysamstats__StatBinned __pyx_base;
};
static struct __pyx_vtabstruct_10pysamstats__TlenBinned *__pyx_vtabptr_10pysamstats__TlenBinned;
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
          if (acquire_gil) { \
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
              PyGILState_Release(__pyx_gilstate_save); \
          } else { \
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #define __Pyx_RefNannyFinishContext() \
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif
#define __Pyx_XDECREF_SET(r, v) do {                            \
        PyObject *tmp = (PyObject *) r;                         \
        r = v; __Pyx_XDECREF(tmp);                              \
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {                             \
        PyObject *tmp = (PyObject *) r;                         \
        r = v; __Pyx_DECREF(tmp);                               \
    } while (0)
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

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

static PyObject *__Pyx_GetBuiltinName(PyObject *name);

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

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

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

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

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

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

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

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);

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

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

#include <string.h>

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

#ifndef __PYX_FORCE_INIT_THREADS
  #define __PYX_FORCE_INIT_THREADS 0
#endif

static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname);

static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);

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

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

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

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

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

static CYTHON_INLINE int __Pyx_IterFinish(void);

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

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

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

static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);

static PyObject* __Pyx_Globals(void);

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

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

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

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

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

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

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

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

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

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

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

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

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

static void* __Pyx_GetVtable(PyObject *dict);

static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);

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

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

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

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

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

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_From_uint64_t(uint64_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value);

static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

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

static int __Pyx_check_binary_version(void);

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

static PyObject *__Pyx_ImportModule(const char *name);

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

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);

static PyObject *__pyx_f_10pysamstats_11_StatBinned_rec(CYTHON_UNUSED struct __pyx_obj_10pysamstats__StatBinned *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_chrom, CYTHON_UNUSED PyObject *__pyx_v_bin_start, CYTHON_UNUSED PyObject *__pyx_v_bin_end, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile); /* proto*/
static PyObject *__pyx_f_10pysamstats_11_StatBinned_recv(CYTHON_UNUSED struct __pyx_obj_10pysamstats__StatBinned *__pyx_v_self, CYTHON_UNUSED bam1_t *__pyx_v_b); /* proto*/
static PyObject *__pyx_f_10pysamstats_15_CoverageBinned_rec(struct __pyx_obj_10pysamstats__CoverageBinned *__pyx_v_self, PyObject *__pyx_v_chrom, PyObject *__pyx_v_bin_start, PyObject *__pyx_v_bin_end, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile); /* proto*/
static PyObject *__pyx_f_10pysamstats_15_CoverageBinned_recv(struct __pyx_obj_10pysamstats__CoverageBinned *__pyx_v_self, bam1_t *__pyx_v_b); /* proto*/
static PyObject *__pyx_f_10pysamstats_18_CoverageExtBinned_rec(struct __pyx_obj_10pysamstats__CoverageExtBinned *__pyx_v_self, PyObject *__pyx_v_chrom, PyObject *__pyx_v_bin_start, PyObject *__pyx_v_bin_end, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile); /* proto*/
static PyObject *__pyx_f_10pysamstats_18_CoverageExtBinned_recv(struct __pyx_obj_10pysamstats__CoverageExtBinned *__pyx_v_self, bam1_t *__pyx_v_b); /* proto*/
static PyObject *__pyx_f_10pysamstats_11_MapqBinned_rec(struct __pyx_obj_10pysamstats__MapqBinned *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_chrom, CYTHON_UNUSED PyObject *__pyx_v_bin_start, CYTHON_UNUSED PyObject *__pyx_v_bin_end, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile); /* proto*/
static PyObject *__pyx_f_10pysamstats_11_MapqBinned_recv(struct __pyx_obj_10pysamstats__MapqBinned *__pyx_v_self, bam1_t *__pyx_v_b); /* proto*/
static PyObject *__pyx_f_10pysamstats_16_AlignmentBinned_rec(struct __pyx_obj_10pysamstats__AlignmentBinned *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_chrom, CYTHON_UNUSED PyObject *__pyx_v_bin_start, CYTHON_UNUSED PyObject *__pyx_v_bin_end, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile); /* proto*/
static PyObject *__pyx_f_10pysamstats_16_AlignmentBinned_recv(struct __pyx_obj_10pysamstats__AlignmentBinned *__pyx_v_self, bam1_t *__pyx_v_b); /* proto*/
static PyObject *__pyx_f_10pysamstats_11_TlenBinned_rec(struct __pyx_obj_10pysamstats__TlenBinned *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_chrom, CYTHON_UNUSED PyObject *__pyx_v_bin_start, CYTHON_UNUSED PyObject *__pyx_v_bin_end, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile); /* proto*/
static PyObject *__pyx_f_10pysamstats_11_TlenBinned_recv(struct __pyx_obj_10pysamstats__TlenBinned *__pyx_v_self, bam1_t *__pyx_v_b); /* proto*/

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

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

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

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

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

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

/* Module declarations from 'pysam.calignmentfile' */
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_AlignedSegment = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_AlignmentFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_PileupColumn = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_PileupRead = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRow = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowHead = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowAll = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowAllRefs = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowSelection = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorColumn = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorColumnRegion = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorColumnAllRefs = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IndexedReads = 0;

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

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

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

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

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

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

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

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

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

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* Module declarations from 'cpython' */

/* Module declarations from 'pysamstats' */
static PyTypeObject *__pyx_ptype_10pysamstats__StatBinned = 0;
static PyTypeObject *__pyx_ptype_10pysamstats__CoverageBinned = 0;
static PyTypeObject *__pyx_ptype_10pysamstats__CoverageExtBinned = 0;
static PyTypeObject *__pyx_ptype_10pysamstats__MapqBinned = 0;
static PyTypeObject *__pyx_ptype_10pysamstats__AlignmentBinned = 0;
static PyTypeObject *__pyx_ptype_10pysamstats__TlenBinned = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct__stat_coverage_gc = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_1__iter_pileup_default = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_3__iter_binned_chrom = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_4_flatten = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_5_genexpr = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_6___iter__ = 0;
static char *__pyx_v_10pysamstats_CODE2CIGAR;
static char *__pyx_v_10pysamstats_bam_nt16_rev_table;
static PyObject *__pyx_f_10pysamstats__rec_coverage(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_pad *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_strand_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_strand_pad *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_ext(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_ext *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_ext_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_ext_pad *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_ext_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_ext_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_ext_strand_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_ext_strand_pad *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_variation(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_variation *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_variation_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_variation_pad *__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__rec_variation_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_variation_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_variation_strand_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_variation_strand_pad *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_tlen(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_tlen *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_tlen_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_tlen_pad *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_tlen_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_tlen_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_tlen_strand_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_tlen_strand_pad *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_mapq(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_mapq *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_mapq_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_mapq_pad *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_mapq_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_mapq_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_mapq_strand_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_mapq_strand_pad *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_pad *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_strand_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_strand_pad *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_ext(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_ext *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_ext_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_ext_pad *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_ext_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_ext_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_ext_strand_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_ext_strand_pad *__pyx_optional_args); /*proto*/
static CYTHON_INLINE int __pyx_f_10pysamstats__gc_content(PyObject *); /*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 int __pyx_f_10pysamstats__rootmean(uint64_t, int); /*proto*/
static CYTHON_INLINE int __pyx_f_10pysamstats__mean(int64_t, int); /*proto*/
#define __Pyx_MODULE_NAME "pysamstats"
int __pyx_module_is_main_pysamstats = 0;

/* Implementation of 'pysamstats' */
static PyObject *__pyx_builtin_object;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_round;
static PyObject *__pyx_builtin_print;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_Exception;
static PyObject *__pyx_pf_10pysamstats__rec_coverage(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_2_rec_coverage_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_4stat_coverage(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_6load_coverage(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_8_rec_coverage_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_10_rec_coverage_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_12stat_coverage_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_14load_coverage_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_16_rec_coverage_ext(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_18_rec_coverage_ext_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_20stat_coverage_ext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_22load_coverage_ext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_24_rec_coverage_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_26_rec_coverage_ext_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_28stat_coverage_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_30load_coverage_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_32_rec_variation(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_34_rec_variation_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_36stat_variation(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_38load_variation(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_40_rec_variation_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_42_rec_variation_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_44stat_variation_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_46load_variation_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_48_rec_tlen(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_50_rec_tlen_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_52stat_tlen(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_54load_tlen(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_56_rec_tlen_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_58_rec_tlen_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_60stat_tlen_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_62load_tlen_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_64_rec_mapq(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_66_rec_mapq_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_68stat_mapq(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_70load_mapq(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_72_rec_mapq_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_74_rec_mapq_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_76stat_mapq_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_78load_mapq_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_80_rec_baseq(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_82_rec_baseq_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_84stat_baseq(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_86load_baseq(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_88_rec_baseq_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_90_rec_baseq_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_92stat_baseq_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_94load_baseq_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_96_rec_baseq_ext(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_98_rec_baseq_ext_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_100stat_baseq_ext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_102load_baseq_ext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_104_rec_baseq_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_106_rec_baseq_ext_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_108stat_baseq_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_110load_baseq_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_16stat_coverage_gc__rec_coverage_gc(PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_16stat_coverage_gc_2_rec_coverage_gc_pad(PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_112stat_coverage_gc(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_truncate, PyObject *__pyx_v_pad, PyObject *__pyx_v_max_depth, PyObject *__pyx_v_window_size, PyObject *__pyx_v_window_offset, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_114load_coverage_gc(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_116stat_coverage_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_10pysamstats_15_CoverageBinned___cinit__(struct __pyx_obj_10pysamstats__CoverageBinned *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10pysamstats_118load_coverage_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_120stat_coverage_ext_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_10pysamstats_18_CoverageExtBinned___cinit__(struct __pyx_obj_10pysamstats__CoverageExtBinned *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10pysamstats_122load_coverage_ext_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_124stat_mapq_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_10pysamstats_11_MapqBinned___cinit__(struct __pyx_obj_10pysamstats__MapqBinned *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10pysamstats_126load_mapq_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_128stat_alignment_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_10pysamstats_16_AlignmentBinned___cinit__(struct __pyx_obj_10pysamstats__AlignmentBinned *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10pysamstats_130load_alignment_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_132stat_tlen_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_10pysamstats_11_TlenBinned___cinit__(struct __pyx_obj_10pysamstats__TlenBinned *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10pysamstats_134load_tlen_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_136_iter_pileup(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_frec, PyObject *__pyx_v_fpad, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_truncate, PyObject *__pyx_v_pad, PyObject *__pyx_v_max_depth, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_138_iter_pileup_default(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_frec, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_truncate, PyObject *__pyx_v_max_depth, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_141_iter_pileup_padded(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_frec, PyObject *__pyx_v_fpad, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_truncate, PyObject *__pyx_v_max_depth, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_143_iter_pileup_padded_chrom(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_frec, PyObject *__pyx_v_fpad, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_truncate, PyObject *__pyx_v_max_depth, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_146_iter_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stat, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_window_size, PyObject *__pyx_v_window_offset, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_148_iter_binned_chrom(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_10pysamstats__StatBinned *__pyx_v_stat, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, int __pyx_v_window_size, int __pyx_v_window_offset, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_151_normalise_coords(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_153write_csv(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stats_type, PyObject *__pyx_v_outfile, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fields, PyObject *__pyx_v_dialect, PyObject *__pyx_v_write_header, PyObject *__pyx_v_progress, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_155write_hdf5(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stats_type, PyObject *__pyx_v_outfile, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fields, PyObject *__pyx_v_progress, PyObject *__pyx_v_hdf5_group, PyObject *__pyx_v_hdf5_dataset, PyObject *__pyx_v_hdf5_complevel, PyObject *__pyx_v_hdf5_complib, PyObject *__pyx_v_hdf5_shuffle, PyObject *__pyx_v_hdf5_fletcher32, PyObject *__pyx_v_hdf5_chunksize, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_7flatten_genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_10pysamstats_157flatten(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_recs, PyObject *__pyx_v_fields); /* proto */
static PyObject *__pyx_pf_10pysamstats_159tabulate(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stat, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_11_StatsTable___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_stats_type, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_11_StatsTable_2__iter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10pysamstats_161_load_stats(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_statfun, PyObject *__pyx_v_default_dtype, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_163count_reads(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end); /* proto */
static PyObject *__pyx_tp_new_10pysamstats__StatBinned(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10pysamstats__CoverageBinned(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10pysamstats__CoverageExtBinned(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10pysamstats__MapqBinned(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10pysamstats__AlignmentBinned(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10pysamstats__TlenBinned(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct__stat_coverage_gc(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_1__iter_pileup_default(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_3__iter_binned_chrom(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_4_flatten(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_5_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_6___iter__(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static char __pyx_k_A[] = "A";
static char __pyx_k_C[] = "C";
static char __pyx_k_D[] = "D";
static char __pyx_k_G[] = "G";
static char __pyx_k_H[] = "H";
static char __pyx_k_I[] = "I";
static char __pyx_k_M[] = "M";
static char __pyx_k_N[] = "N";
static char __pyx_k_P[] = "P";
static char __pyx_k_S[] = "S";
static char __pyx_k_T[] = "T";
static char __pyx_k_X[] = "X";
static char __pyx_k_a[] = "a";
static char __pyx_k_b[] = "b";
static char __pyx_k_f[] = "f";
static char __pyx_k_n[] = "n";
static char __pyx_k_t[] = "t";
static char __pyx_k__5[] = "=";
static char __pyx_k__7[] = "/";
static char __pyx_k_a1[] = "a1";
static char __pyx_k_gc[] = "gc";
static char __pyx_k_i4[] = "i4";
static char __pyx_k_it[] = "it";
static char __pyx_k_np[] = "np";
static char __pyx_k_u1[] = "u1";
static char __pyx_k_PY2[] = "PY2";
static char __pyx_k_a12[] = "a12";
static char __pyx_k_col[] = "col";
static char __pyx_k_csv[] = "_csv";
static char __pyx_k_doc[] = "__doc__";
static char __pyx_k_end[] = "end";
static char __pyx_k_itc[] = "itc";
static char __pyx_k_its[] = "its";
static char __pyx_k_msg[] = "msg";
static char __pyx_k_pad[] = "pad";
static char __pyx_k_pop[] = "pop";
static char __pyx_k_pos[] = "pos";
static char __pyx_k_rec[] = "rec";
static char __pyx_k_ref[] = "ref";
static char __pyx_k_row[] = "row";
static char __pyx_k_sys[] = "_sys";
static char __pyx_k_0_20[] = "0.20";
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_data[] = "data";
static char __pyx_k_file[] = "file";
static char __pyx_k_fpad[] = "fpad";
static char __pyx_k_frec[] = "frec";
static char __pyx_k_init[] = "__init__";
static char __pyx_k_iter[] = "__iter__";
static char __pyx_k_main[] = "__main__";
static char __pyx_k_mode[] = "mode";
static char __pyx_k_recs[] = "recs";
static char __pyx_k_rend[] = "rend";
static char __pyx_k_rows[] = "rows";
static char __pyx_k_rtid[] = "rtid";
static char __pyx_k_self[] = "self";
static char __pyx_k_send[] = "send";
static char __pyx_k_stat[] = "stat";
static char __pyx_k_test[] = "__test__";
static char __pyx_k_time[] = "_time";
static char __pyx_k_view[] = "view";
static char __pyx_k_zlib[] = "zlib";
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_ascii[] = "ascii";
static char __pyx_k_chain[] = "chain";
static char __pyx_k_chrom[] = "chrom";
static char __pyx_k_chunk[] = "chunk";
static char __pyx_k_close[] = "close";
static char __pyx_k_csv_2[] = "csv";
static char __pyx_k_dtype[] = "dtype_";
static char __pyx_k_fetch[] = "fetch";
static char __pyx_k_flush[] = "flush";
static char __pyx_k_index[] = "index";
static char __pyx_k_lower[] = "lower";
static char __pyx_k_numpy[] = "numpy";
static char __pyx_k_print[] = "print";
static char __pyx_k_range[] = "range";
static char __pyx_k_round[] = "round";
static char __pyx_k_start[] = "start";
static char __pyx_k_sys_2[] = "sys";
static char __pyx_k_throw[] = "throw";
static char __pyx_k_title[] = "title";
static char __pyx_k_upper[] = "upper";
static char __pyx_k_append[] = "append";
static char __pyx_k_before[] = "before";
static char __pyx_k_chrlen[] = "chrlen";
static char __pyx_k_curpos[] = "curpos";
static char __pyx_k_fafile[] = "fafile";
static char __pyx_k_fields[] = "fields";
static char __pyx_k_getter[] = "getter";
static char __pyx_k_h5file[] = "h5file";
static char __pyx_k_import[] = "__import__";
static char __pyx_k_islice[] = "islice";
static char __pyx_k_kwargs[] = "kwargs";
static char __pyx_k_module[] = "__module__";
static char __pyx_k_object[] = "object";
static char __pyx_k_pileup[] = "pileup";
static char __pyx_k_rstart[] = "rstart";
static char __pyx_k_stat_2[] = "stat_";
static char __pyx_k_stderr[] = "stderr";
static char __pyx_k_tables[] = "tables";
static char __pyx_k_time_2[] = "time";
static char __pyx_k_update[] = "update";
static char __pyx_k_writer[] = "writer";
static char __pyx_k_Filters[] = "Filters";
static char __pyx_k_bin_end[] = "bin_end";
static char __pyx_k_complib[] = "complib";
static char __pyx_k_counter[] = "counter";
static char __pyx_k_dialect[] = "dialect";
static char __pyx_k_dtype_2[] = "dtype";
static char __pyx_k_elapsed[] = "elapsed";
static char __pyx_k_filters[] = "filters";
static char __pyx_k_flatten[] = "flatten";
static char __pyx_k_genexpr[] = "genexpr";
static char __pyx_k_h5table[] = "h5table";
static char __pyx_k_lengths[] = "lengths";
static char __pyx_k_matches[] = "matches";
static char __pyx_k_modulus[] = "modulus";
static char __pyx_k_outfile[] = "outfile";
static char __pyx_k_prepare[] = "__prepare__";
static char __pyx_k_shuffle[] = "shuffle";
static char __pyx_k_statfun[] = "statfun";
static char __pyx_k_version[] = "__version__";
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_KeyError[] = "KeyError";
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_fields_2[] = "fields_";
static char __pyx_k_fromiter[] = "fromiter";
static char __pyx_k_getrname[] = "getrname";
static char __pyx_k_itemsize[] = "itemsize";
static char __pyx_k_max_mapq[] = "max_mapq";
static char __pyx_k_operator[] = "operator";
static char __pyx_k_progress[] = "progress";
static char __pyx_k_qualname[] = "__qualname__";
static char __pyx_k_reads_pp[] = "reads_pp";
static char __pyx_k_rec_mapq[] = "_rec_mapq";
static char __pyx_k_rec_tlen[] = "_rec_tlen";
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_tabulate[] = "tabulate";
static char __pyx_k_truncate[] = "truncate";
static char __pyx_k_writerow[] = "writerow";
static char __pyx_k_Exception[] = "Exception";
static char __pyx_k_MIDNSHP_X[] = "MIDNSHP=X";
static char __pyx_k_after_all[] = "after_all";
static char __pyx_k_bases_all[] = "bases_all";
static char __pyx_k_bin_start[] = "bin_start";
static char __pyx_k_complevel[] = "complevel";
static char __pyx_k_deletions[] = "deletions";
static char __pyx_k_excel_tab[] = "excel-tab";
static char __pyx_k_has_coord[] = "has_coord";
static char __pyx_k_itertools[] = "_itertools";
static char __pyx_k_load_mapq[] = "load_mapq";
static char __pyx_k_load_tlen[] = "load_tlen";
static char __pyx_k_max_depth[] = "max_depth";
static char __pyx_k_mean_tlen[] = "mean_tlen";
static char __pyx_k_metaclass[] = "__metaclass__";
static char __pyx_k_one_based[] = "one_based";
static char __pyx_k_open_file[] = "open_file";
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_rec_baseq[] = "_rec_baseq";
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_write_csv[] = "write_csv";
static char __pyx_k_StatsTable[] = "_StatsTable";
static char __pyx_k_batch_size[] = "batch_size";
static char __pyx_k_before_all[] = "before_all";
static char __pyx_k_chunkshape[] = "chunkshape";
static char __pyx_k_dtype_mapq[] = "dtype_mapq";
static char __pyx_k_dtype_tlen[] = "dtype_tlen";
static char __pyx_k_fletcher32[] = "fletcher32";
static char __pyx_k_gc_percent[] = "gc_percent";
static char __pyx_k_hdf5_group[] = "hdf5_group";
static char __pyx_k_insertions[] = "insertions";
static char __pyx_k_itemgetter[] = "itemgetter";
static char __pyx_k_load_baseq[] = "load_baseq";
static char __pyx_k_load_stats[] = "_load_stats";
static char __pyx_k_matches_pp[] = "matches_pp";
static char __pyx_k_mismatches[] = "mismatches";
static char __pyx_k_pysamstats[] = "pysamstats";
static char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static char __pyx_k_ref_window[] = "ref_window";
static char __pyx_k_references[] = "references";
static char __pyx_k_stat_baseq[] = "stat_baseq";
static char __pyx_k_stats_type[] = "stats_type";
static char __pyx_k_write_hdf5[] = "write_hdf5";
static char __pyx_k_count_reads[] = "count_reads";
static char __pyx_k_dtype_baseq[] = "dtype_baseq";
static char __pyx_k_elapsed_all[] = "elapsed_all";
static char __pyx_k_fields_mapq[] = "fields_mapq";
static char __pyx_k_fields_tlen[] = "fields_tlen";
static char __pyx_k_iter_binned[] = "_iter_binned";
static char __pyx_k_iter_pileup[] = "_iter_pileup";
static char __pyx_k_itertools_2[] = "itertools";
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_parseRegion[] = "_parseRegion";
static char __pyx_k_reads_mapq0[] = "reads_mapq0";
static char __pyx_k_remove_node[] = "remove_node";
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_window_size[] = "window_size";
static char __pyx_k_create_table[] = "create_table";
static char __pyx_k_deletions_pp[] = "deletions_pp";
static char __pyx_k_fields_baseq[] = "fields_baseq";
static char __pyx_k_hdf5_complib[] = "hdf5_complib";
static char __pyx_k_hdf5_dataset[] = "hdf5_dataset";
static char __pyx_k_hdf5_shuffle[] = "hdf5_shuffle";
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_paired[] = "reads_paired";
static char __pyx_k_reads_pp_fwd[] = "reads_pp_fwd";
static char __pyx_k_reads_pp_rev[] = "reads_pp_rev";
static char __pyx_k_rec_coverage[] = "_rec_coverage";
static char __pyx_k_rec_mapq_pad[] = "_rec_mapq_pad";
static char __pyx_k_rec_tlen_pad[] = "_rec_tlen_pad";
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_string_types[] = "_string_types";
static char __pyx_k_version_info[] = "version_info";
static char __pyx_k_write_header[] = "write_header";
static char __pyx_k_alignmentfile[] = "alignmentfile";
static char __pyx_k_batch_elapsed[] = "batch_elapsed";
static char __pyx_k_createparents[] = "createparents";
static char __pyx_k_default_dtype[] = "default_dtype";
static char __pyx_k_deletions_fwd[] = "deletions_fwd";
static char __pyx_k_deletions_rev[] = "deletions_rev";
static char __pyx_k_hdf5_chunklen[] = "hdf5_chunklen";
static char __pyx_k_insertions_pp[] = "insertions_pp";
static char __pyx_k_load_coverage[] = "load_coverage";
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_rec_baseq_ext[] = "_rec_baseq_ext";
static char __pyx_k_rec_baseq_pad[] = "_rec_baseq_pad";
static char __pyx_k_rec_variation[] = "_rec_variation";
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_window_offset[] = "window_offset";
static char __pyx_k_counter_before[] = "counter_before";
static char __pyx_k_dtype_coverage[] = "dtype_coverage";
static char __pyx_k_hdf5_chunksize[] = "hdf5_chunksize";
static char __pyx_k_hdf5_complevel[] = "hdf5_complevel";
static char __pyx_k_insertions_fwd[] = "insertions_fwd";
static char __pyx_k_insertions_rev[] = "insertions_rev";
static char __pyx_k_load_baseq_ext[] = "load_baseq_ext";
static char __pyx_k_load_variation[] = "load_variation";
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_stats_function[] = "stats_function";
static char __pyx_k_ACMGRSVTWYHKDBN[] = "=ACMGRSVTWYHKDBN";
static char __pyx_k_NoSuchNodeError[] = "NoSuchNodeError";
static char __pyx_k_dtype_baseq_ext[] = "dtype_baseq_ext";
static char __pyx_k_dtype_overrides[] = "dtype_overrides";
static char __pyx_k_dtype_variation[] = "dtype_variation";
static char __pyx_k_fields_coverage[] = "fields_coverage";
static char __pyx_k_hdf5_chunkshape[] = "hdf5_chunkshape";
static char __pyx_k_hdf5_fletcher32[] = "hdf5_fletcher32";
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_rec_coverage_gc[] = "_rec_coverage_gc";
static char __pyx_k_rec_mapq_strand[] = "_rec_mapq_strand";
static char __pyx_k_rec_tlen_strand[] = "_rec_tlen_strand";
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_deletions_pp_fwd[] = "deletions_pp_fwd";
static char __pyx_k_deletions_pp_rev[] = "deletions_pp_rev";
static char __pyx_k_fields_baseq_ext[] = "fields_baseq_ext";
static char __pyx_k_fields_variation[] = "fields_variation";
static char __pyx_k_load_coverage_gc[] = "load_coverage_gc";
static char __pyx_k_load_mapq_binned[] = "load_mapq_binned";
static char __pyx_k_load_mapq_strand[] = "load_mapq_strand";
static char __pyx_k_load_tlen_binned[] = "load_tlen_binned";
static char __pyx_k_load_tlen_strand[] = "load_tlen_strand";
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_reads_paired_fwd[] = "reads_paired_fwd";
static char __pyx_k_reads_paired_rev[] = "reads_paired_rev";
static char __pyx_k_rec_baseq_strand[] = "_rec_baseq_strand";
static char __pyx_k_rec_coverage_ext[] = "_rec_coverage_ext";
static char __pyx_k_rec_coverage_pad[] = "_rec_coverage_pad";
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_binned[] = "stat_mapq_binned";
static char __pyx_k_stat_mapq_strand[] = "stat_mapq_strand";
static char __pyx_k_stat_tlen_binned[] = "stat_tlen_binned";
static char __pyx_k_stat_tlen_strand[] = "stat_tlen_strand";
static char __pyx_k_StatsTable___init[] = "_StatsTable.__init__";
static char __pyx_k_StatsTable___iter[] = "_StatsTable.__iter__";
static char __pyx_k_dtype_coverage_gc[] = "dtype_coverage_gc";
static char __pyx_k_dtype_mapq_binned[] = "dtype_mapq_binned";
static char __pyx_k_dtype_mapq_strand[] = "dtype_mapq_strand";
static char __pyx_k_dtype_tlen_binned[] = "dtype_tlen_binned";
static char __pyx_k_dtype_tlen_strand[] = "dtype_tlen_strand";
static char __pyx_k_insertions_pp_fwd[] = "insertions_pp_fwd";
static char __pyx_k_insertions_pp_rev[] = "insertions_pp_rev";
static char __pyx_k_iter_binned_chrom[] = "_iter_binned_chrom";
static char __pyx_k_load_baseq_strand[] = "load_baseq_strand";
static char __pyx_k_load_coverage_ext[] = "load_coverage_ext";
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_rec_baseq_ext_pad[] = "_rec_baseq_ext_pad";
static char __pyx_k_rec_variation_pad[] = "_rec_variation_pad";
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_chromosome_is_None[] = "chromosome is None";
static char __pyx_k_dtype_baseq_strand[] = "dtype_baseq_strand";
static char __pyx_k_dtype_coverage_ext[] = "dtype_coverage_ext";
static char __pyx_k_fields_coverage_gc[] = "fields_coverage_gc";
static char __pyx_k_fields_mapq_binned[] = "fields_mapq_binned";
static char __pyx_k_fields_mapq_strand[] = "fields_mapq_strand";
static char __pyx_k_fields_tlen_binned[] = "fields_tlen_binned";
static char __pyx_k_fields_tlen_strand[] = "fields_tlen_strand";
static char __pyx_k_iter_pileup_padded[] = "_iter_pileup_padded";
static char __pyx_k_multiple_iterators[] = "multiple_iterators";
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_fields_baseq_strand[] = "fields_baseq_strand";
static char __pyx_k_fields_coverage_ext[] = "fields_coverage_ext";
static char __pyx_k_iter_pileup_default[] = "_iter_pileup_default";
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 char __pyx_k_rec_coverage_gc_pad[] = "_rec_coverage_gc_pad";
static char __pyx_k_rec_coverage_strand[] = "_rec_coverage_strand";
static char __pyx_k_rec_mapq_strand_pad[] = "_rec_mapq_strand_pad";
static char __pyx_k_rec_tlen_strand_pad[] = "_rec_tlen_strand_pad";
static char __pyx_k_load_coverage_binned[] = "load_coverage_binned";
static char __pyx_k_load_coverage_strand[] = "load_coverage_strand";
static char __pyx_k_reads_mate_other_chr[] = "reads_mate_other_chr";
static char __pyx_k_rec_baseq_ext_strand[] = "_rec_baseq_ext_strand";
static char __pyx_k_rec_baseq_strand_pad[] = "_rec_baseq_strand_pad";
static char __pyx_k_rec_coverage_ext_pad[] = "_rec_coverage_ext_pad";
static char __pyx_k_rec_variation_strand[] = "_rec_variation_strand";
static char __pyx_k_rms_baseq_matches_pp[] = "rms_baseq_matches_pp";
static char __pyx_k_rms_baseq_mismatches[] = "rms_baseq_mismatches";
static char __pyx_k_stat_coverage_binned[] = "stat_coverage_binned";
static char __pyx_k_stat_coverage_strand[] = "stat_coverage_strand";
static char __pyx_k_dtype_coverage_binned[] = "dtype_coverage_binned";
static char __pyx_k_dtype_coverage_strand[] = "dtype_coverage_strand";
static char __pyx_k_load_alignment_binned[] = "load_alignment_binned";
static char __pyx_k_load_baseq_ext_strand[] = "load_baseq_ext_strand";
static char __pyx_k_load_variation_strand[] = "load_variation_strand";
static char __pyx_k_reads_softclipped_fwd[] = "reads_softclipped_fwd";
static char __pyx_k_reads_softclipped_rev[] = "reads_softclipped_rev";
static char __pyx_k_rms_baseq_matches_fwd[] = "rms_baseq_matches_fwd";
static char __pyx_k_rms_baseq_matches_rev[] = "rms_baseq_matches_rev";
static char __pyx_k_stat_alignment_binned[] = "stat_alignment_binned";
static char __pyx_k_stat_baseq_ext_strand[] = "stat_baseq_ext_strand";
static char __pyx_k_stat_variation_strand[] = "stat_variation_strand";
static char __pyx_k_dtype_alignment_binned[] = "dtype_alignment_binned";
static char __pyx_k_dtype_baseq_ext_strand[] = "dtype_baseq_ext_strand";
static char __pyx_k_dtype_variation_strand[] = "dtype_variation_strand";
static char __pyx_k_fields_coverage_binned[] = "fields_coverage_binned";
static char __pyx_k_fields_coverage_strand[] = "fields_coverage_strand";
static char __pyx_k_flatten_locals_genexpr[] = "flatten.<locals>.genexpr";
static char __pyx_k_reads_mate_same_strand[] = "reads_mate_same_strand";
static char __pyx_k_fields_alignment_binned[] = "fields_alignment_binned";
static char __pyx_k_fields_baseq_ext_strand[] = "fields_baseq_ext_strand";
static char __pyx_k_fields_variation_strand[] = "fields_variation_strand";
static char __pyx_k_reads_mate_unmapped_fwd[] = "reads_mate_unmapped_fwd";
static char __pyx_k_reads_mate_unmapped_rev[] = "reads_mate_unmapped_rev";
static char __pyx_k_rec_coverage_ext_strand[] = "_rec_coverage_ext_strand";
static char __pyx_k_rec_coverage_strand_pad[] = "_rec_coverage_strand_pad";
static char __pyx_k_rms_baseq_mismatches_pp[] = "rms_baseq_mismatches_pp";
static char __pyx_k_iter_pileup_padded_chrom[] = "_iter_pileup_padded_chrom";
static char __pyx_k_load_coverage_ext_binned[] = "load_coverage_ext_binned";
static char __pyx_k_load_coverage_ext_strand[] = "load_coverage_ext_strand";
static char __pyx_k_reads_mate_other_chr_fwd[] = "reads_mate_other_chr_fwd";
static char __pyx_k_reads_mate_other_chr_rev[] = "reads_mate_other_chr_rev";
static char __pyx_k_rec_baseq_ext_strand_pad[] = "_rec_baseq_ext_strand_pad";
static char __pyx_k_rec_variation_strand_pad[] = "_rec_variation_strand_pad";
static char __pyx_k_rms_baseq_matches_pp_fwd[] = "rms_baseq_matches_pp_fwd";
static char __pyx_k_rms_baseq_matches_pp_rev[] = "rms_baseq_matches_pp_rev";
static char __pyx_k_rms_baseq_mismatches_fwd[] = "rms_baseq_mismatches_fwd";
static char __pyx_k_rms_baseq_mismatches_rev[] = "rms_baseq_mismatches_rev";
static char __pyx_k_stat_coverage_ext_binned[] = "stat_coverage_ext_binned";
static char __pyx_k_stat_coverage_ext_strand[] = "stat_coverage_ext_strand";
static char __pyx_k_dtype_coverage_ext_binned[] = "dtype_coverage_ext_binned";
static char __pyx_k_dtype_coverage_ext_strand[] = "dtype_coverage_ext_strand";
static char __pyx_k_fields_coverage_ext_binned[] = "fields_coverage_ext_binned";
static char __pyx_k_fields_coverage_ext_strand[] = "fields_coverage_ext_strand";
static char __pyx_k_reads_mate_same_strand_fwd[] = "reads_mate_same_strand_fwd";
static char __pyx_k_reads_mate_same_strand_rev[] = "reads_mate_same_strand_rev";
static char __pyx_k_rec_coverage_ext_strand_pad[] = "_rec_coverage_ext_strand_pad";
static char __pyx_k_rms_baseq_mismatches_pp_fwd[] = "rms_baseq_mismatches_pp_fwd";
static char __pyx_k_rms_baseq_mismatches_pp_rev[] = "rms_baseq_mismatches_pp_rev";
static char __pyx_k_statistics_type_not_found_r[] = "statistics type not found: %r";
static char __pyx_k_home_aliman_src_github_alimanfo[] = "/home/aliman/src/github/alimanfoo/pysamstats/pysamstats.pyx";
static char __pyx_k_pysamstats_s_rows_in_2fs_d_rows[] = "[pysamstats] %s rows in %.2fs (%d rows/s); batch in %.2fs (%d rows/s)";
static char __pyx_k_chromosome_not_in_SAM_references[] = "chromosome not in SAM references: %s";
static char __pyx_k_stat_coverage_gc_locals__rec_cov[] = "stat_coverage_gc.<locals>._rec_coverage_gc";
static char __pyx_k_pysamstats_s_rows_in_2fs_d_rows_2[] = "[pysamstats] %s rows in %.2fs (%d rows/s)";
static char __pyx_k_pysamstats_s_rows_in_2fs_d_rows_3[] = "[pysamstats] %s rows in %.2fs (%d rows/s); last %s rows in %.2fs (%d rows/s)";
static char __pyx_k_stat_coverage_gc_locals__rec_cov_2[] = "stat_coverage_gc.<locals>._rec_coverage_gc_pad";
static PyObject *__pyx_kp_s_0_20;
static PyObject *__pyx_n_b_A;
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_b_C;
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_D;
static PyObject *__pyx_n_s_Exception;
static PyObject *__pyx_n_s_Filters;
static PyObject *__pyx_n_b_G;
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_H;
static PyObject *__pyx_n_s_I;
static PyObject *__pyx_n_s_KeyError;
static PyObject *__pyx_n_s_M;
static PyObject *__pyx_n_b_N;
static PyObject *__pyx_n_s_N;
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_NoSuchNodeError;
static PyObject *__pyx_n_s_P;
static PyObject *__pyx_n_s_PY2;
static PyObject *__pyx_n_s_S;
static PyObject *__pyx_n_s_StatsTable;
static PyObject *__pyx_n_s_StatsTable___init;
static PyObject *__pyx_n_s_StatsTable___iter;
static PyObject *__pyx_n_b_T;
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_X;
static PyObject *__pyx_kp_s__5;
static PyObject *__pyx_kp_s__7;
static PyObject *__pyx_n_s_a;
static PyObject *__pyx_n_s_a1;
static PyObject *__pyx_n_s_a12;
static PyObject *__pyx_n_s_after;
static PyObject *__pyx_n_s_after_all;
static PyObject *__pyx_n_s_alignmentfile;
static PyObject *__pyx_n_s_append;
static PyObject *__pyx_n_s_args;
static PyObject *__pyx_n_s_ascii;
static PyObject *__pyx_n_s_b;
static PyObject *__pyx_n_s_bases_all;
static PyObject *__pyx_n_s_batch_elapsed;
static PyObject *__pyx_n_s_batch_size;
static PyObject *__pyx_n_s_before;
static PyObject *__pyx_n_s_before_all;
static PyObject *__pyx_n_s_bin_end;
static PyObject *__pyx_n_s_bin_start;
static PyObject *__pyx_n_s_chain;
static PyObject *__pyx_n_s_chrlen;
static PyObject *__pyx_n_s_chrom;
static PyObject *__pyx_kp_s_chromosome_is_None;
static PyObject *__pyx_kp_s_chromosome_not_in_SAM_references;
static PyObject *__pyx_n_s_chunk;
static PyObject *__pyx_n_s_chunkshape;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_col;
static PyObject *__pyx_n_s_complevel;
static PyObject *__pyx_n_s_complib;
static PyObject *__pyx_n_s_count_reads;
static PyObject *__pyx_n_s_counter;
static PyObject *__pyx_n_s_counter_before;
static PyObject *__pyx_n_s_create_table;
static PyObject *__pyx_n_s_createparents;
static PyObject *__pyx_n_s_csv;
static PyObject *__pyx_n_s_csv_2;
static PyObject *__pyx_n_s_curpos;
static PyObject *__pyx_n_s_data;
static PyObject *__pyx_n_s_default_dtype;
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_doc;
static PyObject *__pyx_n_s_dtype;
static PyObject *__pyx_n_s_dtype_2;
static PyObject *__pyx_n_s_dtype_alignment_binned;
static PyObject *__pyx_n_s_dtype_baseq;
static PyObject *__pyx_n_s_dtype_baseq_ext;
static PyObject *__pyx_n_s_dtype_baseq_ext_strand;
static PyObject *__pyx_n_s_dtype_baseq_strand;
static PyObject *__pyx_n_s_dtype_coverage;
static PyObject *__pyx_n_s_dtype_coverage_binned;
static PyObject *__pyx_n_s_dtype_coverage_ext;
static PyObject *__pyx_n_s_dtype_coverage_ext_binned;
static PyObject *__pyx_n_s_dtype_coverage_ext_strand;
static PyObject *__pyx_n_s_dtype_coverage_gc;
static PyObject *__pyx_n_s_dtype_coverage_strand;
static PyObject *__pyx_n_s_dtype_mapq;
static PyObject *__pyx_n_s_dtype_mapq_binned;
static PyObject *__pyx_n_s_dtype_mapq_strand;
static PyObject *__pyx_n_s_dtype_overrides;
static PyObject *__pyx_n_s_dtype_tlen;
static PyObject *__pyx_n_s_dtype_tlen_binned;
static PyObject *__pyx_n_s_dtype_tlen_strand;
static PyObject *__pyx_n_s_dtype_variation;
static PyObject *__pyx_n_s_dtype_variation_strand;
static PyObject *__pyx_n_s_elapsed;
static PyObject *__pyx_n_s_elapsed_all;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_kp_s_excel_tab;
static PyObject *__pyx_n_s_f;
static PyObject *__pyx_n_s_fafile;
static PyObject *__pyx_n_s_fetch;
static PyObject *__pyx_n_s_fields;
static PyObject *__pyx_n_s_fields_2;
static PyObject *__pyx_n_s_fields_alignment_binned;
static PyObject *__pyx_n_s_fields_baseq;
static PyObject *__pyx_n_s_fields_baseq_ext;
static PyObject *__pyx_n_s_fields_baseq_ext_strand;
static PyObject *__pyx_n_s_fields_baseq_strand;
static PyObject *__pyx_n_s_fields_coverage;
static PyObject *__pyx_n_s_fields_coverage_binned;
static PyObject *__pyx_n_s_fields_coverage_ext;
static PyObject *__pyx_n_s_fields_coverage_ext_binned;
static PyObject *__pyx_n_s_fields_coverage_ext_strand;
static PyObject *__pyx_n_s_fields_coverage_gc;
static PyObject *__pyx_n_s_fields_coverage_strand;
static PyObject *__pyx_n_s_fields_mapq;
static PyObject *__pyx_n_s_fields_mapq_binned;
static PyObject *__pyx_n_s_fields_mapq_strand;
static PyObject *__pyx_n_s_fields_tlen;
static PyObject *__pyx_n_s_fields_tlen_binned;
static PyObject *__pyx_n_s_fields_tlen_strand;
static PyObject *__pyx_n_s_fields_variation;
static PyObject *__pyx_n_s_fields_variation_strand;
static PyObject *__pyx_n_s_file;
static PyObject *__pyx_n_s_filters;
static PyObject *__pyx_n_s_flatten;
static PyObject *__pyx_n_s_flatten_locals_genexpr;
static PyObject *__pyx_n_s_fletcher32;
static PyObject *__pyx_n_s_flush;
static PyObject *__pyx_n_s_fpad;
static PyObject *__pyx_n_s_frec;
static PyObject *__pyx_n_s_fromiter;
static PyObject *__pyx_n_s_gc;
static PyObject *__pyx_n_s_gc_percent;
static PyObject *__pyx_n_s_genexpr;
static PyObject *__pyx_n_s_getrname;
static PyObject *__pyx_n_s_getter;
static PyObject *__pyx_n_s_h5file;
static PyObject *__pyx_n_s_h5table;
static PyObject *__pyx_n_s_has_coord;
static PyObject *__pyx_n_s_hdf5_chunklen;
static PyObject *__pyx_n_s_hdf5_chunkshape;
static PyObject *__pyx_n_s_hdf5_chunksize;
static PyObject *__pyx_n_s_hdf5_complevel;
static PyObject *__pyx_n_s_hdf5_complib;
static PyObject *__pyx_n_s_hdf5_dataset;
static PyObject *__pyx_n_s_hdf5_fletcher32;
static PyObject *__pyx_n_s_hdf5_group;
static PyObject *__pyx_n_s_hdf5_shuffle;
static PyObject *__pyx_kp_s_home_aliman_src_github_alimanfo;
static PyObject *__pyx_n_s_i4;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_index;
static PyObject *__pyx_n_s_init;
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_islice;
static PyObject *__pyx_n_s_it;
static PyObject *__pyx_n_s_itc;
static PyObject *__pyx_n_s_itemgetter;
static PyObject *__pyx_n_s_itemsize;
static PyObject *__pyx_n_s_iter;
static PyObject *__pyx_n_s_iter_binned;
static PyObject *__pyx_n_s_iter_binned_chrom;
static PyObject *__pyx_n_s_iter_pileup;
static PyObject *__pyx_n_s_iter_pileup_default;
static PyObject *__pyx_n_s_iter_pileup_padded;
static PyObject *__pyx_n_s_iter_pileup_padded_chrom;
static PyObject *__pyx_n_s_itertools;
static PyObject *__pyx_n_s_itertools_2;
static PyObject *__pyx_n_s_its;
static PyObject *__pyx_n_s_kwargs;
static PyObject *__pyx_n_s_lengths;
static PyObject *__pyx_n_s_load_alignment_binned;
static PyObject *__pyx_n_s_load_baseq;
static PyObject *__pyx_n_s_load_baseq_ext;
static PyObject *__pyx_n_s_load_baseq_ext_strand;
static PyObject *__pyx_n_s_load_baseq_strand;
static PyObject *__pyx_n_s_load_coverage;
static PyObject *__pyx_n_s_load_coverage_binned;
static PyObject *__pyx_n_s_load_coverage_ext;
static PyObject *__pyx_n_s_load_coverage_ext_binned;
static PyObject *__pyx_n_s_load_coverage_ext_strand;
static PyObject *__pyx_n_s_load_coverage_gc;
static PyObject *__pyx_n_s_load_coverage_strand;
static PyObject *__pyx_n_s_load_mapq;
static PyObject *__pyx_n_s_load_mapq_binned;
static PyObject *__pyx_n_s_load_mapq_strand;
static PyObject *__pyx_n_s_load_stats;
static PyObject *__pyx_n_s_load_tlen;
static PyObject *__pyx_n_s_load_tlen_binned;
static PyObject *__pyx_n_s_load_tlen_strand;
static PyObject *__pyx_n_s_load_variation;
static PyObject *__pyx_n_s_load_variation_strand;
static PyObject *__pyx_n_s_lower;
static PyObject *__pyx_n_s_main;
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_depth;
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_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_metaclass;
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_mode;
static PyObject *__pyx_n_s_module;
static PyObject *__pyx_n_s_modulus;
static PyObject *__pyx_n_s_msg;
static PyObject *__pyx_n_s_multiple_iterators;
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_object;
static PyObject *__pyx_n_s_one_based;
static PyObject *__pyx_n_s_open_file;
static PyObject *__pyx_n_s_operator;
static PyObject *__pyx_n_s_outfile;
static PyObject *__pyx_n_s_pad;
static PyObject *__pyx_n_s_parseRegion;
static PyObject *__pyx_n_s_pileup;
static PyObject *__pyx_n_s_pop;
static PyObject *__pyx_n_s_pos;
static PyObject *__pyx_n_s_prepare;
static PyObject *__pyx_n_s_print;
static PyObject *__pyx_n_s_progress;
static PyObject *__pyx_n_s_pysamstats;
static PyObject *__pyx_kp_s_pysamstats_s_rows_in_2fs_d_rows;
static PyObject *__pyx_kp_s_pysamstats_s_rows_in_2fs_d_rows_2;
static PyObject *__pyx_kp_s_pysamstats_s_rows_in_2fs_d_rows_3;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_s_qualname;
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_other_chr;
static PyObject *__pyx_n_s_reads_mate_other_chr_fwd;
static PyObject *__pyx_n_s_reads_mate_other_chr_rev;
static PyObject *__pyx_n_s_reads_mate_same_strand;
static PyObject *__pyx_n_s_reads_mate_same_strand_fwd;
static PyObject *__pyx_n_s_reads_mate_same_strand_rev;
static PyObject *__pyx_n_s_reads_mate_unmapped;
static PyObject *__pyx_n_s_reads_mate_unmapped_fwd;
static PyObject *__pyx_n_s_reads_mate_unmapped_rev;
static PyObject *__pyx_n_s_reads_paired;
static PyObject *__pyx_n_s_reads_paired_fwd;
static PyObject *__pyx_n_s_reads_paired_rev;
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_reads_softclipped_fwd;
static PyObject *__pyx_n_s_reads_softclipped_rev;
static PyObject *__pyx_n_s_rec;
static PyObject *__pyx_n_s_rec_baseq;
static PyObject *__pyx_n_s_rec_baseq_ext;
static PyObject *__pyx_n_s_rec_baseq_ext_pad;
static PyObject *__pyx_n_s_rec_baseq_ext_strand;
static PyObject *__pyx_n_s_rec_baseq_ext_strand_pad;
static PyObject *__pyx_n_s_rec_baseq_pad;
static PyObject *__pyx_n_s_rec_baseq_strand;
static PyObject *__pyx_n_s_rec_baseq_strand_pad;
static PyObject *__pyx_n_s_rec_coverage;
static PyObject *__pyx_n_s_rec_coverage_ext;
static PyObject *__pyx_n_s_rec_coverage_ext_pad;
static PyObject *__pyx_n_s_rec_coverage_ext_strand;
static PyObject *__pyx_n_s_rec_coverage_ext_strand_pad;
static PyObject *__pyx_n_s_rec_coverage_gc;
static PyObject *__pyx_n_s_rec_coverage_gc_pad;
static PyObject *__pyx_n_s_rec_coverage_pad;
static PyObject *__pyx_n_s_rec_coverage_strand;
static PyObject *__pyx_n_s_rec_coverage_strand_pad;
static PyObject *__pyx_n_s_rec_mapq;
static PyObject *__pyx_n_s_rec_mapq_pad;
static PyObject *__pyx_n_s_rec_mapq_strand;
static PyObject *__pyx_n_s_rec_mapq_strand_pad;
static PyObject *__pyx_n_s_rec_tlen;
static PyObject *__pyx_n_s_rec_tlen_pad;
static PyObject *__pyx_n_s_rec_tlen_strand;
static PyObject *__pyx_n_s_rec_tlen_strand_pad;
static PyObject *__pyx_n_s_rec_variation;
static PyObject *__pyx_n_s_rec_variation_pad;
static PyObject *__pyx_n_s_rec_variation_strand;
static PyObject *__pyx_n_s_rec_variation_strand_pad;
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_references;
static PyObject *__pyx_n_s_remove_node;
static PyObject *__pyx_n_s_rend;
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_matches_fwd;
static PyObject *__pyx_n_s_rms_baseq_matches_pp;
static PyObject *__pyx_n_s_rms_baseq_matches_pp_fwd;
static PyObject *__pyx_n_s_rms_baseq_matches_pp_rev;
static PyObject *__pyx_n_s_rms_baseq_matches_rev;
static PyObject *__pyx_n_s_rms_baseq_mismatches;
static PyObject *__pyx_n_s_rms_baseq_mismatches_fwd;
static PyObject *__pyx_n_s_rms_baseq_mismatches_pp;
static PyObject *__pyx_n_s_rms_baseq_mismatches_pp_fwd;
static PyObject *__pyx_n_s_rms_baseq_mismatches_pp_rev;
static PyObject *__pyx_n_s_rms_baseq_mismatches_rev;
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_row;
static PyObject *__pyx_n_s_rows;
static PyObject *__pyx_n_s_rstart;
static PyObject *__pyx_n_s_rtid;
static PyObject *__pyx_n_s_self;
static PyObject *__pyx_n_s_send;
static PyObject *__pyx_n_s_shuffle;
static PyObject *__pyx_n_s_start;
static PyObject *__pyx_n_s_stat;
static PyObject *__pyx_n_s_stat_2;
static PyObject *__pyx_n_s_stat_alignment_binned;
static PyObject *__pyx_n_s_stat_baseq;
static PyObject *__pyx_n_s_stat_baseq_ext;
static PyObject *__pyx_n_s_stat_baseq_ext_strand;
static PyObject *__pyx_n_s_stat_baseq_strand;
static PyObject *__pyx_n_s_stat_coverage;
static PyObject *__pyx_n_s_stat_coverage_binned;
static PyObject *__pyx_n_s_stat_coverage_ext;
static PyObject *__pyx_n_s_stat_coverage_ext_binned;
static PyObject *__pyx_n_s_stat_coverage_ext_strand;
static PyObject *__pyx_n_s_stat_coverage_gc;
static PyObject *__pyx_n_s_stat_coverage_gc_locals__rec_cov;
static PyObject *__pyx_n_s_stat_coverage_gc_locals__rec_cov_2;
static PyObject *__pyx_n_s_stat_coverage_strand;
static PyObject *__pyx_n_s_stat_mapq;
static PyObject *__pyx_n_s_stat_mapq_binned;
static PyObject *__pyx_n_s_stat_mapq_strand;
static PyObject *__pyx_n_s_stat_tlen;
static PyObject *__pyx_n_s_stat_tlen_binned;
static PyObject *__pyx_n_s_stat_tlen_strand;
static PyObject *__pyx_n_s_stat_variation;
static PyObject *__pyx_n_s_stat_variation_strand;
static PyObject *__pyx_n_s_statfun;
static PyObject *__pyx_kp_s_statistics_type_not_found_r;
static PyObject *__pyx_n_s_stats_function;
static PyObject *__pyx_n_s_stats_type;
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_string_types;
static PyObject *__pyx_n_s_sys;
static PyObject *__pyx_n_s_sys_2;
static PyObject *__pyx_n_s_t;
static PyObject *__pyx_n_s_tables;
static PyObject *__pyx_n_s_tabulate;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_throw;
static PyObject *__pyx_n_s_time;
static PyObject *__pyx_n_s_time_2;
static PyObject *__pyx_n_s_title;
static PyObject *__pyx_n_s_truncate;
static PyObject *__pyx_n_s_u1;
static PyObject *__pyx_n_s_update;
static PyObject *__pyx_n_s_upper;
static PyObject *__pyx_n_s_version;
static PyObject *__pyx_n_s_version_info;
static PyObject *__pyx_n_s_view;
static PyObject *__pyx_n_s_window_offset;
static PyObject *__pyx_n_s_window_size;
static PyObject *__pyx_n_s_write_csv;
static PyObject *__pyx_n_s_write_hdf5;
static PyObject *__pyx_n_s_write_header;
static PyObject *__pyx_n_s_writer;
static PyObject *__pyx_n_s_writerow;
static PyObject *__pyx_n_s_zlib;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_5;
static PyObject *__pyx_int_300;
static PyObject *__pyx_int_8000;
static PyObject *__pyx_int_131072;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_tuple__9;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__11;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__13;
static PyObject *__pyx_tuple__14;
static PyObject *__pyx_tuple__15;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__18;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__21;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__23;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__25;
static PyObject *__pyx_tuple__26;
static PyObject *__pyx_tuple__27;
static PyObject *__pyx_tuple__28;
static PyObject *__pyx_tuple__30;
static PyObject *__pyx_tuple__32;
static PyObject *__pyx_tuple__33;
static PyObject *__pyx_tuple__34;
static PyObject *__pyx_tuple__35;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__37;
static PyObject *__pyx_tuple__38;
static PyObject *__pyx_tuple__39;
static PyObject *__pyx_tuple__40;
static PyObject *__pyx_tuple__41;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__46;
static PyObject *__pyx_tuple__47;
static PyObject *__pyx_tuple__48;
static PyObject *__pyx_tuple__49;
static PyObject *__pyx_tuple__50;
static PyObject *__pyx_tuple__51;
static PyObject *__pyx_tuple__52;
static PyObject *__pyx_tuple__53;
static PyObject *__pyx_tuple__54;
static PyObject *__pyx_tuple__55;
static PyObject *__pyx_tuple__56;
static PyObject *__pyx_tuple__57;
static PyObject *__pyx_tuple__58;
static PyObject *__pyx_tuple__59;
static PyObject *__pyx_tuple__60;
static PyObject *__pyx_tuple__61;
static PyObject *__pyx_tuple__62;
static PyObject *__pyx_tuple__63;
static PyObject *__pyx_tuple__64;
static PyObject *__pyx_tuple__65;
static PyObject *__pyx_tuple__66;
static PyObject *__pyx_tuple__67;
static PyObject *__pyx_tuple__68;
static PyObject *__pyx_tuple__69;
static PyObject *__pyx_tuple__70;
static PyObject *__pyx_tuple__71;
static PyObject *__pyx_tuple__72;
static PyObject *__pyx_tuple__74;
static PyObject *__pyx_tuple__76;
static PyObject *__pyx_tuple__77;
static PyObject *__pyx_tuple__78;
static PyObject *__pyx_tuple__79;
static PyObject *__pyx_tuple__80;
static PyObject *__pyx_tuple__81;
static PyObject *__pyx_tuple__82;
static PyObject *__pyx_tuple__83;
static PyObject *__pyx_tuple__84;
static PyObject *__pyx_tuple__85;
static PyObject *__pyx_tuple__86;
static PyObject *__pyx_tuple__87;
static PyObject *__pyx_tuple__88;
static PyObject *__pyx_tuple__89;
static PyObject *__pyx_tuple__90;
static PyObject *__pyx_tuple__91;
static PyObject *__pyx_tuple__92;
static PyObject *__pyx_tuple__93;
static PyObject *__pyx_tuple__94;
static PyObject *__pyx_tuple__95;
static PyObject *__pyx_tuple__96;
static PyObject *__pyx_tuple__97;
static PyObject *__pyx_tuple__98;
static PyObject *__pyx_tuple__99;
static PyObject *__pyx_codeobj__2;
static PyObject *__pyx_codeobj__4;
static PyObject *__pyx_tuple__101;
static PyObject *__pyx_tuple__103;
static PyObject *__pyx_tuple__104;
static PyObject *__pyx_tuple__105;
static PyObject *__pyx_tuple__106;
static PyObject *__pyx_tuple__107;
static PyObject *__pyx_tuple__108;
static PyObject *__pyx_tuple__109;
static PyObject *__pyx_tuple__110;
static PyObject *__pyx_tuple__111;
static PyObject *__pyx_tuple__112;
static PyObject *__pyx_tuple__113;
static PyObject *__pyx_tuple__114;
static PyObject *__pyx_tuple__115;
static PyObject *__pyx_tuple__116;
static PyObject *__pyx_tuple__117;
static PyObject *__pyx_tuple__118;
static PyObject *__pyx_tuple__119;
static PyObject *__pyx_tuple__120;
static PyObject *__pyx_tuple__121;
static PyObject *__pyx_tuple__122;
static PyObject *__pyx_tuple__123;
static PyObject *__pyx_tuple__124;
static PyObject *__pyx_tuple__125;
static PyObject *__pyx_tuple__126;
static PyObject *__pyx_tuple__127;
static PyObject *__pyx_tuple__128;
static PyObject *__pyx_tuple__129;
static PyObject *__pyx_tuple__130;
static PyObject *__pyx_tuple__131;
static PyObject *__pyx_tuple__132;
static PyObject *__pyx_tuple__133;
static PyObject *__pyx_tuple__134;
static PyObject *__pyx_tuple__135;
static PyObject *__pyx_tuple__136;
static PyObject *__pyx_tuple__137;
static PyObject *__pyx_tuple__138;
static PyObject *__pyx_tuple__139;
static PyObject *__pyx_tuple__140;
static PyObject *__pyx_tuple__141;
static PyObject *__pyx_tuple__142;
static PyObject *__pyx_tuple__143;
static PyObject *__pyx_tuple__144;
static PyObject *__pyx_tuple__145;
static PyObject *__pyx_tuple__146;
static PyObject *__pyx_tuple__147;
static PyObject *__pyx_tuple__148;
static PyObject *__pyx_tuple__149;
static PyObject *__pyx_tuple__150;
static PyObject *__pyx_tuple__151;
static PyObject *__pyx_tuple__152;
static PyObject *__pyx_tuple__153;
static PyObject *__pyx_tuple__154;
static PyObject *__pyx_tuple__155;
static PyObject *__pyx_tuple__156;
static PyObject *__pyx_tuple__157;
static PyObject *__pyx_tuple__158;
static PyObject *__pyx_tuple__159;
static PyObject *__pyx_tuple__160;
static PyObject *__pyx_tuple__161;
static PyObject *__pyx_tuple__162;
static PyObject *__pyx_tuple__163;
static PyObject *__pyx_tuple__164;
static PyObject *__pyx_tuple__165;
static PyObject *__pyx_tuple__166;
static PyObject *__pyx_tuple__168;
static PyObject *__pyx_tuple__170;
static PyObject *__pyx_tuple__171;
static PyObject *__pyx_tuple__172;
static PyObject *__pyx_tuple__173;
static PyObject *__pyx_tuple__174;
static PyObject *__pyx_tuple__175;
static PyObject *__pyx_tuple__176;
static PyObject *__pyx_tuple__177;
static PyObject *__pyx_tuple__178;
static PyObject *__pyx_tuple__179;
static PyObject *__pyx_tuple__180;
static PyObject *__pyx_tuple__181;
static PyObject *__pyx_tuple__183;
static PyObject *__pyx_tuple__185;
static PyObject *__pyx_tuple__186;
static PyObject *__pyx_tuple__187;
static PyObject *__pyx_tuple__188;
static PyObject *__pyx_tuple__189;
static PyObject *__pyx_tuple__190;
static PyObject *__pyx_tuple__191;
static PyObject *__pyx_tuple__192;
static PyObject *__pyx_tuple__193;
static PyObject *__pyx_tuple__194;
static PyObject *__pyx_tuple__195;
static PyObject *__pyx_tuple__196;
static PyObject *__pyx_tuple__197;
static PyObject *__pyx_tuple__198;
static PyObject *__pyx_tuple__199;
static PyObject *__pyx_tuple__200;
static PyObject *__pyx_tuple__201;
static PyObject *__pyx_tuple__202;
static PyObject *__pyx_tuple__203;
static PyObject *__pyx_tuple__204;
static PyObject *__pyx_tuple__205;
static PyObject *__pyx_tuple__206;
static PyObject *__pyx_tuple__207;
static PyObject *__pyx_tuple__208;
static PyObject *__pyx_tuple__209;
static PyObject *__pyx_tuple__210;
static PyObject *__pyx_tuple__211;
static PyObject *__pyx_tuple__212;
static PyObject *__pyx_tuple__213;
static PyObject *__pyx_tuple__214;
static PyObject *__pyx_tuple__216;
static PyObject *__pyx_tuple__218;
static PyObject *__pyx_tuple__219;
static PyObject *__pyx_tuple__220;
static PyObject *__pyx_tuple__221;
static PyObject *__pyx_tuple__222;
static PyObject *__pyx_tuple__223;
static PyObject *__pyx_tuple__224;
static PyObject *__pyx_tuple__225;
static PyObject *__pyx_tuple__226;
static PyObject *__pyx_tuple__227;
static PyObject *__pyx_tuple__228;
static PyObject *__pyx_tuple__230;
static PyObject *__pyx_tuple__232;
static PyObject *__pyx_tuple__233;
static PyObject *__pyx_tuple__234;
static PyObject *__pyx_tuple__235;
static PyObject *__pyx_tuple__236;
static PyObject *__pyx_tuple__237;
static PyObject *__pyx_tuple__238;
static PyObject *__pyx_tuple__239;
static PyObject *__pyx_tuple__240;
static PyObject *__pyx_tuple__241;
static PyObject *__pyx_tuple__242;
static PyObject *__pyx_tuple__243;
static PyObject *__pyx_tuple__244;
static PyObject *__pyx_tuple__245;
static PyObject *__pyx_tuple__246;
static PyObject *__pyx_tuple__247;
static PyObject *__pyx_tuple__248;
static PyObject *__pyx_tuple__249;
static PyObject *__pyx_tuple__250;
static PyObject *__pyx_tuple__251;
static PyObject *__pyx_tuple__252;
static PyObject *__pyx_tuple__253;
static PyObject *__pyx_tuple__254;
static PyObject *__pyx_tuple__255;
static PyObject *__pyx_tuple__256;
static PyObject *__pyx_tuple__257;
static PyObject *__pyx_tuple__258;
static PyObject *__pyx_tuple__260;
static PyObject *__pyx_tuple__262;
static PyObject *__pyx_tuple__263;
static PyObject *__pyx_tuple__264;
static PyObject *__pyx_tuple__265;
static PyObject *__pyx_tuple__266;
static PyObject *__pyx_tuple__267;
static PyObject *__pyx_tuple__268;
static PyObject *__pyx_tuple__270;
static PyObject *__pyx_tuple__272;
static PyObject *__pyx_tuple__273;
static PyObject *__pyx_tuple__274;
static PyObject *__pyx_tuple__275;
static PyObject *__pyx_tuple__276;
static PyObject *__pyx_tuple__277;
static PyObject *__pyx_tuple__278;
static PyObject *__pyx_tuple__279;
static PyObject *__pyx_tuple__280;
static PyObject *__pyx_tuple__281;
static PyObject *__pyx_tuple__282;
static PyObject *__pyx_tuple__283;
static PyObject *__pyx_tuple__284;
static PyObject *__pyx_tuple__285;
static PyObject *__pyx_tuple__286;
static PyObject *__pyx_tuple__288;
static PyObject *__pyx_tuple__290;
static PyObject *__pyx_tuple__291;
static PyObject *__pyx_tuple__292;
static PyObject *__pyx_tuple__293;
static PyObject *__pyx_tuple__294;
static PyObject *__pyx_tuple__295;
static PyObject *__pyx_tuple__296;
static PyObject *__pyx_tuple__297;
static PyObject *__pyx_tuple__298;
static PyObject *__pyx_tuple__299;
static PyObject *__pyx_tuple__300;
static PyObject *__pyx_tuple__301;
static PyObject *__pyx_tuple__302;
static PyObject *__pyx_tuple__303;
static PyObject *__pyx_tuple__304;
static PyObject *__pyx_tuple__305;
static PyObject *__pyx_tuple__307;
static PyObject *__pyx_tuple__309;
static PyObject *__pyx_tuple__310;
static PyObject *__pyx_tuple__311;
static PyObject *__pyx_tuple__312;
static PyObject *__pyx_tuple__313;
static PyObject *__pyx_tuple__314;
static PyObject *__pyx_tuple__315;
static PyObject *__pyx_tuple__316;
static PyObject *__pyx_tuple__317;
static PyObject *__pyx_tuple__318;
static PyObject *__pyx_tuple__319;
static PyObject *__pyx_tuple__320;
static PyObject *__pyx_tuple__321;
static PyObject *__pyx_tuple__322;
static PyObject *__pyx_tuple__323;
static PyObject *__pyx_tuple__324;
static PyObject *__pyx_tuple__325;
static PyObject *__pyx_tuple__326;
static PyObject *__pyx_tuple__327;
static PyObject *__pyx_tuple__328;
static PyObject *__pyx_tuple__329;
static PyObject *__pyx_tuple__330;
static PyObject *__pyx_tuple__331;
static PyObject *__pyx_tuple__332;
static PyObject *__pyx_tuple__333;
static PyObject *__pyx_tuple__334;
static PyObject *__pyx_tuple__335;
static PyObject *__pyx_tuple__336;
static PyObject *__pyx_tuple__337;
static PyObject *__pyx_tuple__338;
static PyObject *__pyx_tuple__339;
static PyObject *__pyx_tuple__340;
static PyObject *__pyx_tuple__341;
static PyObject *__pyx_tuple__342;
static PyObject *__pyx_tuple__343;
static PyObject *__pyx_tuple__344;
static PyObject *__pyx_tuple__345;
static PyObject *__pyx_tuple__346;
static PyObject *__pyx_tuple__347;
static PyObject *__pyx_tuple__348;
static PyObject *__pyx_tuple__350;
static PyObject *__pyx_tuple__352;
static PyObject *__pyx_tuple__353;
static PyObject *__pyx_tuple__354;
static PyObject *__pyx_tuple__355;
static PyObject *__pyx_tuple__356;
static PyObject *__pyx_tuple__357;
static PyObject *__pyx_tuple__359;
static PyObject *__pyx_tuple__361;
static PyObject *__pyx_tuple__362;
static PyObject *__pyx_tuple__363;
static PyObject *__pyx_tuple__364;
static PyObject *__pyx_tuple__365;
static PyObject *__pyx_tuple__366;
static PyObject *__pyx_tuple__368;
static PyObject *__pyx_tuple__370;
static PyObject *__pyx_tuple__371;
static PyObject *__pyx_tuple__372;
static PyObject *__pyx_tuple__373;
static PyObject *__pyx_tuple__374;
static PyObject *__pyx_tuple__375;
static PyObject *__pyx_tuple__376;
static PyObject *__pyx_tuple__377;
static PyObject *__pyx_tuple__378;
static PyObject *__pyx_tuple__379;
static PyObject *__pyx_tuple__380;
static PyObject *__pyx_tuple__381;
static PyObject *__pyx_tuple__383;
static PyObject *__pyx_tuple__385;
static PyObject *__pyx_tuple__386;
static PyObject *__pyx_tuple__387;
static PyObject *__pyx_tuple__388;
static PyObject *__pyx_tuple__389;
static PyObject *__pyx_tuple__390;
static PyObject *__pyx_tuple__392;
static PyObject *__pyx_tuple__394;
static PyObject *__pyx_tuple__395;
static PyObject *__pyx_tuple__396;
static PyObject *__pyx_tuple__397;
static PyObject *__pyx_tuple__398;
static PyObject *__pyx_tuple__399;
static PyObject *__pyx_tuple__400;
static PyObject *__pyx_tuple__401;
static PyObject *__pyx_tuple__402;
static PyObject *__pyx_tuple__403;
static PyObject *__pyx_tuple__404;
static PyObject *__pyx_tuple__405;
static PyObject *__pyx_tuple__406;
static PyObject *__pyx_tuple__407;
static PyObject *__pyx_tuple__409;
static PyObject *__pyx_tuple__411;
static PyObject *__pyx_tuple__412;
static PyObject *__pyx_tuple__413;
static PyObject *__pyx_tuple__414;
static PyObject *__pyx_tuple__415;
static PyObject *__pyx_tuple__416;
static PyObject *__pyx_tuple__417;
static PyObject *__pyx_tuple__418;
static PyObject *__pyx_tuple__419;
static PyObject *__pyx_tuple__421;
static PyObject *__pyx_tuple__423;
static PyObject *__pyx_tuple__425;
static PyObject *__pyx_tuple__427;
static PyObject *__pyx_tuple__429;
static PyObject *__pyx_tuple__431;
static PyObject *__pyx_tuple__433;
static PyObject *__pyx_tuple__435;
static PyObject *__pyx_tuple__437;
static PyObject *__pyx_tuple__439;
static PyObject *__pyx_tuple__441;
static PyObject *__pyx_tuple__443;
static PyObject *__pyx_tuple__445;
static PyObject *__pyx_tuple__447;
static PyObject *__pyx_tuple__449;
static PyObject *__pyx_tuple__451;
static PyObject *__pyx_codeobj__17;
static PyObject *__pyx_codeobj__19;
static PyObject *__pyx_codeobj__29;
static PyObject *__pyx_codeobj__31;
static PyObject *__pyx_codeobj__43;
static PyObject *__pyx_codeobj__45;
static PyObject *__pyx_codeobj__73;
static PyObject *__pyx_codeobj__75;
static PyObject *__pyx_codeobj__100;
static PyObject *__pyx_codeobj__102;
static PyObject *__pyx_codeobj__167;
static PyObject *__pyx_codeobj__169;
static PyObject *__pyx_codeobj__182;
static PyObject *__pyx_codeobj__184;
static PyObject *__pyx_codeobj__215;
static PyObject *__pyx_codeobj__217;
static PyObject *__pyx_codeobj__229;
static PyObject *__pyx_codeobj__231;
static PyObject *__pyx_codeobj__259;
static PyObject *__pyx_codeobj__261;
static PyObject *__pyx_codeobj__269;
static PyObject *__pyx_codeobj__271;
static PyObject *__pyx_codeobj__287;
static PyObject *__pyx_codeobj__289;
static PyObject *__pyx_codeobj__306;
static PyObject *__pyx_codeobj__308;
static PyObject *__pyx_codeobj__349;
static PyObject *__pyx_codeobj__351;
static PyObject *__pyx_codeobj__358;
static PyObject *__pyx_codeobj__360;
static PyObject *__pyx_codeobj__367;
static PyObject *__pyx_codeobj__369;
static PyObject *__pyx_codeobj__382;
static PyObject *__pyx_codeobj__384;
static PyObject *__pyx_codeobj__391;
static PyObject *__pyx_codeobj__393;
static PyObject *__pyx_codeobj__408;
static PyObject *__pyx_codeobj__410;
static PyObject *__pyx_codeobj__420;
static PyObject *__pyx_codeobj__422;
static PyObject *__pyx_codeobj__424;
static PyObject *__pyx_codeobj__426;
static PyObject *__pyx_codeobj__428;
static PyObject *__pyx_codeobj__430;
static PyObject *__pyx_codeobj__432;
static PyObject *__pyx_codeobj__434;
static PyObject *__pyx_codeobj__436;
static PyObject *__pyx_codeobj__438;
static PyObject *__pyx_codeobj__440;
static PyObject *__pyx_codeobj__442;
static PyObject *__pyx_codeobj__444;
static PyObject *__pyx_codeobj__446;
static PyObject *__pyx_codeobj__448;
static PyObject *__pyx_codeobj__450;
static PyObject *__pyx_codeobj__452;

/* "pysamstats.pyx":90
 * 
 * 
 * cpdef dict _rec_coverage(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                          PileupColumn col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_1_rec_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage *__pyx_optional_args) {

  /* "pysamstats.pyx":91
 * 
 * cpdef dict _rec_coverage(AlignmentFile alignmentfile, FastaFile fafile,
 *                          PileupColumn 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;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  int __pyx_v_reads_pp;
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  bam_pileup1_t **__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  long __pyx_t_7;
  int __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":101
 *     cdef uint32_t flag
 *     cdef bint is_proper_pair
 *     cdef int reads_pp = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":104
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":108
 * 
 *     # get chromosome name and position
 *     chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); 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_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":109
 *     # get chromosome name and position
 *     chrom = alignmentfile.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 != 0)) {
    __pyx_t_7 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_7 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_7;

  /* "pysamstats.pyx":112
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":113
 *     # 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":114
 *     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_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

    /* "pysamstats.pyx":115
 *         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_10 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_10;

    /* "pysamstats.pyx":116
 *         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 = ((__pyx_v_flag & 2) != 0);

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

      /* "pysamstats.pyx":118
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         if is_proper_pair:
 *             reads_pp += 1             # <<<<<<<<<<<<<<
 * 
 *     # if not PY2:
 */
      __pyx_v_reads_pp = (__pyx_v_reads_pp + 1);
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

  /* "pysamstats.pyx":122
 *     # if not PY2:
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":123
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_pp': reads_pp}
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":124
 *     return {'chrom': chrom,
 *             'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp}
 * 
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":125
 *             'pos': pos,
 *             'reads_all': n,
 *             'reads_pp': reads_pp}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":90
 * 
 * 
 * cpdef dict _rec_coverage(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                          PileupColumn col, bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._rec_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_1_rec_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats__rec_coverage[] = "_rec_coverage(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_1_rec_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_coverage (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_coverage", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __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("_rec_coverage", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __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, "_rec_coverage") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":91
 * 
 * cpdef dict _rec_coverage(AlignmentFile alignmentfile, FastaFile fafile,
 *                          PileupColumn 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("_rec_coverage", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats__rec_coverage(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":90
 * 
 * 
 * cpdef dict _rec_coverage(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                          PileupColumn col, bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats__rec_coverage(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_coverage __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_coverage(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":128
 * 
 * 
 * cpdef dict _rec_coverage_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                              bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

static PyObject *__pyx_pw_10pysamstats_3_rec_coverage_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_pad(CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_pad *__pyx_optional_args) {

  /* "pysamstats.pyx":129
 * 
 * cpdef dict _rec_coverage_pad(FastaFile fafile, chrom, pos,
 *                              bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_coverage_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":130
 * cpdef dict _rec_coverage_pad(FastaFile fafile, chrom, pos,
 *                              bint one_based=False):
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom,
 *             'pos': pos,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_2 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_1 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":131
 *                              bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":132
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': 0,
 *             'reads_pp': 0}
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":128
 * 
 * 
 * cpdef dict _rec_coverage_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                              bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._rec_coverage_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_3_rec_coverage_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_2_rec_coverage_pad[] = "_rec_coverage_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_3_rec_coverage_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_coverage_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_coverage_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_coverage_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __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, "_rec_coverage_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 129; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":129
 * 
 * cpdef dict _rec_coverage_pad(FastaFile fafile, chrom, pos,
 *                              bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_coverage_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_coverage_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_2_rec_coverage_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

  /* "pysamstats.pyx":128
 * 
 * 
 * cpdef dict _rec_coverage_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                              bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

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

static PyObject *__pyx_pf_10pysamstats_2_rec_coverage_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_coverage_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_coverage_pad", 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__rec_coverage_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_coverage_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":137
 * 
 * 
 * def stat_coverage(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate coverage statistics per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_5stat_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_4stat_coverage[] = "stat_coverage(alignmentfile, **kwargs)\nGenerate coverage statistics per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_5stat_coverage = {"stat_coverage", (PyCFunction)__pyx_pw_10pysamstats_5stat_coverage, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_4stat_coverage};
static PyObject *__pyx_pw_10pysamstats_5stat_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_coverage") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_4stat_coverage(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_4stat_coverage(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  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("stat_coverage", 0);

  /* "pysamstats.pyx":168
 *     """
 * 
 *     return _iter_pileup(_rec_coverage, _rec_coverage_pad,             # <<<<<<<<<<<<<<
 *                         alignmentfile, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_coverage); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_coverage_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":169
 * 
 *     return _iter_pileup(_rec_coverage, _rec_coverage_pad,
 *                         alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":168
 *     """
 * 
 *     return _iter_pileup(_rec_coverage, _rec_coverage_pad,             # <<<<<<<<<<<<<<
 *                         alignmentfile, **kwargs)
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":137
 * 
 * 
 * def stat_coverage(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate coverage statistics per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":172
 * 
 * 
 * def load_coverage(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage, dtype_coverage, *args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_7load_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_6load_coverage[] = "load_coverage(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_7load_coverage = {"load_coverage", (PyCFunction)__pyx_pw_10pysamstats_7load_coverage, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_6load_coverage};
static PyObject *__pyx_pw_10pysamstats_7load_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("load_coverage (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_6load_coverage(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_6load_coverage(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_coverage", 0);

  /* "pysamstats.pyx":173
 * 
 * def load_coverage(*args, **kwargs):
 *     return _load_stats(stat_coverage, dtype_coverage, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_coverage); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":172
 * 
 * 
 * def load_coverage(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage, dtype_coverage, *args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":196
 * 
 * 
 * cpdef dict _rec_coverage_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                 PileupColumn col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_9_rec_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_strand *__pyx_optional_args) {

  /* "pysamstats.pyx":197
 * 
 * cpdef dict _rec_coverage_strand(AlignmentFile alignmentfile, FastaFile fafile,
 *                                 PileupColumn 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;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_reverse;
  int __pyx_v_is_proper_pair;
  int __pyx_v_reads_fwd;
  int __pyx_v_reads_rev;
  int __pyx_v_reads_pp;
  int __pyx_v_reads_pp_fwd;
  int __pyx_v_reads_pp_rev;
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  bam_pileup1_t **__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  long __pyx_t_7;
  int __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":208
 *     cdef bint is_reverse
 *     cdef bint is_proper_pair
 *     cdef int reads_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_rev = 0
 *     cdef int reads_pp = 0
 */
  __pyx_v_reads_fwd = 0;

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

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

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

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

  /* "pysamstats.pyx":215
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":219
 * 
 *     # get chromosome name and position
 *     chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":220
 *     # get chromosome name and position
 *     chrom = alignmentfile.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 != 0)) {
    __pyx_t_7 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_7 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_7;

  /* "pysamstats.pyx":223
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":224
 *     # 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":225
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 */
    __pyx_t_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

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

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

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

      /* "pysamstats.pyx":229
 *         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":231
 *             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":232
 *         else:
 *             reads_fwd += 1
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         if is_proper_pair:
 *             reads_pp += 1
 */
    __pyx_v_is_proper_pair = ((__pyx_v_flag & 2) != 0);

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

      /* "pysamstats.pyx":234
 *         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":235
 *         if is_proper_pair:
 *             reads_pp += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_pp_rev += 1
 *             else:
 */
      __pyx_t_11 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":236
 *             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":238
 *                 reads_pp_rev += 1
 *             else:
 *                 reads_pp_fwd += 1             # <<<<<<<<<<<<<<
 * 
 *     # if not PY2:
 */
        __pyx_v_reads_pp_fwd = (__pyx_v_reads_pp_fwd + 1);
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "pysamstats.pyx":242
 *     # if not PY2:
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":243
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":244
 *     return {'chrom': chrom,
 *             'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":245
 *             'pos': pos,
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,             # <<<<<<<<<<<<<<
 *             'reads_rev': reads_rev,
 *             'reads_pp': reads_pp,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":246
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":247
 *             '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_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":248
 *             'reads_rev': reads_rev,
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,             # <<<<<<<<<<<<<<
 *             'reads_pp_rev': reads_pp_rev}
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":249
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,
 *             'reads_pp_rev': reads_pp_rev}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":196
 * 
 * 
 * cpdef dict _rec_coverage_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                 PileupColumn col, bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._rec_coverage_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_9_rec_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_8_rec_coverage_strand[] = "_rec_coverage_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_9_rec_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_coverage_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_coverage_strand", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __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("_rec_coverage_strand", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __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, "_rec_coverage_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 197; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":197
 * 
 * cpdef dict _rec_coverage_strand(AlignmentFile alignmentfile, FastaFile fafile,
 *                                 PileupColumn 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("_rec_coverage_strand", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._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_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_8_rec_coverage_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":196
 * 
 * 
 * cpdef dict _rec_coverage_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                 PileupColumn col, bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_8_rec_coverage_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_coverage_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_coverage_strand(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_coverage_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":252
 * 
 * 
 * cpdef dict _rec_coverage_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                     bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

static PyObject *__pyx_pw_10pysamstats_11_rec_coverage_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_strand_pad(CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_strand_pad *__pyx_optional_args) {

  /* "pysamstats.pyx":253
 * 
 * cpdef dict _rec_coverage_strand_pad(FastaFile fafile, chrom, pos,
 *                                     bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_coverage_strand_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":254
 * cpdef dict _rec_coverage_strand_pad(FastaFile fafile, chrom, pos,
 *                                     bint one_based=False):
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom,
 *             'pos': pos,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_2 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_1 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":255
 *                                     bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":256
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': 0,
 *             'reads_fwd': 0,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":252
 * 
 * 
 * cpdef dict _rec_coverage_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                     bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._rec_coverage_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_11_rec_coverage_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_10_rec_coverage_strand_pad[] = "_rec_coverage_strand_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_11_rec_coverage_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_coverage_strand_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_coverage_strand_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_coverage_strand_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __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, "_rec_coverage_strand_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 253; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":253
 * 
 * cpdef dict _rec_coverage_strand_pad(FastaFile fafile, chrom, pos,
 *                                     bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_coverage_strand_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_coverage_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_10_rec_coverage_strand_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

  /* "pysamstats.pyx":252
 * 
 * 
 * cpdef dict _rec_coverage_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                     bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

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

static PyObject *__pyx_pf_10pysamstats_10_rec_coverage_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_coverage_strand_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_coverage_strand_pad", 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__rec_coverage_strand_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_coverage_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":265
 * 
 * 
 * def stat_coverage_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate coverage statistics by strand per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_13stat_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_12stat_coverage_strand[] = "stat_coverage_strand(alignmentfile, **kwargs)\nGenerate coverage statistics by strand per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_13stat_coverage_strand = {"stat_coverage_strand", (PyCFunction)__pyx_pw_10pysamstats_13stat_coverage_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_12stat_coverage_strand};
static PyObject *__pyx_pw_10pysamstats_13stat_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_coverage_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage_strand", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_coverage_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_12stat_coverage_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_12stat_coverage_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  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("stat_coverage_strand", 0);

  /* "pysamstats.pyx":296
 *     """
 * 
 *     return _iter_pileup(_rec_coverage_strand,             # <<<<<<<<<<<<<<
 *                         _rec_coverage_strand_pad,
 *                         alignmentfile, **kwargs)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_coverage_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysamstats.pyx":297
 * 
 *     return _iter_pileup(_rec_coverage_strand,
 *                         _rec_coverage_strand_pad,             # <<<<<<<<<<<<<<
 *                         alignmentfile, **kwargs)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_coverage_strand_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":296
 *     """
 * 
 *     return _iter_pileup(_rec_coverage_strand,             # <<<<<<<<<<<<<<
 *                         _rec_coverage_strand_pad,
 *                         alignmentfile, **kwargs)
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":298
 *     return _iter_pileup(_rec_coverage_strand,
 *                         _rec_coverage_strand_pad,
 *                         alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":296
 *     """
 * 
 *     return _iter_pileup(_rec_coverage_strand,             # <<<<<<<<<<<<<<
 *                         _rec_coverage_strand_pad,
 *                         alignmentfile, **kwargs)
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":265
 * 
 * 
 * def stat_coverage_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate coverage statistics by strand per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_coverage_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":301
 * 
 * 
 * def load_coverage_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_strand, dtype_coverage_strand,
 *                       *args, **kwargs)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_15load_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_14load_coverage_strand[] = "load_coverage_strand(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_15load_coverage_strand = {"load_coverage_strand", (PyCFunction)__pyx_pw_10pysamstats_15load_coverage_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_14load_coverage_strand};
static PyObject *__pyx_pw_10pysamstats_15load_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("load_coverage_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_14load_coverage_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_14load_coverage_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_coverage_strand", 0);

  /* "pysamstats.pyx":302
 * 
 * def load_coverage_strand(*args, **kwargs):
 *     return _load_stats(stat_coverage_strand, dtype_coverage_strand,             # <<<<<<<<<<<<<<
 *                       *args, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_coverage_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage_strand); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":303
 * def load_coverage_strand(*args, **kwargs):
 *     return _load_stats(stat_coverage_strand, dtype_coverage_strand,
 *                       *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":302
 * 
 * def load_coverage_strand(*args, **kwargs):
 *     return _load_stats(stat_coverage_strand, dtype_coverage_strand,             # <<<<<<<<<<<<<<
 *                       *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __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_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":303
 * def load_coverage_strand(*args, **kwargs):
 *     return _load_stats(stat_coverage_strand, dtype_coverage_strand,
 *                       *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":302
 * 
 * def load_coverage_strand(*args, **kwargs):
 *     return _load_stats(stat_coverage_strand, dtype_coverage_strand,             # <<<<<<<<<<<<<<
 *                       *args, **kwargs)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":301
 * 
 * 
 * def load_coverage_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_strand, dtype_coverage_strand,
 *                       *args, **kwargs)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_coverage_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":328
 * 
 * 
 * cpdef dict _rec_coverage_ext(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                              bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_17_rec_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_ext(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_ext *__pyx_optional_args) {

  /* "pysamstats.pyx":329
 * 
 * cpdef dict _rec_coverage_ext(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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_is_reverse;
  int __pyx_v_is_proper_pair;
  int __pyx_v_is_duplicate;
  int __pyx_v_mate_is_reverse;
  int __pyx_v_tlen;
  int __pyx_v_reads_pp;
  int __pyx_v_reads_mate_unmapped;
  int __pyx_v_reads_mate_other_chr;
  int __pyx_v_reads_mate_same_strand;
  int __pyx_v_reads_faceaway;
  int __pyx_v_reads_softclipped;
  int __pyx_v_reads_duplicate;
  PyObject *__pyx_v_n = NULL;
  int __pyx_v_tid;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  uint16_t __pyx_v_flag;
  int __pyx_v_mate_is_unmapped;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  bam_pileup1_t **__pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  long __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  int32_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":344
 *     cdef int tlen
 *     # counting variables
 *     cdef int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_mate_unmapped = 0
 *     cdef int reads_mate_other_chr = 0
 */
  __pyx_v_reads_pp = 0;

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

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

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

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

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

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

  /* "pysamstats.pyx":353
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

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

  /* "pysamstats.pyx":358
 *     # get chromosome name and position
 *     tid = col.tid
 *     chrom = alignmentfile.getrname(tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_6) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = NULL;
    PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":362
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_8 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_8 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_8; __pyx_t_3+=1) {
    __pyx_v_i = __pyx_t_3;

    /* "pysamstats.pyx":363
 *     # 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":364
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 */
    __pyx_t_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

    /* "pysamstats.pyx":365
 *         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_10 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_10;

    /* "pysamstats.pyx":366
 *         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 = ((__pyx_v_flag & 16) != 0);

    /* "pysamstats.pyx":367
 *         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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":368
 *         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 = ((__pyx_v_flag & 1024) != 0);

    /* "pysamstats.pyx":369
 *         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 = ((__pyx_v_flag & 8) != 0);

    /* "pysamstats.pyx":370
 *         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 = ((__pyx_v_flag & 32) != 0);

    /* "pysamstats.pyx":371
 *         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_11 = __pyx_v_aln->core.isize;
    __pyx_v_tlen = __pyx_t_11;

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

      /* "pysamstats.pyx":373
 *         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":374
 *         if is_duplicate:
 *             reads_duplicate += 1
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *         if mate_is_unmapped:
 */
    __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":375
 *             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":376
 *         if is_proper_pair:
 *             reads_pp += 1
 *         if mate_is_unmapped:             # <<<<<<<<<<<<<<
 *             reads_mate_unmapped += 1
 *         elif tid != aln.core.mtid:
 */
    __pyx_t_12 = (__pyx_v_mate_is_unmapped != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":377
 *             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":378
 *         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) \
 */
    __pyx_t_12 = ((__pyx_v_tid != __pyx_v_aln->core.mtid) != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":379
 *             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_v_reads_mate_other_chr = (__pyx_v_reads_mate_other_chr + 1);
      goto __pyx_L7;
    }

    /* "pysamstats.pyx":380
 *         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_t_13 = (__pyx_v_is_reverse != 0);
    if (!__pyx_t_13) {
      goto __pyx_L9_next_or;
    } else {
    }
    __pyx_t_13 = (__pyx_v_mate_is_reverse != 0);
    if (!__pyx_t_13) {
    } else {
      __pyx_t_12 = __pyx_t_13;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_L9_next_or:;

    /* "pysamstats.pyx":381
 *             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):
 */
    __pyx_t_13 = ((!(__pyx_v_is_reverse != 0)) != 0);
    if (__pyx_t_13) {
    } else {
      __pyx_t_12 = __pyx_t_13;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_t_13 = ((!(__pyx_v_mate_is_reverse != 0)) != 0);
    __pyx_t_12 = __pyx_t_13;
    __pyx_L8_bool_binop_done:;
    if (__pyx_t_12) {

      /* "pysamstats.pyx":382
 *         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":383
 *                 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):
 */
    __pyx_t_13 = (__pyx_v_is_reverse != 0);
    if (!__pyx_t_13) {
      goto __pyx_L13_next_or;
    } else {
    }
    __pyx_t_13 = ((__pyx_v_tlen > 0) != 0);
    if (!__pyx_t_13) {
    } else {
      __pyx_t_12 = __pyx_t_13;
      goto __pyx_L12_bool_binop_done;
    }
    __pyx_L13_next_or:;
    __pyx_t_13 = ((!(__pyx_v_is_reverse != 0)) != 0);
    if (__pyx_t_13) {
    } else {
      __pyx_t_12 = __pyx_t_13;
      goto __pyx_L12_bool_binop_done;
    }
    __pyx_t_13 = ((__pyx_v_tlen < 0) != 0);
    __pyx_t_12 = __pyx_t_13;
    __pyx_L12_bool_binop_done:;
    if (__pyx_t_12) {

      /* "pysamstats.pyx":384
 *             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":385
 *         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) != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":386
 *             reads_faceaway += 1
 *         if _is_softclipped(aln):
 *             reads_softclipped += 1             # <<<<<<<<<<<<<<
 * 
 *     # if not PY2:
 */
      __pyx_v_reads_softclipped = (__pyx_v_reads_softclipped + 1);
      goto __pyx_L16;
    }
    __pyx_L16:;
  }

  /* "pysamstats.pyx":390
 *     # if not PY2:
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom, 'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_pp': reads_pp,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":391
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom, 'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp,
 *             'reads_mate_unmapped': reads_mate_unmapped,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":392
 *     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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":393
 *             '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_mate_unmapped); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_unmapped, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":394
 *             '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_mate_other_chr); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_other_chr, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":395
 *             '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_mate_same_strand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_same_strand, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":396
 *             '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_faceaway); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_faceaway, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":397
 *             'reads_mate_same_strand': reads_mate_same_strand,
 *             'reads_faceaway': reads_faceaway,
 *             'reads_softclipped': reads_softclipped,             # <<<<<<<<<<<<<<
 *             'reads_duplicate': reads_duplicate}
 * 
 */
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_reads_softclipped); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_softclipped, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

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

  /* "pysamstats.pyx":328
 * 
 * 
 * cpdef dict _rec_coverage_ext(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                              bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysamstats._rec_coverage_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_17_rec_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_16_rec_coverage_ext[] = "_rec_coverage_ext(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_17_rec_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_coverage_ext (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_coverage_ext", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __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("_rec_coverage_ext", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __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, "_rec_coverage_ext") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 329; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":329
 * 
 * cpdef dict _rec_coverage_ext(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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("_rec_coverage_ext", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._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_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_16_rec_coverage_ext(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":328
 * 
 * 
 * cpdef dict _rec_coverage_ext(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                              bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_16_rec_coverage_ext(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_coverage_ext __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_coverage_ext(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_coverage_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":401
 * 
 * 
 * cpdef dict _rec_coverage_ext_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                  bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

static PyObject *__pyx_pw_10pysamstats_19_rec_coverage_ext_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_ext_pad(CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_ext_pad *__pyx_optional_args) {

  /* "pysamstats.pyx":402
 * 
 * cpdef dict _rec_coverage_ext_pad(FastaFile fafile, chrom, pos,
 *                                  bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos,
 */
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_coverage_ext_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":403
 * cpdef dict _rec_coverage_ext_pad(FastaFile fafile, chrom, pos,
 *                                  bint one_based=False):
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom, 'pos': pos,
 *             'reads_all': 0,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_2 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_1 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":404
 *                                  bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': 0,
 *             'reads_pp': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_unmapped, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_other_chr, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_same_strand, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_faceaway, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_softclipped, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_duplicate, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":401
 * 
 * 
 * cpdef dict _rec_coverage_ext_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                  bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._rec_coverage_ext_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_19_rec_coverage_ext_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_18_rec_coverage_ext_pad[] = "_rec_coverage_ext_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_19_rec_coverage_ext_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_coverage_ext_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_coverage_ext_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_coverage_ext_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __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, "_rec_coverage_ext_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 402; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":402
 * 
 * cpdef dict _rec_coverage_ext_pad(FastaFile fafile, chrom, pos,
 *                                  bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos,
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_coverage_ext_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_coverage_ext_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_18_rec_coverage_ext_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

  /* "pysamstats.pyx":401
 * 
 * 
 * cpdef dict _rec_coverage_ext_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                  bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

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

static PyObject *__pyx_pf_10pysamstats_18_rec_coverage_ext_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_coverage_ext_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_coverage_ext_pad", 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__rec_coverage_ext_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_coverage_ext_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":415
 * 
 * 
 * def stat_coverage_ext(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended coverage statistics per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_21stat_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_20stat_coverage_ext[] = "stat_coverage_ext(alignmentfile, **kwargs)\nGenerate extended coverage statistics per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_21stat_coverage_ext = {"stat_coverage_ext", (PyCFunction)__pyx_pw_10pysamstats_21stat_coverage_ext, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_20stat_coverage_ext};
static PyObject *__pyx_pw_10pysamstats_21stat_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_coverage_ext") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage_ext", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_coverage_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_20stat_coverage_ext(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_20stat_coverage_ext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  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("stat_coverage_ext", 0);

  /* "pysamstats.pyx":446
 *     """
 * 
 *     return _iter_pileup(_rec_coverage_ext, _rec_coverage_ext_pad, alignmentfile,             # <<<<<<<<<<<<<<
 *                         **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_coverage_ext); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_coverage_ext_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __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 = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":447
 * 
 *     return _iter_pileup(_rec_coverage_ext, _rec_coverage_ext_pad, alignmentfile,
 *                         **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":446
 *     """
 * 
 *     return _iter_pileup(_rec_coverage_ext, _rec_coverage_ext_pad, alignmentfile,             # <<<<<<<<<<<<<<
 *                         **kwargs)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":415
 * 
 * 
 * def stat_coverage_ext(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended coverage statistics per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_coverage_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":450
 * 
 * 
 * def load_coverage_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_ext, dtype_coverage_ext, *args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_23load_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_22load_coverage_ext[] = "load_coverage_ext(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_23load_coverage_ext = {"load_coverage_ext", (PyCFunction)__pyx_pw_10pysamstats_23load_coverage_ext, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_22load_coverage_ext};
static PyObject *__pyx_pw_10pysamstats_23load_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("load_coverage_ext (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_22load_coverage_ext(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_22load_coverage_ext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_coverage_ext", 0);

  /* "pysamstats.pyx":451
 * 
 * def load_coverage_ext(*args, **kwargs):
 *     return _load_stats(stat_coverage_ext, dtype_coverage_ext, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_coverage_ext); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage_ext); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":450
 * 
 * 
 * def load_coverage_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_ext, dtype_coverage_ext, *args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_coverage_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":492
 * 
 * 
 * cpdef dict _rec_coverage_ext_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                     PileupColumn col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_25_rec_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_ext_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_ext_strand *__pyx_optional_args) {

  /* "pysamstats.pyx":493
 * 
 * cpdef dict _rec_coverage_ext_strand(AlignmentFile alignmentfile, FastaFile fafile,
 *                                     PileupColumn 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_is_reverse;
  int __pyx_v_is_proper_pair;
  int __pyx_v_is_duplicate;
  int __pyx_v_mate_is_reverse;
  int __pyx_v_tlen;
  int __pyx_v_reads_rev;
  int __pyx_v_reads_fwd;
  int __pyx_v_reads_pp;
  int __pyx_v_reads_pp_rev;
  int __pyx_v_reads_pp_fwd;
  int __pyx_v_reads_mate_unmapped;
  int __pyx_v_reads_mate_unmapped_rev;
  int __pyx_v_reads_mate_unmapped_fwd;
  int __pyx_v_reads_mate_other_chr;
  int __pyx_v_reads_mate_other_chr_rev;
  int __pyx_v_reads_mate_other_chr_fwd;
  int __pyx_v_reads_mate_same_strand;
  int __pyx_v_reads_mate_same_strand_rev;
  int __pyx_v_reads_mate_same_strand_fwd;
  int __pyx_v_reads_faceaway;
  int __pyx_v_reads_faceaway_rev;
  int __pyx_v_reads_faceaway_fwd;
  int __pyx_v_reads_softclipped;
  int __pyx_v_reads_softclipped_rev;
  int __pyx_v_reads_softclipped_fwd;
  int __pyx_v_reads_duplicate;
  int __pyx_v_reads_duplicate_rev;
  int __pyx_v_reads_duplicate_fwd;
  PyObject *__pyx_v_n = NULL;
  int __pyx_v_tid;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  uint16_t __pyx_v_flag;
  int __pyx_v_mate_is_unmapped;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  bam_pileup1_t **__pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  long __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  int32_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":508
 *     cdef int tlen
 *     # counting variables
 *     cdef int reads_rev = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_fwd = 0
 *     cdef int reads_pp = 0
 */
  __pyx_v_reads_rev = 0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  /* "pysamstats.pyx":533
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

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

  /* "pysamstats.pyx":538
 *     # get chromosome name and position
 *     tid = col.tid
 *     chrom = alignmentfile.getrname(tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_6) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = NULL;
    PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":542
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_8 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_8 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_8; __pyx_t_3+=1) {
    __pyx_v_i = __pyx_t_3;

    /* "pysamstats.pyx":543
 *     # 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":544
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 */
    __pyx_t_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

    /* "pysamstats.pyx":545
 *         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_10 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_10;

    /* "pysamstats.pyx":546
 *         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 = ((__pyx_v_flag & 16) != 0);

    /* "pysamstats.pyx":547
 *         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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":548
 *         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 = ((__pyx_v_flag & 1024) != 0);

    /* "pysamstats.pyx":549
 *         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 = ((__pyx_v_flag & 8) != 0);

    /* "pysamstats.pyx":550
 *         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 = ((__pyx_v_flag & 32) != 0);

    /* "pysamstats.pyx":551
 *         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_11 = __pyx_v_aln->core.isize;
    __pyx_v_tlen = __pyx_t_11;

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

      /* "pysamstats.pyx":553
 *         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":555
 *             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":556
 *         else:
 *             reads_fwd += 1
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *             if is_reverse:
 */
    __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":557
 *             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":558
 *         if is_proper_pair:
 *             reads_pp += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_pp_rev += 1
 *             else:
 */
      __pyx_t_12 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":559
 *             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":561
 *                 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":562
 *             else:
 *                 reads_pp_fwd += 1
 *         if mate_is_unmapped:             # <<<<<<<<<<<<<<
 *             reads_mate_unmapped += 1
 *             if is_reverse:
 */
    __pyx_t_12 = (__pyx_v_mate_is_unmapped != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":563
 *                 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":564
 *         if mate_is_unmapped:
 *             reads_mate_unmapped += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_mate_unmapped_rev += 1
 *             else:
 */
      __pyx_t_12 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":565
 *             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":567
 *                 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":568
 *             else:
 *                 reads_mate_unmapped_fwd += 1
 *         elif tid != aln.core.mtid:             # <<<<<<<<<<<<<<
 *             reads_mate_other_chr += 1
 *             if is_reverse:
 */
    __pyx_t_12 = ((__pyx_v_tid != __pyx_v_aln->core.mtid) != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":569
 *                 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":570
 *         elif tid != aln.core.mtid:
 *             reads_mate_other_chr += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_mate_other_chr_rev += 1
 *             else:
 */
      __pyx_t_12 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":571
 *             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":573
 *                 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":574
 *             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
 */
    __pyx_t_13 = (__pyx_v_is_reverse != 0);
    if (__pyx_t_13) {
    } else {
      __pyx_t_12 = __pyx_t_13;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_13 = (__pyx_v_mate_is_reverse != 0);
    __pyx_t_12 = __pyx_t_13;
    __pyx_L11_bool_binop_done:;
    if (__pyx_t_12) {

      /* "pysamstats.pyx":575
 *                 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":576
 *         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":577
 *             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_13 = ((!(__pyx_v_is_reverse != 0)) != 0);
    if (__pyx_t_13) {
    } else {
      __pyx_t_12 = __pyx_t_13;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_13 = ((!(__pyx_v_mate_is_reverse != 0)) != 0);
    __pyx_t_12 = __pyx_t_13;
    __pyx_L13_bool_binop_done:;
    if (__pyx_t_12) {

      /* "pysamstats.pyx":578
 *             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":579
 *         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":580
 *             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:
 */
    __pyx_t_13 = (__pyx_v_is_reverse != 0);
    if (!__pyx_t_13) {
      goto __pyx_L16_next_or;
    } else {
    }
    __pyx_t_13 = ((__pyx_v_tlen > 0) != 0);
    if (!__pyx_t_13) {
    } else {
      __pyx_t_12 = __pyx_t_13;
      goto __pyx_L15_bool_binop_done;
    }
    __pyx_L16_next_or:;
    __pyx_t_13 = ((!(__pyx_v_is_reverse != 0)) != 0);
    if (__pyx_t_13) {
    } else {
      __pyx_t_12 = __pyx_t_13;
      goto __pyx_L15_bool_binop_done;
    }
    __pyx_t_13 = ((__pyx_v_tlen < 0) != 0);
    __pyx_t_12 = __pyx_t_13;
    __pyx_L15_bool_binop_done:;
    if (__pyx_t_12) {

      /* "pysamstats.pyx":581
 *             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":582
 *         elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 *             reads_faceaway += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_faceaway_rev += 1
 *             else:
 */
      __pyx_t_12 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":583
 *             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_L19;
      }
      /*else*/ {

        /* "pysamstats.pyx":585
 *                 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_L19:;
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "pysamstats.pyx":586
 *             else:
 *                 reads_faceaway_fwd += 1
 *         if _is_softclipped(aln):             # <<<<<<<<<<<<<<
 *             reads_softclipped += 1
 *             if is_reverse:
 */
    __pyx_t_12 = (__pyx_f_10pysamstats__is_softclipped(__pyx_v_aln) != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":587
 *                 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":588
 *         if _is_softclipped(aln):
 *             reads_softclipped += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_softclipped_rev += 1
 *             else:
 */
      __pyx_t_12 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":589
 *             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_L21;
      }
      /*else*/ {

        /* "pysamstats.pyx":591
 *                 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_L21:;
      goto __pyx_L20;
    }
    __pyx_L20:;

    /* "pysamstats.pyx":592
 *             else:
 *                 reads_softclipped_fwd += 1
 *         if is_duplicate:             # <<<<<<<<<<<<<<
 *             reads_duplicate += 1
 *             if is_reverse:
 */
    __pyx_t_12 = (__pyx_v_is_duplicate != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":593
 *                 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":594
 *         if is_duplicate:
 *             reads_duplicate += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_duplicate_rev += 1
 *             else:
 */
      __pyx_t_12 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":595
 *             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_L23;
      }
      /*else*/ {

        /* "pysamstats.pyx":597
 *                 reads_duplicate_rev += 1
 *             else:
 *                 reads_duplicate_fwd += 1             # <<<<<<<<<<<<<<
 * 
 *     # if not PY2:
 */
        __pyx_v_reads_duplicate_fwd = (__pyx_v_reads_duplicate_fwd + 1);
      }
      __pyx_L23:;
      goto __pyx_L22;
    }
    __pyx_L22:;
  }

  /* "pysamstats.pyx":601
 *     # if not PY2:
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom, 'pos': pos,             # <<<<<<<<<<<<<<
 *            'reads_all': n,
 *            'reads_fwd': reads_fwd,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":602
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom, 'pos': pos,
 *            'reads_all': n,             # <<<<<<<<<<<<<<
 *            'reads_fwd': reads_fwd,
 *            'reads_rev': reads_rev,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":603
 *     return {'chrom': chrom, 'pos': pos,
 *            'reads_all': n,
 *            'reads_fwd': reads_fwd,             # <<<<<<<<<<<<<<
 *            'reads_rev': reads_rev,
 *            'reads_pp': reads_pp,
 */
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_reads_fwd); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_fwd, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":604
 *            'reads_all': n,
 *            'reads_fwd': reads_fwd,
 *            'reads_rev': reads_rev,             # <<<<<<<<<<<<<<
 *            'reads_pp': reads_pp,
 *            'reads_pp_fwd': reads_pp_fwd,
 */
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_reads_rev); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_rev, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":605
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":606
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_pp_fwd); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_fwd, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":607
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_pp_rev); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_rev, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":608
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_mate_unmapped); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_unmapped, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":609
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_mate_unmapped_fwd); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_unmapped_fwd, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":610
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_mate_unmapped_rev); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_unmapped_rev, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":611
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_mate_other_chr); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_other_chr, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":612
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_mate_other_chr_fwd); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_other_chr_fwd, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":613
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_mate_other_chr_rev); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_other_chr_rev, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":614
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_mate_same_strand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_same_strand, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":615
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_mate_same_strand_fwd); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_same_strand_fwd, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":616
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_mate_same_strand_rev); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 616; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_same_strand_rev, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":617
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_faceaway); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_faceaway, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":618
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_faceaway_fwd); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 618; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_faceaway_fwd, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":619
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_faceaway_rev); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_faceaway_rev, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":620
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_softclipped); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_softclipped, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":621
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_softclipped_fwd); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_softclipped_fwd, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":622
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_softclipped_rev); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_softclipped_rev, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":623
 *            '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_4 = __Pyx_PyInt_From_int(__pyx_v_reads_duplicate); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_duplicate, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":624
 *            'reads_softclipped_rev': reads_softclipped_rev,
 *            'reads_duplicate': reads_duplicate,
 *            'reads_duplicate_fwd': reads_duplicate_fwd,             # <<<<<<<<<<<<<<
 *            'reads_duplicate_rev': reads_duplicate_rev,
 *            }
 */
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_reads_duplicate_fwd); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_duplicate_fwd, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

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

  /* "pysamstats.pyx":492
 * 
 * 
 * cpdef dict _rec_coverage_ext_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                     PileupColumn col, bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysamstats._rec_coverage_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_25_rec_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_24_rec_coverage_ext_strand[] = "_rec_coverage_ext_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_25_rec_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_coverage_ext_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_coverage_ext_strand", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __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("_rec_coverage_ext_strand", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __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, "_rec_coverage_ext_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 493; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":493
 * 
 * cpdef dict _rec_coverage_ext_strand(AlignmentFile alignmentfile, FastaFile fafile,
 *                                     PileupColumn 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("_rec_coverage_ext_strand", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._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_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_24_rec_coverage_ext_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":492
 * 
 * 
 * cpdef dict _rec_coverage_ext_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                     PileupColumn col, bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_24_rec_coverage_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_coverage_ext_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_coverage_ext_strand(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); 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_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_coverage_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":629
 * 
 * 
 * cpdef dict _rec_coverage_ext_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                         bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

static PyObject *__pyx_pw_10pysamstats_27_rec_coverage_ext_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_coverage_ext_strand_pad(CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_coverage_ext_strand_pad *__pyx_optional_args) {

  /* "pysamstats.pyx":630
 * 
 * cpdef dict _rec_coverage_ext_strand_pad(FastaFile fafile, chrom, pos,
 *                                         bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos,
 */
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_coverage_ext_strand_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":631
 * cpdef dict _rec_coverage_ext_strand_pad(FastaFile fafile, chrom, pos,
 *                                         bint one_based=False):
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom, 'pos': pos,
 *            'reads_all': 0,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_2 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_1 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":632
 *                                         bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos,             # <<<<<<<<<<<<<<
 *            'reads_all': 0,
 *            'reads_fwd': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); 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);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_unmapped, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_unmapped_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_unmapped_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_other_chr, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_other_chr_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_other_chr_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_same_strand, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_same_strand_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_same_strand_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_faceaway, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_faceaway_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_faceaway_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_softclipped, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_softclipped_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_softclipped_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_duplicate, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_duplicate_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_duplicate_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":629
 * 
 * 
 * cpdef dict _rec_coverage_ext_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                         bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._rec_coverage_ext_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_27_rec_coverage_ext_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_26_rec_coverage_ext_strand_pad[] = "_rec_coverage_ext_strand_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_27_rec_coverage_ext_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_coverage_ext_strand_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_coverage_ext_strand_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_coverage_ext_strand_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __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, "_rec_coverage_ext_strand_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 630; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":630
 * 
 * cpdef dict _rec_coverage_ext_strand_pad(FastaFile fafile, chrom, pos,
 *                                         bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos,
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_coverage_ext_strand_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_coverage_ext_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_26_rec_coverage_ext_strand_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

  /* "pysamstats.pyx":629
 * 
 * 
 * cpdef dict _rec_coverage_ext_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                         bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

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

static PyObject *__pyx_pf_10pysamstats_26_rec_coverage_ext_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_coverage_ext_strand_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_coverage_ext_strand_pad", 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__rec_coverage_ext_strand_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); 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_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_coverage_ext_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":660
 * 
 * 
 * def stat_coverage_ext_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended coverage statistics by strand per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_29stat_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_28stat_coverage_ext_strand[] = "stat_coverage_ext_strand(alignmentfile, **kwargs)\nGenerate extended coverage statistics by strand per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_29stat_coverage_ext_strand = {"stat_coverage_ext_strand", (PyCFunction)__pyx_pw_10pysamstats_29stat_coverage_ext_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_28stat_coverage_ext_strand};
static PyObject *__pyx_pw_10pysamstats_29stat_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_coverage_ext_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage_ext_strand", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_coverage_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_28stat_coverage_ext_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_28stat_coverage_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  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("stat_coverage_ext_strand", 0);

  /* "pysamstats.pyx":691
 *     """
 * 
 *     return _iter_pileup(_rec_coverage_ext_strand,             # <<<<<<<<<<<<<<
 *                         _rec_coverage_ext_strand_pad, alignmentfile, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_coverage_ext_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysamstats.pyx":692
 * 
 *     return _iter_pileup(_rec_coverage_ext_strand,
 *                         _rec_coverage_ext_strand_pad, alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_coverage_ext_strand_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":691
 *     """
 * 
 *     return _iter_pileup(_rec_coverage_ext_strand,             # <<<<<<<<<<<<<<
 *                         _rec_coverage_ext_strand_pad, alignmentfile, **kwargs)
 * 
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":692
 * 
 *     return _iter_pileup(_rec_coverage_ext_strand,
 *                         _rec_coverage_ext_strand_pad, alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":691
 *     """
 * 
 *     return _iter_pileup(_rec_coverage_ext_strand,             # <<<<<<<<<<<<<<
 *                         _rec_coverage_ext_strand_pad, alignmentfile, **kwargs)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":660
 * 
 * 
 * def stat_coverage_ext_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended coverage statistics by strand per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_coverage_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":695
 * 
 * 
 * def load_coverage_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_ext_strand, dtype_coverage_ext_strand,
 *                        *args, **kwargs)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_31load_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_30load_coverage_ext_strand[] = "load_coverage_ext_strand(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_31load_coverage_ext_strand = {"load_coverage_ext_strand", (PyCFunction)__pyx_pw_10pysamstats_31load_coverage_ext_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_30load_coverage_ext_strand};
static PyObject *__pyx_pw_10pysamstats_31load_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("load_coverage_ext_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_30load_coverage_ext_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_30load_coverage_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_coverage_ext_strand", 0);

  /* "pysamstats.pyx":696
 * 
 * def load_coverage_ext_strand(*args, **kwargs):
 *     return _load_stats(stat_coverage_ext_strand, dtype_coverage_ext_strand,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_coverage_ext_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage_ext_strand); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":697
 * def load_coverage_ext_strand(*args, **kwargs):
 *     return _load_stats(stat_coverage_ext_strand, dtype_coverage_ext_strand,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":696
 * 
 * def load_coverage_ext_strand(*args, **kwargs):
 *     return _load_stats(stat_coverage_ext_strand, dtype_coverage_ext_strand,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __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_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":697
 * def load_coverage_ext_strand(*args, **kwargs):
 *     return _load_stats(stat_coverage_ext_strand, dtype_coverage_ext_strand,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":696
 * 
 * def load_coverage_ext_strand(*args, **kwargs):
 *     return _load_stats(stat_coverage_ext_strand, dtype_coverage_ext_strand,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":695
 * 
 * 
 * def load_coverage_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_ext_strand, dtype_coverage_ext_strand,
 *                        *args, **kwargs)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_coverage_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":735
 * 
 * 
 * cpdef dict _rec_variation(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                           PileupColumn col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_33_rec_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_variation(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_variation *__pyx_optional_args) {

  /* "pysamstats.pyx":736
 * 
 * cpdef dict _rec_variation(AlignmentFile alignmentfile, FastaFile fafile,
 *                           PileupColumn 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_reads_all;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  int __pyx_v_reads_pp;
  int __pyx_v_matches;
  int __pyx_v_matches_pp;
  int __pyx_v_mismatches;
  int __pyx_v_mismatches_pp;
  int __pyx_v_deletions;
  int __pyx_v_deletions_pp;
  int __pyx_v_insertions;
  int __pyx_v_insertions_pp;
  int __pyx_v_a;
  int __pyx_v_a_pp;
  int __pyx_v_c;
  int __pyx_v_c_pp;
  int __pyx_v_t;
  int __pyx_v_t_pp;
  int __pyx_v_g;
  int __pyx_v_g_pp;
  int __pyx_v_n;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  long __pyx_t_8;
  int __pyx_t_9;
  bam1_t *__pyx_t_10;
  uint16_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":747
 *     cdef bint is_proper_pair
 *     # counting variables
 *     cdef int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int matches = 0
 *     cdef int matches_pp = 0
 */
  __pyx_v_reads_pp = 0;

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

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

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

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

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

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

  /* "pysamstats.pyx":754
 *     cdef int deletions = 0
 *     cdef int deletions_pp = 0
 *     cdef int insertions = 0             # <<<<<<<<<<<<<<
 *     cdef int insertions_pp = 0
 *     cdef int a = 0
 */
  __pyx_v_insertions = 0;

  /* "pysamstats.pyx":755
 *     cdef int deletions_pp = 0
 *     cdef int insertions = 0
 *     cdef int insertions_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int a = 0
 *     cdef int a_pp = 0
 */
  __pyx_v_insertions_pp = 0;

  /* "pysamstats.pyx":756
 *     cdef int insertions = 0
 *     cdef int insertions_pp = 0
 *     cdef int a = 0             # <<<<<<<<<<<<<<
 *     cdef int a_pp = 0
 *     cdef int c = 0
 */
  __pyx_v_a = 0;

  /* "pysamstats.pyx":757
 *     cdef int insertions_pp = 0
 *     cdef int a = 0
 *     cdef int a_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int c = 0
 *     cdef int c_pp = 0
 */
  __pyx_v_a_pp = 0;

  /* "pysamstats.pyx":758
 *     cdef int a = 0
 *     cdef int a_pp = 0
 *     cdef int c = 0             # <<<<<<<<<<<<<<
 *     cdef int c_pp = 0
 *     cdef int t = 0
 */
  __pyx_v_c = 0;

  /* "pysamstats.pyx":759
 *     cdef int a_pp = 0
 *     cdef int c = 0
 *     cdef int c_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int t = 0
 *     cdef int t_pp = 0
 */
  __pyx_v_c_pp = 0;

  /* "pysamstats.pyx":760
 *     cdef int c = 0
 *     cdef int c_pp = 0
 *     cdef int t = 0             # <<<<<<<<<<<<<<
 *     cdef int t_pp = 0
 *     cdef int g = 0
 */
  __pyx_v_t = 0;

  /* "pysamstats.pyx":761
 *     cdef int c_pp = 0
 *     cdef int t = 0
 *     cdef int t_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int g = 0
 *     cdef int g_pp = 0
 */
  __pyx_v_t_pp = 0;

  /* "pysamstats.pyx":762
 *     cdef int t = 0
 *     cdef int t_pp = 0
 *     cdef int g = 0             # <<<<<<<<<<<<<<
 *     cdef int g_pp = 0
 *     cdef int n = 0
 */
  __pyx_v_g = 0;

  /* "pysamstats.pyx":763
 *     cdef int t_pp = 0
 *     cdef int g = 0
 *     cdef int g_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int n = 0
 *     cdef int n_pp = 0
 */
  __pyx_v_g_pp = 0;

  /* "pysamstats.pyx":764
 *     cdef int g = 0
 *     cdef int g_pp = 0
 *     cdef int n = 0             # <<<<<<<<<<<<<<
 *     cdef int n_pp = 0
 * 
 */
  __pyx_v_n = 0;

  /* "pysamstats.pyx":765
 *     cdef int g_pp = 0
 *     cdef int n = 0
 *     cdef int n_pp = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_n_pp = 0;

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

  /* "pysamstats.pyx":769
 *     # initialise variables
 *     reads_all = 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":772
 * 
 *     # get chromosome name and position
 *     chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_col->tid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_6) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = NULL;
    PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":777
 *     # reference base
 *     refbase = fafile\
 *         .fetch(reference=chrom, start=col.pos, end=col.pos+1)\             # <<<<<<<<<<<<<<
 *         .upper()
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_fafile), __pyx_n_s_fetch); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_reference, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_col->pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_start, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_long((__pyx_v_col->pos + 1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_end, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_7); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysamstats.pyx":778
 *     refbase = fafile\
 *         .fetch(reference=chrom, start=col.pos, end=col.pos+1)\
 *         .upper()             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_upper); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_refbase = __pyx_t_1;
  __pyx_t_1 = 0;

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

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

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

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

    /* "pysamstats.pyx":788
 *         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 = ((__pyx_v_flag & 2) != 0);

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

      /* "pysamstats.pyx":790
 *         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":791
 *         if is_proper_pair:
 *             reads_pp += 1
 *         if read.is_del:             # <<<<<<<<<<<<<<
 *             deletions += 1
 *             if is_proper_pair:
 */
    __pyx_t_12 = (__pyx_v_read->is_del != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":792
 *             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":793
 *         if read.is_del:
 *             deletions += 1
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 deletions_pp += 1
 *         else:
 */
      __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":794
 *             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":797
 *         else:
 * #            alnbase = get_seq_range(aln, 0, aln.core.l_qseq)[read.qpos]
 *             alnbase = _get_seq_base(aln, read.qpos)             # <<<<<<<<<<<<<<
 *             if alnbase == b'A':
 *                 a += 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 = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_alnbase, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysamstats.pyx":798
 * #            alnbase = get_seq_range(aln, 0, aln.core.l_qseq)[read.qpos]
 *             alnbase = _get_seq_base(aln, read.qpos)
 *             if alnbase == b'A':             # <<<<<<<<<<<<<<
 *                 a += 1
 *                 if is_proper_pair:
 */
      __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_v_alnbase, __pyx_n_b_A, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_12) {

        /* "pysamstats.pyx":799
 *             alnbase = _get_seq_base(aln, read.qpos)
 *             if alnbase == b'A':
 *                 a += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     a_pp += 1
 */
        __pyx_v_a = (__pyx_v_a + 1);

        /* "pysamstats.pyx":800
 *             if alnbase == b'A':
 *                 a += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     a_pp += 1
 *             elif alnbase == b'T':
 */
        __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
        if (__pyx_t_12) {

          /* "pysamstats.pyx":801
 *                 a += 1
 *                 if is_proper_pair:
 *                     a_pp += 1             # <<<<<<<<<<<<<<
 *             elif alnbase == b'T':
 *                 t += 1
 */
          __pyx_v_a_pp = (__pyx_v_a_pp + 1);
          goto __pyx_L9;
        }
        __pyx_L9:;
        goto __pyx_L8;
      }

      /* "pysamstats.pyx":802
 *                 if is_proper_pair:
 *                     a_pp += 1
 *             elif alnbase == b'T':             # <<<<<<<<<<<<<<
 *                 t += 1
 *                 if is_proper_pair:
 */
      __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_v_alnbase, __pyx_n_b_T, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_12) {

        /* "pysamstats.pyx":803
 *                     a_pp += 1
 *             elif alnbase == b'T':
 *                 t += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     t_pp += 1
 */
        __pyx_v_t = (__pyx_v_t + 1);

        /* "pysamstats.pyx":804
 *             elif alnbase == b'T':
 *                 t += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     t_pp += 1
 *             elif alnbase == b'C':
 */
        __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
        if (__pyx_t_12) {

          /* "pysamstats.pyx":805
 *                 t += 1
 *                 if is_proper_pair:
 *                     t_pp += 1             # <<<<<<<<<<<<<<
 *             elif alnbase == b'C':
 *                 c += 1
 */
          __pyx_v_t_pp = (__pyx_v_t_pp + 1);
          goto __pyx_L10;
        }
        __pyx_L10:;
        goto __pyx_L8;
      }

      /* "pysamstats.pyx":806
 *                 if is_proper_pair:
 *                     t_pp += 1
 *             elif alnbase == b'C':             # <<<<<<<<<<<<<<
 *                 c += 1
 *                 if is_proper_pair:
 */
      __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_v_alnbase, __pyx_n_b_C, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_12) {

        /* "pysamstats.pyx":807
 *                     t_pp += 1
 *             elif alnbase == b'C':
 *                 c += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     c_pp += 1
 */
        __pyx_v_c = (__pyx_v_c + 1);

        /* "pysamstats.pyx":808
 *             elif alnbase == b'C':
 *                 c += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     c_pp += 1
 *             elif alnbase == b'G':
 */
        __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
        if (__pyx_t_12) {

          /* "pysamstats.pyx":809
 *                 c += 1
 *                 if is_proper_pair:
 *                     c_pp += 1             # <<<<<<<<<<<<<<
 *             elif alnbase == b'G':
 *                 g += 1
 */
          __pyx_v_c_pp = (__pyx_v_c_pp + 1);
          goto __pyx_L11;
        }
        __pyx_L11:;
        goto __pyx_L8;
      }

      /* "pysamstats.pyx":810
 *                 if is_proper_pair:
 *                     c_pp += 1
 *             elif alnbase == b'G':             # <<<<<<<<<<<<<<
 *                 g += 1
 *                 if is_proper_pair:
 */
      __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_v_alnbase, __pyx_n_b_G, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_12) {

        /* "pysamstats.pyx":811
 *                     c_pp += 1
 *             elif alnbase == b'G':
 *                 g += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     g_pp += 1
 */
        __pyx_v_g = (__pyx_v_g + 1);

        /* "pysamstats.pyx":812
 *             elif alnbase == b'G':
 *                 g += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     g_pp += 1
 *             elif alnbase == b'N':
 */
        __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
        if (__pyx_t_12) {

          /* "pysamstats.pyx":813
 *                 g += 1
 *                 if is_proper_pair:
 *                     g_pp += 1             # <<<<<<<<<<<<<<
 *             elif alnbase == b'N':
 *                 n += 1
 */
          __pyx_v_g_pp = (__pyx_v_g_pp + 1);
          goto __pyx_L12;
        }
        __pyx_L12:;
        goto __pyx_L8;
      }

      /* "pysamstats.pyx":814
 *                 if is_proper_pair:
 *                     g_pp += 1
 *             elif alnbase == b'N':             # <<<<<<<<<<<<<<
 *                 n += 1
 *                 if is_proper_pair:
 */
      __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_v_alnbase, __pyx_n_b_N, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_12) {

        /* "pysamstats.pyx":815
 *                     g_pp += 1
 *             elif alnbase == b'N':
 *                 n += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     n_pp += 1
 */
        __pyx_v_n = (__pyx_v_n + 1);

        /* "pysamstats.pyx":816
 *             elif alnbase == b'N':
 *                 n += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     n_pp += 1
 *             if read.indel > 0:
 */
        __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
        if (__pyx_t_12) {

          /* "pysamstats.pyx":817
 *                 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":818
 *                 if is_proper_pair:
 *                     n_pp += 1
 *             if read.indel > 0:             # <<<<<<<<<<<<<<
 *                 insertions += 1
 *                 if is_proper_pair:
 */
      __pyx_t_12 = ((__pyx_v_read->indel > 0) != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":819
 *                     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":820
 *             if read.indel > 0:
 *                 insertions += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     insertions_pp += 1
 *             if alnbase == refbase:
 */
        __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
        if (__pyx_t_12) {

          /* "pysamstats.pyx":821
 *                 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":822
 *                 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 = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_12) {

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

        /* "pysamstats.pyx":824
 *             if alnbase == refbase:
 *                 matches += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     matches_pp += 1
 *             else:
 */
        __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
        if (__pyx_t_12) {

          /* "pysamstats.pyx":825
 *                 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":827
 *                     matches_pp += 1
 *             else:
 *                 mismatches += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     mismatches_pp += 1
 */
        __pyx_v_mismatches = (__pyx_v_mismatches + 1);

        /* "pysamstats.pyx":828
 *             else:
 *                 mismatches += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     mismatches_pp += 1
 * 
 */
        __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
        if (__pyx_t_12) {

          /* "pysamstats.pyx":829
 *                 mismatches += 1
 *                 if is_proper_pair:
 *                     mismatches_pp += 1             # <<<<<<<<<<<<<<
 * 
 *     if not PY2:
 */
          __pyx_v_mismatches_pp = (__pyx_v_mismatches_pp + 1);
          goto __pyx_L18;
        }
        __pyx_L18:;
      }
      __pyx_L16:;
    }
    __pyx_L6:;
  }

  /* "pysamstats.pyx":831
 *                     mismatches_pp += 1
 * 
 *     if not PY2:             # <<<<<<<<<<<<<<
 *         refbase = str(refbase, 'ascii')
 *         # chrom = str(chrom, 'ascii')
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_PY2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_13 = ((!__pyx_t_12) != 0);
  if (__pyx_t_13) {

    /* "pysamstats.pyx":832
 * 
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')             # <<<<<<<<<<<<<<
 *         # chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_refbase);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_refbase);
    __Pyx_GIVEREF(__pyx_v_refbase);
    __Pyx_INCREF(__pyx_n_s_ascii);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_ascii);
    __Pyx_GIVEREF(__pyx_n_s_ascii);
    __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_1, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_refbase, __pyx_t_7);
    __pyx_t_7 = 0;
    goto __pyx_L19;
  }
  __pyx_L19:;

  /* "pysamstats.pyx":834
 *         refbase = str(refbase, 'ascii')
 *         # chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,             # <<<<<<<<<<<<<<
 *             'reads_all': reads_all, 'reads_pp': reads_pp,
 *             'matches': matches,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_pos, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_ref, __pyx_v_refbase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":835
 *         # chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 *             'reads_all': reads_all, 'reads_pp': reads_pp,             # <<<<<<<<<<<<<<
 *             'matches': matches,
 *             'matches_pp': matches_pp,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_reads_all); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_reads_all, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_reads_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":836
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 *             'reads_all': reads_all, 'reads_pp': reads_pp,
 *             'matches': matches,             # <<<<<<<<<<<<<<
 *             'matches_pp': matches_pp,
 *             'mismatches': mismatches,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_matches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_matches, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":837
 *             'reads_all': reads_all, 'reads_pp': reads_pp,
 *             'matches': matches,
 *             'matches_pp': matches_pp,             # <<<<<<<<<<<<<<
 *             'mismatches': mismatches,
 *             'mismatches_pp': mismatches_pp,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_matches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_matches_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":838
 *             'matches': matches,
 *             'matches_pp': matches_pp,
 *             'mismatches': mismatches,             # <<<<<<<<<<<<<<
 *             'mismatches_pp': mismatches_pp,
 *             'deletions': deletions,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_mismatches, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":839
 *             'matches_pp': matches_pp,
 *             'mismatches': mismatches,
 *             'mismatches_pp': mismatches_pp,             # <<<<<<<<<<<<<<
 *             'deletions': deletions,
 *             'deletions_pp': deletions_pp,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches_pp); 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 (PyDict_SetItem(__pyx_t_7, __pyx_n_s_mismatches_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":840
 *             'mismatches': mismatches,
 *             'mismatches_pp': mismatches_pp,
 *             'deletions': deletions,             # <<<<<<<<<<<<<<
 *             'deletions_pp': deletions_pp,
 *             'insertions': insertions,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_deletions); 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);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_deletions, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":841
 *             'mismatches_pp': mismatches_pp,
 *             'deletions': deletions,
 *             'deletions_pp': deletions_pp,             # <<<<<<<<<<<<<<
 *             'insertions': insertions,
 *             'insertions_pp': insertions_pp,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_deletions_pp); 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);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_deletions_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":842
 *             'deletions': deletions,
 *             'deletions_pp': deletions_pp,
 *             'insertions': insertions,             # <<<<<<<<<<<<<<
 *             'insertions_pp': insertions_pp,
 *             'A': a, 'A_pp': a_pp,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_insertions); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_insertions, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":843
 *             'deletions_pp': deletions_pp,
 *             'insertions': insertions,
 *             'insertions_pp': insertions_pp,             # <<<<<<<<<<<<<<
 *             'A': a, 'A_pp': a_pp,
 *             'C': c, 'C_pp': c_pp,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_insertions_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_insertions_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":844
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_a); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_A, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_a_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_A_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":845
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_c); 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 (PyDict_SetItem(__pyx_t_7, __pyx_n_s_C, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_c_pp); 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 (PyDict_SetItem(__pyx_t_7, __pyx_n_s_C_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":846
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_t); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_T, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_t_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_T_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":847
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_g); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 847; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_G, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_g_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 847; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_G_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":848
 *             'T': t, 'T_pp': t_pp,
 *             'G': g, 'G_pp': g_pp,
 *             'N': n, 'N_pp': n_pp}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_N, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_N_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = ((PyObject*)__pyx_t_7);
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":735
 * 
 * 
 * cpdef dict _rec_variation(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                           PileupColumn col, bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysamstats._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_33_rec_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_32_rec_variation[] = "_rec_variation(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_33_rec_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_variation (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_variation", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 735; __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("_rec_variation", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 735; __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, "_rec_variation") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 735; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 736; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":736
 * 
 * cpdef dict _rec_variation(AlignmentFile alignmentfile, FastaFile fafile,
 *                           PileupColumn 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("_rec_variation", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_variation", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_32_rec_variation(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":735
 * 
 * 
 * cpdef dict _rec_variation(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                           PileupColumn col, bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_32_rec_variation(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_variation __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_variation(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_variation", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":851
 * 
 * 
 * cpdef dict _rec_variation_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                               bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */

static PyObject *__pyx_pw_10pysamstats_35_rec_variation_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_variation_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_variation_pad *__pyx_optional_args) {

  /* "pysamstats.pyx":852
 * 
 * cpdef dict _rec_variation_pad(FastaFile fafile, chrom, pos,
 *                               bint one_based=False):             # <<<<<<<<<<<<<<
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:
 */
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_v_refbase = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_variation_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":853
 * cpdef dict _rec_variation_pad(FastaFile fafile, chrom, pos,
 *                               bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()             # <<<<<<<<<<<<<<
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_fafile), __pyx_n_s_fetch); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reference, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_start, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_end, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_upper); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_refbase = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":854
 *                               bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:             # <<<<<<<<<<<<<<
 *         refbase = str(refbase, 'ascii')
 *     pos = pos + 1 if one_based else pos
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_PY2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (__pyx_t_6) {

    /* "pysamstats.pyx":855
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_refbase);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_refbase);
    __Pyx_GIVEREF(__pyx_v_refbase);
    __Pyx_INCREF(__pyx_n_s_ascii);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_ascii);
    __Pyx_GIVEREF(__pyx_n_s_ascii);
    __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_refbase, __pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":856
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 *             'reads_all': 0, 'reads_pp': 0,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_1 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __pyx_t_1;
    __pyx_t_1 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_3 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":857
 *         refbase = str(refbase, 'ascii')
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,             # <<<<<<<<<<<<<<
 *             'reads_all': 0, 'reads_pp': 0,
 *             'matches': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_ref, __pyx_v_refbase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_deletions, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_deletions_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_insertions, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_insertions_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_A, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_A_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_C, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_C_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_T, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_T_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_G, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_G_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_N, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_N_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":851
 * 
 * 
 * cpdef dict _rec_variation_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                               bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats._rec_variation_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_refbase);
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_35_rec_variation_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_34_rec_variation_pad[] = "_rec_variation_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_35_rec_variation_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_variation_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_variation_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_variation_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 851; __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, "_rec_variation_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 851; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 852; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":852
 * 
 * cpdef dict _rec_variation_pad(FastaFile fafile, chrom, pos,
 *                               bint one_based=False):             # <<<<<<<<<<<<<<
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_variation_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_variation_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_34_rec_variation_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

  /* "pysamstats.pyx":851
 * 
 * 
 * cpdef dict _rec_variation_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                               bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */

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

static PyObject *__pyx_pf_10pysamstats_34_rec_variation_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_variation_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_variation_pad", 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__rec_variation_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); 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_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_variation_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":874
 * 
 * 
 * def stat_variation(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate variation statistics per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_37stat_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_36stat_variation[] = "stat_variation(alignmentfile, fafile, **kwargs)\nGenerate variation statistics per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    fafile : pysam.FastaFile or string\n        FASTA file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_37stat_variation = {"stat_variation", (PyCFunction)__pyx_pw_10pysamstats_37stat_variation, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_36stat_variation};
static PyObject *__pyx_pw_10pysamstats_37stat_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_fafile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,&__pyx_n_s_fafile,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 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", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      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 = 874; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_alignmentfile = values[0];
    __pyx_v_fafile = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_variation", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_variation", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_36stat_variation(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_36stat_variation(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_kwargs) {
  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("stat_variation", 0);

  /* "pysamstats.pyx":907
 *     """
 * 
 *     return _iter_pileup(_rec_variation, _rec_variation_pad,             # <<<<<<<<<<<<<<
 *                         alignmentfile, fafile=fafile, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_variation); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_variation_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":908
 * 
 *     return _iter_pileup(_rec_variation, _rec_variation_pad,
 *                         alignmentfile, fafile=fafile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":907
 *     """
 * 
 *     return _iter_pileup(_rec_variation, _rec_variation_pad,             # <<<<<<<<<<<<<<
 *                         alignmentfile, fafile=fafile, **kwargs)
 * 
 */
  __pyx_t_3 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":908
 * 
 *     return _iter_pileup(_rec_variation, _rec_variation_pad,
 *                         alignmentfile, fafile=fafile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_fafile))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_fafile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":907
 *     """
 * 
 *     return _iter_pileup(_rec_variation, _rec_variation_pad,             # <<<<<<<<<<<<<<
 *                         alignmentfile, fafile=fafile, **kwargs)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":874
 * 
 * 
 * def stat_variation(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate variation statistics per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_variation", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":911
 * 
 * 
 * def load_variation(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_variation, dtype_variation, *args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_39load_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_38load_variation[] = "load_variation(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_39load_variation = {"load_variation", (PyCFunction)__pyx_pw_10pysamstats_39load_variation, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_38load_variation};
static PyObject *__pyx_pw_10pysamstats_39load_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("load_variation (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_38load_variation(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_38load_variation(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_variation", 0);

  /* "pysamstats.pyx":912
 * 
 * def load_variation(*args, **kwargs):
 *     return _load_stats(stat_variation, dtype_variation, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_variation); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_variation); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 912; __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_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":911
 * 
 * 
 * def load_variation(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_variation, dtype_variation, *args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_variation", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":974
 * 
 * 
 * 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":975
 * 
 * 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;

  /* "pysamstats.pyx":974
 * 
 * 
 * cdef inline _init_pp_strand(_CountPpStrand* c):             # <<<<<<<<<<<<<<
 *     c.all = c.fwd = c.rev = c.pp = c.pp_fwd = c.pp_rev = 0
 * 
 */

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

/* "pysamstats.pyx":978
 * 
 * 
 * cdef inline _incr_pp_strand(_CountPpStrand* c, bint is_reverse,             # <<<<<<<<<<<<<<
 *                            bint is_proper_pair):
 *     c.all += 1
 */

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
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("_incr_pp_strand", 0);

  /* "pysamstats.pyx":980
 * 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":981
 *                            bint is_proper_pair):
 *     c.all += 1
 *     if is_reverse:             # <<<<<<<<<<<<<<
 *         c.rev += 1
 *         if is_proper_pair:
 */
  __pyx_t_1 = (__pyx_v_is_reverse != 0);
  if (__pyx_t_1) {

    /* "pysamstats.pyx":982
 *     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":983
 *     if is_reverse:
 *         c.rev += 1
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             c.pp += 1
 *             c.pp_rev += 1
 */
    __pyx_t_1 = (__pyx_v_is_proper_pair != 0);
    if (__pyx_t_1) {

      /* "pysamstats.pyx":984
 *         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":985
 *         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":987
 *             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":988
 *     else:
 *         c.fwd += 1
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             c.pp += 1
 *             c.pp_fwd += 1
 */
    __pyx_t_1 = (__pyx_v_is_proper_pair != 0);
    if (__pyx_t_1) {

      /* "pysamstats.pyx":989
 *         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":990
 *         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:;

  /* "pysamstats.pyx":978
 * 
 * 
 * cdef inline _incr_pp_strand(_CountPpStrand* c, bint is_reverse,             # <<<<<<<<<<<<<<
 *                            bint is_proper_pair):
 *     c.all += 1
 */

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

/* "pysamstats.pyx":993
 * 
 * 
 * cpdef dict _rec_variation_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                  PileupColumn col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_41_rec_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_variation_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_variation_strand *__pyx_optional_args) {

  /* "pysamstats.pyx":994
 * 
 * cpdef dict _rec_variation_strand(AlignmentFile alignmentfile, FastaFile fafile,
 *                                  PileupColumn 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;
  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_n = NULL;
  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;
  bam_pileup1_t **__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  long __pyx_t_7;
  int __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":1009
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 *     _init_pp_strand(&reads)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":1011
 *     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 = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1012
 *     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 = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1013
 *     _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 = 1013; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1014
 *     _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 = 1014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1015
 *     _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 = 1015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1016
 *     _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 = 1016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1017
 *     _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 = 1017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1018
 *     _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 = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1019
 *     _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 = 1019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1020
 *     _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 = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1023
 * 
 *     # get chromosome name and position
 *     chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->tid); 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 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":1027
 * 
 *     # reference base
 *     refbase = fafile.fetch(reference=chrom, start=col.pos, end=col.pos+1).upper()             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_fafile), __pyx_n_s_fetch); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reference, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->pos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_start, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_From_long((__pyx_v_col->pos + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_end, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_upper); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_refbase = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1030
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         # read.qpos
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":1031
 *     # 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":1035
 *         # read.is_del
 *         # read.indel
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

    /* "pysamstats.pyx":1036
 *         # 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_10 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_10;

    /* "pysamstats.pyx":1037
 *         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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":1038
 *         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 = ((__pyx_v_flag & 16) != 0);

    /* "pysamstats.pyx":1039
 *         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 = 1039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysamstats.pyx":1040
 *         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:
 */
    __pyx_t_11 = (__pyx_v_read->is_del != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":1041
 *         _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 = 1041; __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":1043
 *             _incr_pp_strand(&deletions, is_reverse, is_proper_pair)
 *         else:
 *             alnbase = _get_seq_base(aln, read.qpos)             # <<<<<<<<<<<<<<
 *             if alnbase == b'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 = 1043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_alnbase, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysamstats.pyx":1044
 *         else:
 *             alnbase = _get_seq_base(aln, read.qpos)
 *             if alnbase == b'A':             # <<<<<<<<<<<<<<
 *                 _incr_pp_strand(&A, is_reverse, is_proper_pair)
 *             elif alnbase == b'T':
 */
      __pyx_t_11 = (__Pyx_PyBytes_Equals(__pyx_v_alnbase, __pyx_n_b_A, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_11) {

        /* "pysamstats.pyx":1045
 *             alnbase = _get_seq_base(aln, read.qpos)
 *             if alnbase == b'A':
 *                 _incr_pp_strand(&A, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *             elif alnbase == b'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 = 1045; __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":1046
 *             if alnbase == b'A':
 *                 _incr_pp_strand(&A, is_reverse, is_proper_pair)
 *             elif alnbase == b'T':             # <<<<<<<<<<<<<<
 *                 _incr_pp_strand(&T, is_reverse, is_proper_pair)
 *             elif alnbase == b'C':
 */
      __pyx_t_11 = (__Pyx_PyBytes_Equals(__pyx_v_alnbase, __pyx_n_b_T, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_11) {

        /* "pysamstats.pyx":1047
 *                 _incr_pp_strand(&A, is_reverse, is_proper_pair)
 *             elif alnbase == b'T':
 *                 _incr_pp_strand(&T, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *             elif alnbase == b'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 = 1047; __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":1048
 *             elif alnbase == b'T':
 *                 _incr_pp_strand(&T, is_reverse, is_proper_pair)
 *             elif alnbase == b'C':             # <<<<<<<<<<<<<<
 *                 _incr_pp_strand(&C, is_reverse, is_proper_pair)
 *             elif alnbase == b'G':
 */
      __pyx_t_11 = (__Pyx_PyBytes_Equals(__pyx_v_alnbase, __pyx_n_b_C, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_11) {

        /* "pysamstats.pyx":1049
 *                 _incr_pp_strand(&T, is_reverse, is_proper_pair)
 *             elif alnbase == b'C':
 *                 _incr_pp_strand(&C, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *             elif alnbase == b'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 = 1049; __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":1050
 *             elif alnbase == b'C':
 *                 _incr_pp_strand(&C, is_reverse, is_proper_pair)
 *             elif alnbase == b'G':             # <<<<<<<<<<<<<<
 *                 _incr_pp_strand(&G, is_reverse, is_proper_pair)
 *             elif alnbase == b'N':
 */
      __pyx_t_11 = (__Pyx_PyBytes_Equals(__pyx_v_alnbase, __pyx_n_b_G, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_11) {

        /* "pysamstats.pyx":1051
 *                 _incr_pp_strand(&C, is_reverse, is_proper_pair)
 *             elif alnbase == b'G':
 *                 _incr_pp_strand(&G, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *             elif alnbase == b'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 = 1051; __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":1052
 *             elif alnbase == b'G':
 *                 _incr_pp_strand(&G, is_reverse, is_proper_pair)
 *             elif alnbase == b'N':             # <<<<<<<<<<<<<<
 *                 _incr_pp_strand(&N, is_reverse, is_proper_pair)
 *             if read.indel > 0:
 */
      __pyx_t_11 = (__Pyx_PyBytes_Equals(__pyx_v_alnbase, __pyx_n_b_N, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_11) {

        /* "pysamstats.pyx":1053
 *                 _incr_pp_strand(&G, is_reverse, is_proper_pair)
 *             elif alnbase == b'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 = 1053; __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":1054
 *             elif alnbase == b'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_11 = ((__pyx_v_read->indel > 0) != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":1055
 *                 _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 = 1055; __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":1056
 *             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 = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_11) {

        /* "pysamstats.pyx":1057
 *                 _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 = 1057; __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":1059
 *                 _incr_pp_strand(&matches, is_reverse, is_proper_pair)
 *             else:
 *                 _incr_pp_strand(&mismatches, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 * 
 *     if not PY2:
 */
        __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 = 1059; __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":1061
 *                 _incr_pp_strand(&mismatches, is_reverse, is_proper_pair)
 * 
 *     if not PY2:             # <<<<<<<<<<<<<<
 *         refbase = str(refbase, 'ascii')
 *         # chrom = str(chrom, 'ascii')
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_PY2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_12 = ((!__pyx_t_11) != 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":1062
 * 
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')             # <<<<<<<<<<<<<<
 *         # chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_refbase);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_refbase);
    __Pyx_GIVEREF(__pyx_v_refbase);
    __Pyx_INCREF(__pyx_n_s_ascii);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_ascii);
    __Pyx_GIVEREF(__pyx_n_s_ascii);
    __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_refbase, __pyx_t_6);
    __pyx_t_6 = 0;
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "pysamstats.pyx":1064
 *         refbase = str(refbase, 'ascii')
 *         # chrom = str(chrom, 'ascii')
 *     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_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_pos, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_ref, __pyx_v_refbase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1065
 *         # chrom = str(chrom, 'ascii')
 *     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,
 */
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_reads.fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_reads.rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1066
 *     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_1 = __Pyx_PyInt_From_int(__pyx_v_reads.pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_reads.pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_reads.pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1067
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_matches.all); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1067; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_matches.fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1067; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_matches.rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1067; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1068
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_matches.pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_matches.pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_matches.pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1069
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches.all); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches.fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches.rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1070
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches.pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches.pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches.pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1071
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_deletions.all); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_deletions, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_deletions.fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_deletions_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_deletions.rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_deletions_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1072
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_deletions.pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1072; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_deletions_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_deletions.pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1072; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_deletions_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_deletions.pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1072; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_deletions_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1073
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_insertions.all); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_insertions, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_insertions.fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_insertions_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_insertions.rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_insertions_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1074
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_insertions.pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_insertions_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_insertions.pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_insertions_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_insertions.pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_insertions_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1075
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_A.all); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_A, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_A.fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_A_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_A.rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_A_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_A.pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_A_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_A.pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_A_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_A.pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_A_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1076
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_C.all); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_C, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_C.fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_C_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_C.rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_C_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_C.pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_C_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_C.pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_C_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_C.pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_C_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1077
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_T.all); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1077; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_T, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_T.fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1077; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_T_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_T.rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1077; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_T_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_T.pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1077; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_T_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_T.pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1077; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_T_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_T.pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1077; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_T_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1078
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_G.all); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_G, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_G.fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_G_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_G.rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_G_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_G.pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_G_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_G.pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_G_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_G.pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_G_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1079
 *             '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_1 = __Pyx_PyInt_From_int(__pyx_v_N.all); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_N, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N.fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_N_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N.rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_N_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N.pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_N_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N.pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_N_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N.pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_N_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = ((PyObject*)__pyx_t_6);
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":993
 * 
 * 
 * cpdef dict _rec_variation_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                  PileupColumn col, bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._rec_variation_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __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_41_rec_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_40_rec_variation_strand[] = "_rec_variation_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_41_rec_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_variation_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_variation_strand", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __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("_rec_variation_strand", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __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, "_rec_variation_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 994; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":994
 * 
 * cpdef dict _rec_variation_strand(AlignmentFile alignmentfile, FastaFile fafile,
 *                                  PileupColumn 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("_rec_variation_strand", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._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_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_40_rec_variation_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":993
 * 
 * 
 * cpdef dict _rec_variation_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                  PileupColumn col, bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_40_rec_variation_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_variation_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_variation_strand(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_variation_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1083
 * 
 * 
 * cpdef dict _rec_variation_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                      bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */

static PyObject *__pyx_pw_10pysamstats_43_rec_variation_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_variation_strand_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_variation_strand_pad *__pyx_optional_args) {

  /* "pysamstats.pyx":1084
 * 
 * cpdef dict _rec_variation_strand_pad(FastaFile fafile, chrom, pos,
 *                                      bint one_based=False):             # <<<<<<<<<<<<<<
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:
 */
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_v_refbase = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_variation_strand_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":1085
 * cpdef dict _rec_variation_strand_pad(FastaFile fafile, chrom, pos,
 *                                      bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()             # <<<<<<<<<<<<<<
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_fafile), __pyx_n_s_fetch); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reference, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_start, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_end, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_upper); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_refbase = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1086
 *                                      bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:             # <<<<<<<<<<<<<<
 *         refbase = str(refbase, 'ascii')
 *     pos = pos + 1 if one_based else pos
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_PY2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (__pyx_t_6) {

    /* "pysamstats.pyx":1087
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_refbase);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_refbase);
    __Pyx_GIVEREF(__pyx_v_refbase);
    __Pyx_INCREF(__pyx_n_s_ascii);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_ascii);
    __Pyx_GIVEREF(__pyx_n_s_ascii);
    __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_refbase, __pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":1088
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 *             'reads_all': 0, 'reads_fwd': 0, 'reads_rev': 0,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_1 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __pyx_t_1;
    __pyx_t_1 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_3 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":1089
 *         refbase = str(refbase, 'ascii')
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,             # <<<<<<<<<<<<<<
 *             'reads_all': 0, 'reads_fwd': 0, 'reads_rev': 0,
 *             'reads_pp': 0, 'reads_pp_fwd': 0, 'reads_pp_rev': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_ref, __pyx_v_refbase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_deletions, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_deletions_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_deletions_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_deletions_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_deletions_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_deletions_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_insertions, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_insertions_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_insertions_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_insertions_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_insertions_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_insertions_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_A, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_A_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_A_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_A_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_A_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_A_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_C, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_C_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_C_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_C_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_C_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_C_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_T, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_T_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_T_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_T_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_T_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_T_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_G, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_G_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_G_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_G_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_G_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_G_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_N, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_N_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_N_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_N_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_N_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_N_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1083
 * 
 * 
 * cpdef dict _rec_variation_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                      bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats._rec_variation_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_refbase);
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_43_rec_variation_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_42_rec_variation_strand_pad[] = "_rec_variation_strand_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_43_rec_variation_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_variation_strand_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_variation_strand_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_variation_strand_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __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, "_rec_variation_strand_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 1084; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":1084
 * 
 * cpdef dict _rec_variation_strand_pad(FastaFile fafile, chrom, pos,
 *                                      bint one_based=False):             # <<<<<<<<<<<<<<
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_variation_strand_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_variation_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_42_rec_variation_strand_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

  /* "pysamstats.pyx":1083
 * 
 * 
 * cpdef dict _rec_variation_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                      bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */

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

static PyObject *__pyx_pf_10pysamstats_42_rec_variation_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_variation_strand_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_variation_strand_pad", 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__rec_variation_strand_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_variation_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1113
 * 
 * 
 * def stat_variation_strand(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate variation statistics by strand per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_45stat_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_44stat_variation_strand[] = "stat_variation_strand(alignmentfile, fafile, **kwargs)\nGenerate variation statistics by strand per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    fafile : pysam.FastaFile or string\n        FASTA file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_45stat_variation_strand = {"stat_variation_strand", (PyCFunction)__pyx_pw_10pysamstats_45stat_variation_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_44stat_variation_strand};
static PyObject *__pyx_pw_10pysamstats_45stat_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_fafile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,&__pyx_n_s_fafile,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 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", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      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 = 1113; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_alignmentfile = values[0];
    __pyx_v_fafile = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_variation_strand", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_variation_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_44stat_variation_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_44stat_variation_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_kwargs) {
  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("stat_variation_strand", 0);

  /* "pysamstats.pyx":1146
 *     """
 * 
 *     return _iter_pileup(_rec_variation_strand,             # <<<<<<<<<<<<<<
 *                         _rec_variation_strand_pad,
 *                         alignmentfile, fafile=fafile, **kwargs)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); 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_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_variation_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysamstats.pyx":1147
 * 
 *     return _iter_pileup(_rec_variation_strand,
 *                         _rec_variation_strand_pad,             # <<<<<<<<<<<<<<
 *                         alignmentfile, fafile=fafile, **kwargs)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_variation_strand_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":1146
 *     """
 * 
 *     return _iter_pileup(_rec_variation_strand,             # <<<<<<<<<<<<<<
 *                         _rec_variation_strand_pad,
 *                         alignmentfile, fafile=fafile, **kwargs)
 */
  __pyx_t_4 = PyTuple_New(3); 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);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":1148
 *     return _iter_pileup(_rec_variation_strand,
 *                         _rec_variation_strand_pad,
 *                         alignmentfile, fafile=fafile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_fafile))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_fafile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1146
 *     """
 * 
 *     return _iter_pileup(_rec_variation_strand,             # <<<<<<<<<<<<<<
 *                         _rec_variation_strand_pad,
 *                         alignmentfile, fafile=fafile, **kwargs)
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1113
 * 
 * 
 * def stat_variation_strand(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate variation statistics by strand per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_variation_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1151
 * 
 * 
 * def load_variation_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_variation_strand, dtype_variation_strand,
 *                        *args, **kwargs)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_47load_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_46load_variation_strand[] = "load_variation_strand(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_47load_variation_strand = {"load_variation_strand", (PyCFunction)__pyx_pw_10pysamstats_47load_variation_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_46load_variation_strand};
static PyObject *__pyx_pw_10pysamstats_47load_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("load_variation_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_46load_variation_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_46load_variation_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_variation_strand", 0);

  /* "pysamstats.pyx":1152
 * 
 * def load_variation_strand(*args, **kwargs):
 *     return _load_stats(stat_variation_strand, dtype_variation_strand,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_variation_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_variation_strand); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":1153
 * def load_variation_strand(*args, **kwargs):
 *     return _load_stats(stat_variation_strand, dtype_variation_strand,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":1152
 * 
 * def load_variation_strand(*args, **kwargs):
 *     return _load_stats(stat_variation_strand, dtype_variation_strand,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1152; __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_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1153
 * def load_variation_strand(*args, **kwargs):
 *     return _load_stats(stat_variation_strand, dtype_variation_strand,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":1152
 * 
 * def load_variation_strand(*args, **kwargs):
 *     return _load_stats(stat_variation_strand, dtype_variation_strand,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1151
 * 
 * 
 * def load_variation_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_variation_strand, dtype_variation_strand,
 *                        *args, **kwargs)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_variation_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1179
 * 
 * 
 * cpdef dict _rec_tlen(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                      bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_49_rec_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_tlen(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_tlen *__pyx_optional_args) {

  /* "pysamstats.pyx":1180
 * 
 * cpdef dict _rec_tlen(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  int __pyx_v_mate_other_chr;
  int __pyx_v_reads_p;
  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_n = NULL;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  int __pyx_v_mate_is_unmapped;
  PyObject *__pyx_v_mean_tlen = NULL;
  long __pyx_v_rms_tlen;
  double __pyx_v_variance_tlen;
  PyObject *__pyx_v_std_tlen = NULL;
  CYTHON_UNUSED long __pyx_v_median_tlen;
  PyObject *__pyx_v_mean_tlen_pp = NULL;
  long __pyx_v_rms_tlen_pp;
  double __pyx_v_variance_tlen_pp;
  PyObject *__pyx_v_std_tlen_pp = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  bam_pileup1_t **__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  long __pyx_t_7;
  int __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  int32_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":1194
 *     # reads "paired", i.e., mate is mapped to same chromosome, so tlen is
 *     # meaningful
 *     cdef int reads_p = 0             # <<<<<<<<<<<<<<
 *     # reads "properly paired", as defined by aligner
 *     cdef int reads_pp = 0
 */
  __pyx_v_reads_p = 0;

  /* "pysamstats.pyx":1196
 *     cdef int reads_p = 0
 *     # reads "properly paired", as defined by aligner
 *     cdef int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen
 *     cdef int64_t tlen_squared
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":1199
 *     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":1200
 *     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":1202
 *     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":1203
 *     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":1204
 *     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":1205
 *     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":1207
 *     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":1208
 *     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":1211
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); 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_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":1215
 * 
 *     # get chromosome name and position
 *     chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":1219
 * 
 *     # loop over reads
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":1220
 *     # 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":1221
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 * 
 */
    __pyx_t_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

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

    /* "pysamstats.pyx":1224
 *         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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":1225
 * 
 *         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 = ((__pyx_v_flag & 8) != 0);

    /* "pysamstats.pyx":1226
 *         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 = ((__pyx_v_aln->core.tid != __pyx_v_aln->core.mtid) != 0);

    /* "pysamstats.pyx":1230
 *         # 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_11 = __pyx_v_aln->core.isize;
    __pyx_v_tlen = __pyx_t_11;

    /* "pysamstats.pyx":1231
 *         # 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":1234
 * 
 *         # 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_13 = ((!(__pyx_v_mate_is_unmapped != 0)) != 0);
    if (__pyx_t_13) {
    } else {
      __pyx_t_12 = __pyx_t_13;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_13 = ((!(__pyx_v_mate_other_chr != 0)) != 0);
    __pyx_t_12 = __pyx_t_13;
    __pyx_L6_bool_binop_done:;
    if (__pyx_t_12) {

      /* "pysamstats.pyx":1235
 *         # 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":1236
 *         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":1237
 *             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":1238
 *             tlen_p_sum += tlen
 *             tlen_p_squared_sum += tlen_squared
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 reads_pp += 1
 *                 tlen_pp_sum += tlen
 */
      __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":1239
 *             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":1240
 *             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":1241
 *                 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_L8;
      }
      __pyx_L8:;
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

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

    /* "pysamstats.pyx":1245
 *     # calculate intermediate variables
 *     if reads_p > 0:
 *         tlen_p_mean = tlen_p_sum / reads_p             # <<<<<<<<<<<<<<
 *     if reads_pp > 0:
 *         tlen_pp_mean = tlen_pp_sum / reads_pp
 */
    if (unlikely(__pyx_v_reads_p == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_tlen_p_mean = (((double)__pyx_v_tlen_p_sum) / ((double)__pyx_v_reads_p));
    goto __pyx_L9;
  }
  __pyx_L9:;

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

    /* "pysamstats.pyx":1247
 *         tlen_p_mean = tlen_p_sum / reads_p
 *     if reads_pp > 0:
 *         tlen_pp_mean = tlen_pp_sum / reads_pp             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads again to calculate variance (and hence std)
 */
    if (unlikely(__pyx_v_reads_pp == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_tlen_pp_mean = (((double)__pyx_v_tlen_pp_sum) / ((double)__pyx_v_reads_pp));
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "pysamstats.pyx":1250
 * 
 *     # loop over reads again to calculate variance (and hence std)
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":1251
 *     # 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":1252
 *     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_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

    /* "pysamstats.pyx":1253
 *         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_10 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_10;

    /* "pysamstats.pyx":1254
 *         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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":1255
 *         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 = ((__pyx_v_flag & 8) != 0);

    /* "pysamstats.pyx":1256
 *         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 = ((__pyx_v_aln->core.tid != __pyx_v_aln->core.mtid) != 0);

    /* "pysamstats.pyx":1257
 *         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_11 = __pyx_v_aln->core.isize;
    __pyx_v_tlen = __pyx_t_11;

    /* "pysamstats.pyx":1259
 *         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 != 0)) != 0);
    if (__pyx_t_13) {
    } else {
      __pyx_t_12 = __pyx_t_13;
      goto __pyx_L14_bool_binop_done;
    }
    __pyx_t_13 = ((!(__pyx_v_mate_other_chr != 0)) != 0);
    __pyx_t_12 = __pyx_t_13;
    __pyx_L14_bool_binop_done:;
    if (__pyx_t_12) {

      /* "pysamstats.pyx":1260
 *         # 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":1261
 *         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":1262
 *             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
 */
      __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":1263
 *             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":1264
 *             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_L16;
      }
      __pyx_L16:;
      goto __pyx_L13;
    }
    __pyx_L13:;
  }

  /* "pysamstats.pyx":1269
 *     # 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 = _rootmean(tlen_p_squared_sum, reads_p)
 */
  __pyx_t_12 = ((__pyx_v_reads_p > 0) != 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":1270
 *     # interesting
 *     if reads_p > 0:
 *         mean_tlen = int(round(tlen_p_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen = _rootmean(tlen_p_squared_sum, reads_p)
 *         variance_tlen = tlen_p_dev_squared_sum / reads_p
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_tlen_p_mean); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_mean_tlen = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1271
 *     if reads_p > 0:
 *         mean_tlen = int(round(tlen_p_mean))
 *         rms_tlen = _rootmean(tlen_p_squared_sum, reads_p)             # <<<<<<<<<<<<<<
 *         variance_tlen = tlen_p_dev_squared_sum / reads_p
 *         std_tlen = int(round(sqrt(variance_tlen)))
 */
    __pyx_v_rms_tlen = __pyx_f_10pysamstats__rootmean(__pyx_v_tlen_p_squared_sum, __pyx_v_reads_p);

    /* "pysamstats.pyx":1272
 *         mean_tlen = int(round(tlen_p_mean))
 *         rms_tlen = _rootmean(tlen_p_squared_sum, reads_p)
 *         variance_tlen = tlen_p_dev_squared_sum / reads_p             # <<<<<<<<<<<<<<
 *         std_tlen = int(round(sqrt(variance_tlen)))
 *     else:
 */
    if (unlikely(__pyx_v_reads_p == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen = (__pyx_v_tlen_p_dev_squared_sum / ((double)__pyx_v_reads_p));

    /* "pysamstats.pyx":1273
 *         rms_tlen = _rootmean(tlen_p_squared_sum, reads_p)
 *         variance_tlen = tlen_p_dev_squared_sum / reads_p
 *         std_tlen = int(round(sqrt(variance_tlen)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen = std_tlen = mean_tlen = median_tlen = 0
 */
    __pyx_t_3 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_std_tlen = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L17;
  }
  /*else*/ {

    /* "pysamstats.pyx":1275
 *         std_tlen = int(round(sqrt(variance_tlen)))
 *     else:
 *         rms_tlen = std_tlen = mean_tlen = median_tlen = 0             # <<<<<<<<<<<<<<
 *     if reads_pp > 0:
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 */
    __pyx_v_rms_tlen = 0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_std_tlen = __pyx_int_0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_mean_tlen = __pyx_int_0;
    __pyx_v_median_tlen = 0;
  }
  __pyx_L17:;

  /* "pysamstats.pyx":1276
 *     else:
 *         rms_tlen = std_tlen = mean_tlen = median_tlen = 0
 *     if reads_pp > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 *         rms_tlen_pp = _rootmean(tlen_pp_squared_sum, reads_pp)
 */
  __pyx_t_12 = ((__pyx_v_reads_pp > 0) != 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":1277
 *         rms_tlen = std_tlen = mean_tlen = median_tlen = 0
 *     if reads_pp > 0:
 *         mean_tlen_pp = int(round(tlen_pp_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen_pp = _rootmean(tlen_pp_squared_sum, reads_pp)
 *         variance_tlen_pp = tlen_pp_dev_squared_sum / reads_pp
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_tlen_pp_mean); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_mean_tlen_pp = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1278
 *     if reads_pp > 0:
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 *         rms_tlen_pp = _rootmean(tlen_pp_squared_sum, reads_pp)             # <<<<<<<<<<<<<<
 *         variance_tlen_pp = tlen_pp_dev_squared_sum / reads_pp
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))
 */
    __pyx_v_rms_tlen_pp = __pyx_f_10pysamstats__rootmean(__pyx_v_tlen_pp_squared_sum, __pyx_v_reads_pp);

    /* "pysamstats.pyx":1279
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 *         rms_tlen_pp = _rootmean(tlen_pp_squared_sum, reads_pp)
 *         variance_tlen_pp = tlen_pp_dev_squared_sum / reads_pp             # <<<<<<<<<<<<<<
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))
 *     else:
 */
    if (unlikely(__pyx_v_reads_pp == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen_pp = (__pyx_v_tlen_pp_dev_squared_sum / ((double)__pyx_v_reads_pp));

    /* "pysamstats.pyx":1280
 *         rms_tlen_pp = _rootmean(tlen_pp_squared_sum, reads_pp)
 *         variance_tlen_pp = tlen_pp_dev_squared_sum / reads_pp
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 0
 */
    __pyx_t_3 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen_pp)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_std_tlen_pp = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L18;
  }
  /*else*/ {

    /* "pysamstats.pyx":1282
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))
 *     else:
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 0             # <<<<<<<<<<<<<<
 * 
 *     # if not PY2:
 */
    __pyx_v_rms_tlen_pp = 0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_std_tlen_pp = __pyx_int_0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_mean_tlen_pp = __pyx_int_0;
  }
  __pyx_L18:;

  /* "pysamstats.pyx":1286
 *     # if not PY2:
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1287
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_paired': reads_p,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1288
 *     return {'chrom': chrom,
 *             'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_paired': reads_p,
 *             'reads_pp': reads_pp,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1289
 *             'pos': pos,
 *             'reads_all': n,
 *             'reads_paired': reads_p,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp,
 *             'mean_tlen': mean_tlen,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_p); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_paired, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1290
 *             'reads_all': n,
 *             'reads_paired': reads_p,
 *             'reads_pp': reads_pp,             # <<<<<<<<<<<<<<
 *             'mean_tlen': mean_tlen,
 *             'mean_tlen_pp': mean_tlen_pp,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1291
 *             '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_1, __pyx_n_s_mean_tlen, __pyx_v_mean_tlen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1292
 *             '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_1, __pyx_n_s_mean_tlen_pp, __pyx_v_mean_tlen_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1293
 *             'mean_tlen': mean_tlen,
 *             'mean_tlen_pp': mean_tlen_pp,
 *             'rms_tlen': rms_tlen,             # <<<<<<<<<<<<<<
 *             'rms_tlen_pp': rms_tlen_pp,
 *             'std_tlen': std_tlen,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_tlen); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1294
 *             '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}
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_tlen_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1295
 *             '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_1, __pyx_n_s_std_tlen, __pyx_v_std_tlen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

  /* "pysamstats.pyx":1179
 * 
 * 
 * cpdef dict _rec_tlen(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                      bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._rec_tlen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_mean_tlen);
  __Pyx_XDECREF(__pyx_v_std_tlen);
  __Pyx_XDECREF(__pyx_v_mean_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_49_rec_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_48_rec_tlen[] = "_rec_tlen(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_49_rec_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_tlen (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_tlen", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __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("_rec_tlen", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __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, "_rec_tlen") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 1180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":1180
 * 
 * cpdef dict _rec_tlen(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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("_rec_tlen", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_tlen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_48_rec_tlen(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":1179
 * 
 * 
 * cpdef dict _rec_tlen(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                      bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_48_rec_tlen(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_tlen __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_tlen(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_tlen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1299
 * 
 * 
 * cpdef dict _rec_tlen_pad(FastaFile fafile, chrom, pos, bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */

static PyObject *__pyx_pw_10pysamstats_51_rec_tlen_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_tlen_pad(CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_tlen_pad *__pyx_optional_args) {
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_tlen_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":1300
 * 
 * cpdef dict _rec_tlen_pad(FastaFile fafile, chrom, pos, bint one_based=False):
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom,
 *             'pos': pos,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_2 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_1 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1301
 * cpdef dict _rec_tlen_pad(FastaFile fafile, chrom, pos, bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1302
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': 0,
 *             'reads_paired': 0,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_paired, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_mean_tlen, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_mean_tlen_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_std_tlen, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_std_tlen_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1299
 * 
 * 
 * cpdef dict _rec_tlen_pad(FastaFile fafile, chrom, pos, bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._rec_tlen_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_51_rec_tlen_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_50_rec_tlen_pad[] = "_rec_tlen_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_51_rec_tlen_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_tlen_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_tlen_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_tlen_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __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, "_rec_tlen_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 1299; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_tlen_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_tlen_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_50_rec_tlen_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

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

static PyObject *__pyx_pf_10pysamstats_50_rec_tlen_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_tlen_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_tlen_pad", 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__rec_tlen_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_tlen_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1315
 * 
 * 
 * def stat_tlen(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate insert size statistics per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_53stat_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_52stat_tlen[] = "stat_tlen(alignmentfile, **kwargs)\nGenerate insert size statistics per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_53stat_tlen = {"stat_tlen", (PyCFunction)__pyx_pw_10pysamstats_53stat_tlen, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_52stat_tlen};
static PyObject *__pyx_pw_10pysamstats_53stat_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_tlen") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1315; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_tlen", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1315; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_tlen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_52stat_tlen(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_52stat_tlen(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  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("stat_tlen", 0);

  /* "pysamstats.pyx":1346
 *     """
 * 
 *     return _iter_pileup(_rec_tlen, _rec_tlen_pad, alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_tlen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_tlen_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __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 = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1315
 * 
 * 
 * def stat_tlen(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate insert size statistics per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_tlen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1349
 * 
 * 
 * def load_tlen(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_tlen, dtype_tlen, *args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_55load_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_54load_tlen[] = "load_tlen(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_55load_tlen = {"load_tlen", (PyCFunction)__pyx_pw_10pysamstats_55load_tlen, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_54load_tlen};
static PyObject *__pyx_pw_10pysamstats_55load_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("load_tlen (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_54load_tlen(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_54load_tlen(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_tlen", 0);

  /* "pysamstats.pyx":1350
 * 
 * def load_tlen(*args, **kwargs):
 *     return _load_stats(stat_tlen, dtype_tlen, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_tlen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_tlen); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1349
 * 
 * 
 * def load_tlen(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_tlen, dtype_tlen, *args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_tlen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1394
 * 
 * 
 * cpdef dict _rec_tlen_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                             bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_57_rec_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_tlen_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_tlen_strand *__pyx_optional_args) {

  /* "pysamstats.pyx":1395
 * 
 * cpdef dict _rec_tlen_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  int __pyx_v_mate_other_chr;
  int __pyx_v_reads_fwd;
  int __pyx_v_reads_rev;
  int __pyx_v_reads_p;
  int __pyx_v_reads_p_fwd;
  int __pyx_v_reads_p_rev;
  int __pyx_v_reads_pp;
  int __pyx_v_reads_pp_fwd;
  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_n = NULL;
  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;
  long __pyx_v_rms_tlen;
  double __pyx_v_variance_tlen;
  PyObject *__pyx_v_std_tlen = NULL;
  PyObject *__pyx_v_mean_tlen_rev = NULL;
  long __pyx_v_rms_tlen_rev;
  double __pyx_v_variance_tlen_rev;
  PyObject *__pyx_v_std_tlen_rev = NULL;
  PyObject *__pyx_v_mean_tlen_fwd = NULL;
  long __pyx_v_rms_tlen_fwd;
  double __pyx_v_variance_tlen_fwd;
  PyObject *__pyx_v_std_tlen_fwd = NULL;
  PyObject *__pyx_v_mean_tlen_pp = NULL;
  long __pyx_v_rms_tlen_pp;
  double __pyx_v_variance_tlen_pp;
  PyObject *__pyx_v_std_tlen_pp = NULL;
  PyObject *__pyx_v_mean_tlen_pp_rev = NULL;
  long __pyx_v_rms_tlen_pp_rev;
  double __pyx_v_variance_tlen_pp_rev;
  PyObject *__pyx_v_std_tlen_pp_rev = NULL;
  PyObject *__pyx_v_mean_tlen_pp_fwd = NULL;
  long __pyx_v_rms_tlen_pp_fwd;
  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;
  bam_pileup1_t **__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  long __pyx_t_7;
  int __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  int __pyx_t_11;
  int32_t __pyx_t_12;
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":1409
 * 
 *     # counting variables
 *     cdef int reads_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_rev = 0
 *     # reads "paired", i.e., mate is mapped to same chromosome, so tlen is
 */
  __pyx_v_reads_fwd = 0;

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

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

  /* "pysamstats.pyx":1414
 *     # meaningful
 *     cdef int reads_p = 0
 *     cdef int reads_p_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_p_rev = 0
 *     # reads "properly paired", as defined by aligner
 */
  __pyx_v_reads_p_fwd = 0;

  /* "pysamstats.pyx":1415
 *     cdef int reads_p = 0
 *     cdef int reads_p_fwd = 0
 *     cdef int reads_p_rev = 0             # <<<<<<<<<<<<<<
 *     # reads "properly paired", as defined by aligner
 *     cdef int reads_pp = 0
 */
  __pyx_v_reads_p_rev = 0;

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

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

  /* "pysamstats.pyx":1419
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_fwd = 0
 *     cdef int reads_pp_rev = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int64_t tlen
 */
  __pyx_v_reads_pp_rev = 0;

  /* "pysamstats.pyx":1424
 *     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":1425
 * 
 *     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":1427
 *     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":1428
 *     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":1429
 *     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":1430
 *     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":1432
 *     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":1433
 *     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":1434
 *     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":1435
 *     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":1437
 *     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":1438
 *     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":1440
 *     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":1441
 * 
 *     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":1443
 *     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":1444
 *     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":1445
 *     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":1446
 *     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":1448
 *     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":1449
 *     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":1450
 *     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":1451
 *     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":1453
 *     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":1454
 *     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":1457
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":1461
 * 
 *     # get chromosome name and position
 *     chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":1465
 * 
 *     # loop over reads
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":1466
 *     # 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":1467
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 * 
 */
    __pyx_t_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

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

    /* "pysamstats.pyx":1470
 *         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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":1471
 * 
 *         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 = ((__pyx_v_flag & 16) != 0);

    /* "pysamstats.pyx":1472
 *         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 = ((__pyx_v_flag & 8) != 0);

    /* "pysamstats.pyx":1473
 *         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 = ((__pyx_v_aln->core.tid != __pyx_v_aln->core.mtid) != 0);

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

      /* "pysamstats.pyx":1477
 *         # 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":1479
 *             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":1483
 *         # 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_12 = __pyx_v_aln->core.isize;
    __pyx_v_tlen = __pyx_t_12;

    /* "pysamstats.pyx":1484
 *         # 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
 */
    __pyx_v_tlen_squared = __Pyx_pow_long(((long)__pyx_v_tlen), 2);

    /* "pysamstats.pyx":1488
 *         # 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_13 = ((!(__pyx_v_mate_is_unmapped != 0)) != 0);
    if (__pyx_t_13) {
    } else {
      __pyx_t_11 = __pyx_t_13;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_13 = ((!(__pyx_v_mate_other_chr != 0)) != 0);
    __pyx_t_11 = __pyx_t_13;
    __pyx_L7_bool_binop_done:;
    if (__pyx_t_11) {

      /* "pysamstats.pyx":1489
 *         # 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":1490
 *         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":1491
 *             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":1492
 *             tlen_p_sum += tlen
 *             tlen_p_squared_sum += tlen_squared
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_p_rev += 1
 *                 tlen_p_rev_sum += tlen
 */
      __pyx_t_11 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":1493
 *             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":1494
 *             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":1495
 *                 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_L9;
      }
      /*else*/ {

        /* "pysamstats.pyx":1497
 *                 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":1498
 *             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":1499
 *                 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_L9:;

      /* "pysamstats.pyx":1501
 *                 tlen_p_fwd_squared_sum += tlen_squared
 * 
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 reads_pp += 1
 *                 tlen_pp_sum += tlen
 */
      __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":1502
 * 
 *             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":1503
 *             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":1504
 *                 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":1505
 *                 tlen_pp_sum += tlen
 *                 tlen_pp_squared_sum += tlen_squared
 *                 if is_reverse:             # <<<<<<<<<<<<<<
 *                     reads_pp_rev += 1
 *                     tlen_pp_rev_sum += tlen
 */
        __pyx_t_11 = (__pyx_v_is_reverse != 0);
        if (__pyx_t_11) {

          /* "pysamstats.pyx":1506
 *                 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":1507
 *                 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":1508
 *                     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_L11;
        }
        /*else*/ {

          /* "pysamstats.pyx":1510
 *                     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":1511
 *                 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":1512
 *                     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_L11:;
        goto __pyx_L10;
      }
      __pyx_L10:;
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "pysamstats.pyx":1515
 * 
 *     # calculate intermediate variables
 *     if reads_p > 0:             # <<<<<<<<<<<<<<
 *         tlen_p_mean = tlen_p_sum / reads_p
 *         if reads_p_rev > 0:
 */
  __pyx_t_11 = ((__pyx_v_reads_p > 0) != 0);
  if (__pyx_t_11) {

    /* "pysamstats.pyx":1516
 *     # calculate intermediate variables
 *     if reads_p > 0:
 *         tlen_p_mean = tlen_p_sum / reads_p             # <<<<<<<<<<<<<<
 *         if reads_p_rev > 0:
 *             tlen_p_rev_mean = tlen_p_rev_sum / reads_p_rev
 */
    if (unlikely(__pyx_v_reads_p == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_tlen_p_mean = (((double)__pyx_v_tlen_p_sum) / ((double)__pyx_v_reads_p));

    /* "pysamstats.pyx":1517
 *     if reads_p > 0:
 *         tlen_p_mean = tlen_p_sum / reads_p
 *         if reads_p_rev > 0:             # <<<<<<<<<<<<<<
 *             tlen_p_rev_mean = tlen_p_rev_sum / reads_p_rev
 *         if reads_p_fwd > 0:
 */
    __pyx_t_11 = ((__pyx_v_reads_p_rev > 0) != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":1518
 *         tlen_p_mean = tlen_p_sum / reads_p
 *         if reads_p_rev > 0:
 *             tlen_p_rev_mean = tlen_p_rev_sum / reads_p_rev             # <<<<<<<<<<<<<<
 *         if reads_p_fwd > 0:
 *             tlen_p_fwd_mean = tlen_p_fwd_sum / reads_p_fwd
 */
      if (unlikely(__pyx_v_reads_p_rev == 0)) {
        #ifdef WITH_THREAD
        PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
        #endif
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        #ifdef WITH_THREAD
        PyGILState_Release(__pyx_gilstate_save);
        #endif
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_v_tlen_p_rev_mean = (((double)__pyx_v_tlen_p_rev_sum) / ((double)__pyx_v_reads_p_rev));
      goto __pyx_L13;
    }
    __pyx_L13:;

    /* "pysamstats.pyx":1519
 *         if reads_p_rev > 0:
 *             tlen_p_rev_mean = tlen_p_rev_sum / reads_p_rev
 *         if reads_p_fwd > 0:             # <<<<<<<<<<<<<<
 *             tlen_p_fwd_mean = tlen_p_fwd_sum / reads_p_fwd
 *     if reads_pp > 0:
 */
    __pyx_t_11 = ((__pyx_v_reads_p_fwd > 0) != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":1520
 *             tlen_p_rev_mean = tlen_p_rev_sum / reads_p_rev
 *         if reads_p_fwd > 0:
 *             tlen_p_fwd_mean = tlen_p_fwd_sum / reads_p_fwd             # <<<<<<<<<<<<<<
 *     if reads_pp > 0:
 *         tlen_pp_mean = tlen_pp_sum / reads_pp
 */
      if (unlikely(__pyx_v_reads_p_fwd == 0)) {
        #ifdef WITH_THREAD
        PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
        #endif
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        #ifdef WITH_THREAD
        PyGILState_Release(__pyx_gilstate_save);
        #endif
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_v_tlen_p_fwd_mean = (((double)__pyx_v_tlen_p_fwd_sum) / ((double)__pyx_v_reads_p_fwd));
      goto __pyx_L14;
    }
    __pyx_L14:;
    goto __pyx_L12;
  }
  __pyx_L12:;

  /* "pysamstats.pyx":1521
 *         if reads_p_fwd > 0:
 *             tlen_p_fwd_mean = tlen_p_fwd_sum / reads_p_fwd
 *     if reads_pp > 0:             # <<<<<<<<<<<<<<
 *         tlen_pp_mean = tlen_pp_sum / reads_pp
 *         if reads_pp_rev > 0:
 */
  __pyx_t_11 = ((__pyx_v_reads_pp > 0) != 0);
  if (__pyx_t_11) {

    /* "pysamstats.pyx":1522
 *             tlen_p_fwd_mean = tlen_p_fwd_sum / reads_p_fwd
 *     if reads_pp > 0:
 *         tlen_pp_mean = tlen_pp_sum / reads_pp             # <<<<<<<<<<<<<<
 *         if reads_pp_rev > 0:
 *             tlen_pp_rev_mean = tlen_pp_rev_sum / reads_pp_rev
 */
    if (unlikely(__pyx_v_reads_pp == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1522; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_tlen_pp_mean = (((double)__pyx_v_tlen_pp_sum) / ((double)__pyx_v_reads_pp));

    /* "pysamstats.pyx":1523
 *     if reads_pp > 0:
 *         tlen_pp_mean = tlen_pp_sum / reads_pp
 *         if reads_pp_rev > 0:             # <<<<<<<<<<<<<<
 *             tlen_pp_rev_mean = tlen_pp_rev_sum / reads_pp_rev
 *         if reads_pp_fwd > 0:
 */
    __pyx_t_11 = ((__pyx_v_reads_pp_rev > 0) != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":1524
 *         tlen_pp_mean = tlen_pp_sum / reads_pp
 *         if reads_pp_rev > 0:
 *             tlen_pp_rev_mean = tlen_pp_rev_sum / reads_pp_rev             # <<<<<<<<<<<<<<
 *         if reads_pp_fwd > 0:
 *             tlen_pp_fwd_mean = tlen_pp_fwd_sum / reads_pp_fwd
 */
      if (unlikely(__pyx_v_reads_pp_rev == 0)) {
        #ifdef WITH_THREAD
        PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
        #endif
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        #ifdef WITH_THREAD
        PyGILState_Release(__pyx_gilstate_save);
        #endif
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_v_tlen_pp_rev_mean = (((double)__pyx_v_tlen_pp_rev_sum) / ((double)__pyx_v_reads_pp_rev));
      goto __pyx_L16;
    }
    __pyx_L16:;

    /* "pysamstats.pyx":1525
 *         if reads_pp_rev > 0:
 *             tlen_pp_rev_mean = tlen_pp_rev_sum / reads_pp_rev
 *         if reads_pp_fwd > 0:             # <<<<<<<<<<<<<<
 *             tlen_pp_fwd_mean = tlen_pp_fwd_sum / reads_pp_fwd
 * 
 */
    __pyx_t_11 = ((__pyx_v_reads_pp_fwd > 0) != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":1526
 *             tlen_pp_rev_mean = tlen_pp_rev_sum / reads_pp_rev
 *         if reads_pp_fwd > 0:
 *             tlen_pp_fwd_mean = tlen_pp_fwd_sum / reads_pp_fwd             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads again to calculate variance (and hence std)
 */
      if (unlikely(__pyx_v_reads_pp_fwd == 0)) {
        #ifdef WITH_THREAD
        PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
        #endif
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        #ifdef WITH_THREAD
        PyGILState_Release(__pyx_gilstate_save);
        #endif
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_v_tlen_pp_fwd_mean = (((double)__pyx_v_tlen_pp_fwd_sum) / ((double)__pyx_v_reads_pp_fwd));
      goto __pyx_L17;
    }
    __pyx_L17:;
    goto __pyx_L15;
  }
  __pyx_L15:;

  /* "pysamstats.pyx":1529
 * 
 *     # loop over reads again to calculate variance (and hence std)
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":1530
 *     # 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":1531
 *     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_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

    /* "pysamstats.pyx":1532
 *         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_10 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_10;

    /* "pysamstats.pyx":1533
 *         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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":1534
 *         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 = ((__pyx_v_flag & 16) != 0);

    /* "pysamstats.pyx":1535
 *         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 = ((__pyx_v_flag & 8) != 0);

    /* "pysamstats.pyx":1536
 *         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
 */
    __pyx_v_mate_other_chr = ((__pyx_v_aln->core.tid != __pyx_v_aln->core.mtid) != 0);

    /* "pysamstats.pyx":1537
 *         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_t_12 = __pyx_v_aln->core.isize;
    __pyx_v_tlen = __pyx_t_12;

    /* "pysamstats.pyx":1540
 *         # 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 != 0)) != 0);
    if (__pyx_t_13) {
    } else {
      __pyx_t_11 = __pyx_t_13;
      goto __pyx_L21_bool_binop_done;
    }
    __pyx_t_13 = ((!(__pyx_v_mate_other_chr != 0)) != 0);
    __pyx_t_11 = __pyx_t_13;
    __pyx_L21_bool_binop_done:;
    if (__pyx_t_11) {

      /* "pysamstats.pyx":1541
 *         # 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":1542
 *         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":1543
 *             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
 */
      __pyx_t_11 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":1544
 *             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":1545
 *             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_L23;
      }
      /*else*/ {

        /* "pysamstats.pyx":1547
 *                 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":1548
 *             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_L23:;

      /* "pysamstats.pyx":1549
 *                 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
 */
      __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":1550
 *                 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":1551
 *             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":1552
 *                 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
 */
        __pyx_t_11 = (__pyx_v_is_reverse != 0);
        if (__pyx_t_11) {

          /* "pysamstats.pyx":1553
 *                 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":1554
 *                 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_L25;
        }
        /*else*/ {

          /* "pysamstats.pyx":1556
 *                     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":1557
 *                 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_L25:;
        goto __pyx_L24;
      }
      __pyx_L24:;
      goto __pyx_L20;
    }
    __pyx_L20:;
  }

  /* "pysamstats.pyx":1562
 *     # 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 = _rootmean(tlen_p_squared_sum, reads_p)
 */
  __pyx_t_11 = ((__pyx_v_reads_p > 0) != 0);
  if (__pyx_t_11) {

    /* "pysamstats.pyx":1563
 *     # interesting
 *     if reads_p > 0:
 *         mean_tlen = int(round(tlen_p_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen = _rootmean(tlen_p_squared_sum, reads_p)
 *         variance_tlen = tlen_p_dev_squared_sum / reads_p
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_tlen_p_mean); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_mean_tlen = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1564
 *     if reads_p > 0:
 *         mean_tlen = int(round(tlen_p_mean))
 *         rms_tlen = _rootmean(tlen_p_squared_sum, reads_p)             # <<<<<<<<<<<<<<
 *         variance_tlen = tlen_p_dev_squared_sum / reads_p
 *         std_tlen = int(round(sqrt(variance_tlen)))
 */
    __pyx_v_rms_tlen = __pyx_f_10pysamstats__rootmean(__pyx_v_tlen_p_squared_sum, __pyx_v_reads_p);

    /* "pysamstats.pyx":1565
 *         mean_tlen = int(round(tlen_p_mean))
 *         rms_tlen = _rootmean(tlen_p_squared_sum, reads_p)
 *         variance_tlen = tlen_p_dev_squared_sum / reads_p             # <<<<<<<<<<<<<<
 *         std_tlen = int(round(sqrt(variance_tlen)))
 *     else:
 */
    if (unlikely(__pyx_v_reads_p == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen = (__pyx_v_tlen_p_dev_squared_sum / ((double)__pyx_v_reads_p));

    /* "pysamstats.pyx":1566
 *         rms_tlen = _rootmean(tlen_p_squared_sum, reads_p)
 *         variance_tlen = tlen_p_dev_squared_sum / reads_p
 *         std_tlen = int(round(sqrt(variance_tlen)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen = std_tlen = mean_tlen = 0
 */
    __pyx_t_3 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_std_tlen = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L26;
  }
  /*else*/ {

    /* "pysamstats.pyx":1568
 *         std_tlen = int(round(sqrt(variance_tlen)))
 *     else:
 *         rms_tlen = std_tlen = mean_tlen = 0             # <<<<<<<<<<<<<<
 *     if reads_p_rev > 0:
 *         mean_tlen_rev = int(round(tlen_p_rev_mean))
 */
    __pyx_v_rms_tlen = 0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_std_tlen = __pyx_int_0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_mean_tlen = __pyx_int_0;
  }
  __pyx_L26:;

  /* "pysamstats.pyx":1569
 *     else:
 *         rms_tlen = std_tlen = mean_tlen = 0
 *     if reads_p_rev > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen_rev = int(round(tlen_p_rev_mean))
 *         rms_tlen_rev = _rootmean(tlen_p_rev_squared_sum, reads_p_rev)
 */
  __pyx_t_11 = ((__pyx_v_reads_p_rev > 0) != 0);
  if (__pyx_t_11) {

    /* "pysamstats.pyx":1570
 *         rms_tlen = std_tlen = mean_tlen = 0
 *     if reads_p_rev > 0:
 *         mean_tlen_rev = int(round(tlen_p_rev_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen_rev = _rootmean(tlen_p_rev_squared_sum, reads_p_rev)
 *         variance_tlen_rev = tlen_p_rev_dev_squared_sum / reads_p_rev
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_tlen_p_rev_mean); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_mean_tlen_rev = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1571
 *     if reads_p_rev > 0:
 *         mean_tlen_rev = int(round(tlen_p_rev_mean))
 *         rms_tlen_rev = _rootmean(tlen_p_rev_squared_sum, reads_p_rev)             # <<<<<<<<<<<<<<
 *         variance_tlen_rev = tlen_p_rev_dev_squared_sum / reads_p_rev
 *         std_tlen_rev = int(round(sqrt(variance_tlen_rev)))
 */
    __pyx_v_rms_tlen_rev = __pyx_f_10pysamstats__rootmean(__pyx_v_tlen_p_rev_squared_sum, __pyx_v_reads_p_rev);

    /* "pysamstats.pyx":1572
 *         mean_tlen_rev = int(round(tlen_p_rev_mean))
 *         rms_tlen_rev = _rootmean(tlen_p_rev_squared_sum, reads_p_rev)
 *         variance_tlen_rev = tlen_p_rev_dev_squared_sum / reads_p_rev             # <<<<<<<<<<<<<<
 *         std_tlen_rev = int(round(sqrt(variance_tlen_rev)))
 *     else:
 */
    if (unlikely(__pyx_v_reads_p_rev == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1572; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen_rev = (__pyx_v_tlen_p_rev_dev_squared_sum / ((double)__pyx_v_reads_p_rev));

    /* "pysamstats.pyx":1573
 *         rms_tlen_rev = _rootmean(tlen_p_rev_squared_sum, reads_p_rev)
 *         variance_tlen_rev = tlen_p_rev_dev_squared_sum / reads_p_rev
 *         std_tlen_rev = int(round(sqrt(variance_tlen_rev)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen_rev = std_tlen_rev = mean_tlen_rev = 0
 */
    __pyx_t_3 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen_rev)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_std_tlen_rev = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L27;
  }
  /*else*/ {

    /* "pysamstats.pyx":1575
 *         std_tlen_rev = int(round(sqrt(variance_tlen_rev)))
 *     else:
 *         rms_tlen_rev = std_tlen_rev = mean_tlen_rev = 0             # <<<<<<<<<<<<<<
 *     if reads_p_fwd > 0:
 *         mean_tlen_fwd = int(round(tlen_p_fwd_mean))
 */
    __pyx_v_rms_tlen_rev = 0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_std_tlen_rev = __pyx_int_0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_mean_tlen_rev = __pyx_int_0;
  }
  __pyx_L27:;

  /* "pysamstats.pyx":1576
 *     else:
 *         rms_tlen_rev = std_tlen_rev = mean_tlen_rev = 0
 *     if reads_p_fwd > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen_fwd = int(round(tlen_p_fwd_mean))
 *         rms_tlen_fwd = _rootmean(tlen_p_fwd_squared_sum, reads_p_fwd)
 */
  __pyx_t_11 = ((__pyx_v_reads_p_fwd > 0) != 0);
  if (__pyx_t_11) {

    /* "pysamstats.pyx":1577
 *         rms_tlen_rev = std_tlen_rev = mean_tlen_rev = 0
 *     if reads_p_fwd > 0:
 *         mean_tlen_fwd = int(round(tlen_p_fwd_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen_fwd = _rootmean(tlen_p_fwd_squared_sum, reads_p_fwd)
 *         variance_tlen_fwd = tlen_p_fwd_dev_squared_sum / reads_p_fwd
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_tlen_p_fwd_mean); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_mean_tlen_fwd = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1578
 *     if reads_p_fwd > 0:
 *         mean_tlen_fwd = int(round(tlen_p_fwd_mean))
 *         rms_tlen_fwd = _rootmean(tlen_p_fwd_squared_sum, reads_p_fwd)             # <<<<<<<<<<<<<<
 *         variance_tlen_fwd = tlen_p_fwd_dev_squared_sum / reads_p_fwd
 *         std_tlen_fwd = int(round(sqrt(variance_tlen_fwd)))
 */
    __pyx_v_rms_tlen_fwd = __pyx_f_10pysamstats__rootmean(__pyx_v_tlen_p_fwd_squared_sum, __pyx_v_reads_p_fwd);

    /* "pysamstats.pyx":1579
 *         mean_tlen_fwd = int(round(tlen_p_fwd_mean))
 *         rms_tlen_fwd = _rootmean(tlen_p_fwd_squared_sum, reads_p_fwd)
 *         variance_tlen_fwd = tlen_p_fwd_dev_squared_sum / reads_p_fwd             # <<<<<<<<<<<<<<
 *         std_tlen_fwd = int(round(sqrt(variance_tlen_fwd)))
 *     else:
 */
    if (unlikely(__pyx_v_reads_p_fwd == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen_fwd = (__pyx_v_tlen_p_fwd_dev_squared_sum / ((double)__pyx_v_reads_p_fwd));

    /* "pysamstats.pyx":1580
 *         rms_tlen_fwd = _rootmean(tlen_p_fwd_squared_sum, reads_p_fwd)
 *         variance_tlen_fwd = tlen_p_fwd_dev_squared_sum / reads_p_fwd
 *         std_tlen_fwd = int(round(sqrt(variance_tlen_fwd)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen_fwd = std_tlen_fwd = mean_tlen_fwd = 0
 */
    __pyx_t_3 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen_fwd)); 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_t_1 = PyTuple_New(1); 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);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_1, 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_t_1 = PyNumber_Int(__pyx_t_3); 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_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_std_tlen_fwd = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L28;
  }
  /*else*/ {

    /* "pysamstats.pyx":1582
 *         std_tlen_fwd = int(round(sqrt(variance_tlen_fwd)))
 *     else:
 *         rms_tlen_fwd = std_tlen_fwd = mean_tlen_fwd = 0             # <<<<<<<<<<<<<<
 *     if reads_pp > 0:
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 */
    __pyx_v_rms_tlen_fwd = 0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_std_tlen_fwd = __pyx_int_0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_mean_tlen_fwd = __pyx_int_0;
  }
  __pyx_L28:;

  /* "pysamstats.pyx":1583
 *     else:
 *         rms_tlen_fwd = std_tlen_fwd = mean_tlen_fwd = 0
 *     if reads_pp > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 *         rms_tlen_pp = _rootmean(tlen_pp_squared_sum, reads_pp)
 */
  __pyx_t_11 = ((__pyx_v_reads_pp > 0) != 0);
  if (__pyx_t_11) {

    /* "pysamstats.pyx":1584
 *         rms_tlen_fwd = std_tlen_fwd = mean_tlen_fwd = 0
 *     if reads_pp > 0:
 *         mean_tlen_pp = int(round(tlen_pp_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen_pp = _rootmean(tlen_pp_squared_sum, reads_pp)
 *         variance_tlen_pp = tlen_pp_dev_squared_sum / reads_pp
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_tlen_pp_mean); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_mean_tlen_pp = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1585
 *     if reads_pp > 0:
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 *         rms_tlen_pp = _rootmean(tlen_pp_squared_sum, reads_pp)             # <<<<<<<<<<<<<<
 *         variance_tlen_pp = tlen_pp_dev_squared_sum / reads_pp
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))
 */
    __pyx_v_rms_tlen_pp = __pyx_f_10pysamstats__rootmean(__pyx_v_tlen_pp_squared_sum, __pyx_v_reads_pp);

    /* "pysamstats.pyx":1586
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 *         rms_tlen_pp = _rootmean(tlen_pp_squared_sum, reads_pp)
 *         variance_tlen_pp = tlen_pp_dev_squared_sum / reads_pp             # <<<<<<<<<<<<<<
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))
 *     else:
 */
    if (unlikely(__pyx_v_reads_pp == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen_pp = (__pyx_v_tlen_pp_dev_squared_sum / ((double)__pyx_v_reads_pp));

    /* "pysamstats.pyx":1587
 *         rms_tlen_pp = _rootmean(tlen_pp_squared_sum, reads_pp)
 *         variance_tlen_pp = tlen_pp_dev_squared_sum / reads_pp
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 0
 */
    __pyx_t_3 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen_pp)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_std_tlen_pp = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L29;
  }
  /*else*/ {

    /* "pysamstats.pyx":1589
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))
 *     else:
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 0             # <<<<<<<<<<<<<<
 *     if reads_pp_rev > 0:
 *         mean_tlen_pp_rev = int(round(tlen_pp_rev_mean))
 */
    __pyx_v_rms_tlen_pp = 0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_std_tlen_pp = __pyx_int_0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_mean_tlen_pp = __pyx_int_0;
  }
  __pyx_L29:;

  /* "pysamstats.pyx":1590
 *     else:
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 0
 *     if reads_pp_rev > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen_pp_rev = int(round(tlen_pp_rev_mean))
 *         rms_tlen_pp_rev = _rootmean(tlen_pp_rev_squared_sum, reads_pp_rev)
 */
  __pyx_t_11 = ((__pyx_v_reads_pp_rev > 0) != 0);
  if (__pyx_t_11) {

    /* "pysamstats.pyx":1591
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 0
 *     if reads_pp_rev > 0:
 *         mean_tlen_pp_rev = int(round(tlen_pp_rev_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen_pp_rev = _rootmean(tlen_pp_rev_squared_sum, reads_pp_rev)
 *         variance_tlen_pp_rev = tlen_pp_rev_dev_squared_sum / reads_pp_rev
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_tlen_pp_rev_mean); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_mean_tlen_pp_rev = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1592
 *     if reads_pp_rev > 0:
 *         mean_tlen_pp_rev = int(round(tlen_pp_rev_mean))
 *         rms_tlen_pp_rev = _rootmean(tlen_pp_rev_squared_sum, reads_pp_rev)             # <<<<<<<<<<<<<<
 *         variance_tlen_pp_rev = tlen_pp_rev_dev_squared_sum / reads_pp_rev
 *         std_tlen_pp_rev = int(round(sqrt(variance_tlen_pp_rev)))
 */
    __pyx_v_rms_tlen_pp_rev = __pyx_f_10pysamstats__rootmean(__pyx_v_tlen_pp_rev_squared_sum, __pyx_v_reads_pp_rev);

    /* "pysamstats.pyx":1593
 *         mean_tlen_pp_rev = int(round(tlen_pp_rev_mean))
 *         rms_tlen_pp_rev = _rootmean(tlen_pp_rev_squared_sum, reads_pp_rev)
 *         variance_tlen_pp_rev = tlen_pp_rev_dev_squared_sum / reads_pp_rev             # <<<<<<<<<<<<<<
 *         std_tlen_pp_rev = int(round(sqrt(variance_tlen_pp_rev)))
 *     else:
 */
    if (unlikely(__pyx_v_reads_pp_rev == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen_pp_rev = (__pyx_v_tlen_pp_rev_dev_squared_sum / ((double)__pyx_v_reads_pp_rev));

    /* "pysamstats.pyx":1594
 *         rms_tlen_pp_rev = _rootmean(tlen_pp_rev_squared_sum, reads_pp_rev)
 *         variance_tlen_pp_rev = tlen_pp_rev_dev_squared_sum / 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 = 0
 */
    __pyx_t_3 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen_pp_rev)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_std_tlen_pp_rev = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L30;
  }
  /*else*/ {

    /* "pysamstats.pyx":1596
 *         std_tlen_pp_rev = int(round(sqrt(variance_tlen_pp_rev)))
 *     else:
 *         rms_tlen_pp_rev = std_tlen_pp_rev = mean_tlen_pp_rev = 0             # <<<<<<<<<<<<<<
 *     if reads_pp_fwd > 0:
 *         mean_tlen_pp_fwd = int(round(tlen_pp_fwd_mean))
 */
    __pyx_v_rms_tlen_pp_rev = 0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_std_tlen_pp_rev = __pyx_int_0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_mean_tlen_pp_rev = __pyx_int_0;
  }
  __pyx_L30:;

  /* "pysamstats.pyx":1597
 *     else:
 *         rms_tlen_pp_rev = std_tlen_pp_rev = mean_tlen_pp_rev = 0
 *     if reads_pp_fwd > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen_pp_fwd = int(round(tlen_pp_fwd_mean))
 *         rms_tlen_pp_fwd = _rootmean(tlen_pp_fwd_squared_sum, reads_pp_fwd)
 */
  __pyx_t_11 = ((__pyx_v_reads_pp_fwd > 0) != 0);
  if (__pyx_t_11) {

    /* "pysamstats.pyx":1598
 *         rms_tlen_pp_rev = std_tlen_pp_rev = mean_tlen_pp_rev = 0
 *     if reads_pp_fwd > 0:
 *         mean_tlen_pp_fwd = int(round(tlen_pp_fwd_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen_pp_fwd = _rootmean(tlen_pp_fwd_squared_sum, reads_pp_fwd)
 *         variance_tlen_pp_fwd = tlen_pp_fwd_dev_squared_sum / reads_pp_fwd
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_tlen_pp_fwd_mean); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_mean_tlen_pp_fwd = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1599
 *     if reads_pp_fwd > 0:
 *         mean_tlen_pp_fwd = int(round(tlen_pp_fwd_mean))
 *         rms_tlen_pp_fwd = _rootmean(tlen_pp_fwd_squared_sum, reads_pp_fwd)             # <<<<<<<<<<<<<<
 *         variance_tlen_pp_fwd = tlen_pp_fwd_dev_squared_sum / reads_pp_fwd
 *         std_tlen_pp_fwd = int(round(sqrt(variance_tlen_pp_fwd)))
 */
    __pyx_v_rms_tlen_pp_fwd = __pyx_f_10pysamstats__rootmean(__pyx_v_tlen_pp_fwd_squared_sum, __pyx_v_reads_pp_fwd);

    /* "pysamstats.pyx":1600
 *         mean_tlen_pp_fwd = int(round(tlen_pp_fwd_mean))
 *         rms_tlen_pp_fwd = _rootmean(tlen_pp_fwd_squared_sum, reads_pp_fwd)
 *         variance_tlen_pp_fwd = tlen_pp_fwd_dev_squared_sum / reads_pp_fwd             # <<<<<<<<<<<<<<
 *         std_tlen_pp_fwd = int(round(sqrt(variance_tlen_pp_fwd)))
 *     else:
 */
    if (unlikely(__pyx_v_reads_pp_fwd == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen_pp_fwd = (__pyx_v_tlen_pp_fwd_dev_squared_sum / ((double)__pyx_v_reads_pp_fwd));

    /* "pysamstats.pyx":1601
 *         rms_tlen_pp_fwd = _rootmean(tlen_pp_fwd_squared_sum, reads_pp_fwd)
 *         variance_tlen_pp_fwd = tlen_pp_fwd_dev_squared_sum / 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 = 0
 */
    __pyx_t_3 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen_pp_fwd)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_std_tlen_pp_fwd = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L31;
  }
  /*else*/ {

    /* "pysamstats.pyx":1603
 *         std_tlen_pp_fwd = int(round(sqrt(variance_tlen_pp_fwd)))
 *     else:
 *         rms_tlen_pp_fwd = std_tlen_pp_fwd = mean_tlen_pp_fwd = 0             # <<<<<<<<<<<<<<
 * 
 *     # if not PY2:
 */
    __pyx_v_rms_tlen_pp_fwd = 0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_std_tlen_pp_fwd = __pyx_int_0;
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_mean_tlen_pp_fwd = __pyx_int_0;
  }
  __pyx_L31:;

  /* "pysamstats.pyx":1607
 *     # if not PY2:
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1608
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1609
 *     return {'chrom': chrom,
 *             'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1610
 *             'pos': pos,
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,             # <<<<<<<<<<<<<<
 *             'reads_rev': reads_rev,
 *             'reads_paired': reads_p,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1611
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,             # <<<<<<<<<<<<<<
 *             'reads_paired': reads_p,
 *             'reads_paired_fwd': reads_p_fwd,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1612
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,
 *             'reads_paired': reads_p,             # <<<<<<<<<<<<<<
 *             'reads_paired_fwd': reads_p_fwd,
 *             'reads_paired_rev': reads_p_rev,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_p); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_paired, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1613
 *             'reads_rev': reads_rev,
 *             'reads_paired': reads_p,
 *             'reads_paired_fwd': reads_p_fwd,             # <<<<<<<<<<<<<<
 *             'reads_paired_rev': reads_p_rev,
 *             'reads_pp': reads_pp,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_p_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_paired_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1614
 *             'reads_paired': reads_p,
 *             'reads_paired_fwd': reads_p_fwd,
 *             'reads_paired_rev': reads_p_rev,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_p_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_paired_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1615
 *             'reads_paired_fwd': reads_p_fwd,
 *             'reads_paired_rev': reads_p_rev,
 *             'reads_pp': reads_pp,             # <<<<<<<<<<<<<<
 *             'reads_pp_fwd': reads_pp_fwd,
 *             'reads_pp_rev': reads_pp_rev,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1616
 *             'reads_paired_rev': reads_p_rev,
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,             # <<<<<<<<<<<<<<
 *             'reads_pp_rev': reads_pp_rev,
 *             'mean_tlen': mean_tlen,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1616; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1617
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,
 *             'reads_pp_rev': reads_pp_rev,             # <<<<<<<<<<<<<<
 *             'mean_tlen': mean_tlen,
 *             'mean_tlen_fwd': mean_tlen_fwd,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1618
 *             '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_1, __pyx_n_s_mean_tlen, __pyx_v_mean_tlen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1619
 *             '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_1, __pyx_n_s_mean_tlen_fwd, __pyx_v_mean_tlen_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1620
 *             '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_1, __pyx_n_s_mean_tlen_rev, __pyx_v_mean_tlen_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1621
 *             '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_1, __pyx_n_s_mean_tlen_pp, __pyx_v_mean_tlen_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1622
 *             '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_1, __pyx_n_s_mean_tlen_pp_fwd, __pyx_v_mean_tlen_pp_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1623
 *             '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_1, __pyx_n_s_mean_tlen_pp_rev, __pyx_v_mean_tlen_pp_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1624
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_tlen); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1625
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_tlen_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1626
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_tlen_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1627
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_tlen_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1628
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_tlen_pp_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_pp_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1629
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_tlen_pp_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_pp_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1630
 *             '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_1, __pyx_n_s_std_tlen, __pyx_v_std_tlen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1631
 *             '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_1, __pyx_n_s_std_tlen_fwd, __pyx_v_std_tlen_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1632
 *             '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_1, __pyx_n_s_std_tlen_rev, __pyx_v_std_tlen_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1633
 *             '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_1, __pyx_n_s_std_tlen_pp, __pyx_v_std_tlen_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1634
 *             '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_1, __pyx_n_s_std_tlen_pp_fwd, __pyx_v_std_tlen_pp_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1635
 *             '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_1, __pyx_n_s_std_tlen_pp_rev, __pyx_v_std_tlen_pp_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1394
 * 
 * 
 * cpdef dict _rec_tlen_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                             bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._rec_tlen_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_mean_tlen);
  __Pyx_XDECREF(__pyx_v_std_tlen);
  __Pyx_XDECREF(__pyx_v_mean_tlen_rev);
  __Pyx_XDECREF(__pyx_v_std_tlen_rev);
  __Pyx_XDECREF(__pyx_v_mean_tlen_fwd);
  __Pyx_XDECREF(__pyx_v_std_tlen_fwd);
  __Pyx_XDECREF(__pyx_v_mean_tlen_pp);
  __Pyx_XDECREF(__pyx_v_std_tlen_pp);
  __Pyx_XDECREF(__pyx_v_mean_tlen_pp_rev);
  __Pyx_XDECREF(__pyx_v_std_tlen_pp_rev);
  __Pyx_XDECREF(__pyx_v_mean_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_57_rec_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_56_rec_tlen_strand[] = "_rec_tlen_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_57_rec_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_tlen_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_tlen_strand", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __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("_rec_tlen_strand", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __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, "_rec_tlen_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 1395; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":1395
 * 
 * cpdef dict _rec_tlen_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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("_rec_tlen_strand", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._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_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_56_rec_tlen_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":1394
 * 
 * 
 * cpdef dict _rec_tlen_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                             bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_56_rec_tlen_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_tlen_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_tlen_strand(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_tlen_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1638
 * 
 * 
 * cpdef dict _rec_tlen_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                 bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

static PyObject *__pyx_pw_10pysamstats_59_rec_tlen_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_tlen_strand_pad(CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_tlen_strand_pad *__pyx_optional_args) {

  /* "pysamstats.pyx":1639
 * 
 * cpdef dict _rec_tlen_strand_pad(FastaFile fafile, chrom, pos,
 *                                 bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_tlen_strand_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":1640
 * cpdef dict _rec_tlen_strand_pad(FastaFile fafile, chrom, pos,
 *                                 bint one_based=False):
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom,
 *             'pos': pos,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_2 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_1 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1641
 *                                 bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1642
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': 0,
 *             'reads_fwd': 0,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_paired, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_paired_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_paired_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_mean_tlen, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_mean_tlen_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_mean_tlen_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_mean_tlen_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_mean_tlen_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_mean_tlen_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_std_tlen, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_std_tlen_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_std_tlen_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_std_tlen_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_std_tlen_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_std_tlen_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1638
 * 
 * 
 * cpdef dict _rec_tlen_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                 bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._rec_tlen_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_59_rec_tlen_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_58_rec_tlen_strand_pad[] = "_rec_tlen_strand_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_59_rec_tlen_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_tlen_strand_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_tlen_strand_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1638; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_tlen_strand_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1638; __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, "_rec_tlen_strand_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1638; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 1639; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":1639
 * 
 * cpdef dict _rec_tlen_strand_pad(FastaFile fafile, chrom, pos,
 *                                 bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_tlen_strand_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1638; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_tlen_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_58_rec_tlen_strand_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

  /* "pysamstats.pyx":1638
 * 
 * 
 * cpdef dict _rec_tlen_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                 bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

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

static PyObject *__pyx_pf_10pysamstats_58_rec_tlen_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_tlen_strand_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_tlen_strand_pad", 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__rec_tlen_strand_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_tlen_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1673
 * 
 * 
 * def stat_tlen_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate insert size statistics by strand per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_61stat_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_60stat_tlen_strand[] = "stat_tlen_strand(alignmentfile, **kwargs)\nGenerate insert size statistics by strand per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_61stat_tlen_strand = {"stat_tlen_strand", (PyCFunction)__pyx_pw_10pysamstats_61stat_tlen_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_60stat_tlen_strand};
static PyObject *__pyx_pw_10pysamstats_61stat_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_tlen_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1673; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_tlen_strand", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1673; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_tlen_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_60stat_tlen_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_60stat_tlen_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  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("stat_tlen_strand", 0);

  /* "pysamstats.pyx":1704
 *     """
 * 
 *     return _iter_pileup(_rec_tlen_strand, _rec_tlen_strand_pad, alignmentfile,             # <<<<<<<<<<<<<<
 *                         **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_tlen_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_tlen_strand_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1704; __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 = 1704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":1705
 * 
 *     return _iter_pileup(_rec_tlen_strand, _rec_tlen_strand_pad, alignmentfile,
 *                         **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":1704
 *     """
 * 
 *     return _iter_pileup(_rec_tlen_strand, _rec_tlen_strand_pad, alignmentfile,             # <<<<<<<<<<<<<<
 *                         **kwargs)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1673
 * 
 * 
 * def stat_tlen_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate insert size statistics by strand per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_tlen_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1708
 * 
 * 
 * def load_tlen_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_tlen_strand, dtype_tlen_strand, *args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_63load_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_62load_tlen_strand[] = "load_tlen_strand(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_63load_tlen_strand = {"load_tlen_strand", (PyCFunction)__pyx_pw_10pysamstats_63load_tlen_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_62load_tlen_strand};
static PyObject *__pyx_pw_10pysamstats_63load_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("load_tlen_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_62load_tlen_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_62load_tlen_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_tlen_strand", 0);

  /* "pysamstats.pyx":1709
 * 
 * def load_tlen_strand(*args, **kwargs):
 *     return _load_stats(stat_tlen_strand, dtype_tlen_strand, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_tlen_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_tlen_strand); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __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_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1708
 * 
 * 
 * def load_tlen_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_tlen_strand, dtype_tlen_strand, *args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_tlen_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1734
 * 
 * 
 * cpdef dict _rec_mapq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                      bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_65_rec_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_mapq(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_mapq *__pyx_optional_args) {

  /* "pysamstats.pyx":1735
 * 
 * cpdef dict _rec_mapq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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;
  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;
  int __pyx_v_reads_pp;
  int __pyx_v_reads_mapq0;
  int __pyx_v_reads_mapq0_pp;
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  int __pyx_v_rms_mapq;
  uint64_t __pyx_v_max_mapq;
  long __pyx_v_rms_mapq_pp;
  uint64_t __pyx_v_max_mapq_pp;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  bam_pileup1_t **__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  long __pyx_t_7;
  int __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  uint8_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":1745
 *     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":1746
 *     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":1748
 *     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":1749
 *     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 int reads_pp = 0
 */
  __pyx_v_mapq_pp_squared_sum = 0;

  /* "pysamstats.pyx":1751
 *     cdef uint64_t mapq_pp_squared_sum = 0
 *     cdef bint is_proper_pair
 *     cdef int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_mapq0 = 0
 *     cdef int reads_mapq0_pp = 0
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":1752
 *     cdef bint is_proper_pair
 *     cdef int reads_pp = 0
 *     cdef int reads_mapq0 = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_mapq0_pp = 0
 * 
 */
  __pyx_v_reads_mapq0 = 0;

  /* "pysamstats.pyx":1753
 *     cdef int reads_pp = 0
 *     cdef int reads_mapq0 = 0
 *     cdef int reads_mapq0_pp = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_reads_mapq0_pp = 0;

  /* "pysamstats.pyx":1756
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":1760
 * 
 *     # get chromosome name and position
 *     chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1761
 *     # get chromosome name and position
 *     chrom = alignmentfile.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 != 0)) {
    __pyx_t_7 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_7 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_7;

  /* "pysamstats.pyx":1764
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":1765
 *     # 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":1766
 *     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_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

    /* "pysamstats.pyx":1767
 *         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_10 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_10;

    /* "pysamstats.pyx":1768
 *         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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":1769
 *         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_11 = __pyx_v_aln->core.qual;
    __pyx_v_mapq = __pyx_t_11;

    /* "pysamstats.pyx":1770
 *         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":1771
 *         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":1772
 *         mapq_squared = mapq**2
 *         mapq_squared_sum += mapq_squared
 *         if mapq == 0:             # <<<<<<<<<<<<<<
 *             reads_mapq0 += 1
 *         if mapq > mapq_max:
 */
    __pyx_t_12 = ((__pyx_v_mapq == 0) != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":1773
 *         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":1774
 *         if mapq == 0:
 *             reads_mapq0 += 1
 *         if mapq > mapq_max:             # <<<<<<<<<<<<<<
 *             mapq_max = mapq
 *         if is_proper_pair:
 */
    __pyx_t_12 = ((__pyx_v_mapq > __pyx_v_mapq_max) != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":1775
 *             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":1776
 *         if mapq > mapq_max:
 *             mapq_max = mapq
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *             mapq_pp_squared_sum += mapq_squared
 */
    __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":1777
 *             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":1778
 *         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":1779
 *             reads_pp += 1
 *             mapq_pp_squared_sum += mapq_squared
 *             if mapq > mapq_pp_max:             # <<<<<<<<<<<<<<
 *                 mapq_pp_max = mapq
 *             if mapq == 0:
 */
      __pyx_t_12 = ((__pyx_v_mapq > __pyx_v_mapq_pp_max) != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":1780
 *             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":1781
 *             if mapq > mapq_pp_max:
 *                 mapq_pp_max = mapq
 *             if mapq == 0:             # <<<<<<<<<<<<<<
 *                 reads_mapq0_pp += 1
 * 
 */
      __pyx_t_12 = ((__pyx_v_mapq == 0) != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":1782
 *                 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":1785
 * 
 *     # construct output variables
 *     rms_mapq = _rootmean(mapq_squared_sum, n)             # <<<<<<<<<<<<<<
 *     max_mapq = mapq_max
 *     if reads_pp > 0:
 */
  __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_n); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_rms_mapq = __pyx_f_10pysamstats__rootmean(__pyx_v_mapq_squared_sum, __pyx_t_8);

  /* "pysamstats.pyx":1786
 *     # construct output variables
 *     rms_mapq = _rootmean(mapq_squared_sum, n)
 *     max_mapq = mapq_max             # <<<<<<<<<<<<<<
 *     if reads_pp > 0:
 *         rms_mapq_pp = _rootmean(mapq_pp_squared_sum, reads_pp)
 */
  __pyx_v_max_mapq = __pyx_v_mapq_max;

  /* "pysamstats.pyx":1787
 *     rms_mapq = _rootmean(mapq_squared_sum, n)
 *     max_mapq = mapq_max
 *     if reads_pp > 0:             # <<<<<<<<<<<<<<
 *         rms_mapq_pp = _rootmean(mapq_pp_squared_sum, reads_pp)
 *         max_mapq_pp = mapq_pp_max
 */
  __pyx_t_12 = ((__pyx_v_reads_pp > 0) != 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":1788
 *     max_mapq = mapq_max
 *     if reads_pp > 0:
 *         rms_mapq_pp = _rootmean(mapq_pp_squared_sum, reads_pp)             # <<<<<<<<<<<<<<
 *         max_mapq_pp = mapq_pp_max
 *     else:
 */
    __pyx_v_rms_mapq_pp = __pyx_f_10pysamstats__rootmean(__pyx_v_mapq_pp_squared_sum, __pyx_v_reads_pp);

    /* "pysamstats.pyx":1789
 *     if reads_pp > 0:
 *         rms_mapq_pp = _rootmean(mapq_pp_squared_sum, reads_pp)
 *         max_mapq_pp = mapq_pp_max             # <<<<<<<<<<<<<<
 *     else:
 *         rms_mapq_pp = max_mapq_pp = 0
 */
    __pyx_v_max_mapq_pp = __pyx_v_mapq_pp_max;
    goto __pyx_L10;
  }
  /*else*/ {

    /* "pysamstats.pyx":1791
 *         max_mapq_pp = mapq_pp_max
 *     else:
 *         rms_mapq_pp = max_mapq_pp = 0             # <<<<<<<<<<<<<<
 * 
 *     # if not PY2:
 */
    __pyx_v_rms_mapq_pp = 0;
    __pyx_v_max_mapq_pp = 0;
  }
  __pyx_L10:;

  /* "pysamstats.pyx":1795
 *     # if not PY2:
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1796
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_pp': reads_pp,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1797
 *     return {'chrom': chrom,
 *             'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp,
 *             'reads_mapq0': reads_mapq0,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1798
 *             'pos': pos,
 *             'reads_all': n,
 *             'reads_pp': reads_pp,             # <<<<<<<<<<<<<<
 *             'reads_mapq0': reads_mapq0,
 *             'reads_mapq0_pp': reads_mapq0_pp,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1799
 *             'reads_all': n,
 *             'reads_pp': reads_pp,
 *             'reads_mapq0': reads_mapq0,             # <<<<<<<<<<<<<<
 *             'reads_mapq0_pp': reads_mapq0_pp,
 *             'rms_mapq': rms_mapq,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_mapq0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1800
 *             '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_3 = __Pyx_PyInt_From_int(__pyx_v_reads_mapq0_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1801
 *             'reads_mapq0': reads_mapq0,
 *             'reads_mapq0_pp': reads_mapq0_pp,
 *             'rms_mapq': rms_mapq,             # <<<<<<<<<<<<<<
 *             'rms_mapq_pp': rms_mapq_pp,
 *             'max_mapq': max_mapq,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_rms_mapq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1802
 *             '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}
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_mapq_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1803
 *             'rms_mapq': rms_mapq,
 *             'rms_mapq_pp': rms_mapq_pp,
 *             'max_mapq': max_mapq,             # <<<<<<<<<<<<<<
 *             'max_mapq_pp': max_mapq_pp}
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_uint64_t(__pyx_v_max_mapq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":1804
 *             'rms_mapq_pp': rms_mapq_pp,
 *             'max_mapq': max_mapq,
 *             'max_mapq_pp': max_mapq_pp}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_uint64_t(__pyx_v_max_mapq_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1734
 * 
 * 
 * cpdef dict _rec_mapq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                      bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._rec_mapq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_65_rec_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_64_rec_mapq[] = "_rec_mapq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_65_rec_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_mapq (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_mapq", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __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("_rec_mapq", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __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, "_rec_mapq") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 1735; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":1735
 * 
 * cpdef dict _rec_mapq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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("_rec_mapq", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_mapq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_64_rec_mapq(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":1734
 * 
 * 
 * cpdef dict _rec_mapq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                      bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_64_rec_mapq(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_mapq __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_mapq(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_mapq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1807
 * 
 * 
 * cpdef dict _rec_mapq_pad(FastaFile fafile, chrom, pos, bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */

static PyObject *__pyx_pw_10pysamstats_67_rec_mapq_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_mapq_pad(CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_mapq_pad *__pyx_optional_args) {
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_mapq_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":1808
 * 
 * cpdef dict _rec_mapq_pad(FastaFile fafile, chrom, pos, bint one_based=False):
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom,
 *             'pos': pos,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_2 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_1 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1809
 * cpdef dict _rec_mapq_pad(FastaFile fafile, chrom, pos, bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1810
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': 0,
 *             'reads_pp': 0,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1807
 * 
 * 
 * cpdef dict _rec_mapq_pad(FastaFile fafile, chrom, pos, bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._rec_mapq_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_67_rec_mapq_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_66_rec_mapq_pad[] = "_rec_mapq_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_67_rec_mapq_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_mapq_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_mapq_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_mapq_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __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, "_rec_mapq_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 1807; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_mapq_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_mapq_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_66_rec_mapq_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

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

static PyObject *__pyx_pf_10pysamstats_66_rec_mapq_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_mapq_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_mapq_pad", 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__rec_mapq_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_mapq_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1822
 * 
 * 
 * def stat_mapq(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate mapping quality statistics per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_69stat_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_68stat_mapq[] = "stat_mapq(alignmentfile, **kwargs)\nGenerate mapping quality statistics per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_69stat_mapq = {"stat_mapq", (PyCFunction)__pyx_pw_10pysamstats_69stat_mapq, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_68stat_mapq};
static PyObject *__pyx_pw_10pysamstats_69stat_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_mapq") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1822; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_mapq", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1822; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_mapq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_68stat_mapq(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_68stat_mapq(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  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("stat_mapq", 0);

  /* "pysamstats.pyx":1853
 *     """
 * 
 *     return _iter_pileup(_rec_mapq, _rec_mapq_pad, alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_mapq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_mapq_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1853; __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 = 1853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1822
 * 
 * 
 * def stat_mapq(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate mapping quality statistics per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_mapq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1856
 * 
 * 
 * def load_mapq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_mapq, dtype_mapq, *args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_71load_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_70load_mapq[] = "load_mapq(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_71load_mapq = {"load_mapq", (PyCFunction)__pyx_pw_10pysamstats_71load_mapq, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_70load_mapq};
static PyObject *__pyx_pw_10pysamstats_71load_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("load_mapq (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_70load_mapq(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_70load_mapq(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_mapq", 0);

  /* "pysamstats.pyx":1857
 * 
 * def load_mapq(*args, **kwargs):
 *     return _load_stats(stat_mapq, dtype_mapq, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_mapq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_mapq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __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_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1856
 * 
 * 
 * def load_mapq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_mapq, dtype_mapq, *args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_mapq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1898
 * 
 * 
 * cpdef dict _rec_mapq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                             bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_73_rec_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_mapq_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_mapq_strand *__pyx_optional_args) {

  /* "pysamstats.pyx":1899
 * 
 * cpdef dict _rec_mapq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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;
  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;
  int __pyx_v_reads_rev;
  int __pyx_v_reads_fwd;
  int __pyx_v_reads_pp;
  int __pyx_v_reads_pp_rev;
  int __pyx_v_reads_pp_fwd;
  int __pyx_v_reads_mapq0;
  int __pyx_v_reads_mapq0_fwd;
  int __pyx_v_reads_mapq0_rev;
  int __pyx_v_reads_mapq0_pp;
  int __pyx_v_reads_mapq0_pp_fwd;
  int __pyx_v_reads_mapq0_pp_rev;
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  int __pyx_v_rms_mapq;
  uint64_t __pyx_v_max_mapq;
  long __pyx_v_rms_mapq_rev;
  uint64_t __pyx_v_max_mapq_rev;
  long __pyx_v_rms_mapq_fwd;
  uint64_t __pyx_v_max_mapq_fwd;
  long __pyx_v_rms_mapq_pp;
  uint64_t __pyx_v_max_mapq_pp;
  long __pyx_v_rms_mapq_pp_fwd;
  uint64_t __pyx_v_max_mapq_pp_fwd;
  long __pyx_v_rms_mapq_pp_rev;
  uint64_t __pyx_v_max_mapq_pp_rev;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  bam_pileup1_t **__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  long __pyx_t_7;
  int __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  uint8_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":1914
 *     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":1915
 * 
 *     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":1916
 *     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":1917
 *     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":1918
 *     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":1919
 *     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":1920
 *     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":1921
 *     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":1922
 *     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":1923
 *     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":1924
 *     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":1925
 *     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 int reads_rev = 0
 */
  __pyx_v_mapq_pp_rev_squared_sum = 0;

  /* "pysamstats.pyx":1927
 *     cdef uint64_t mapq_pp_rev_squared_sum = 0
 * 
 *     cdef int reads_rev = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_fwd = 0
 *     cdef int reads_pp = 0
 */
  __pyx_v_reads_rev = 0;

  /* "pysamstats.pyx":1928
 * 
 *     cdef int reads_rev = 0
 *     cdef int reads_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_rev = 0
 */
  __pyx_v_reads_fwd = 0;

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

  /* "pysamstats.pyx":1930
 *     cdef int reads_fwd = 0
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_rev = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp_fwd = 0
 *     cdef int reads_mapq0 = 0
 */
  __pyx_v_reads_pp_rev = 0;

  /* "pysamstats.pyx":1931
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_rev = 0
 *     cdef int reads_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_mapq0 = 0
 *     cdef int reads_mapq0_fwd = 0
 */
  __pyx_v_reads_pp_fwd = 0;

  /* "pysamstats.pyx":1932
 *     cdef int reads_pp_rev = 0
 *     cdef int reads_pp_fwd = 0
 *     cdef int reads_mapq0 = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_mapq0_fwd = 0
 *     cdef int reads_mapq0_rev = 0
 */
  __pyx_v_reads_mapq0 = 0;

  /* "pysamstats.pyx":1933
 *     cdef int reads_pp_fwd = 0
 *     cdef int reads_mapq0 = 0
 *     cdef int reads_mapq0_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_mapq0_rev = 0
 *     cdef int reads_mapq0_pp = 0
 */
  __pyx_v_reads_mapq0_fwd = 0;

  /* "pysamstats.pyx":1934
 *     cdef int reads_mapq0 = 0
 *     cdef int reads_mapq0_fwd = 0
 *     cdef int reads_mapq0_rev = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_mapq0_pp = 0
 *     cdef int reads_mapq0_pp_fwd = 0
 */
  __pyx_v_reads_mapq0_rev = 0;

  /* "pysamstats.pyx":1935
 *     cdef int reads_mapq0_fwd = 0
 *     cdef int reads_mapq0_rev = 0
 *     cdef int reads_mapq0_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_mapq0_pp_fwd = 0
 *     cdef int reads_mapq0_pp_rev = 0
 */
  __pyx_v_reads_mapq0_pp = 0;

  /* "pysamstats.pyx":1936
 *     cdef int reads_mapq0_rev = 0
 *     cdef int reads_mapq0_pp = 0
 *     cdef int reads_mapq0_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_mapq0_pp_rev = 0
 * 
 */
  __pyx_v_reads_mapq0_pp_fwd = 0;

  /* "pysamstats.pyx":1937
 *     cdef int reads_mapq0_pp = 0
 *     cdef int reads_mapq0_pp_fwd = 0
 *     cdef int reads_mapq0_pp_rev = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_reads_mapq0_pp_rev = 0;

  /* "pysamstats.pyx":1940
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":1944
 * 
 *     # get chromosome name and position
 *     chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); 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 = __Pyx_PyInt_From_int(__pyx_v_col->tid); 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_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1945
 *     # get chromosome name and position
 *     chrom = alignmentfile.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 != 0)) {
    __pyx_t_7 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_7 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_7;

  /* "pysamstats.pyx":1948
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":1949
 *     # 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":1950
 *     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_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

    /* "pysamstats.pyx":1951
 *         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_10 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_10;

    /* "pysamstats.pyx":1952
 *         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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":1953
 *         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 = ((__pyx_v_flag & 16) != 0);

    /* "pysamstats.pyx":1954
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         mapq = aln.core.qual             # <<<<<<<<<<<<<<
 *         mapq_squared = mapq**2
 * 
 */
    __pyx_t_11 = __pyx_v_aln->core.qual;
    __pyx_v_mapq = __pyx_t_11;

    /* "pysamstats.pyx":1955
 *         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":1957
 *         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":1958
 * 
 *         mapq_squared_sum += mapq_squared
 *         if mapq > mapq_max:             # <<<<<<<<<<<<<<
 *             mapq_max = mapq
 *         if is_reverse:
 */
    __pyx_t_12 = ((__pyx_v_mapq > __pyx_v_mapq_max) != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":1959
 *         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":1960
 *         if mapq > mapq_max:
 *             mapq_max = mapq
 *         if is_reverse:             # <<<<<<<<<<<<<<
 *             reads_rev += 1
 *             mapq_rev_squared_sum += mapq_squared
 */
    __pyx_t_12 = (__pyx_v_is_reverse != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":1961
 *             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":1962
 *         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":1963
 *             reads_rev += 1
 *             mapq_rev_squared_sum += mapq_squared
 *             if mapq > mapq_rev_max:             # <<<<<<<<<<<<<<
 *                 mapq_rev_max = mapq
 *         else:
 */
      __pyx_t_12 = ((__pyx_v_mapq > __pyx_v_mapq_rev_max) != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":1964
 *             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":1966
 *                 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":1967
 *         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":1968
 *             reads_fwd += 1
 *             mapq_fwd_squared_sum += mapq_squared
 *             if mapq > mapq_fwd_max:             # <<<<<<<<<<<<<<
 *                 mapq_fwd_max = mapq
 * 
 */
      __pyx_t_12 = ((__pyx_v_mapq > __pyx_v_mapq_fwd_max) != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":1969
 *             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":1971
 *                 mapq_fwd_max = mapq
 * 
 *         if mapq == 0:             # <<<<<<<<<<<<<<
 *             reads_mapq0 += 1
 *             if is_reverse:
 */
    __pyx_t_12 = ((__pyx_v_mapq == 0) != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":1972
 * 
 *         if mapq == 0:
 *             reads_mapq0 += 1             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_mapq0_rev += 1
 */
      __pyx_v_reads_mapq0 = (__pyx_v_reads_mapq0 + 1);

      /* "pysamstats.pyx":1973
 *         if mapq == 0:
 *             reads_mapq0 += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_mapq0_rev += 1
 *             else:
 */
      __pyx_t_12 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":1974
 *             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":1976
 *                 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":1978
 *                 reads_mapq0_fwd += 1
 * 
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *             mapq_pp_squared_sum += mapq_squared
 */
    __pyx_t_12 = (__pyx_v_is_proper_pair != 0);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":1979
 * 
 *         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":1980
 *         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":1981
 *             reads_pp += 1
 *             mapq_pp_squared_sum += mapq_squared
 *             if mapq > mapq_pp_max:             # <<<<<<<<<<<<<<
 *                 mapq_pp_max = mapq
 *             if is_reverse:
 */
      __pyx_t_12 = ((__pyx_v_mapq > __pyx_v_mapq_pp_max) != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":1982
 *             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":1983
 *             if mapq > mapq_pp_max:
 *                 mapq_pp_max = mapq
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_pp_rev += 1
 *                 mapq_pp_rev_squared_sum += mapq_squared
 */
      __pyx_t_12 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":1984
 *                 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":1985
 *             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":1986
 *                 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_12 = ((__pyx_v_mapq > __pyx_v_mapq_pp_rev_max) != 0);
        if (__pyx_t_12) {

          /* "pysamstats.pyx":1987
 *                 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":1989
 *                     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":1990
 *             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":1991
 *                 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_12 = ((__pyx_v_mapq > __pyx_v_mapq_pp_fwd_max) != 0);
        if (__pyx_t_12) {

          /* "pysamstats.pyx":1992
 *                 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":1993
 *                 if mapq > mapq_pp_fwd_max:
 *                     mapq_pp_fwd_max = mapq
 *             if mapq == 0:             # <<<<<<<<<<<<<<
 *                 reads_mapq0_pp += 1
 *                 if is_reverse:
 */
      __pyx_t_12 = ((__pyx_v_mapq == 0) != 0);
      if (__pyx_t_12) {

        /* "pysamstats.pyx":1994
 *                     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":1995
 *             if mapq == 0:
 *                 reads_mapq0_pp += 1
 *                 if is_reverse:             # <<<<<<<<<<<<<<
 *                     reads_mapq0_pp_rev += 1
 *                 else:
 */
        __pyx_t_12 = (__pyx_v_is_reverse != 0);
        if (__pyx_t_12) {

          /* "pysamstats.pyx":1996
 *                 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":1998
 *                     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":2001
 * 
 *     # construct output variables
 *     rms_mapq = _rootmean(mapq_squared_sum, n)             # <<<<<<<<<<<<<<
 *     max_mapq = mapq_max
 *     if reads_rev > 0:
 */
  __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_n); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_rms_mapq = __pyx_f_10pysamstats__rootmean(__pyx_v_mapq_squared_sum, __pyx_t_8);

  /* "pysamstats.pyx":2002
 *     # construct output variables
 *     rms_mapq = _rootmean(mapq_squared_sum, n)
 *     max_mapq = mapq_max             # <<<<<<<<<<<<<<
 *     if reads_rev > 0:
 *         rms_mapq_rev = _rootmean(mapq_rev_squared_sum, reads_rev)
 */
  __pyx_v_max_mapq = __pyx_v_mapq_max;

  /* "pysamstats.pyx":2003
 *     rms_mapq = _rootmean(mapq_squared_sum, n)
 *     max_mapq = mapq_max
 *     if reads_rev > 0:             # <<<<<<<<<<<<<<
 *         rms_mapq_rev = _rootmean(mapq_rev_squared_sum, reads_rev)
 *         max_mapq_rev = mapq_rev_max
 */
  __pyx_t_12 = ((__pyx_v_reads_rev > 0) != 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":2004
 *     max_mapq = mapq_max
 *     if reads_rev > 0:
 *         rms_mapq_rev = _rootmean(mapq_rev_squared_sum, reads_rev)             # <<<<<<<<<<<<<<
 *         max_mapq_rev = mapq_rev_max
 *     else:
 */
    __pyx_v_rms_mapq_rev = __pyx_f_10pysamstats__rootmean(__pyx_v_mapq_rev_squared_sum, __pyx_v_reads_rev);

    /* "pysamstats.pyx":2005
 *     if reads_rev > 0:
 *         rms_mapq_rev = _rootmean(mapq_rev_squared_sum, reads_rev)
 *         max_mapq_rev = mapq_rev_max             # <<<<<<<<<<<<<<
 *     else:
 *         rms_mapq_rev = max_mapq_rev = 0
 */
    __pyx_v_max_mapq_rev = __pyx_v_mapq_rev_max;
    goto __pyx_L18;
  }
  /*else*/ {

    /* "pysamstats.pyx":2007
 *         max_mapq_rev = mapq_rev_max
 *     else:
 *         rms_mapq_rev = max_mapq_rev = 0             # <<<<<<<<<<<<<<
 *     if reads_fwd > 0:
 *         rms_mapq_fwd = _rootmean(mapq_fwd_squared_sum, reads_fwd)
 */
    __pyx_v_rms_mapq_rev = 0;
    __pyx_v_max_mapq_rev = 0;
  }
  __pyx_L18:;

  /* "pysamstats.pyx":2008
 *     else:
 *         rms_mapq_rev = max_mapq_rev = 0
 *     if reads_fwd > 0:             # <<<<<<<<<<<<<<
 *         rms_mapq_fwd = _rootmean(mapq_fwd_squared_sum, reads_fwd)
 *         max_mapq_fwd = mapq_fwd_max
 */
  __pyx_t_12 = ((__pyx_v_reads_fwd > 0) != 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":2009
 *         rms_mapq_rev = max_mapq_rev = 0
 *     if reads_fwd > 0:
 *         rms_mapq_fwd = _rootmean(mapq_fwd_squared_sum, reads_fwd)             # <<<<<<<<<<<<<<
 *         max_mapq_fwd = mapq_fwd_max
 *     else:
 */
    __pyx_v_rms_mapq_fwd = __pyx_f_10pysamstats__rootmean(__pyx_v_mapq_fwd_squared_sum, __pyx_v_reads_fwd);

    /* "pysamstats.pyx":2010
 *     if reads_fwd > 0:
 *         rms_mapq_fwd = _rootmean(mapq_fwd_squared_sum, reads_fwd)
 *         max_mapq_fwd = mapq_fwd_max             # <<<<<<<<<<<<<<
 *     else:
 *         rms_mapq_fwd = max_mapq_fwd = 0
 */
    __pyx_v_max_mapq_fwd = __pyx_v_mapq_fwd_max;
    goto __pyx_L19;
  }
  /*else*/ {

    /* "pysamstats.pyx":2012
 *         max_mapq_fwd = mapq_fwd_max
 *     else:
 *         rms_mapq_fwd = max_mapq_fwd = 0             # <<<<<<<<<<<<<<
 *     if reads_pp > 0:
 *         rms_mapq_pp = _rootmean(mapq_pp_squared_sum, reads_pp)
 */
    __pyx_v_rms_mapq_fwd = 0;
    __pyx_v_max_mapq_fwd = 0;
  }
  __pyx_L19:;

  /* "pysamstats.pyx":2013
 *     else:
 *         rms_mapq_fwd = max_mapq_fwd = 0
 *     if reads_pp > 0:             # <<<<<<<<<<<<<<
 *         rms_mapq_pp = _rootmean(mapq_pp_squared_sum, reads_pp)
 *         max_mapq_pp = mapq_pp_max
 */
  __pyx_t_12 = ((__pyx_v_reads_pp > 0) != 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":2014
 *         rms_mapq_fwd = max_mapq_fwd = 0
 *     if reads_pp > 0:
 *         rms_mapq_pp = _rootmean(mapq_pp_squared_sum, reads_pp)             # <<<<<<<<<<<<<<
 *         max_mapq_pp = mapq_pp_max
 *     else:
 */
    __pyx_v_rms_mapq_pp = __pyx_f_10pysamstats__rootmean(__pyx_v_mapq_pp_squared_sum, __pyx_v_reads_pp);

    /* "pysamstats.pyx":2015
 *     if reads_pp > 0:
 *         rms_mapq_pp = _rootmean(mapq_pp_squared_sum, reads_pp)
 *         max_mapq_pp = mapq_pp_max             # <<<<<<<<<<<<<<
 *     else:
 *         rms_mapq_pp = max_mapq_pp = 0
 */
    __pyx_v_max_mapq_pp = __pyx_v_mapq_pp_max;
    goto __pyx_L20;
  }
  /*else*/ {

    /* "pysamstats.pyx":2017
 *         max_mapq_pp = mapq_pp_max
 *     else:
 *         rms_mapq_pp = max_mapq_pp = 0             # <<<<<<<<<<<<<<
 *     if reads_pp_fwd > 0:
 *         rms_mapq_pp_fwd = _rootmean(mapq_pp_fwd_squared_sum, reads_pp_fwd)
 */
    __pyx_v_rms_mapq_pp = 0;
    __pyx_v_max_mapq_pp = 0;
  }
  __pyx_L20:;

  /* "pysamstats.pyx":2018
 *     else:
 *         rms_mapq_pp = max_mapq_pp = 0
 *     if reads_pp_fwd > 0:             # <<<<<<<<<<<<<<
 *         rms_mapq_pp_fwd = _rootmean(mapq_pp_fwd_squared_sum, reads_pp_fwd)
 *         max_mapq_pp_fwd = mapq_pp_fwd_max
 */
  __pyx_t_12 = ((__pyx_v_reads_pp_fwd > 0) != 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":2019
 *         rms_mapq_pp = max_mapq_pp = 0
 *     if reads_pp_fwd > 0:
 *         rms_mapq_pp_fwd = _rootmean(mapq_pp_fwd_squared_sum, reads_pp_fwd)             # <<<<<<<<<<<<<<
 *         max_mapq_pp_fwd = mapq_pp_fwd_max
 *     else:
 */
    __pyx_v_rms_mapq_pp_fwd = __pyx_f_10pysamstats__rootmean(__pyx_v_mapq_pp_fwd_squared_sum, __pyx_v_reads_pp_fwd);

    /* "pysamstats.pyx":2020
 *     if reads_pp_fwd > 0:
 *         rms_mapq_pp_fwd = _rootmean(mapq_pp_fwd_squared_sum, reads_pp_fwd)
 *         max_mapq_pp_fwd = mapq_pp_fwd_max             # <<<<<<<<<<<<<<
 *     else:
 *         rms_mapq_pp_fwd = max_mapq_pp_fwd = 0
 */
    __pyx_v_max_mapq_pp_fwd = __pyx_v_mapq_pp_fwd_max;
    goto __pyx_L21;
  }
  /*else*/ {

    /* "pysamstats.pyx":2022
 *         max_mapq_pp_fwd = mapq_pp_fwd_max
 *     else:
 *         rms_mapq_pp_fwd = max_mapq_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     if reads_pp_rev > 0:
 *         rms_mapq_pp_rev = _rootmean(mapq_pp_rev_squared_sum, reads_pp_rev)
 */
    __pyx_v_rms_mapq_pp_fwd = 0;
    __pyx_v_max_mapq_pp_fwd = 0;
  }
  __pyx_L21:;

  /* "pysamstats.pyx":2023
 *     else:
 *         rms_mapq_pp_fwd = max_mapq_pp_fwd = 0
 *     if reads_pp_rev > 0:             # <<<<<<<<<<<<<<
 *         rms_mapq_pp_rev = _rootmean(mapq_pp_rev_squared_sum, reads_pp_rev)
 *         max_mapq_pp_rev = mapq_pp_rev_max
 */
  __pyx_t_12 = ((__pyx_v_reads_pp_rev > 0) != 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":2024
 *         rms_mapq_pp_fwd = max_mapq_pp_fwd = 0
 *     if reads_pp_rev > 0:
 *         rms_mapq_pp_rev = _rootmean(mapq_pp_rev_squared_sum, reads_pp_rev)             # <<<<<<<<<<<<<<
 *         max_mapq_pp_rev = mapq_pp_rev_max
 *     else:
 */
    __pyx_v_rms_mapq_pp_rev = __pyx_f_10pysamstats__rootmean(__pyx_v_mapq_pp_rev_squared_sum, __pyx_v_reads_pp_rev);

    /* "pysamstats.pyx":2025
 *     if reads_pp_rev > 0:
 *         rms_mapq_pp_rev = _rootmean(mapq_pp_rev_squared_sum, reads_pp_rev)
 *         max_mapq_pp_rev = mapq_pp_rev_max             # <<<<<<<<<<<<<<
 *     else:
 *         rms_mapq_pp_rev = max_mapq_pp_rev = 0
 */
    __pyx_v_max_mapq_pp_rev = __pyx_v_mapq_pp_rev_max;
    goto __pyx_L22;
  }
  /*else*/ {

    /* "pysamstats.pyx":2027
 *         max_mapq_pp_rev = mapq_pp_rev_max
 *     else:
 *         rms_mapq_pp_rev = max_mapq_pp_rev = 0             # <<<<<<<<<<<<<<
 * 
 *     # if not PY2:
 */
    __pyx_v_rms_mapq_pp_rev = 0;
    __pyx_v_max_mapq_pp_rev = 0;
  }
  __pyx_L22:;

  /* "pysamstats.pyx":2031
 *     # if not PY2:
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); 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);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2032
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_pos); 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);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2033
 *     return {'chrom': chrom,
 *             'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2034
 *             'pos': pos,
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,             # <<<<<<<<<<<<<<
 *             'reads_rev': reads_rev,
 *             'reads_pp': reads_pp,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2035
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2036
 *             '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_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2037
 *             '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_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2038
 *             '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_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2039
 *             '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_3 = __Pyx_PyInt_From_int(__pyx_v_reads_mapq0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2040
 *             '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_3 = __Pyx_PyInt_From_int(__pyx_v_reads_mapq0_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2041
 *             '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_3 = __Pyx_PyInt_From_int(__pyx_v_reads_mapq0_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2042
 *             '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_3 = __Pyx_PyInt_From_int(__pyx_v_reads_mapq0_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2043
 *             '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_3 = __Pyx_PyInt_From_int(__pyx_v_reads_mapq0_pp_fwd); 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);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0_pp_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2044
 *             '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_3 = __Pyx_PyInt_From_int(__pyx_v_reads_mapq0_pp_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0_pp_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2045
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_rms_mapq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2046
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_mapq_fwd); 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);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2047
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_mapq_rev); 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);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2048
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_mapq_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2049
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_mapq_pp_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq_pp_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2050
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_rms_mapq_pp_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq_pp_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2051
 *             '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_3 = __Pyx_PyInt_From_uint64_t(__pyx_v_max_mapq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2052
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_uint64_t(__pyx_v_max_mapq_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2053
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_uint64_t(__pyx_v_max_mapq_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2054
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_uint64_t(__pyx_v_max_mapq_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2055
 *             '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,
 *             }
 */
  __pyx_t_3 = __Pyx_PyInt_From_uint64_t(__pyx_v_max_mapq_pp_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2055; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq_pp_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2056
 *             'max_mapq_pp': max_mapq_pp,
 *             'max_mapq_pp_fwd': max_mapq_pp_fwd,
 *             'max_mapq_pp_rev': max_mapq_pp_rev,             # <<<<<<<<<<<<<<
 *             }
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_uint64_t(__pyx_v_max_mapq_pp_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq_pp_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":1898
 * 
 * 
 * cpdef dict _rec_mapq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                             bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._rec_mapq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_73_rec_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_72_rec_mapq_strand[] = "_rec_mapq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_73_rec_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_mapq_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_mapq_strand", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __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("_rec_mapq_strand", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __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, "_rec_mapq_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 1899; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":1899
 * 
 * cpdef dict _rec_mapq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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("_rec_mapq_strand", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._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_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_72_rec_mapq_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":1898
 * 
 * 
 * cpdef dict _rec_mapq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                             bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_72_rec_mapq_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_mapq_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_mapq_strand(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_mapq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2060
 * 
 * 
 * cpdef dict _rec_mapq_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                 bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

static PyObject *__pyx_pw_10pysamstats_75_rec_mapq_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_mapq_strand_pad(CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_mapq_strand_pad *__pyx_optional_args) {

  /* "pysamstats.pyx":2061
 * 
 * cpdef dict _rec_mapq_strand_pad(FastaFile fafile, chrom, pos,
 *                                 bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_mapq_strand_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":2062
 * cpdef dict _rec_mapq_strand_pad(FastaFile fafile, chrom, pos,
 *                                 bint one_based=False):
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom,
 *             'pos': pos,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_2 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_1 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":2063
 *                                 bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2064
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': 0,
 *             'reads_fwd': 0,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_max_mapq_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2060
 * 
 * 
 * cpdef dict _rec_mapq_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                 bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._rec_mapq_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_75_rec_mapq_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_74_rec_mapq_strand_pad[] = "_rec_mapq_strand_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_75_rec_mapq_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_mapq_strand_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_mapq_strand_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2060; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_mapq_strand_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2060; __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, "_rec_mapq_strand_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2060; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 2061; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":2061
 * 
 * cpdef dict _rec_mapq_strand_pad(FastaFile fafile, chrom, pos,
 *                                 bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_mapq_strand_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2060; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_mapq_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_74_rec_mapq_strand_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

  /* "pysamstats.pyx":2060
 * 
 * 
 * cpdef dict _rec_mapq_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                 bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

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

static PyObject *__pyx_pf_10pysamstats_74_rec_mapq_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_mapq_strand_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_mapq_strand_pad", 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__rec_mapq_strand_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_mapq_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2092
 * 
 * 
 * def stat_mapq_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate mapping quality statistics by strand per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_77stat_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_76stat_mapq_strand[] = "stat_mapq_strand(alignmentfile, **kwargs)\nGenerate mapping quality statistics by strand per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_77stat_mapq_strand = {"stat_mapq_strand", (PyCFunction)__pyx_pw_10pysamstats_77stat_mapq_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_76stat_mapq_strand};
static PyObject *__pyx_pw_10pysamstats_77stat_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_mapq_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2092; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_mapq_strand", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2092; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_mapq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_76stat_mapq_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_76stat_mapq_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  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("stat_mapq_strand", 0);

  /* "pysamstats.pyx":2123
 *     """
 * 
 *     return _iter_pileup(_rec_mapq_strand, _rec_mapq_strand_pad, alignmentfile,             # <<<<<<<<<<<<<<
 *                         **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); 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_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_mapq_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_mapq_strand_pad); 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_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":2124
 * 
 *     return _iter_pileup(_rec_mapq_strand, _rec_mapq_strand_pad, alignmentfile,
 *                         **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":2123
 *     """
 * 
 *     return _iter_pileup(_rec_mapq_strand, _rec_mapq_strand_pad, alignmentfile,             # <<<<<<<<<<<<<<
 *                         **kwargs)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2092
 * 
 * 
 * def stat_mapq_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate mapping quality statistics by strand per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_mapq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2127
 * 
 * 
 * def load_mapq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_mapq_strand, dtype_mapq_strand, *args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_79load_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_78load_mapq_strand[] = "load_mapq_strand(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_79load_mapq_strand = {"load_mapq_strand", (PyCFunction)__pyx_pw_10pysamstats_79load_mapq_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_78load_mapq_strand};
static PyObject *__pyx_pw_10pysamstats_79load_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("load_mapq_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_78load_mapq_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_78load_mapq_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_mapq_strand", 0);

  /* "pysamstats.pyx":2128
 * 
 * def load_mapq_strand(*args, **kwargs):
 *     return _load_stats(stat_mapq_strand, dtype_mapq_strand, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_mapq_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_mapq_strand); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __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_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2127
 * 
 * 
 * def load_mapq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_mapq_strand, dtype_mapq_strand, *args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_mapq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2149
 * 
 * 
 * cpdef dict _rec_baseq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                       bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_81_rec_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq *__pyx_optional_args) {

  /* "pysamstats.pyx":2150
 * 
 * cpdef dict _rec_baseq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  int __pyx_v_reads_nodel;
  int __pyx_v_reads_pp;
  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_n = NULL;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  int __pyx_v_rms_baseq;
  int __pyx_v_rms_baseq_pp;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  bam_pileup1_t **__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  long __pyx_t_7;
  int __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":2160
 *     cdef uint32_t flag
 *     cdef bint is_proper_pair
 *     cdef int reads_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_nodel = 0
 */
  __pyx_v_reads_nodel = 0;

  /* "pysamstats.pyx":2161
 *     cdef bint is_proper_pair
 *     cdef int reads_nodel = 0
 *     cdef int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp_nodel = 0
 *     cdef uint64_t baseq, baseq_squared
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":2162
 *     cdef int reads_nodel = 0
 *     cdef int reads_pp = 0
 *     cdef 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":2164
 *     cdef 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":2165
 *     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":2168
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":2172
 * 
 *     # get chromosome name and position
 *     chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":2173
 *     # get chromosome name and position
 *     chrom = alignmentfile.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 != 0)) {
    __pyx_t_7 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_7 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_7;

  /* "pysamstats.pyx":2176
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":2177
 *     # 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":2178
 *     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_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

    /* "pysamstats.pyx":2179
 *         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_10 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_10;

    /* "pysamstats.pyx":2180
 *         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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":2181
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *         # N.B., base quality only makes sense if the aligned read is not a
 */
    __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":2182
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         if is_proper_pair:
 *             reads_pp += 1             # <<<<<<<<<<<<<<
 *         # N.B., base quality only makes sense if the aligned read is not a
 *         # deletion
 */
      __pyx_v_reads_pp = (__pyx_v_reads_pp + 1);
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "pysamstats.pyx":2185
 *         # N.B., base quality only makes sense if the aligned read is not a
 *         # deletion
 *         if not read.is_del:             # <<<<<<<<<<<<<<
 *             reads_nodel += 1
 *             baseq = pysam_bam_get_qual(aln)[read.qpos]
 */
    __pyx_t_11 = ((!(__pyx_v_read->is_del != 0)) != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":2186
 *         # deletion
 *         if not read.is_del:
 *             reads_nodel += 1             # <<<<<<<<<<<<<<
 *             baseq = pysam_bam_get_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2
 */
      __pyx_v_reads_nodel = (__pyx_v_reads_nodel + 1);

      /* "pysamstats.pyx":2187
 *         if not read.is_del:
 *             reads_nodel += 1
 *             baseq = pysam_bam_get_qual(aln)[read.qpos]             # <<<<<<<<<<<<<<
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 */
      __pyx_v_baseq = (pysam_bam_get_qual(__pyx_v_aln)[__pyx_v_read->qpos]);

      /* "pysamstats.pyx":2188
 *             reads_nodel += 1
 *             baseq = pysam_bam_get_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":2189
 *             baseq = pysam_bam_get_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":2190
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared
 */
      __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":2191
 *             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":2192
 *             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_L7;
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "pysamstats.pyx":2195
 * 
 *     # output variables
 *     rms_baseq = _rootmean(baseq_squared_sum, reads_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_pp = _rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 * 
 */
  __pyx_v_rms_baseq = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_squared_sum, __pyx_v_reads_nodel);

  /* "pysamstats.pyx":2196
 *     # output variables
 *     rms_baseq = _rootmean(baseq_squared_sum, reads_nodel)
 *     rms_baseq_pp = _rootmean(baseq_pp_squared_sum, reads_pp_nodel)             # <<<<<<<<<<<<<<
 * 
 *     # if not PY2:
 */
  __pyx_v_rms_baseq_pp = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_pp_squared_sum, __pyx_v_reads_pp_nodel);

  /* "pysamstats.pyx":2200
 *     # if not PY2:
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2201
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_pp': reads_pp,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2202
 *     return {'chrom': chrom,
 *             'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp,
 *             'rms_baseq': rms_baseq,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2203
 *             'pos': pos,
 *             'reads_all': n,
 *             'reads_pp': reads_pp,             # <<<<<<<<<<<<<<
 *             'rms_baseq': rms_baseq,
 *             'rms_baseq_pp': rms_baseq_pp}
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2204
 *             'reads_all': n,
 *             'reads_pp': reads_pp,
 *             'rms_baseq': rms_baseq,             # <<<<<<<<<<<<<<
 *             'rms_baseq_pp': rms_baseq_pp}
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2205
 *             'reads_pp': reads_pp,
 *             'rms_baseq': rms_baseq,
 *             'rms_baseq_pp': rms_baseq_pp}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2149
 * 
 * 
 * cpdef dict _rec_baseq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                       bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._rec_baseq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_81_rec_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_80_rec_baseq[] = "_rec_baseq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_81_rec_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_baseq (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_baseq", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __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("_rec_baseq", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __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, "_rec_baseq") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 2150; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":2150
 * 
 * cpdef dict _rec_baseq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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("_rec_baseq", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_baseq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_80_rec_baseq(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":2149
 * 
 * 
 * cpdef dict _rec_baseq(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                       bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_80_rec_baseq(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_baseq __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_baseq(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_baseq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2208
 * 
 * 
 * cpdef dict _rec_baseq_pad(FastaFile fafile, chrom, pos, bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */

static PyObject *__pyx_pw_10pysamstats_83_rec_baseq_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_pad(CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_pad *__pyx_optional_args) {
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_baseq_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":2209
 * 
 * cpdef dict _rec_baseq_pad(FastaFile fafile, chrom, pos, bint one_based=False):
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom,
 *             'pos': pos,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_2 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_1 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":2210
 * cpdef dict _rec_baseq_pad(FastaFile fafile, chrom, pos, bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2211
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': 0,
 *             'reads_pp': 0,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2208
 * 
 * 
 * cpdef dict _rec_baseq_pad(FastaFile fafile, chrom, pos, bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._rec_baseq_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_83_rec_baseq_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_82_rec_baseq_pad[] = "_rec_baseq_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_83_rec_baseq_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_baseq_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_baseq_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_baseq_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __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, "_rec_baseq_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 2208; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_baseq_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_baseq_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_82_rec_baseq_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

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

static PyObject *__pyx_pf_10pysamstats_82_rec_baseq_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_baseq_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_baseq_pad", 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__rec_baseq_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_baseq_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2219
 * 
 * 
 * def stat_baseq(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate base quality statistics per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_85stat_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_84stat_baseq[] = "stat_baseq(alignmentfile, **kwargs)\nGenerate base quality statistics per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_85stat_baseq = {"stat_baseq", (PyCFunction)__pyx_pw_10pysamstats_85stat_baseq, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_84stat_baseq};
static PyObject *__pyx_pw_10pysamstats_85stat_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_baseq") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2219; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_baseq", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2219; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_baseq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_84stat_baseq(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_84stat_baseq(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  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("stat_baseq", 0);

  /* "pysamstats.pyx":2250
 *     """
 * 
 *     return _iter_pileup(_rec_baseq, _rec_baseq_pad, alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_baseq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_baseq_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __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 = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2219
 * 
 * 
 * def stat_baseq(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate base quality statistics per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_baseq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2253
 * 
 * 
 * def load_baseq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq, dtype_baseq, *args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_87load_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_86load_baseq[] = "load_baseq(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_87load_baseq = {"load_baseq", (PyCFunction)__pyx_pw_10pysamstats_87load_baseq, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_86load_baseq};
static PyObject *__pyx_pw_10pysamstats_87load_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("load_baseq (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_86load_baseq(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_86load_baseq(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_baseq", 0);

  /* "pysamstats.pyx":2254
 * 
 * def load_baseq(*args, **kwargs):
 *     return _load_stats(stat_baseq, dtype_baseq, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_baseq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_baseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2254; __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_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2253
 * 
 * 
 * def load_baseq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq, dtype_baseq, *args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_baseq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2283
 * 
 * 
 * cpdef dict _rec_baseq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                              bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_89_rec_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_strand *__pyx_optional_args) {

  /* "pysamstats.pyx":2284
 * 
 * cpdef dict _rec_baseq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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;
  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;
  int __pyx_v_reads_rev;
  int __pyx_v_reads_fwd;
  int __pyx_v_reads_pp;
  int __pyx_v_reads_pp_rev;
  int __pyx_v_reads_pp_fwd;
  int __pyx_v_reads_nodel;
  int __pyx_v_reads_rev_nodel;
  int __pyx_v_reads_fwd_nodel;
  int __pyx_v_reads_pp_nodel;
  int __pyx_v_reads_pp_rev_nodel;
  int __pyx_v_reads_pp_fwd_nodel;
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  int __pyx_v_rms_baseq;
  int __pyx_v_rms_baseq_rev;
  int __pyx_v_rms_baseq_fwd;
  int __pyx_v_rms_baseq_pp;
  int __pyx_v_rms_baseq_pp_fwd;
  int __pyx_v_rms_baseq_pp_rev;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  bam_pileup1_t **__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  long __pyx_t_7;
  int __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":2299
 *     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":2300
 * 
 *     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":2301
 *     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":2302
 *     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":2303
 *     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":2304
 *     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 int reads_rev = 0
 */
  __pyx_v_baseq_pp_rev_squared_sum = 0;

  /* "pysamstats.pyx":2306
 *     cdef uint64_t baseq_pp_rev_squared_sum = 0
 * 
 *     cdef int reads_rev = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_fwd = 0
 *     cdef int reads_pp = 0
 */
  __pyx_v_reads_rev = 0;

  /* "pysamstats.pyx":2307
 * 
 *     cdef int reads_rev = 0
 *     cdef int reads_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_rev = 0
 */
  __pyx_v_reads_fwd = 0;

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

  /* "pysamstats.pyx":2309
 *     cdef int reads_fwd = 0
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_rev = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp_fwd = 0
 *     cdef int reads_nodel = 0
 */
  __pyx_v_reads_pp_rev = 0;

  /* "pysamstats.pyx":2310
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_rev = 0
 *     cdef int reads_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_nodel = 0
 *     cdef int reads_rev_nodel = 0
 */
  __pyx_v_reads_pp_fwd = 0;

  /* "pysamstats.pyx":2311
 *     cdef int reads_pp_rev = 0
 *     cdef int reads_pp_fwd = 0
 *     cdef int reads_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_rev_nodel = 0
 *     cdef int reads_fwd_nodel = 0
 */
  __pyx_v_reads_nodel = 0;

  /* "pysamstats.pyx":2312
 *     cdef int reads_pp_fwd = 0
 *     cdef int reads_nodel = 0
 *     cdef int reads_rev_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_fwd_nodel = 0
 *     cdef int reads_pp_nodel = 0
 */
  __pyx_v_reads_rev_nodel = 0;

  /* "pysamstats.pyx":2313
 *     cdef int reads_nodel = 0
 *     cdef int reads_rev_nodel = 0
 *     cdef int reads_fwd_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp_nodel = 0
 *     cdef int reads_pp_rev_nodel = 0
 */
  __pyx_v_reads_fwd_nodel = 0;

  /* "pysamstats.pyx":2314
 *     cdef int reads_rev_nodel = 0
 *     cdef int reads_fwd_nodel = 0
 *     cdef int reads_pp_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp_rev_nodel = 0
 *     cdef int reads_pp_fwd_nodel = 0
 */
  __pyx_v_reads_pp_nodel = 0;

  /* "pysamstats.pyx":2315
 *     cdef int reads_fwd_nodel = 0
 *     cdef int reads_pp_nodel = 0
 *     cdef int reads_pp_rev_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp_fwd_nodel = 0
 * 
 */
  __pyx_v_reads_pp_rev_nodel = 0;

  /* "pysamstats.pyx":2316
 *     cdef int reads_pp_nodel = 0
 *     cdef int reads_pp_rev_nodel = 0
 *     cdef int reads_pp_fwd_nodel = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_reads_pp_fwd_nodel = 0;

  /* "pysamstats.pyx":2319
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":2323
 * 
 *     # get chromosome name and position
 *     chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":2324
 *     # get chromosome name and position
 *     chrom = alignmentfile.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 != 0)) {
    __pyx_t_7 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_7 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_7;

  /* "pysamstats.pyx":2327
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":2328
 *     # 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":2329
 *     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_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

    /* "pysamstats.pyx":2330
 *         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_10 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_10;

    /* "pysamstats.pyx":2331
 *         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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":2332
 *         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 = ((__pyx_v_flag & 16) != 0);

    /* "pysamstats.pyx":2334
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 * 
 *         if is_reverse:             # <<<<<<<<<<<<<<
 *             reads_rev += 1
 *         else:
 */
    __pyx_t_11 = (__pyx_v_is_reverse != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":2335
 * 
 *         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":2337
 *             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":2338
 *         else:
 *             reads_fwd += 1
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *             if is_reverse:
 */
    __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":2339
 *             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":2340
 *         if is_proper_pair:
 *             reads_pp += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_pp_rev += 1
 *             else:
 */
      __pyx_t_11 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":2341
 *             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":2343
 *                 reads_pp_rev += 1
 *             else:
 *                 reads_pp_fwd += 1             # <<<<<<<<<<<<<<
 * 
 *         # N.B., baseq only makes sense if not a deletion
 */
        __pyx_v_reads_pp_fwd = (__pyx_v_reads_pp_fwd + 1);
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysamstats.pyx":2346
 * 
 *         # N.B., baseq only makes sense if not a deletion
 *         if not read.is_del:             # <<<<<<<<<<<<<<
 *             reads_nodel += 1
 *             baseq = pysam_bam_get_qual(aln)[read.qpos]
 */
    __pyx_t_11 = ((!(__pyx_v_read->is_del != 0)) != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":2347
 *         # N.B., baseq only makes sense if not a deletion
 *         if not read.is_del:
 *             reads_nodel += 1             # <<<<<<<<<<<<<<
 *             baseq = pysam_bam_get_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2
 */
      __pyx_v_reads_nodel = (__pyx_v_reads_nodel + 1);

      /* "pysamstats.pyx":2348
 *         if not read.is_del:
 *             reads_nodel += 1
 *             baseq = pysam_bam_get_qual(aln)[read.qpos]             # <<<<<<<<<<<<<<
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 */
      __pyx_v_baseq = (pysam_bam_get_qual(__pyx_v_aln)[__pyx_v_read->qpos]);

      /* "pysamstats.pyx":2349
 *             reads_nodel += 1
 *             baseq = pysam_bam_get_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":2350
 *             baseq = pysam_bam_get_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":2351
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_rev_nodel += 1
 *                 baseq_rev_squared_sum += baseq_squared
 */
      __pyx_t_11 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":2352
 *             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":2353
 *             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_L9;
      }
      /*else*/ {

        /* "pysamstats.pyx":2355
 *                 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":2356
 *             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_L9:;

      /* "pysamstats.pyx":2357
 *                 reads_fwd_nodel += 1
 *                 baseq_fwd_squared_sum += baseq_squared
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared
 */
      __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":2358
 *                 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":2359
 *             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":2360
 *                 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
 */
        __pyx_t_11 = (__pyx_v_is_reverse != 0);
        if (__pyx_t_11) {

          /* "pysamstats.pyx":2361
 *                 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":2362
 *                 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_L11;
        }
        /*else*/ {

          /* "pysamstats.pyx":2364
 *                     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":2365
 *                 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_L11:;
        goto __pyx_L10;
      }
      __pyx_L10:;
      goto __pyx_L8;
    }
    __pyx_L8:;
  }

  /* "pysamstats.pyx":2368
 * 
 *     # 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_v_rms_baseq = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_squared_sum, __pyx_v_reads_nodel);

  /* "pysamstats.pyx":2369
 *     # 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_v_rms_baseq_rev = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_rev_squared_sum, __pyx_v_reads_rev_nodel);

  /* "pysamstats.pyx":2370
 *     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_v_rms_baseq_fwd = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_fwd_squared_sum, __pyx_v_reads_fwd_nodel);

  /* "pysamstats.pyx":2371
 *     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_v_rms_baseq_pp = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_pp_squared_sum, __pyx_v_reads_pp_nodel);

  /* "pysamstats.pyx":2372
 *     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_v_rms_baseq_pp_fwd = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_pp_fwd_squared_sum, __pyx_v_reads_pp_fwd_nodel);

  /* "pysamstats.pyx":2373
 *     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)             # <<<<<<<<<<<<<<
 * 
 *     # if not PY2:
 */
  __pyx_v_rms_baseq_pp_rev = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_pp_rev_squared_sum, __pyx_v_reads_pp_rev_nodel);

  /* "pysamstats.pyx":2377
 *     # if not PY2:
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2378
 *     #     chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2379
 *     return {'chrom': chrom,
 *             'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2380
 *             'pos': pos,
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,             # <<<<<<<<<<<<<<
 *             'reads_rev': reads_rev,
 *             'reads_pp': reads_pp,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2381
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2382
 *             '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_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2383
 *             'reads_rev': reads_rev,
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,             # <<<<<<<<<<<<<<
 *             'reads_pp_rev': reads_pp_rev,
 *             'rms_baseq': rms_baseq,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2384
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,
 *             'reads_pp_rev': reads_pp_rev,             # <<<<<<<<<<<<<<
 *             'rms_baseq': rms_baseq,
 *             'rms_baseq_fwd': rms_baseq_fwd,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_reads_pp_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2385
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2385; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2386
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2387
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2388
 *             '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,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2389
 *             '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,
 *             }
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_pp_fwd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq_pp_fwd, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2390
 *             'rms_baseq_pp': rms_baseq_pp,
 *             'rms_baseq_pp_fwd': rms_baseq_pp_fwd,
 *             'rms_baseq_pp_rev': rms_baseq_pp_rev,             # <<<<<<<<<<<<<<
 *             }
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_pp_rev); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq_pp_rev, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2283
 * 
 * 
 * cpdef dict _rec_baseq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                              bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._rec_baseq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_89_rec_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_88_rec_baseq_strand[] = "_rec_baseq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_89_rec_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_baseq_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_baseq_strand", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __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("_rec_baseq_strand", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __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, "_rec_baseq_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 2284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":2284
 * 
 * cpdef dict _rec_baseq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn 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("_rec_baseq_strand", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._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_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_88_rec_baseq_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":2283
 * 
 * 
 * cpdef dict _rec_baseq_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col,             # <<<<<<<<<<<<<<
 *                              bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_88_rec_baseq_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_baseq_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_baseq_strand(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_baseq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2394
 * 
 * 
 * cpdef dict _rec_baseq_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                  bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

static PyObject *__pyx_pw_10pysamstats_91_rec_baseq_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_strand_pad(CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_strand_pad *__pyx_optional_args) {

  /* "pysamstats.pyx":2395
 * 
 * cpdef dict _rec_baseq_strand_pad(FastaFile fafile, chrom, pos,
 *                                  bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_baseq_strand_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":2396
 * cpdef dict _rec_baseq_strand_pad(FastaFile fafile, chrom, pos,
 *                                  bint one_based=False):
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom,
 *             'pos': pos,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_2 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_1 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":2397
 *                                  bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2398
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': 0,
 *             'reads_fwd': 0,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_baseq_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2394
 * 
 * 
 * cpdef dict _rec_baseq_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                  bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._rec_baseq_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_91_rec_baseq_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_90_rec_baseq_strand_pad[] = "_rec_baseq_strand_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_91_rec_baseq_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_baseq_strand_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_baseq_strand_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2394; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_baseq_strand_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2394; __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, "_rec_baseq_strand_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2394; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 2395; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":2395
 * 
 * cpdef dict _rec_baseq_strand_pad(FastaFile fafile, chrom, pos,
 *                                  bint one_based=False):             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom,
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_baseq_strand_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2394; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_baseq_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_90_rec_baseq_strand_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

  /* "pysamstats.pyx":2394
 * 
 * 
 * cpdef dict _rec_baseq_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                  bint one_based=False):
 *     pos = pos + 1 if one_based else pos
 */

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

static PyObject *__pyx_pf_10pysamstats_90_rec_baseq_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_baseq_strand_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_baseq_strand_pad", 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__rec_baseq_strand_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_baseq_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2414
 * 
 * 
 * def stat_baseq_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate base quality statistics by strand per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_93stat_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_92stat_baseq_strand[] = "stat_baseq_strand(alignmentfile, **kwargs)\nGenerate base quality statistics by strand per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_93stat_baseq_strand = {"stat_baseq_strand", (PyCFunction)__pyx_pw_10pysamstats_93stat_baseq_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_92stat_baseq_strand};
static PyObject *__pyx_pw_10pysamstats_93stat_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_baseq_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_baseq_strand", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_baseq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_92stat_baseq_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_92stat_baseq_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  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("stat_baseq_strand", 0);

  /* "pysamstats.pyx":2445
 *     """
 * 
 *     return _iter_pileup(_rec_baseq_strand, _rec_baseq_strand_pad,             # <<<<<<<<<<<<<<
 *                         alignmentfile, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_baseq_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_baseq_strand_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":2446
 * 
 *     return _iter_pileup(_rec_baseq_strand, _rec_baseq_strand_pad,
 *                         alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":2445
 *     """
 * 
 *     return _iter_pileup(_rec_baseq_strand, _rec_baseq_strand_pad,             # <<<<<<<<<<<<<<
 *                         alignmentfile, **kwargs)
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2414
 * 
 * 
 * def stat_baseq_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate base quality statistics by strand per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_baseq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2449
 * 
 * 
 * def load_baseq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq_strand, dtype_baseq_strand,
 *                        *args, **kwargs)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_95load_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_94load_baseq_strand[] = "load_baseq_strand(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_95load_baseq_strand = {"load_baseq_strand", (PyCFunction)__pyx_pw_10pysamstats_95load_baseq_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_94load_baseq_strand};
static PyObject *__pyx_pw_10pysamstats_95load_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("load_baseq_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_94load_baseq_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_94load_baseq_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_baseq_strand", 0);

  /* "pysamstats.pyx":2450
 * 
 * def load_baseq_strand(*args, **kwargs):
 *     return _load_stats(stat_baseq_strand, dtype_baseq_strand,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_baseq_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_baseq_strand); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":2451
 * def load_baseq_strand(*args, **kwargs):
 *     return _load_stats(stat_baseq_strand, dtype_baseq_strand,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":2450
 * 
 * def load_baseq_strand(*args, **kwargs):
 *     return _load_stats(stat_baseq_strand, dtype_baseq_strand,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2450; __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_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2451
 * def load_baseq_strand(*args, **kwargs):
 *     return _load_stats(stat_baseq_strand, dtype_baseq_strand,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":2450
 * 
 * def load_baseq_strand(*args, **kwargs):
 *     return _load_stats(stat_baseq_strand, dtype_baseq_strand,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2449
 * 
 * 
 * def load_baseq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq_strand, dtype_baseq_strand,
 *                        *args, **kwargs)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_baseq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2481
 * 
 * 
 * cpdef dict _rec_baseq_ext(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                           PileupColumn col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_97_rec_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_ext(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_ext *__pyx_optional_args) {

  /* "pysamstats.pyx":2482
 * 
 * cpdef dict _rec_baseq_ext(AlignmentFile alignmentfile, FastaFile fafile,
 *                           PileupColumn 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;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  int __pyx_v_reads_nodel;
  int __pyx_v_reads_pp;
  int __pyx_v_reads_pp_nodel;
  int __pyx_v_matches;
  int __pyx_v_matches_pp;
  int __pyx_v_mismatches;
  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_n = NULL;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_v_refbase = NULL;
  PyObject *__pyx_v_alnbase = NULL;
  int __pyx_v_rms_baseq;
  int __pyx_v_rms_baseq_pp;
  int __pyx_v_rms_baseq_matches;
  int __pyx_v_rms_baseq_matches_pp;
  int __pyx_v_rms_baseq_mismatches;
  int __pyx_v_rms_baseq_mismatches_pp;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  bam_pileup1_t **__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  long __pyx_t_7;
  int __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":2493
 *     cdef bint is_proper_pair
 *     # counting variables
 *     cdef int reads_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_nodel = 0
 */
  __pyx_v_reads_nodel = 0;

  /* "pysamstats.pyx":2494
 *     # counting variables
 *     cdef int reads_nodel = 0
 *     cdef int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp_nodel = 0
 *     cdef int matches = 0
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":2495
 *     cdef int reads_nodel = 0
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int matches = 0
 *     cdef int matches_pp = 0
 */
  __pyx_v_reads_pp_nodel = 0;

  /* "pysamstats.pyx":2496
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_nodel = 0
 *     cdef int matches = 0             # <<<<<<<<<<<<<<
 *     cdef int matches_pp = 0
 *     cdef int mismatches = 0
 */
  __pyx_v_matches = 0;

  /* "pysamstats.pyx":2497
 *     cdef int reads_pp_nodel = 0
 *     cdef int matches = 0
 *     cdef int matches_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int mismatches = 0
 *     cdef int mismatches_pp = 0
 */
  __pyx_v_matches_pp = 0;

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

  /* "pysamstats.pyx":2499
 *     cdef int matches_pp = 0
 *     cdef int mismatches = 0
 *     cdef int mismatches_pp = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef uint64_t baseq
 */
  __pyx_v_mismatches_pp = 0;

  /* "pysamstats.pyx":2504
 *     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":2505
 * 
 *     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":2506
 *     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":2507
 *     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":2508
 *     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":2509
 *     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":2512
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":2516
 * 
 *     # get chromosome name and position
 *     chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":2520
 * 
 *     # reference base
 *     refbase = fafile.fetch(reference=chrom, start=col.pos,             # <<<<<<<<<<<<<<
 *                            end=col.pos + 1).upper()
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_fafile), __pyx_n_s_fetch); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reference, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->pos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_start, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":2521
 *     # 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 = __Pyx_PyInt_From_long((__pyx_v_col->pos + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_end, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":2520
 * 
 *     # reference base
 *     refbase = fafile.fetch(reference=chrom, start=col.pos,             # <<<<<<<<<<<<<<
 *                            end=col.pos + 1).upper()
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pysamstats.pyx":2521
 *     # reference base
 *     refbase = fafile.fetch(reference=chrom, start=col.pos,
 *                            end=col.pos + 1).upper()             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_upper); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_refbase = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":2524
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":2525
 *     # 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":2526
 *     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_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

    /* "pysamstats.pyx":2527
 *         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_10 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_10;

    /* "pysamstats.pyx":2528
 *         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 = ((__pyx_v_flag & 2) != 0);

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

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

    /* "pysamstats.pyx":2531
 *         if is_proper_pair:
 *             reads_pp += 1
 *         if not read.is_del:             # <<<<<<<<<<<<<<
 *             reads_nodel += 1
 *             baseq = pysam_bam_get_qual(aln)[read.qpos]
 */
    __pyx_t_11 = ((!(__pyx_v_read->is_del != 0)) != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":2532
 *             reads_pp += 1
 *         if not read.is_del:
 *             reads_nodel += 1             # <<<<<<<<<<<<<<
 *             baseq = pysam_bam_get_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2
 */
      __pyx_v_reads_nodel = (__pyx_v_reads_nodel + 1);

      /* "pysamstats.pyx":2533
 *         if not read.is_del:
 *             reads_nodel += 1
 *             baseq = pysam_bam_get_qual(aln)[read.qpos]             # <<<<<<<<<<<<<<
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 */
      __pyx_v_baseq = (pysam_bam_get_qual(__pyx_v_aln)[__pyx_v_read->qpos]);

      /* "pysamstats.pyx":2534
 *             reads_nodel += 1
 *             baseq = pysam_bam_get_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":2535
 *             baseq = pysam_bam_get_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":2536
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared
 */
      __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":2537
 *             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":2538
 *             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_L7;
      }
      __pyx_L7:;

      /* "pysamstats.pyx":2539
 *                 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 = 2539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_alnbase, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysamstats.pyx":2540
 *                 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 = 2540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_11) {

        /* "pysamstats.pyx":2541
 *             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":2542
 *             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":2543
 *                 matches += 1
 *                 baseq_matches_squared_sum += baseq_squared
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     matches_pp += 1
 *                     baseq_matches_pp_squared_sum += baseq_squared
 */
        __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
        if (__pyx_t_11) {

          /* "pysamstats.pyx":2544
 *                 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":2545
 *                 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_L9;
        }
        __pyx_L9:;
        goto __pyx_L8;
      }
      /*else*/ {

        /* "pysamstats.pyx":2547
 *                     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":2548
 *             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":2549
 *                 mismatches += 1
 *                 baseq_mismatches_squared_sum += baseq_squared
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     mismatches_pp += 1
 *                     baseq_mismatches_pp_squared_sum += baseq_squared
 */
        __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
        if (__pyx_t_11) {

          /* "pysamstats.pyx":2550
 *                 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":2551
 *                 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_L10;
        }
        __pyx_L10:;
      }
      __pyx_L8:;
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "pysamstats.pyx":2554
 * 
 *     # 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_v_rms_baseq = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_squared_sum, __pyx_v_reads_nodel);

  /* "pysamstats.pyx":2555
 *     # 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_v_rms_baseq_pp = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_pp_squared_sum, __pyx_v_reads_pp_nodel);

  /* "pysamstats.pyx":2556
 *     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_v_rms_baseq_matches = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_matches_squared_sum, __pyx_v_matches);

  /* "pysamstats.pyx":2557
 *     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,
 */
  __pyx_v_rms_baseq_matches_pp = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_matches_pp_squared_sum, __pyx_v_matches_pp);

  /* "pysamstats.pyx":2558
 *     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_v_rms_baseq_mismatches = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_mismatches_squared_sum, __pyx_v_mismatches);

  /* "pysamstats.pyx":2559
 *     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_v_rms_baseq_mismatches_pp = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_mismatches_pp_squared_sum, __pyx_v_mismatches_pp);

  /* "pysamstats.pyx":2562
 *                                         mismatches_pp)
 * 
 *     if not PY2:             # <<<<<<<<<<<<<<
 *         refbase = str(refbase, 'ascii')
 *         # chrom = str(chrom, 'ascii')
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_PY2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_12 = ((!__pyx_t_11) != 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":2563
 * 
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')             # <<<<<<<<<<<<<<
 *         # chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_refbase);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_refbase);
    __Pyx_GIVEREF(__pyx_v_refbase);
    __Pyx_INCREF(__pyx_n_s_ascii);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_ascii);
    __Pyx_GIVEREF(__pyx_n_s_ascii);
    __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_refbase, __pyx_t_6);
    __pyx_t_6 = 0;
    goto __pyx_L11;
  }
  __pyx_L11:;

  /* "pysamstats.pyx":2565
 *         refbase = str(refbase, 'ascii')
 *         # chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,             # <<<<<<<<<<<<<<
 *             'reads_all': n, 'reads_pp': reads_pp,
 *             'matches': matches,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_pos, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_ref, __pyx_v_refbase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2566
 *         # chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 *             'reads_all': n, 'reads_pp': reads_pp,             # <<<<<<<<<<<<<<
 *             'matches': matches,
 *             'matches_pp': matches_pp,
 */
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":2568
 *             'reads_all': n, 'reads_pp': reads_pp,
 *             'matches': matches,
 *             'matches_pp': matches_pp,             # <<<<<<<<<<<<<<
 *             'mismatches': mismatches,
 *             'mismatches_pp': mismatches_pp,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_matches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2569
 *             'matches': matches,
 *             'matches_pp': matches_pp,
 *             'mismatches': mismatches,             # <<<<<<<<<<<<<<
 *             'mismatches_pp': mismatches_pp,
 *             'rms_baseq': rms_baseq,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2570
 *             'matches_pp': matches_pp,
 *             'mismatches': mismatches,
 *             'mismatches_pp': mismatches_pp,             # <<<<<<<<<<<<<<
 *             'rms_baseq': rms_baseq,
 *             'rms_baseq_pp': rms_baseq_pp,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2571
 *             'mismatches': mismatches,
 *             'mismatches_pp': mismatches_pp,
 *             'rms_baseq': rms_baseq,             # <<<<<<<<<<<<<<
 *             'rms_baseq_pp': rms_baseq_pp,
 *             'rms_baseq_matches': rms_baseq_matches,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2572
 *             '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,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2572; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2573
 *             '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,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_matches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_matches, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2574
 *             '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,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_matches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_matches_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2575
 *             '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,
 *             }
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_mismatches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_mismatches, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2576
 *             'rms_baseq_matches_pp': rms_baseq_matches_pp,
 *             'rms_baseq_mismatches': rms_baseq_mismatches,
 *             'rms_baseq_mismatches_pp': rms_baseq_mismatches_pp,             # <<<<<<<<<<<<<<
 *             }
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_mismatches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_mismatches_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = ((PyObject*)__pyx_t_6);
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2481
 * 
 * 
 * cpdef dict _rec_baseq_ext(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                           PileupColumn col, bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._rec_baseq_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __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_97_rec_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_96_rec_baseq_ext[] = "_rec_baseq_ext(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_97_rec_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_baseq_ext (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_baseq_ext", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2481; __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("_rec_baseq_ext", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2481; __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, "_rec_baseq_ext") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2481; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 2482; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":2482
 * 
 * cpdef dict _rec_baseq_ext(AlignmentFile alignmentfile, FastaFile fafile,
 *                           PileupColumn 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("_rec_baseq_ext", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2481; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._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_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_96_rec_baseq_ext(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":2481
 * 
 * 
 * cpdef dict _rec_baseq_ext(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                           PileupColumn col, bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_96_rec_baseq_ext(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_baseq_ext __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_baseq_ext(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_baseq_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2580
 * 
 * 
 * cpdef dict _rec_baseq_ext_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                               bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */

static PyObject *__pyx_pw_10pysamstats_99_rec_baseq_ext_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_ext_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_ext_pad *__pyx_optional_args) {

  /* "pysamstats.pyx":2581
 * 
 * cpdef dict _rec_baseq_ext_pad(FastaFile fafile, chrom, pos,
 *                               bint one_based=False):             # <<<<<<<<<<<<<<
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:
 */
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_v_refbase = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_baseq_ext_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":2582
 * cpdef dict _rec_baseq_ext_pad(FastaFile fafile, chrom, pos,
 *                               bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()             # <<<<<<<<<<<<<<
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_fafile), __pyx_n_s_fetch); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reference, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_start, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_end, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_upper); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_refbase = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":2583
 *                               bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:             # <<<<<<<<<<<<<<
 *         refbase = str(refbase, 'ascii')
 *     pos = pos + 1 if one_based else pos
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_PY2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (__pyx_t_6) {

    /* "pysamstats.pyx":2584
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_refbase);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_refbase);
    __Pyx_GIVEREF(__pyx_v_refbase);
    __Pyx_INCREF(__pyx_n_s_ascii);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_ascii);
    __Pyx_GIVEREF(__pyx_n_s_ascii);
    __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_refbase, __pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":2585
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 *             'reads_all': 0, 'reads_pp': 0,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_1 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __pyx_t_1;
    __pyx_t_1 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_3 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":2586
 *         refbase = str(refbase, 'ascii')
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,             # <<<<<<<<<<<<<<
 *             'reads_all': 0, 'reads_pp': 0,
 *             'matches': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_ref, __pyx_v_refbase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_matches, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_matches_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_mismatches, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_mismatches_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2580
 * 
 * 
 * cpdef dict _rec_baseq_ext_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                               bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats._rec_baseq_ext_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_refbase);
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_99_rec_baseq_ext_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_98_rec_baseq_ext_pad[] = "_rec_baseq_ext_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_99_rec_baseq_ext_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_baseq_ext_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_baseq_ext_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2580; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_baseq_ext_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2580; __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, "_rec_baseq_ext_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2580; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 2581; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":2581
 * 
 * cpdef dict _rec_baseq_ext_pad(FastaFile fafile, chrom, pos,
 *                               bint one_based=False):             # <<<<<<<<<<<<<<
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_baseq_ext_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2580; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_baseq_ext_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_98_rec_baseq_ext_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

  /* "pysamstats.pyx":2580
 * 
 * 
 * cpdef dict _rec_baseq_ext_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                               bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */

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

static PyObject *__pyx_pf_10pysamstats_98_rec_baseq_ext_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_baseq_ext_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_baseq_ext_pad", 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__rec_baseq_ext_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_baseq_ext_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2601
 * 
 * 
 * def stat_baseq_ext(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended base quality statistics per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_101stat_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_100stat_baseq_ext[] = "stat_baseq_ext(alignmentfile, fafile, **kwargs)\nGenerate extended base quality statistics per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    fafile : pysam.FastaFile or string\n        FASTA file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_101stat_baseq_ext = {"stat_baseq_ext", (PyCFunction)__pyx_pw_10pysamstats_101stat_baseq_ext, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_100stat_baseq_ext};
static PyObject *__pyx_pw_10pysamstats_101stat_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_fafile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,&__pyx_n_s_fafile,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 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", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2601; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      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 = 2601; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_alignmentfile = values[0];
    __pyx_v_fafile = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_baseq_ext", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2601; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_baseq_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_100stat_baseq_ext(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_100stat_baseq_ext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_kwargs) {
  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("stat_baseq_ext", 0);

  /* "pysamstats.pyx":2634
 *     """
 * 
 *     return _iter_pileup(_rec_baseq_ext, _rec_baseq_ext_pad, alignmentfile,             # <<<<<<<<<<<<<<
 *                         fafile=fafile, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_baseq_ext); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_baseq_ext_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":2635
 * 
 *     return _iter_pileup(_rec_baseq_ext, _rec_baseq_ext_pad, alignmentfile,
 *                         fafile=fafile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_fafile))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_fafile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2634
 *     """
 * 
 *     return _iter_pileup(_rec_baseq_ext, _rec_baseq_ext_pad, alignmentfile,             # <<<<<<<<<<<<<<
 *                         fafile=fafile, **kwargs)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2601
 * 
 * 
 * def stat_baseq_ext(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended base quality statistics per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_baseq_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2638
 * 
 * 
 * def load_baseq_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq_ext, dtype_baseq_ext, *args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_103load_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_102load_baseq_ext[] = "load_baseq_ext(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_103load_baseq_ext = {"load_baseq_ext", (PyCFunction)__pyx_pw_10pysamstats_103load_baseq_ext, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_102load_baseq_ext};
static PyObject *__pyx_pw_10pysamstats_103load_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("load_baseq_ext (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_102load_baseq_ext(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_102load_baseq_ext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_baseq_ext", 0);

  /* "pysamstats.pyx":2639
 * 
 * def load_baseq_ext(*args, **kwargs):
 *     return _load_stats(stat_baseq_ext, dtype_baseq_ext, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_baseq_ext); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_baseq_ext); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2639; __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_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2638
 * 
 * 
 * def load_baseq_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq_ext, dtype_baseq_ext, *args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_baseq_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2693
 * 
 * 
 * cpdef dict _rec_baseq_ext_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                  PileupColumn col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_105_rec_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_ext_strand(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_ext_strand *__pyx_optional_args) {

  /* "pysamstats.pyx":2694
 * 
 * cpdef dict _rec_baseq_ext_strand(AlignmentFile alignmentfile, FastaFile fafile,
 *                                  PileupColumn 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;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  int __pyx_v_is_reverse;
  int __pyx_v_reads_fwd;
  int __pyx_v_reads_rev;
  int __pyx_v_reads_nodel;
  int __pyx_v_reads_fwd_nodel;
  int __pyx_v_reads_rev_nodel;
  int __pyx_v_reads_pp;
  int __pyx_v_reads_pp_fwd;
  int __pyx_v_reads_pp_rev;
  int __pyx_v_reads_pp_nodel;
  int __pyx_v_reads_pp_fwd_nodel;
  int __pyx_v_reads_pp_rev_nodel;
  int __pyx_v_matches;
  int __pyx_v_matches_fwd;
  int __pyx_v_matches_rev;
  int __pyx_v_matches_pp;
  int __pyx_v_matches_pp_fwd;
  int __pyx_v_matches_pp_rev;
  int __pyx_v_mismatches;
  int __pyx_v_mismatches_fwd;
  int __pyx_v_mismatches_rev;
  int __pyx_v_mismatches_pp;
  int __pyx_v_mismatches_pp_fwd;
  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_n = NULL;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_v_refbase = NULL;
  PyObject *__pyx_v_alnbase = NULL;
  int __pyx_v_rms_baseq;
  int __pyx_v_rms_baseq_fwd;
  int __pyx_v_rms_baseq_rev;
  int __pyx_v_rms_baseq_pp;
  int __pyx_v_rms_baseq_pp_fwd;
  int __pyx_v_rms_baseq_pp_rev;
  int __pyx_v_rms_baseq_matches;
  int __pyx_v_rms_baseq_matches_fwd;
  int __pyx_v_rms_baseq_matches_rev;
  int __pyx_v_rms_baseq_matches_pp;
  int __pyx_v_rms_baseq_matches_pp_fwd;
  int __pyx_v_rms_baseq_matches_pp_rev;
  int __pyx_v_rms_baseq_mismatches;
  int __pyx_v_rms_baseq_mismatches_fwd;
  int __pyx_v_rms_baseq_mismatches_rev;
  int __pyx_v_rms_baseq_mismatches_pp;
  int __pyx_v_rms_baseq_mismatches_pp_fwd;
  int __pyx_v_rms_baseq_mismatches_pp_rev;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  bam_pileup1_t **__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  long __pyx_t_7;
  int __pyx_t_8;
  bam1_t *__pyx_t_9;
  uint16_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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":2707
 * 
 *     # counting variables
 *     cdef int reads_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_rev = 0
 *     cdef int reads_nodel = 0
 */
  __pyx_v_reads_fwd = 0;

  /* "pysamstats.pyx":2708
 *     # counting variables
 *     cdef int reads_fwd = 0
 *     cdef int reads_rev = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_nodel = 0
 *     cdef int reads_fwd_nodel = 0
 */
  __pyx_v_reads_rev = 0;

  /* "pysamstats.pyx":2709
 *     cdef int reads_fwd = 0
 *     cdef int reads_rev = 0
 *     cdef int reads_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_fwd_nodel = 0
 *     cdef int reads_rev_nodel = 0
 */
  __pyx_v_reads_nodel = 0;

  /* "pysamstats.pyx":2710
 *     cdef int reads_rev = 0
 *     cdef int reads_nodel = 0
 *     cdef int reads_fwd_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_rev_nodel = 0
 *     cdef int reads_pp = 0
 */
  __pyx_v_reads_fwd_nodel = 0;

  /* "pysamstats.pyx":2711
 *     cdef int reads_nodel = 0
 *     cdef int reads_fwd_nodel = 0
 *     cdef int reads_rev_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_fwd = 0
 */
  __pyx_v_reads_rev_nodel = 0;

  /* "pysamstats.pyx":2712
 *     cdef int reads_fwd_nodel = 0
 *     cdef int reads_rev_nodel = 0
 *     cdef int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp_fwd = 0
 *     cdef int reads_pp_rev = 0
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":2713
 *     cdef int reads_rev_nodel = 0
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp_rev = 0
 *     cdef int reads_pp_nodel = 0
 */
  __pyx_v_reads_pp_fwd = 0;

  /* "pysamstats.pyx":2714
 *     cdef int reads_pp = 0
 *     cdef int reads_pp_fwd = 0
 *     cdef int reads_pp_rev = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp_nodel = 0
 *     cdef int reads_pp_fwd_nodel = 0
 */
  __pyx_v_reads_pp_rev = 0;

  /* "pysamstats.pyx":2715
 *     cdef int reads_pp_fwd = 0
 *     cdef int reads_pp_rev = 0
 *     cdef int reads_pp_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp_fwd_nodel = 0
 *     cdef int reads_pp_rev_nodel = 0
 */
  __pyx_v_reads_pp_nodel = 0;

  /* "pysamstats.pyx":2716
 *     cdef int reads_pp_rev = 0
 *     cdef int reads_pp_nodel = 0
 *     cdef int reads_pp_fwd_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int reads_pp_rev_nodel = 0
 *     cdef int matches = 0
 */
  __pyx_v_reads_pp_fwd_nodel = 0;

  /* "pysamstats.pyx":2717
 *     cdef int reads_pp_nodel = 0
 *     cdef int reads_pp_fwd_nodel = 0
 *     cdef int reads_pp_rev_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef int matches = 0
 *     cdef int matches_fwd = 0
 */
  __pyx_v_reads_pp_rev_nodel = 0;

  /* "pysamstats.pyx":2718
 *     cdef int reads_pp_fwd_nodel = 0
 *     cdef int reads_pp_rev_nodel = 0
 *     cdef int matches = 0             # <<<<<<<<<<<<<<
 *     cdef int matches_fwd = 0
 *     cdef int matches_rev = 0
 */
  __pyx_v_matches = 0;

  /* "pysamstats.pyx":2719
 *     cdef int reads_pp_rev_nodel = 0
 *     cdef int matches = 0
 *     cdef int matches_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int matches_rev = 0
 *     cdef int matches_pp = 0
 */
  __pyx_v_matches_fwd = 0;

  /* "pysamstats.pyx":2720
 *     cdef int matches = 0
 *     cdef int matches_fwd = 0
 *     cdef int matches_rev = 0             # <<<<<<<<<<<<<<
 *     cdef int matches_pp = 0
 *     cdef int matches_pp_fwd = 0
 */
  __pyx_v_matches_rev = 0;

  /* "pysamstats.pyx":2721
 *     cdef int matches_fwd = 0
 *     cdef int matches_rev = 0
 *     cdef int matches_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int matches_pp_fwd = 0
 *     cdef int matches_pp_rev = 0
 */
  __pyx_v_matches_pp = 0;

  /* "pysamstats.pyx":2722
 *     cdef int matches_rev = 0
 *     cdef int matches_pp = 0
 *     cdef int matches_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int matches_pp_rev = 0
 *     cdef int mismatches = 0
 */
  __pyx_v_matches_pp_fwd = 0;

  /* "pysamstats.pyx":2723
 *     cdef int matches_pp = 0
 *     cdef int matches_pp_fwd = 0
 *     cdef int matches_pp_rev = 0             # <<<<<<<<<<<<<<
 *     cdef int mismatches = 0
 *     cdef int mismatches_fwd = 0
 */
  __pyx_v_matches_pp_rev = 0;

  /* "pysamstats.pyx":2724
 *     cdef int matches_pp_fwd = 0
 *     cdef int matches_pp_rev = 0
 *     cdef int mismatches = 0             # <<<<<<<<<<<<<<
 *     cdef int mismatches_fwd = 0
 *     cdef int mismatches_rev = 0
 */
  __pyx_v_mismatches = 0;

  /* "pysamstats.pyx":2725
 *     cdef int matches_pp_rev = 0
 *     cdef int mismatches = 0
 *     cdef int mismatches_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int mismatches_rev = 0
 *     cdef int mismatches_pp = 0
 */
  __pyx_v_mismatches_fwd = 0;

  /* "pysamstats.pyx":2726
 *     cdef int mismatches = 0
 *     cdef int mismatches_fwd = 0
 *     cdef int mismatches_rev = 0             # <<<<<<<<<<<<<<
 *     cdef int mismatches_pp = 0
 *     cdef int mismatches_pp_fwd = 0
 */
  __pyx_v_mismatches_rev = 0;

  /* "pysamstats.pyx":2727
 *     cdef int mismatches_fwd = 0
 *     cdef int mismatches_rev = 0
 *     cdef int mismatches_pp = 0             # <<<<<<<<<<<<<<
 *     cdef int mismatches_pp_fwd = 0
 *     cdef int mismatches_pp_rev = 0
 */
  __pyx_v_mismatches_pp = 0;

  /* "pysamstats.pyx":2728
 *     cdef int mismatches_rev = 0
 *     cdef int mismatches_pp = 0
 *     cdef int mismatches_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef int mismatches_pp_rev = 0
 * 
 */
  __pyx_v_mismatches_pp_fwd = 0;

  /* "pysamstats.pyx":2729
 *     cdef int mismatches_pp = 0
 *     cdef int mismatches_pp_fwd = 0
 *     cdef int mismatches_pp_rev = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef uint64_t baseq
 */
  __pyx_v_mismatches_pp_rev = 0;

  /* "pysamstats.pyx":2734
 *     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":2735
 * 
 *     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":2736
 *     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":2737
 *     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":2738
 *     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":2739
 *     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":2740
 *     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":2741
 *     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":2742
 *     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":2743
 *     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":2744
 *     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":2745
 *     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":2746
 *     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":2747
 *     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":2748
 *     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":2749
 *     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":2750
 *     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":2751
 *     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":2754
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_col), __pyx_n_s_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_n = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":2758
 * 
 *     # get chromosome name and position
 *     chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "pysamstats.pyx":2762
 * 
 *     # reference base
 *     refbase = fafile.fetch(reference=chrom, start=col.pos, end=col.pos+1).upper()             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_fafile), __pyx_n_s_fetch); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reference, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_col->pos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_start, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_From_long((__pyx_v_col->pos + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_end, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_upper); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_refbase = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":2765
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_v_n); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_i = __pyx_t_8;

    /* "pysamstats.pyx":2766
 *     # 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":2767
 *     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_9 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_9;

    /* "pysamstats.pyx":2768
 *         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_10 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_10;

    /* "pysamstats.pyx":2769
 *         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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":2770
 *         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 = ((__pyx_v_flag & 16) != 0);

    /* "pysamstats.pyx":2772
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 * 
 *         if is_reverse:             # <<<<<<<<<<<<<<
 *             reads_rev += 1
 *         else:
 */
    __pyx_t_11 = (__pyx_v_is_reverse != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":2773
 * 
 *         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":2775
 *             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":2776
 *         else:
 *             reads_fwd += 1
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *             if is_reverse:
 */
    __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":2777
 *             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":2778
 *         if is_proper_pair:
 *             reads_pp += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_pp_rev += 1
 *             else:
 */
      __pyx_t_11 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":2779
 *             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":2781
 *                 reads_pp_rev += 1
 *             else:
 *                 reads_pp_fwd += 1             # <<<<<<<<<<<<<<
 * 
 *         if not read.is_del:
 */
        __pyx_v_reads_pp_fwd = (__pyx_v_reads_pp_fwd + 1);
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysamstats.pyx":2783
 *                 reads_pp_fwd += 1
 * 
 *         if not read.is_del:             # <<<<<<<<<<<<<<
 *             reads_nodel += 1
 *             baseq = pysam_bam_get_qual(aln)[read.qpos]
 */
    __pyx_t_11 = ((!(__pyx_v_read->is_del != 0)) != 0);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":2784
 * 
 *         if not read.is_del:
 *             reads_nodel += 1             # <<<<<<<<<<<<<<
 *             baseq = pysam_bam_get_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2
 */
      __pyx_v_reads_nodel = (__pyx_v_reads_nodel + 1);

      /* "pysamstats.pyx":2785
 *         if not read.is_del:
 *             reads_nodel += 1
 *             baseq = pysam_bam_get_qual(aln)[read.qpos]             # <<<<<<<<<<<<<<
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 */
      __pyx_v_baseq = (pysam_bam_get_qual(__pyx_v_aln)[__pyx_v_read->qpos]);

      /* "pysamstats.pyx":2786
 *             reads_nodel += 1
 *             baseq = pysam_bam_get_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":2787
 *             baseq = pysam_bam_get_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":2788
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_rev_nodel += 1
 *                 baseq_rev_squared_sum += baseq_squared
 */
      __pyx_t_11 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":2789
 *             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":2790
 *             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_L9;
      }
      /*else*/ {

        /* "pysamstats.pyx":2792
 *                 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":2793
 *             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_L9:;

      /* "pysamstats.pyx":2794
 *                 reads_fwd_nodel += 1
 *                 baseq_fwd_squared_sum += baseq_squared
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared
 */
      __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
      if (__pyx_t_11) {

        /* "pysamstats.pyx":2795
 *                 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":2796
 *             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":2797
 *                 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
 */
        __pyx_t_11 = (__pyx_v_is_reverse != 0);
        if (__pyx_t_11) {

          /* "pysamstats.pyx":2798
 *                 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":2799
 *                 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_L11;
        }
        /*else*/ {

          /* "pysamstats.pyx":2801
 *                     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":2802
 *                 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_L11:;
        goto __pyx_L10;
      }
      __pyx_L10:;

      /* "pysamstats.pyx":2803
 *                     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 = 2803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_alnbase, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysamstats.pyx":2804
 *                     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 = 2804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_11) {

        /* "pysamstats.pyx":2805
 *             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":2806
 *             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":2807
 *                 matches += 1
 *                 baseq_matches_squared_sum += baseq_squared
 *                 if is_reverse:             # <<<<<<<<<<<<<<
 *                     matches_rev += 1
 *                     baseq_matches_rev_squared_sum += baseq_squared
 */
        __pyx_t_11 = (__pyx_v_is_reverse != 0);
        if (__pyx_t_11) {

          /* "pysamstats.pyx":2808
 *                 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":2809
 *                 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_L13;
        }
        /*else*/ {

          /* "pysamstats.pyx":2811
 *                     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":2812
 *                 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_L13:;

        /* "pysamstats.pyx":2814
 *                     baseq_matches_fwd_squared_sum += baseq_squared
 * 
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     matches_pp += 1
 *                     baseq_matches_pp_squared_sum += baseq_squared
 */
        __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
        if (__pyx_t_11) {

          /* "pysamstats.pyx":2815
 * 
 *                 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":2816
 *                 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":2817
 *                     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
 */
          __pyx_t_11 = (__pyx_v_is_reverse != 0);
          if (__pyx_t_11) {

            /* "pysamstats.pyx":2818
 *                     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":2819
 *                     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_L15;
          }
          /*else*/ {

            /* "pysamstats.pyx":2821
 *                         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":2822
 *                     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_L15:;
          goto __pyx_L14;
        }
        __pyx_L14:;
        goto __pyx_L12;
      }
      /*else*/ {

        /* "pysamstats.pyx":2824
 *                         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":2825
 *             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":2826
 *                 mismatches += 1
 *                 baseq_mismatches_squared_sum += baseq_squared
 *                 if is_reverse:             # <<<<<<<<<<<<<<
 *                     mismatches_rev += 1
 *                     baseq_mismatches_rev_squared_sum += baseq_squared
 */
        __pyx_t_11 = (__pyx_v_is_reverse != 0);
        if (__pyx_t_11) {

          /* "pysamstats.pyx":2827
 *                 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":2828
 *                 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_L16;
        }
        /*else*/ {

          /* "pysamstats.pyx":2830
 *                     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":2831
 *                 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_L16:;

        /* "pysamstats.pyx":2833
 *                     baseq_mismatches_fwd_squared_sum += baseq_squared
 * 
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     mismatches_pp += 1
 *                     baseq_mismatches_pp_squared_sum += baseq_squared
 */
        __pyx_t_11 = (__pyx_v_is_proper_pair != 0);
        if (__pyx_t_11) {

          /* "pysamstats.pyx":2834
 * 
 *                 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":2835
 *                 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":2836
 *                     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
 */
          __pyx_t_11 = (__pyx_v_is_reverse != 0);
          if (__pyx_t_11) {

            /* "pysamstats.pyx":2837
 *                     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":2838
 *                     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_L18;
          }
          /*else*/ {

            /* "pysamstats.pyx":2840
 *                         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":2841
 *                     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_L18:;
          goto __pyx_L17;
        }
        __pyx_L17:;
      }
      __pyx_L12:;
      goto __pyx_L8;
    }
    __pyx_L8:;
  }

  /* "pysamstats.pyx":2844
 * 
 *     # 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_v_rms_baseq = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_squared_sum, __pyx_v_reads_nodel);

  /* "pysamstats.pyx":2845
 *     # 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_v_rms_baseq_fwd = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_fwd_squared_sum, __pyx_v_reads_fwd_nodel);

  /* "pysamstats.pyx":2846
 *     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_v_rms_baseq_rev = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_rev_squared_sum, __pyx_v_reads_rev_nodel);

  /* "pysamstats.pyx":2847
 *     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_v_rms_baseq_pp = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_pp_squared_sum, __pyx_v_reads_pp_nodel);

  /* "pysamstats.pyx":2848
 *     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_v_rms_baseq_pp_fwd = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_pp_fwd_squared_sum, __pyx_v_reads_pp_fwd_nodel);

  /* "pysamstats.pyx":2849
 *     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,
 */
  __pyx_v_rms_baseq_pp_rev = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_pp_rev_squared_sum, __pyx_v_reads_pp_rev_nodel);

  /* "pysamstats.pyx":2850
 *     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_v_rms_baseq_matches = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_matches_squared_sum, __pyx_v_matches);

  /* "pysamstats.pyx":2851
 *     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,
 */
  __pyx_v_rms_baseq_matches_fwd = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_matches_fwd_squared_sum, __pyx_v_matches_fwd);

  /* "pysamstats.pyx":2853
 *     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_v_rms_baseq_matches_rev = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_matches_rev_squared_sum, __pyx_v_matches_rev);

  /* "pysamstats.pyx":2855
 *     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_v_rms_baseq_matches_pp = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_matches_pp_squared_sum, __pyx_v_matches_pp);

  /* "pysamstats.pyx":2856
 *                                       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,
 */
  __pyx_v_rms_baseq_matches_pp_fwd = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_matches_pp_fwd_squared_sum, __pyx_v_matches_pp_fwd);

  /* "pysamstats.pyx":2858
 *     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_v_rms_baseq_matches_pp_rev = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_matches_pp_rev_squared_sum, __pyx_v_matches_pp_rev);

  /* "pysamstats.pyx":2860
 *     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_v_rms_baseq_mismatches = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_mismatches_squared_sum, __pyx_v_mismatches);

  /* "pysamstats.pyx":2861
 *                                          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,
 */
  __pyx_v_rms_baseq_mismatches_fwd = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_mismatches_fwd_squared_sum, __pyx_v_mismatches_fwd);

  /* "pysamstats.pyx":2863
 *     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,
 */
  __pyx_v_rms_baseq_mismatches_rev = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_mismatches_rev_squared_sum, __pyx_v_mismatches_rev);

  /* "pysamstats.pyx":2865
 *     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,
 */
  __pyx_v_rms_baseq_mismatches_pp = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_mismatches_pp_squared_sum, __pyx_v_mismatches_pp);

  /* "pysamstats.pyx":2867
 *     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,
 */
  __pyx_v_rms_baseq_mismatches_pp_fwd = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_mismatches_pp_fwd_squared_sum, __pyx_v_mismatches_pp_fwd);

  /* "pysamstats.pyx":2869
 *     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_v_rms_baseq_mismatches_pp_rev = __pyx_f_10pysamstats__rootmean(__pyx_v_baseq_mismatches_pp_rev_squared_sum, __pyx_v_mismatches_pp_rev);

  /* "pysamstats.pyx":2872
 *                                             mismatches_pp_rev)
 * 
 *     if not PY2:             # <<<<<<<<<<<<<<
 *         refbase = str(refbase, 'ascii')
 *         # chrom = str(chrom, 'ascii')
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_PY2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_12 = ((!__pyx_t_11) != 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":2873
 * 
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')             # <<<<<<<<<<<<<<
 *         # chrom = str(chrom, 'ascii')
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_refbase);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_refbase);
    __Pyx_GIVEREF(__pyx_v_refbase);
    __Pyx_INCREF(__pyx_n_s_ascii);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_ascii);
    __Pyx_GIVEREF(__pyx_n_s_ascii);
    __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_refbase, __pyx_t_6);
    __pyx_t_6 = 0;
    goto __pyx_L19;
  }
  __pyx_L19:;

  /* "pysamstats.pyx":2875
 *         refbase = str(refbase, 'ascii')
 *         # chrom = str(chrom, 'ascii')
 *     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_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_pos, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_ref, __pyx_v_refbase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2876
 *         # chrom = str(chrom, 'ascii')
 *     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, 'matches_fwd': matches_fwd, 'matches_rev': matches_rev,
 */
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_all, __pyx_v_n) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_reads_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_reads_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2877
 *     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, '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_1 = __Pyx_PyInt_From_int(__pyx_v_reads_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_reads_pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_reads_pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reads_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2878
 *             '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, '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, 'mismatches_fwd': mismatches_fwd, 'mismatches_rev': mismatches_rev,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_matches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_matches_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_matches_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2879
 *             'reads_pp': reads_pp, 'reads_pp_fwd': reads_pp_fwd, 'reads_pp_rev': reads_pp_rev,
 *             'matches': matches, '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, '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_1 = __Pyx_PyInt_From_int(__pyx_v_matches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_matches_pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_matches_pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_matches_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2880
 *             'matches': matches, '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, '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,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2881
 *             'matches_pp': matches_pp, 'matches_pp_fwd': matches_pp_fwd, 'matches_pp_rev': matches_pp_rev,
 *             '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,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches_pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_mismatches_pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mismatches_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2882
 *             '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,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2883
 *             '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,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2884
 *             '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,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_matches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_matches, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_matches_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_matches_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_matches_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_matches_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2885
 *             '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,
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_matches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_matches_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_matches_pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_matches_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_matches_pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_matches_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2886
 *             '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,
 *             }
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_mismatches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_mismatches, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_mismatches_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_mismatches_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_mismatches_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_mismatches_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2887
 *             '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,             # <<<<<<<<<<<<<<
 *             }
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_mismatches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_mismatches_pp, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_mismatches_pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_mismatches_pp_fwd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rms_baseq_mismatches_pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_rms_baseq_mismatches_pp_rev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = ((PyObject*)__pyx_t_6);
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2693
 * 
 * 
 * cpdef dict _rec_baseq_ext_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                  PileupColumn col, bint one_based=False):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._rec_baseq_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __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_105_rec_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_104_rec_baseq_ext_strand[] = "_rec_baseq_ext_strand(AlignmentFile alignmentfile, FastaFile fafile, PileupColumn col, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_105_rec_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_baseq_ext_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_baseq_ext_strand", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2693; __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("_rec_baseq_ext_strand", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2693; __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, "_rec_baseq_ext_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2693; __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_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = 2694; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":2694
 * 
 * cpdef dict _rec_baseq_ext_strand(AlignmentFile alignmentfile, FastaFile fafile,
 *                                  PileupColumn 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("_rec_baseq_ext_strand", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2693; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._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_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_104_rec_baseq_ext_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

  /* "pysamstats.pyx":2693
 * 
 * 
 * cpdef dict _rec_baseq_ext_strand(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                                  PileupColumn col, bint one_based=False):
 * 
 */

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

static PyObject *__pyx_pf_10pysamstats_104_rec_baseq_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_baseq_ext_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_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__rec_baseq_ext_strand(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_baseq_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2891
 * 
 * 
 * cpdef dict _rec_baseq_ext_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                      bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */

static PyObject *__pyx_pw_10pysamstats_107_rec_baseq_ext_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats__rec_baseq_ext_strand_pad(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats__rec_baseq_ext_strand_pad *__pyx_optional_args) {

  /* "pysamstats.pyx":2892
 * 
 * cpdef dict _rec_baseq_ext_strand_pad(FastaFile fafile, chrom, pos,
 *                                      bint one_based=False):             # <<<<<<<<<<<<<<
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:
 */
  int __pyx_v_one_based = ((int)0);
  PyObject *__pyx_v_refbase = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_baseq_ext_strand_pad", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }
  __Pyx_INCREF(__pyx_v_pos);

  /* "pysamstats.pyx":2893
 * cpdef dict _rec_baseq_ext_strand_pad(FastaFile fafile, chrom, pos,
 *                                      bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()             # <<<<<<<<<<<<<<
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_fafile), __pyx_n_s_fetch); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reference, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_start, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_end, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_upper); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_refbase = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":2894
 *                                      bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:             # <<<<<<<<<<<<<<
 *         refbase = str(refbase, 'ascii')
 *     pos = pos + 1 if one_based else pos
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_PY2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (__pyx_t_6) {

    /* "pysamstats.pyx":2895
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')             # <<<<<<<<<<<<<<
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_refbase);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_refbase);
    __Pyx_GIVEREF(__pyx_v_refbase);
    __Pyx_INCREF(__pyx_n_s_ascii);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_ascii);
    __Pyx_GIVEREF(__pyx_n_s_ascii);
    __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_refbase, __pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":2896
 *     if not PY2:
 *         refbase = str(refbase, 'ascii')
 *     pos = pos + 1 if one_based else pos             # <<<<<<<<<<<<<<
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 *             'reads_all': 0, 'reads_fwd': 0, 'reads_rev': 0,
 */
  if ((__pyx_v_one_based != 0)) {
    __pyx_t_1 = PyNumber_Add(__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __pyx_t_1;
    __pyx_t_1 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_pos);
    __pyx_t_3 = __pyx_v_pos;
  }
  __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":2897
 *         refbase = str(refbase, 'ascii')
 *     pos = pos + 1 if one_based else pos
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,             # <<<<<<<<<<<<<<
 *             'reads_all': 0, 'reads_fwd': 0, 'reads_rev': 0,
 *             'reads_pp': 0, 'reads_pp_fwd': 0, 'reads_pp_rev': 0,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_pos, __pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_ref, __pyx_v_refbase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_all, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reads_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_matches_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mismatches_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_matches, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_matches_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_matches_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_matches_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_matches_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_matches_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_mismatches, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_mismatches_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_mismatches_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_mismatches_pp, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_mismatches_pp_fwd, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_rms_baseq_mismatches_pp_rev, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2891
 * 
 * 
 * cpdef dict _rec_baseq_ext_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                      bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats._rec_baseq_ext_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_refbase);
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_107_rec_baseq_ext_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_106_rec_baseq_ext_strand_pad[] = "_rec_baseq_ext_strand_pad(FastaFile fafile, chrom, pos, bool one_based=False) -> dict";
static PyObject *__pyx_pw_10pysamstats_107_rec_baseq_ext_strand_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_baseq_ext_strand_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_baseq_ext_strand_pad", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2891; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_baseq_ext_strand_pad", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2891; __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, "_rec_baseq_ext_strand_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2891; __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_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = 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 = 2892; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":2892
 * 
 * cpdef dict _rec_baseq_ext_strand_pad(FastaFile fafile, chrom, pos,
 *                                      bint one_based=False):             # <<<<<<<<<<<<<<
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 *     if not PY2:
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_baseq_ext_strand_pad", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2891; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats._rec_baseq_ext_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_106_rec_baseq_ext_strand_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

  /* "pysamstats.pyx":2891
 * 
 * 
 * cpdef dict _rec_baseq_ext_strand_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                                      bint one_based=False):
 *     refbase = fafile.fetch(reference=chrom, start=pos, end=pos+1).upper()
 */

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

static PyObject *__pyx_pf_10pysamstats_106_rec_baseq_ext_strand_pad(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_baseq_ext_strand_pad __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_baseq_ext_strand_pad", 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__rec_baseq_ext_strand_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._rec_baseq_ext_strand_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2913
 * 
 * 
 * def stat_baseq_ext_strand(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended base quality statistics by strand per genome position.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_109stat_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_108stat_baseq_ext_strand[] = "stat_baseq_ext_strand(alignmentfile, fafile, **kwargs)\nGenerate extended base quality statistics by strand per genome position.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    fafile : pysam.FastaFile or string\n        FASTA file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_109stat_baseq_ext_strand = {"stat_baseq_ext_strand", (PyCFunction)__pyx_pw_10pysamstats_109stat_baseq_ext_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_108stat_baseq_ext_strand};
static PyObject *__pyx_pw_10pysamstats_109stat_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_fafile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,&__pyx_n_s_fafile,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 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", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2913; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      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 = 2913; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_alignmentfile = values[0];
    __pyx_v_fafile = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_baseq_ext_strand", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2913; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_baseq_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_108stat_baseq_ext_strand(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_108stat_baseq_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_kwargs) {
  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("stat_baseq_ext_strand", 0);

  /* "pysamstats.pyx":2946
 *     """
 * 
 *     return _iter_pileup(_rec_baseq_ext_strand, _rec_baseq_ext_strand_pad,             # <<<<<<<<<<<<<<
 *                         alignmentfile, fafile=fafile, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_baseq_ext_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_rec_baseq_ext_strand_pad); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":2947
 * 
 *     return _iter_pileup(_rec_baseq_ext_strand, _rec_baseq_ext_strand_pad,
 *                         alignmentfile, fafile=fafile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":2946
 *     """
 * 
 *     return _iter_pileup(_rec_baseq_ext_strand, _rec_baseq_ext_strand_pad,             # <<<<<<<<<<<<<<
 *                         alignmentfile, fafile=fafile, **kwargs)
 * 
 */
  __pyx_t_3 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":2947
 * 
 *     return _iter_pileup(_rec_baseq_ext_strand, _rec_baseq_ext_strand_pad,
 *                         alignmentfile, fafile=fafile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_fafile))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_fafile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2946
 *     """
 * 
 *     return _iter_pileup(_rec_baseq_ext_strand, _rec_baseq_ext_strand_pad,             # <<<<<<<<<<<<<<
 *                         alignmentfile, fafile=fafile, **kwargs)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2913
 * 
 * 
 * def stat_baseq_ext_strand(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended base quality statistics by strand per genome position.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_baseq_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2950
 * 
 * 
 * def load_baseq_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq_ext_strand, dtype_baseq_ext_strand,
 *                        *args, **kwargs)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_111load_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_110load_baseq_ext_strand[] = "load_baseq_ext_strand(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_111load_baseq_ext_strand = {"load_baseq_ext_strand", (PyCFunction)__pyx_pw_10pysamstats_111load_baseq_ext_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_110load_baseq_ext_strand};
static PyObject *__pyx_pw_10pysamstats_111load_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("load_baseq_ext_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_110load_baseq_ext_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_110load_baseq_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_baseq_ext_strand", 0);

  /* "pysamstats.pyx":2951
 * 
 * def load_baseq_ext_strand(*args, **kwargs):
 *     return _load_stats(stat_baseq_ext_strand, dtype_baseq_ext_strand,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_baseq_ext_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_baseq_ext_strand); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":2952
 * def load_baseq_ext_strand(*args, **kwargs):
 *     return _load_stats(stat_baseq_ext_strand, dtype_baseq_ext_strand,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":2951
 * 
 * def load_baseq_ext_strand(*args, **kwargs):
 *     return _load_stats(stat_baseq_ext_strand, dtype_baseq_ext_strand,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __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_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":2952
 * def load_baseq_ext_strand(*args, **kwargs):
 *     return _load_stats(stat_baseq_ext_strand, dtype_baseq_ext_strand,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":2951
 * 
 * def load_baseq_ext_strand(*args, **kwargs):
 *     return _load_stats(stat_baseq_ext_strand, dtype_baseq_ext_strand,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2950
 * 
 * 
 * def load_baseq_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq_ext_strand, dtype_baseq_ext_strand,
 *                        *args, **kwargs)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_baseq_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2970
 * 
 * 
 * def stat_coverage_gc(alignmentfile, fafile, chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                      one_based=False, truncate=False, pad=False, max_depth=8000,
 *                      window_size=300, window_offset=None, **kwargs):
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_113stat_coverage_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_112stat_coverage_gc[] = "stat_coverage_gc(alignmentfile, fafile, chrom=None, start=None, end=None, one_based=False, truncate=False, pad=False, max_depth=8000, window_size=300, window_offset=None, **kwargs)\nGenerate coverage statistics per genome position with reference genome\n    %GC composition in surrounding window.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    fafile : pysam.FastaFile or string\n        FASTA file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n    window_size : int\n        size of surrounding window in base pairs\n    window_offset :\n        distance from window start to record position\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_113stat_coverage_gc = {"stat_coverage_gc", (PyCFunction)__pyx_pw_10pysamstats_113stat_coverage_gc, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_112stat_coverage_gc};
static PyObject *__pyx_pw_10pysamstats_113stat_coverage_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__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_truncate = 0;
  PyObject *__pyx_v_pad = 0;
  PyObject *__pyx_v_max_depth = 0;
  PyObject *__pyx_v_window_size = 0;
  PyObject *__pyx_v_window_offset = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("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_alignmentfile,&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_one_based,&__pyx_n_s_truncate,&__pyx_n_s_pad,&__pyx_n_s_max_depth,&__pyx_n_s_window_size,&__pyx_n_s_window_offset,0};
    PyObject* values[11] = {0,0,0,0,0,0,0,0,0,0,0};
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);

    /* "pysamstats.pyx":2971
 * 
 * def stat_coverage_gc(alignmentfile, fafile, chrom=None, start=None, end=None,
 *                      one_based=False, truncate=False, pad=False, max_depth=8000,             # <<<<<<<<<<<<<<
 *                      window_size=300, window_offset=None, **kwargs):
 *     """Generate coverage statistics per genome position with reference genome
 */
    values[5] = ((PyObject *)Py_False);
    values[6] = ((PyObject *)Py_False);
    values[7] = ((PyObject *)Py_False);
    values[8] = ((PyObject *)__pyx_int_8000);
    values[9] = ((PyObject *)__pyx_int_300);

    /* "pysamstats.pyx":2972
 * def stat_coverage_gc(alignmentfile, fafile, chrom=None, start=None, end=None,
 *                      one_based=False, truncate=False, pad=False, max_depth=8000,
 *                      window_size=300, window_offset=None, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate coverage statistics per genome position with reference genome
 *     %GC composition in surrounding window.
 */
    values[10] = ((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 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_alignmentfile)) != 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, 11, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2970; __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_truncate);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pad);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_depth);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_window_size);
          if (value) { values[9] = value; kw_args--; }
        }
        case 10:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_window_offset);
          if (value) { values[10] = 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 = 2970; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_alignmentfile = values[0];
    __pyx_v_fafile = 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_truncate = values[6];
    __pyx_v_pad = values[7];
    __pyx_v_max_depth = values[8];
    __pyx_v_window_size = values[9];
    __pyx_v_window_offset = values[10];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage_gc", 0, 2, 11, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2970; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_coverage_gc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_112stat_coverage_gc(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_truncate, __pyx_v_pad, __pyx_v_max_depth, __pyx_v_window_size, __pyx_v_window_offset, __pyx_v_kwargs);

  /* "pysamstats.pyx":2970
 * 
 * 
 * def stat_coverage_gc(alignmentfile, fafile, chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                      one_based=False, truncate=False, pad=False, max_depth=8000,
 *                      window_size=300, window_offset=None, **kwargs):
 */

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

/* "pysamstats.pyx":3014
 *         window_offset = window_size / 2
 * 
 *     def _rec_coverage_gc(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                          PileupColumn col, bint one_based):
 *         chrom = alignmentfile.getrname(col.tid)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_16stat_coverage_gc_1_rec_coverage_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_16stat_coverage_gc_1_rec_coverage_gc = {"_rec_coverage_gc", (PyCFunction)__pyx_pw_10pysamstats_16stat_coverage_gc_1_rec_coverage_gc, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_10pysamstats_16stat_coverage_gc_1_rec_coverage_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_coverage_gc (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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_alignmentfile)) != 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("_rec_coverage_gc", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __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("_rec_coverage_gc", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_one_based)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_coverage_gc", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_rec_coverage_gc") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
    }
    __pyx_v_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)values[2]);
    __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 = 3015; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_coverage_gc", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.stat_coverage_gc._rec_coverage_gc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_14calignmentfile_PileupColumn, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_16stat_coverage_gc__rec_coverage_gc(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);

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

static PyObject *__pyx_pf_10pysamstats_16stat_coverage_gc__rec_coverage_gc(PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_col, int __pyx_v_one_based) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *__pyx_cur_scope;
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *__pyx_outer_scope;
  PyObject *__pyx_v_chrom = NULL;
  PyObject *__pyx_v_ref_window_start = NULL;
  PyObject *__pyx_v_ref_window_end = NULL;
  PyObject *__pyx_v_ref_window = NULL;
  long __pyx_v_gc_percent;
  PyObject *__pyx_v_rec = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  struct __pyx_opt_args_10pysamstats__rec_coverage __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_coverage_gc", 0);
  __pyx_outer_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *) __Pyx_CyFunction_GetClosure(__pyx_self);
  __pyx_cur_scope = __pyx_outer_scope;

  /* "pysamstats.pyx":3016
 *     def _rec_coverage_gc(AlignmentFile alignmentfile, FastaFile fafile,
 *                          PileupColumn col, bint one_based):
 *         chrom = alignmentfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 * 
 *         ref_window_start = col.pos - window_offset
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_getrname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_col->tid); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3018
 *         chrom = alignmentfile.getrname(col.tid)
 * 
 *         ref_window_start = col.pos - window_offset             # <<<<<<<<<<<<<<
 *         ref_window_end = ref_window_start + window_size
 *         if ref_window_start < 0:
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_col->pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(!__pyx_cur_scope->__pyx_v_window_offset)) { __Pyx_RaiseClosureNameError("window_offset"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3018; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
  __pyx_t_2 = PyNumber_Subtract(__pyx_t_1, __pyx_cur_scope->__pyx_v_window_offset); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ref_window_start = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":3019
 * 
 *         ref_window_start = col.pos - window_offset
 *         ref_window_end = ref_window_start + window_size             # <<<<<<<<<<<<<<
 *         if ref_window_start < 0:
 *             ref_window_start = 0
 */
  if (unlikely(!__pyx_cur_scope->__pyx_v_window_size)) { __Pyx_RaiseClosureNameError("window_size"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3019; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
  __pyx_t_2 = PyNumber_Add(__pyx_v_ref_window_start, __pyx_cur_scope->__pyx_v_window_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_ref_window_end = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":3020
 *         ref_window_start = col.pos - window_offset
 *         ref_window_end = ref_window_start + window_size
 *         if ref_window_start < 0:             # <<<<<<<<<<<<<<
 *             ref_window_start = 0
 *         ref_window = fafile\
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_ref_window_start, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_6) {

    /* "pysamstats.pyx":3021
 *         ref_window_end = ref_window_start + window_size
 *         if ref_window_start < 0:
 *             ref_window_start = 0             # <<<<<<<<<<<<<<
 *         ref_window = fafile\
 *             .fetch(chrom, ref_window_start, ref_window_end)\
 */
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_DECREF_SET(__pyx_v_ref_window_start, __pyx_int_0);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":3023
 *             ref_window_start = 0
 *         ref_window = fafile\
 *             .fetch(chrom, ref_window_start, ref_window_end)\             # <<<<<<<<<<<<<<
 *             .lower()
 *         if len(ref_window) == 0:
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_fafile), __pyx_n_s_fetch); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = NULL;
  __pyx_t_7 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
      __pyx_t_7 = 1;
    }
  }
  __pyx_t_4 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (__pyx_t_3) {
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
  }
  __Pyx_INCREF(__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_7, __pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_v_chrom);
  __Pyx_INCREF(__pyx_v_ref_window_start);
  PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_7, __pyx_v_ref_window_start);
  __Pyx_GIVEREF(__pyx_v_ref_window_start);
  __Pyx_INCREF(__pyx_v_ref_window_end);
  PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_7, __pyx_v_ref_window_end);
  __Pyx_GIVEREF(__pyx_v_ref_window_end);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":3024
 *         ref_window = fafile\
 *             .fetch(chrom, ref_window_start, ref_window_end)\
 *             .lower()             # <<<<<<<<<<<<<<
 *         if len(ref_window) == 0:
 *             gc_percent = -1
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_lower); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (__pyx_t_1) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_ref_window = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":3025
 *             .fetch(chrom, ref_window_start, ref_window_end)\
 *             .lower()
 *         if len(ref_window) == 0:             # <<<<<<<<<<<<<<
 *             gc_percent = -1
 *         else:
 */
  __pyx_t_7 = PyObject_Length(__pyx_v_ref_window); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((__pyx_t_7 == 0) != 0);
  if (__pyx_t_6) {

    /* "pysamstats.pyx":3026
 *             .lower()
 *         if len(ref_window) == 0:
 *             gc_percent = -1             # <<<<<<<<<<<<<<
 *         else:
 *             gc_percent = _gc_content(ref_window)
 */
    __pyx_v_gc_percent = -1;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "pysamstats.pyx":3028
 *             gc_percent = -1
 *         else:
 *             gc_percent = _gc_content(ref_window)             # <<<<<<<<<<<<<<
 * 
 *         rec = _rec_coverage(alignmentfile, fafile, col, one_based)
 */
    __pyx_v_gc_percent = __pyx_f_10pysamstats__gc_content(__pyx_v_ref_window);
  }
  __pyx_L4:;

  /* "pysamstats.pyx":3030
 *             gc_percent = _gc_content(ref_window)
 * 
 *         rec = _rec_coverage(alignmentfile, fafile, col, one_based)             # <<<<<<<<<<<<<<
 *         rec['gc'] = gc_percent
 *         return rec
 */
  __pyx_t_8.__pyx_n = 1;
  __pyx_t_8.one_based = __pyx_v_one_based;
  __pyx_t_2 = __pyx_f_10pysamstats__rec_coverage(__pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_rec = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":3031
 * 
 *         rec = _rec_coverage(alignmentfile, fafile, col, one_based)
 *         rec['gc'] = gc_percent             # <<<<<<<<<<<<<<
 *         return rec
 * 
 */
  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_gc_percent); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (unlikely(__pyx_v_rec == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (unlikely(PyDict_SetItem(__pyx_v_rec, __pyx_n_s_gc, __pyx_t_2) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3032
 *         rec = _rec_coverage(alignmentfile, fafile, col, one_based)
 *         rec['gc'] = gc_percent
 *         return rec             # <<<<<<<<<<<<<<
 * 
 *     def _rec_coverage_gc_pad(FastaFile fafile, chrom, pos,
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_rec);
  __pyx_r = __pyx_v_rec;
  goto __pyx_L0;

  /* "pysamstats.pyx":3014
 *         window_offset = window_size / 2
 * 
 *     def _rec_coverage_gc(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                          PileupColumn col, bint one_based):
 *         chrom = alignmentfile.getrname(col.tid)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.stat_coverage_gc._rec_coverage_gc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_ref_window_start);
  __Pyx_XDECREF(__pyx_v_ref_window_end);
  __Pyx_XDECREF(__pyx_v_ref_window);
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3034
 *         return rec
 * 
 *     def _rec_coverage_gc_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                              bint one_based):
 *         ref_window_start = pos - window_offset
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_16stat_coverage_gc_3_rec_coverage_gc_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_16stat_coverage_gc_3_rec_coverage_gc_pad = {"_rec_coverage_gc_pad", (PyCFunction)__pyx_pw_10pysamstats_16stat_coverage_gc_3_rec_coverage_gc_pad, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_10pysamstats_16stat_coverage_gc_3_rec_coverage_gc_pad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_pos = 0;
  int __pyx_v_one_based;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_rec_coverage_gc_pad (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_pos,&__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_fafile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_coverage_gc_pad", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3034; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_coverage_gc_pad", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3034; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_one_based)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_rec_coverage_gc_pad", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3034; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_rec_coverage_gc_pad") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3034; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
    }
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_pos = values[2];
    __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 = 3035; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_rec_coverage_gc_pad", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3034; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.stat_coverage_gc._rec_coverage_gc_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_16stat_coverage_gc_2_rec_coverage_gc_pad(__pyx_self, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, __pyx_v_one_based);

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

static PyObject *__pyx_pf_10pysamstats_16stat_coverage_gc_2_rec_coverage_gc_pad(PyObject *__pyx_self, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_pos, int __pyx_v_one_based) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *__pyx_cur_scope;
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *__pyx_outer_scope;
  PyObject *__pyx_v_ref_window_start = NULL;
  PyObject *__pyx_v_ref_window_end = NULL;
  PyObject *__pyx_v_ref_window = NULL;
  long __pyx_v_gc_percent;
  PyObject *__pyx_v_rec = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  struct __pyx_opt_args_10pysamstats__rec_coverage_pad __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rec_coverage_gc_pad", 0);
  __pyx_outer_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *) __Pyx_CyFunction_GetClosure(__pyx_self);
  __pyx_cur_scope = __pyx_outer_scope;

  /* "pysamstats.pyx":3036
 *     def _rec_coverage_gc_pad(FastaFile fafile, chrom, pos,
 *                              bint one_based):
 *         ref_window_start = pos - window_offset             # <<<<<<<<<<<<<<
 *         ref_window_end = ref_window_start + window_size
 *         if ref_window_start < 0:
 */
  if (unlikely(!__pyx_cur_scope->__pyx_v_window_offset)) { __Pyx_RaiseClosureNameError("window_offset"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3036; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
  __pyx_t_1 = PyNumber_Subtract(__pyx_v_pos, __pyx_cur_scope->__pyx_v_window_offset); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_ref_window_start = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3037
 *                              bint one_based):
 *         ref_window_start = pos - window_offset
 *         ref_window_end = ref_window_start + window_size             # <<<<<<<<<<<<<<
 *         if ref_window_start < 0:
 *             ref_window_start = 0
 */
  if (unlikely(!__pyx_cur_scope->__pyx_v_window_size)) { __Pyx_RaiseClosureNameError("window_size"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3037; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
  __pyx_t_1 = PyNumber_Add(__pyx_v_ref_window_start, __pyx_cur_scope->__pyx_v_window_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_ref_window_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3038
 *         ref_window_start = pos - window_offset
 *         ref_window_end = ref_window_start + window_size
 *         if ref_window_start < 0:             # <<<<<<<<<<<<<<
 *             ref_window_start = 0
 *         ref_window = fafile\
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_ref_window_start, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3039
 *         ref_window_end = ref_window_start + window_size
 *         if ref_window_start < 0:
 *             ref_window_start = 0             # <<<<<<<<<<<<<<
 *         ref_window = fafile\
 *             .fetch(chrom, ref_window_start, ref_window_end)\
 */
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_DECREF_SET(__pyx_v_ref_window_start, __pyx_int_0);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":3041
 *             ref_window_start = 0
 *         ref_window = fafile\
 *             .fetch(chrom, ref_window_start, ref_window_end)\             # <<<<<<<<<<<<<<
 *             .lower()
 *         if len(ref_window) == 0:
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_fafile), __pyx_n_s_fetch); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_6 = 1;
    }
  }
  __pyx_t_7 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (__pyx_t_5) {
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
  }
  __Pyx_INCREF(__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_v_chrom);
  __Pyx_INCREF(__pyx_v_ref_window_start);
  PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_ref_window_start);
  __Pyx_GIVEREF(__pyx_v_ref_window_start);
  __Pyx_INCREF(__pyx_v_ref_window_end);
  PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_v_ref_window_end);
  __Pyx_GIVEREF(__pyx_v_ref_window_end);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":3042
 *         ref_window = fafile\
 *             .fetch(chrom, ref_window_start, ref_window_end)\
 *             .lower()             # <<<<<<<<<<<<<<
 *         if len(ref_window) == 0:
 *             gc_percent = -1
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_lower); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_ref_window = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3043
 *             .fetch(chrom, ref_window_start, ref_window_end)\
 *             .lower()
 *         if len(ref_window) == 0:             # <<<<<<<<<<<<<<
 *             gc_percent = -1
 *         else:
 */
  __pyx_t_6 = PyObject_Length(__pyx_v_ref_window); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = ((__pyx_t_6 == 0) != 0);
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3044
 *             .lower()
 *         if len(ref_window) == 0:
 *             gc_percent = -1             # <<<<<<<<<<<<<<
 *         else:
 *             gc_percent = _gc_content(ref_window)
 */
    __pyx_v_gc_percent = -1;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "pysamstats.pyx":3046
 *             gc_percent = -1
 *         else:
 *             gc_percent = _gc_content(ref_window)             # <<<<<<<<<<<<<<
 *         rec = _rec_coverage_pad(fafile, chrom, pos, one_based)
 *         rec['gc'] = gc_percent
 */
    __pyx_v_gc_percent = __pyx_f_10pysamstats__gc_content(__pyx_v_ref_window);
  }
  __pyx_L4:;

  /* "pysamstats.pyx":3047
 *         else:
 *             gc_percent = _gc_content(ref_window)
 *         rec = _rec_coverage_pad(fafile, chrom, pos, one_based)             # <<<<<<<<<<<<<<
 *         rec['gc'] = gc_percent
 *         return rec
 */
  __pyx_t_8.__pyx_n = 1;
  __pyx_t_8.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats__rec_coverage_pad(__pyx_v_fafile, __pyx_v_chrom, __pyx_v_pos, 0, &__pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rec = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3048
 *             gc_percent = _gc_content(ref_window)
 *         rec = _rec_coverage_pad(fafile, chrom, pos, one_based)
 *         rec['gc'] = gc_percent             # <<<<<<<<<<<<<<
 *         return rec
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_gc_percent); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(__pyx_v_rec == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (unlikely(PyDict_SetItem(__pyx_v_rec, __pyx_n_s_gc, __pyx_t_1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":3049
 *         rec = _rec_coverage_pad(fafile, chrom, pos, one_based)
 *         rec['gc'] = gc_percent
 *         return rec             # <<<<<<<<<<<<<<
 * 
 *     return _iter_pileup(_rec_coverage_gc,
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_rec);
  __pyx_r = __pyx_v_rec;
  goto __pyx_L0;

  /* "pysamstats.pyx":3034
 *         return rec
 * 
 *     def _rec_coverage_gc_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                              bint one_based):
 *         ref_window_start = pos - window_offset
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysamstats.stat_coverage_gc._rec_coverage_gc_pad", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ref_window_start);
  __Pyx_XDECREF(__pyx_v_ref_window_end);
  __Pyx_XDECREF(__pyx_v_ref_window);
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2970
 * 
 * 
 * def stat_coverage_gc(alignmentfile, fafile, chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                      one_based=False, truncate=False, pad=False, max_depth=8000,
 *                      window_size=300, window_offset=None, **kwargs):
 */

static PyObject *__pyx_pf_10pysamstats_112stat_coverage_gc(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_truncate, PyObject *__pyx_v_pad, PyObject *__pyx_v_max_depth, PyObject *__pyx_v_window_size, PyObject *__pyx_v_window_offset, PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *__pyx_cur_scope;
  PyObject *__pyx_v__rec_coverage_gc = 0;
  PyObject *__pyx_v__rec_coverage_gc_pad = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_coverage_gc", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *)__pyx_tp_new_10pysamstats___pyx_scope_struct__stat_coverage_gc(__pyx_ptype_10pysamstats___pyx_scope_struct__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_window_size = __pyx_v_window_size;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_window_size);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_window_size);
  __pyx_cur_scope->__pyx_v_window_offset = __pyx_v_window_offset;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_window_offset);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_window_offset);

  /* "pysamstats.pyx":3011
 * 
 * 
 *     if window_offset is None:             # <<<<<<<<<<<<<<
 *         window_offset = window_size / 2
 * 
 */
  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_window_offset == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3012
 * 
 *     if window_offset is None:
 *         window_offset = window_size / 2             # <<<<<<<<<<<<<<
 * 
 *     def _rec_coverage_gc(AlignmentFile alignmentfile, FastaFile fafile,
 */
    __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_cur_scope->__pyx_v_window_size, __pyx_int_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_window_offset);
    __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_window_offset, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":3014
 *         window_offset = window_size / 2
 * 
 *     def _rec_coverage_gc(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                          PileupColumn col, bint one_based):
 *         chrom = alignmentfile.getrname(col.tid)
 */
  __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_10pysamstats_16stat_coverage_gc_1_rec_coverage_gc, 0, __pyx_n_s_stat_coverage_gc_locals__rec_cov, ((PyObject*)__pyx_cur_scope), __pyx_n_s_pysamstats, __pyx_d, ((PyObject *)__pyx_codeobj__2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v__rec_coverage_gc = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":3034
 *         return rec
 * 
 *     def _rec_coverage_gc_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                              bint one_based):
 *         ref_window_start = pos - window_offset
 */
  __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_10pysamstats_16stat_coverage_gc_3_rec_coverage_gc_pad, 0, __pyx_n_s_stat_coverage_gc_locals__rec_cov_2, ((PyObject*)__pyx_cur_scope), __pyx_n_s_pysamstats, __pyx_d, ((PyObject *)__pyx_codeobj__4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v__rec_coverage_gc_pad = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":3051
 *         return rec
 * 
 *     return _iter_pileup(_rec_coverage_gc,             # <<<<<<<<<<<<<<
 *                         _rec_coverage_gc_pad,
 *                         alignmentfile, fafile=fafile, chrom=chrom, start=start,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":3053
 *     return _iter_pileup(_rec_coverage_gc,
 *                         _rec_coverage_gc_pad,
 *                         alignmentfile, fafile=fafile, chrom=chrom, start=start,             # <<<<<<<<<<<<<<
 *                         end=end, one_based=one_based,
 *                         truncate=truncate, pad=pad,
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v__rec_coverage_gc);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v__rec_coverage_gc);
  __Pyx_GIVEREF(__pyx_v__rec_coverage_gc);
  __Pyx_INCREF(__pyx_v__rec_coverage_gc_pad);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v__rec_coverage_gc_pad);
  __Pyx_GIVEREF(__pyx_v__rec_coverage_gc_pad);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);

  /* "pysamstats.pyx":3057
 *                         truncate=truncate, pad=pad,
 *                         max_depth=max_depth,
 *                         **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysamstats.pyx":3053
 *     return _iter_pileup(_rec_coverage_gc,
 *                         _rec_coverage_gc_pad,
 *                         alignmentfile, fafile=fafile, chrom=chrom, start=start,             # <<<<<<<<<<<<<<
 *                         end=end, one_based=one_based,
 *                         truncate=truncate, pad=pad,
 */
  if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_fafile))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_fafile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_chrom))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_chrom); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_start))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_start); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_start, __pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3054
 *                         _rec_coverage_gc_pad,
 *                         alignmentfile, fafile=fafile, chrom=chrom, start=start,
 *                         end=end, one_based=one_based,             # <<<<<<<<<<<<<<
 *                         truncate=truncate, pad=pad,
 *                         max_depth=max_depth,
 */
  if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_end))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_end); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_end, __pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_one_based))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_one_based); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_one_based, __pyx_v_one_based) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3055
 *                         alignmentfile, fafile=fafile, chrom=chrom, start=start,
 *                         end=end, one_based=one_based,
 *                         truncate=truncate, pad=pad,             # <<<<<<<<<<<<<<
 *                         max_depth=max_depth,
 *                         **kwargs)
 */
  if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_truncate))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_truncate); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_truncate, __pyx_v_truncate) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_pad))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_pad); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_pad, __pyx_v_pad) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3056
 *                         end=end, one_based=one_based,
 *                         truncate=truncate, pad=pad,
 *                         max_depth=max_depth,             # <<<<<<<<<<<<<<
 *                         **kwargs)
 * 
 */
  if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_max_depth))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_max_depth); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_max_depth, __pyx_v_max_depth) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3051
 *         return rec
 * 
 *     return _iter_pileup(_rec_coverage_gc,             # <<<<<<<<<<<<<<
 *                         _rec_coverage_gc_pad,
 *                         alignmentfile, fafile=fafile, chrom=chrom, start=start,
 */
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":2970
 * 
 * 
 * def stat_coverage_gc(alignmentfile, fafile, chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                      one_based=False, truncate=False, pad=False, max_depth=8000,
 *                      window_size=300, window_offset=None, **kwargs):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats.stat_coverage_gc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__rec_coverage_gc);
  __Pyx_XDECREF(__pyx_v__rec_coverage_gc_pad);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3060
 * 
 * 
 * def load_coverage_gc(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_gc, dtype_coverage_gc, *args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_115load_coverage_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_114load_coverage_gc[] = "load_coverage_gc(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_115load_coverage_gc = {"load_coverage_gc", (PyCFunction)__pyx_pw_10pysamstats_115load_coverage_gc, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_114load_coverage_gc};
static PyObject *__pyx_pw_10pysamstats_115load_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("load_coverage_gc (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_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_114load_coverage_gc(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_114load_coverage_gc(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_coverage_gc", 0);

  /* "pysamstats.pyx":3061
 * 
 * def load_coverage_gc(*args, **kwargs):
 *     return _load_stats(stat_coverage_gc, dtype_coverage_gc, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_coverage_gc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage_gc); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3061; __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_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":3060
 * 
 * 
 * def load_coverage_gc(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_gc, dtype_coverage_gc, *args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_coverage_gc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3079
 * 
 * 
 * def stat_coverage_binned(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned coverage statistics.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_117stat_coverage_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_116stat_coverage_binned[] = "stat_coverage_binned(alignmentfile, fafile, **kwargs)\nGenerate binned coverage statistics.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    fafile : pysam.FastaFile or string\n        FASTA file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n    window_size : int\n        size of surrounding window in base pairs\n    window_offset :\n        distance from window start to record position\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_117stat_coverage_binned = {"stat_coverage_binned", (PyCFunction)__pyx_pw_10pysamstats_117stat_coverage_binned, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_116stat_coverage_binned};
static PyObject *__pyx_pw_10pysamstats_117stat_coverage_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_fafile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_coverage_binned (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_alignmentfile,&__pyx_n_s_fafile,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 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_binned", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3079; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_coverage_binned") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3079; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_alignmentfile = values[0];
    __pyx_v_fafile = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage_binned", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3079; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_coverage_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_116stat_coverage_binned(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_116stat_coverage_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats__CoverageBinned *__pyx_v_stat = 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("stat_coverage_binned", 0);

  /* "pysamstats.pyx":3116
 *     """
 * 
 *     stat = _CoverageBinned()             # <<<<<<<<<<<<<<
 *     return _iter_binned(stat, alignmentfile=alignmentfile, fafile=fafile, **kwargs)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_10pysamstats__CoverageBinned)), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_stat = ((struct __pyx_obj_10pysamstats__CoverageBinned *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3117
 * 
 *     stat = _CoverageBinned()
 *     return _iter_binned(stat, alignmentfile=alignmentfile, fafile=fafile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_binned); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_stat));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_stat));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_stat));
  __pyx_t_3 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_alignmentfile))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_alignmentfile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_alignmentfile, __pyx_v_alignmentfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_fafile))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_fafile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":3079
 * 
 * 
 * def stat_coverage_binned(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned coverage statistics.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_coverage_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_stat);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3120
 * 
 * 
 * cdef inline int _gc_content(ref_window):             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i, n
 *     cdef char* seq
 */

static CYTHON_INLINE int __pyx_f_10pysamstats__gc_content(PyObject *__pyx_v_ref_window) {
  Py_ssize_t __pyx_v_i;
  Py_ssize_t __pyx_v_n;
  char *__pyx_v_seq;
  int __pyx_v_gc_count;
  PyObject *__pyx_v_gc_percent = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  char *__pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  double __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_gc_content", 0);

  /* "pysamstats.pyx":3123
 *     cdef Py_ssize_t i, n
 *     cdef char* seq
 *     cdef int gc_count = 0             # <<<<<<<<<<<<<<
 *     n = len(ref_window)
 *     seq = ref_window
 */
  __pyx_v_gc_count = 0;

  /* "pysamstats.pyx":3124
 *     cdef char* seq
 *     cdef int gc_count = 0
 *     n = len(ref_window)             # <<<<<<<<<<<<<<
 *     seq = ref_window
 *     for i in range(n):
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_ref_window); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_n = __pyx_t_1;

  /* "pysamstats.pyx":3125
 *     cdef int gc_count = 0
 *     n = len(ref_window)
 *     seq = ref_window             # <<<<<<<<<<<<<<
 *     for i in range(n):
 *         if seq[i] == b'g' or seq[i] == b'c':
 */
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v_ref_window); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_seq = __pyx_t_2;

  /* "pysamstats.pyx":3126
 *     n = len(ref_window)
 *     seq = ref_window
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         if seq[i] == b'g' or seq[i] == b'c':
 *             gc_count += 1
 */
  __pyx_t_1 = __pyx_v_n;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_1; __pyx_t_3+=1) {
    __pyx_v_i = __pyx_t_3;

    /* "pysamstats.pyx":3127
 *     seq = ref_window
 *     for i in range(n):
 *         if seq[i] == b'g' or seq[i] == b'c':             # <<<<<<<<<<<<<<
 *             gc_count += 1
 *     gc_percent = int(round(gc_count * 100. / n))
 */
    __pyx_t_5 = (((__pyx_v_seq[__pyx_v_i]) == 'g') != 0);
    if (!__pyx_t_5) {
    } else {
      __pyx_t_4 = __pyx_t_5;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_5 = (((__pyx_v_seq[__pyx_v_i]) == 'c') != 0);
    __pyx_t_4 = __pyx_t_5;
    __pyx_L6_bool_binop_done:;
    if (__pyx_t_4) {

      /* "pysamstats.pyx":3128
 *     for i in range(n):
 *         if seq[i] == b'g' or seq[i] == b'c':
 *             gc_count += 1             # <<<<<<<<<<<<<<
 *     gc_percent = int(round(gc_count * 100. / n))
 *     return gc_percent
 */
      __pyx_v_gc_count = (__pyx_v_gc_count + 1);
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

  /* "pysamstats.pyx":3129
 *         if seq[i] == b'g' or seq[i] == b'c':
 *             gc_count += 1
 *     gc_percent = int(round(gc_count * 100. / n))             # <<<<<<<<<<<<<<
 *     return gc_percent
 * 
 */
  __pyx_t_6 = (__pyx_v_gc_count * 100.);
  if (unlikely(__pyx_v_n == 0)) {
    #ifdef WITH_THREAD
    PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
    #endif
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    #ifdef WITH_THREAD
    PyGILState_Release(__pyx_gilstate_save);
    #endif
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_7 = PyFloat_FromDouble((__pyx_t_6 / ((double)__pyx_v_n))); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyNumber_Int(__pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_gc_percent = __pyx_t_8;
  __pyx_t_8 = 0;

  /* "pysamstats.pyx":3130
 *             gc_count += 1
 *     gc_percent = int(round(gc_count * 100. / n))
 *     return gc_percent             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_v_gc_percent); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_9;
  goto __pyx_L0;

  /* "pysamstats.pyx":3120
 * 
 * 
 * cdef inline int _gc_content(ref_window):             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i, n
 *     cdef char* seq
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_WriteUnraisable("pysamstats._gc_content", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_gc_percent);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3135
 * cdef class _StatBinned(object):
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):             # <<<<<<<<<<<<<<
 *         return dict()
 * 
 */

static PyObject *__pyx_f_10pysamstats_11_StatBinned_rec(CYTHON_UNUSED struct __pyx_obj_10pysamstats__StatBinned *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_chrom, CYTHON_UNUSED PyObject *__pyx_v_bin_start, CYTHON_UNUSED PyObject *__pyx_v_bin_end, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile) {
  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("rec", 0);

  /* "pysamstats.pyx":3136
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):
 *         return dict()             # <<<<<<<<<<<<<<
 * 
 *     cdef recv(self, bam1_t * b):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":3135
 * cdef class _StatBinned(object):
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):             # <<<<<<<<<<<<<<
 *         return dict()
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats._StatBinned.rec", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3138
 *         return dict()
 * 
 *     cdef recv(self, bam1_t * b):             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

static PyObject *__pyx_f_10pysamstats_11_StatBinned_recv(CYTHON_UNUSED struct __pyx_obj_10pysamstats__StatBinned *__pyx_v_self, CYTHON_UNUSED bam1_t *__pyx_v_b) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("recv", 0);

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

/* "pysamstats.pyx":3146
 *     cdef int reads_all, reads_pp
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.reads_all = self.reads_pp = 0
 * 
 */

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

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

static int __pyx_pf_10pysamstats_15_CoverageBinned___cinit__(struct __pyx_obj_10pysamstats__CoverageBinned *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "pysamstats.pyx":3147
 * 
 *     def __cinit__(self):
 *         self.reads_all = self.reads_pp = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):
 */
  __pyx_v_self->reads_all = 0;
  __pyx_v_self->reads_pp = 0;

  /* "pysamstats.pyx":3146
 *     cdef int reads_all, reads_pp
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.reads_all = self.reads_pp = 0
 * 
 */

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

/* "pysamstats.pyx":3149
 *         self.reads_all = self.reads_pp = 0
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):             # <<<<<<<<<<<<<<
 * 
 *         # determine %GC
 */

static PyObject *__pyx_f_10pysamstats_15_CoverageBinned_rec(struct __pyx_obj_10pysamstats__CoverageBinned *__pyx_v_self, PyObject *__pyx_v_chrom, PyObject *__pyx_v_bin_start, PyObject *__pyx_v_bin_end, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile) {
  PyObject *__pyx_v_ref_window = NULL;
  int __pyx_v_gc_percent;
  PyObject *__pyx_v_rec = 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;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("rec", 0);

  /* "pysamstats.pyx":3152
 * 
 *         # determine %GC
 *         ref_window = fafile.fetch(chrom, bin_start, bin_end).lower()             # <<<<<<<<<<<<<<
 *         gc_percent = _gc_content(ref_window)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_fafile), __pyx_n_s_fetch); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  __pyx_t_6 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (__pyx_t_4) {
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
  }
  __Pyx_INCREF(__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_v_chrom);
  __Pyx_INCREF(__pyx_v_bin_start);
  PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_bin_start);
  __Pyx_GIVEREF(__pyx_v_bin_start);
  __Pyx_INCREF(__pyx_v_bin_end);
  PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_5, __pyx_v_bin_end);
  __Pyx_GIVEREF(__pyx_v_bin_end);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_lower); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_ref_window = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3153
 *         # determine %GC
 *         ref_window = fafile.fetch(chrom, bin_start, bin_end).lower()
 *         gc_percent = _gc_content(ref_window)             # <<<<<<<<<<<<<<
 * 
 *         # make record for bin
 */
  __pyx_v_gc_percent = __pyx_f_10pysamstats__gc_content(__pyx_v_ref_window);

  /* "pysamstats.pyx":3156
 * 
 *         # make record for bin
 *         rec = {'gc': gc_percent,             # <<<<<<<<<<<<<<
 *                'reads_all': self.reads_all,
 *                'reads_pp': self.reads_pp}
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_gc_percent); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_gc, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3157
 *         # make record for bin
 *         rec = {'gc': gc_percent,
 *                'reads_all': self.reads_all,             # <<<<<<<<<<<<<<
 *                'reads_pp': self.reads_pp}
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->reads_all); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3158
 *         rec = {'gc': gc_percent,
 *                'reads_all': self.reads_all,
 *                'reads_pp': self.reads_pp}             # <<<<<<<<<<<<<<
 * 
 *         # reset counters
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->reads_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_rec = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3161
 * 
 *         # reset counters
 *         self.reads_all = self.reads_pp = 0             # <<<<<<<<<<<<<<
 * 
 *         return rec
 */
  __pyx_v_self->reads_all = 0;
  __pyx_v_self->reads_pp = 0;

  /* "pysamstats.pyx":3163
 *         self.reads_all = self.reads_pp = 0
 * 
 *         return rec             # <<<<<<<<<<<<<<
 * 
 *     cdef recv(self, bam1_t * b):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_rec);
  __pyx_r = __pyx_v_rec;
  goto __pyx_L0;

  /* "pysamstats.pyx":3149
 *         self.reads_all = self.reads_pp = 0
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):             # <<<<<<<<<<<<<<
 * 
 *         # determine %GC
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._CoverageBinned.rec", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ref_window);
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3165
 *         return rec
 * 
 *     cdef recv(self, bam1_t * b):             # <<<<<<<<<<<<<<
 *         cdef uint32_t flag
 *         cdef bint is_unmapped
 */

static PyObject *__pyx_f_10pysamstats_15_CoverageBinned_recv(struct __pyx_obj_10pysamstats__CoverageBinned *__pyx_v_self, bam1_t *__pyx_v_b) {
  uint32_t __pyx_v_flag;
  int __pyx_v_is_unmapped;
  int __pyx_v_is_proper_pair;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("recv", 0);

  /* "pysamstats.pyx":3169
 *         cdef bint is_unmapped
 *         cdef bint is_proper_pair
 *         flag = b.core.flag             # <<<<<<<<<<<<<<
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:
 */
  __pyx_t_1 = __pyx_v_b->core.flag;
  __pyx_v_flag = __pyx_t_1;

  /* "pysamstats.pyx":3170
 *         cdef bint is_proper_pair
 *         flag = b.core.flag
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)             # <<<<<<<<<<<<<<
 *         if not is_unmapped:
 *             self.reads_all += 1
 */
  __pyx_v_is_unmapped = ((__pyx_v_flag & 4) != 0);

  /* "pysamstats.pyx":3171
 *         flag = b.core.flag
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:             # <<<<<<<<<<<<<<
 *             self.reads_all += 1
 *             is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
  __pyx_t_2 = ((!(__pyx_v_is_unmapped != 0)) != 0);
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3172
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:
 *             self.reads_all += 1             # <<<<<<<<<<<<<<
 *             is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *             if is_proper_pair:
 */
    __pyx_v_self->reads_all = (__pyx_v_self->reads_all + 1);

    /* "pysamstats.pyx":3173
 *         if not is_unmapped:
 *             self.reads_all += 1
 *             is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *             if is_proper_pair:
 *                 self.reads_pp += 1
 */
    __pyx_v_is_proper_pair = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":3174
 *             self.reads_all += 1
 *             is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 self.reads_pp += 1
 * 
 */
    __pyx_t_2 = (__pyx_v_is_proper_pair != 0);
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3175
 *             is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *             if is_proper_pair:
 *                 self.reads_pp += 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_v_self->reads_pp = (__pyx_v_self->reads_pp + 1);
      goto __pyx_L4;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":3165
 *         return rec
 * 
 *     cdef recv(self, bam1_t * b):             # <<<<<<<<<<<<<<
 *         cdef uint32_t flag
 *         cdef bint is_unmapped
 */

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

/* "pysamstats.pyx":3178
 * 
 * 
 * def load_coverage_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_binned, dtype_coverage_binned,
 *                        *args, **kwargs)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_119load_coverage_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_118load_coverage_binned[] = "load_coverage_binned(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_119load_coverage_binned = {"load_coverage_binned", (PyCFunction)__pyx_pw_10pysamstats_119load_coverage_binned, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_118load_coverage_binned};
static PyObject *__pyx_pw_10pysamstats_119load_coverage_binned(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("load_coverage_binned (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_coverage_binned", 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_118load_coverage_binned(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_118load_coverage_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_coverage_binned", 0);

  /* "pysamstats.pyx":3179
 * 
 * def load_coverage_binned(*args, **kwargs):
 *     return _load_stats(stat_coverage_binned, dtype_coverage_binned,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_coverage_binned); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage_binned); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":3180
 * def load_coverage_binned(*args, **kwargs):
 *     return _load_stats(stat_coverage_binned, dtype_coverage_binned,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":3179
 * 
 * def load_coverage_binned(*args, **kwargs):
 *     return _load_stats(stat_coverage_binned, dtype_coverage_binned,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3179; __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_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3180
 * def load_coverage_binned(*args, **kwargs):
 *     return _load_stats(stat_coverage_binned, dtype_coverage_binned,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":3179
 * 
 * def load_coverage_binned(*args, **kwargs):
 *     return _load_stats(stat_coverage_binned, dtype_coverage_binned,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":3178
 * 
 * 
 * def load_coverage_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_binned, dtype_coverage_binned,
 *                        *args, **kwargs)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_coverage_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3204
 * 
 * 
 * def stat_coverage_ext_binned(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned extended coverage statistics.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_121stat_coverage_ext_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_120stat_coverage_ext_binned[] = "stat_coverage_ext_binned(alignmentfile, fafile, **kwargs)\nGenerate binned extended coverage statistics.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    fafile : pysam.FastaFile or string\n        FASTA file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n    window_size : int\n        size of surrounding window in base pairs\n    window_offset :\n        distance from window start to record position\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_121stat_coverage_ext_binned = {"stat_coverage_ext_binned", (PyCFunction)__pyx_pw_10pysamstats_121stat_coverage_ext_binned, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_120stat_coverage_ext_binned};
static PyObject *__pyx_pw_10pysamstats_121stat_coverage_ext_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_fafile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_coverage_ext_binned (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_alignmentfile,&__pyx_n_s_fafile,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 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_ext_binned", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3204; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_coverage_ext_binned") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3204; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_alignmentfile = values[0];
    __pyx_v_fafile = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage_ext_binned", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3204; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_coverage_ext_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_120stat_coverage_ext_binned(__pyx_self, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_120stat_coverage_ext_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats__CoverageExtBinned *__pyx_v_stat = 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("stat_coverage_ext_binned", 0);

  /* "pysamstats.pyx":3241
 *     """
 * 
 *     stat = _CoverageExtBinned()             # <<<<<<<<<<<<<<
 *     return _iter_binned(stat, alignmentfile=alignmentfile, fafile=fafile,
 *                         **kwargs)
 */
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_10pysamstats__CoverageExtBinned)), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_stat = ((struct __pyx_obj_10pysamstats__CoverageExtBinned *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3242
 * 
 *     stat = _CoverageExtBinned()
 *     return _iter_binned(stat, alignmentfile=alignmentfile, fafile=fafile,             # <<<<<<<<<<<<<<
 *                         **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_binned); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_stat));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_stat));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_stat));

  /* "pysamstats.pyx":3243
 *     stat = _CoverageExtBinned()
 *     return _iter_binned(stat, alignmentfile=alignmentfile, fafile=fafile,
 *                         **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":3242
 * 
 *     stat = _CoverageExtBinned()
 *     return _iter_binned(stat, alignmentfile=alignmentfile, fafile=fafile,             # <<<<<<<<<<<<<<
 *                         **kwargs)
 * 
 */
  if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_alignmentfile))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_alignmentfile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_alignmentfile, __pyx_v_alignmentfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_fafile))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_fafile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":3204
 * 
 * 
 * def stat_coverage_ext_binned(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned extended coverage statistics.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_coverage_ext_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_stat);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3252
 *         reads_duplicate
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.reads_all = self.reads_pp = self.reads_mate_unmapped \
 *             = self.reads_mate_other_chr = self.reads_mate_same_strand\
 */

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

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

static int __pyx_pf_10pysamstats_18_CoverageExtBinned___cinit__(struct __pyx_obj_10pysamstats__CoverageExtBinned *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "pysamstats.pyx":3253
 * 
 *     def __cinit__(self):
 *         self.reads_all = self.reads_pp = self.reads_mate_unmapped \             # <<<<<<<<<<<<<<
 *             = self.reads_mate_other_chr = self.reads_mate_same_strand\
 *             = self.reads_faceaway = self.reads_softclipped \
 */
  __pyx_v_self->reads_all = 0;
  __pyx_v_self->reads_pp = 0;
  __pyx_v_self->reads_mate_unmapped = 0;

  /* "pysamstats.pyx":3254
 *     def __cinit__(self):
 *         self.reads_all = self.reads_pp = self.reads_mate_unmapped \
 *             = self.reads_mate_other_chr = self.reads_mate_same_strand\             # <<<<<<<<<<<<<<
 *             = self.reads_faceaway = self.reads_softclipped \
 *             = self.reads_duplicate = 0
 */
  __pyx_v_self->reads_mate_other_chr = 0;
  __pyx_v_self->reads_mate_same_strand = 0;

  /* "pysamstats.pyx":3255
 *         self.reads_all = self.reads_pp = self.reads_mate_unmapped \
 *             = self.reads_mate_other_chr = self.reads_mate_same_strand\
 *             = self.reads_faceaway = self.reads_softclipped \             # <<<<<<<<<<<<<<
 *             = self.reads_duplicate = 0
 * 
 */
  __pyx_v_self->reads_faceaway = 0;
  __pyx_v_self->reads_softclipped = 0;

  /* "pysamstats.pyx":3256
 *             = self.reads_mate_other_chr = self.reads_mate_same_strand\
 *             = self.reads_faceaway = self.reads_softclipped \
 *             = self.reads_duplicate = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):
 */
  __pyx_v_self->reads_duplicate = 0;

  /* "pysamstats.pyx":3252
 *         reads_duplicate
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.reads_all = self.reads_pp = self.reads_mate_unmapped \
 *             = self.reads_mate_other_chr = self.reads_mate_same_strand\
 */

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

/* "pysamstats.pyx":3258
 *             = self.reads_duplicate = 0
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):             # <<<<<<<<<<<<<<
 * 
 *         # determine %GC
 */

static PyObject *__pyx_f_10pysamstats_18_CoverageExtBinned_rec(struct __pyx_obj_10pysamstats__CoverageExtBinned *__pyx_v_self, PyObject *__pyx_v_chrom, PyObject *__pyx_v_bin_start, PyObject *__pyx_v_bin_end, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile) {
  PyObject *__pyx_v_ref_window = NULL;
  int __pyx_v_gc_percent;
  PyObject *__pyx_v_rec = 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;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("rec", 0);

  /* "pysamstats.pyx":3261
 * 
 *         # determine %GC
 *         ref_window = fafile.fetch(chrom, bin_start, bin_end).lower()             # <<<<<<<<<<<<<<
 *         gc_percent = _gc_content(ref_window)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_fafile), __pyx_n_s_fetch); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  __pyx_t_6 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (__pyx_t_4) {
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
  }
  __Pyx_INCREF(__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_v_chrom);
  __Pyx_INCREF(__pyx_v_bin_start);
  PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_bin_start);
  __Pyx_GIVEREF(__pyx_v_bin_start);
  __Pyx_INCREF(__pyx_v_bin_end);
  PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_5, __pyx_v_bin_end);
  __Pyx_GIVEREF(__pyx_v_bin_end);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_lower); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_ref_window = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3262
 *         # determine %GC
 *         ref_window = fafile.fetch(chrom, bin_start, bin_end).lower()
 *         gc_percent = _gc_content(ref_window)             # <<<<<<<<<<<<<<
 * 
 *         # make record for bin
 */
  __pyx_v_gc_percent = __pyx_f_10pysamstats__gc_content(__pyx_v_ref_window);

  /* "pysamstats.pyx":3265
 * 
 *         # make record for bin
 *         rec = {'gc': gc_percent,             # <<<<<<<<<<<<<<
 *                'reads_all': self.reads_all,
 *                'reads_pp': self.reads_pp,
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_gc_percent); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_gc, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3266
 *         # make record for bin
 *         rec = {'gc': gc_percent,
 *                'reads_all': self.reads_all,             # <<<<<<<<<<<<<<
 *                'reads_pp': self.reads_pp,
 *                'reads_mate_unmapped': self.reads_mate_unmapped,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->reads_all); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3267
 *         rec = {'gc': gc_percent,
 *                'reads_all': self.reads_all,
 *                'reads_pp': self.reads_pp,             # <<<<<<<<<<<<<<
 *                'reads_mate_unmapped': self.reads_mate_unmapped,
 *                'reads_mate_other_chr': self.reads_mate_other_chr,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->reads_pp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3268
 *                'reads_all': self.reads_all,
 *                'reads_pp': self.reads_pp,
 *                'reads_mate_unmapped': self.reads_mate_unmapped,             # <<<<<<<<<<<<<<
 *                'reads_mate_other_chr': self.reads_mate_other_chr,
 *                'reads_mate_same_strand': self.reads_mate_same_strand,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->reads_mate_unmapped); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_unmapped, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3269
 *                'reads_pp': self.reads_pp,
 *                'reads_mate_unmapped': self.reads_mate_unmapped,
 *                'reads_mate_other_chr': self.reads_mate_other_chr,             # <<<<<<<<<<<<<<
 *                'reads_mate_same_strand': self.reads_mate_same_strand,
 *                'reads_faceaway': self.reads_faceaway,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->reads_mate_other_chr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_other_chr, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3270
 *                'reads_mate_unmapped': self.reads_mate_unmapped,
 *                'reads_mate_other_chr': self.reads_mate_other_chr,
 *                'reads_mate_same_strand': self.reads_mate_same_strand,             # <<<<<<<<<<<<<<
 *                'reads_faceaway': self.reads_faceaway,
 *                'reads_softclipped': self.reads_softclipped,
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->reads_mate_same_strand); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mate_same_strand, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3271
 *                'reads_mate_other_chr': self.reads_mate_other_chr,
 *                'reads_mate_same_strand': self.reads_mate_same_strand,
 *                'reads_faceaway': self.reads_faceaway,             # <<<<<<<<<<<<<<
 *                'reads_softclipped': self.reads_softclipped,
 *                'reads_duplicate': self.reads_duplicate}
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->reads_faceaway); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_faceaway, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3272
 *                'reads_mate_same_strand': self.reads_mate_same_strand,
 *                'reads_faceaway': self.reads_faceaway,
 *                'reads_softclipped': self.reads_softclipped,             # <<<<<<<<<<<<<<
 *                'reads_duplicate': self.reads_duplicate}
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->reads_softclipped); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_softclipped, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3273
 *                'reads_faceaway': self.reads_faceaway,
 *                'reads_softclipped': self.reads_softclipped,
 *                'reads_duplicate': self.reads_duplicate}             # <<<<<<<<<<<<<<
 * 
 *         # reset counters
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->reads_duplicate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_duplicate, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_rec = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3276
 * 
 *         # reset counters
 *         self.reads_all = self.reads_pp = self.reads_mate_unmapped \             # <<<<<<<<<<<<<<
 *             = self.reads_mate_other_chr = self.reads_mate_same_strand\
 *             = self.reads_faceaway = self.reads_softclipped \
 */
  __pyx_v_self->reads_all = 0;
  __pyx_v_self->reads_pp = 0;
  __pyx_v_self->reads_mate_unmapped = 0;

  /* "pysamstats.pyx":3277
 *         # reset counters
 *         self.reads_all = self.reads_pp = self.reads_mate_unmapped \
 *             = self.reads_mate_other_chr = self.reads_mate_same_strand\             # <<<<<<<<<<<<<<
 *             = self.reads_faceaway = self.reads_softclipped \
 *             = self.reads_duplicate = 0
 */
  __pyx_v_self->reads_mate_other_chr = 0;
  __pyx_v_self->reads_mate_same_strand = 0;

  /* "pysamstats.pyx":3278
 *         self.reads_all = self.reads_pp = self.reads_mate_unmapped \
 *             = self.reads_mate_other_chr = self.reads_mate_same_strand\
 *             = self.reads_faceaway = self.reads_softclipped \             # <<<<<<<<<<<<<<
 *             = self.reads_duplicate = 0
 * 
 */
  __pyx_v_self->reads_faceaway = 0;
  __pyx_v_self->reads_softclipped = 0;

  /* "pysamstats.pyx":3279
 *             = self.reads_mate_other_chr = self.reads_mate_same_strand\
 *             = self.reads_faceaway = self.reads_softclipped \
 *             = self.reads_duplicate = 0             # <<<<<<<<<<<<<<
 * 
 *         return rec
 */
  __pyx_v_self->reads_duplicate = 0;

  /* "pysamstats.pyx":3281
 *             = self.reads_duplicate = 0
 * 
 *         return rec             # <<<<<<<<<<<<<<
 * 
 *     cdef recv(self, bam1_t * b):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_rec);
  __pyx_r = __pyx_v_rec;
  goto __pyx_L0;

  /* "pysamstats.pyx":3258
 *             = self.reads_duplicate = 0
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):             # <<<<<<<<<<<<<<
 * 
 *         # determine %GC
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._CoverageExtBinned.rec", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ref_window);
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3283
 *         return rec
 * 
 *     cdef recv(self, bam1_t * b):             # <<<<<<<<<<<<<<
 *         cdef uint32_t flag
 *         cdef bint is_unmapped
 */

static PyObject *__pyx_f_10pysamstats_18_CoverageExtBinned_recv(struct __pyx_obj_10pysamstats__CoverageExtBinned *__pyx_v_self, bam1_t *__pyx_v_b) {
  uint32_t __pyx_v_flag;
  int __pyx_v_is_unmapped;
  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;
  int __pyx_v_mate_is_unmapped;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_t_2;
  int32_t __pyx_t_3;
  int __pyx_t_4;
  __Pyx_RefNannySetupContext("recv", 0);

  /* "pysamstats.pyx":3292
 *         cdef bint mate_is_reverse
 *         cdef int tlen
 *         flag = b.core.flag             # <<<<<<<<<<<<<<
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:
 */
  __pyx_t_1 = __pyx_v_b->core.flag;
  __pyx_v_flag = __pyx_t_1;

  /* "pysamstats.pyx":3293
 *         cdef int tlen
 *         flag = b.core.flag
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)             # <<<<<<<<<<<<<<
 *         if not is_unmapped:
 *             self.reads_all += 1
 */
  __pyx_v_is_unmapped = ((__pyx_v_flag & 4) != 0);

  /* "pysamstats.pyx":3294
 *         flag = b.core.flag
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:             # <<<<<<<<<<<<<<
 *             self.reads_all += 1
 *             is_reverse = <bint>(flag & BAM_FREVERSE)
 */
  __pyx_t_2 = ((!(__pyx_v_is_unmapped != 0)) != 0);
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3295
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:
 *             self.reads_all += 1             # <<<<<<<<<<<<<<
 *             is_reverse = <bint>(flag & BAM_FREVERSE)
 *             is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_v_self->reads_all = (__pyx_v_self->reads_all + 1);

    /* "pysamstats.pyx":3296
 *         if not is_unmapped:
 *             self.reads_all += 1
 *             is_reverse = <bint>(flag & BAM_FREVERSE)             # <<<<<<<<<<<<<<
 *             is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *             is_duplicate = <bint>(flag & BAM_FDUP)
 */
    __pyx_v_is_reverse = ((__pyx_v_flag & 16) != 0);

    /* "pysamstats.pyx":3297
 *             self.reads_all += 1
 *             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 = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":3298
 *             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 = ((__pyx_v_flag & 1024) != 0);

    /* "pysamstats.pyx":3299
 *             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 = b.core.isize
 */
    __pyx_v_mate_is_unmapped = ((__pyx_v_flag & 8) != 0);

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

    /* "pysamstats.pyx":3301
 *             mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *             mate_is_reverse = <bint>(flag & BAM_FMREVERSE)
 *             tlen = b.core.isize             # <<<<<<<<<<<<<<
 *             if is_duplicate:
 *                 self.reads_duplicate += 1
 */
    __pyx_t_3 = __pyx_v_b->core.isize;
    __pyx_v_tlen = __pyx_t_3;

    /* "pysamstats.pyx":3302
 *             mate_is_reverse = <bint>(flag & BAM_FMREVERSE)
 *             tlen = b.core.isize
 *             if is_duplicate:             # <<<<<<<<<<<<<<
 *                 self.reads_duplicate += 1
 *             if is_proper_pair:
 */
    __pyx_t_2 = (__pyx_v_is_duplicate != 0);
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3303
 *             tlen = b.core.isize
 *             if is_duplicate:
 *                 self.reads_duplicate += 1             # <<<<<<<<<<<<<<
 *             if is_proper_pair:
 *                 self.reads_pp += 1
 */
      __pyx_v_self->reads_duplicate = (__pyx_v_self->reads_duplicate + 1);
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "pysamstats.pyx":3304
 *             if is_duplicate:
 *                 self.reads_duplicate += 1
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 self.reads_pp += 1
 *             if mate_is_unmapped:
 */
    __pyx_t_2 = (__pyx_v_is_proper_pair != 0);
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3305
 *                 self.reads_duplicate += 1
 *             if is_proper_pair:
 *                 self.reads_pp += 1             # <<<<<<<<<<<<<<
 *             if mate_is_unmapped:
 *                 self.reads_mate_unmapped += 1
 */
      __pyx_v_self->reads_pp = (__pyx_v_self->reads_pp + 1);
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "pysamstats.pyx":3306
 *             if is_proper_pair:
 *                 self.reads_pp += 1
 *             if mate_is_unmapped:             # <<<<<<<<<<<<<<
 *                 self.reads_mate_unmapped += 1
 *             elif b.core.tid != b.core.mtid:
 */
    __pyx_t_2 = (__pyx_v_mate_is_unmapped != 0);
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3307
 *                 self.reads_pp += 1
 *             if mate_is_unmapped:
 *                 self.reads_mate_unmapped += 1             # <<<<<<<<<<<<<<
 *             elif b.core.tid != b.core.mtid:
 *                 self.reads_mate_other_chr += 1
 */
      __pyx_v_self->reads_mate_unmapped = (__pyx_v_self->reads_mate_unmapped + 1);
      goto __pyx_L6;
    }

    /* "pysamstats.pyx":3308
 *             if mate_is_unmapped:
 *                 self.reads_mate_unmapped += 1
 *             elif b.core.tid != b.core.mtid:             # <<<<<<<<<<<<<<
 *                 self.reads_mate_other_chr += 1
 *             elif (is_reverse and mate_is_reverse) \
 */
    __pyx_t_2 = ((__pyx_v_b->core.tid != __pyx_v_b->core.mtid) != 0);
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3309
 *                 self.reads_mate_unmapped += 1
 *             elif b.core.tid != b.core.mtid:
 *                 self.reads_mate_other_chr += 1             # <<<<<<<<<<<<<<
 *             elif (is_reverse and mate_is_reverse) \
 *                     or (not is_reverse and not mate_is_reverse):
 */
      __pyx_v_self->reads_mate_other_chr = (__pyx_v_self->reads_mate_other_chr + 1);
      goto __pyx_L6;
    }

    /* "pysamstats.pyx":3310
 *             elif b.core.tid != b.core.mtid:
 *                 self.reads_mate_other_chr += 1
 *             elif (is_reverse and mate_is_reverse) \             # <<<<<<<<<<<<<<
 *                     or (not is_reverse and not mate_is_reverse):
 *                 self.reads_mate_same_strand += 1
 */
    __pyx_t_4 = (__pyx_v_is_reverse != 0);
    if (!__pyx_t_4) {
      goto __pyx_L8_next_or;
    } else {
    }
    __pyx_t_4 = (__pyx_v_mate_is_reverse != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_L8_next_or:;

    /* "pysamstats.pyx":3311
 *                 self.reads_mate_other_chr += 1
 *             elif (is_reverse and mate_is_reverse) \
 *                     or (not is_reverse and not mate_is_reverse):             # <<<<<<<<<<<<<<
 *                 self.reads_mate_same_strand += 1
 *             elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 */
    __pyx_t_4 = ((!(__pyx_v_is_reverse != 0)) != 0);
    if (__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_4 = ((!(__pyx_v_mate_is_reverse != 0)) != 0);
    __pyx_t_2 = __pyx_t_4;
    __pyx_L7_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3312
 *             elif (is_reverse and mate_is_reverse) \
 *                     or (not is_reverse and not mate_is_reverse):
 *                 self.reads_mate_same_strand += 1             # <<<<<<<<<<<<<<
 *             elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 *                 self.reads_faceaway += 1
 */
      __pyx_v_self->reads_mate_same_strand = (__pyx_v_self->reads_mate_same_strand + 1);
      goto __pyx_L6;
    }

    /* "pysamstats.pyx":3313
 *                     or (not is_reverse and not mate_is_reverse):
 *                 self.reads_mate_same_strand += 1
 *             elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):             # <<<<<<<<<<<<<<
 *                 self.reads_faceaway += 1
 *             if _is_softclipped(b):
 */
    __pyx_t_4 = (__pyx_v_is_reverse != 0);
    if (!__pyx_t_4) {
      goto __pyx_L12_next_or;
    } else {
    }
    __pyx_t_4 = ((__pyx_v_tlen > 0) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_L12_next_or:;
    __pyx_t_4 = ((!(__pyx_v_is_reverse != 0)) != 0);
    if (__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_4 = ((__pyx_v_tlen < 0) != 0);
    __pyx_t_2 = __pyx_t_4;
    __pyx_L11_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3314
 *                 self.reads_mate_same_strand += 1
 *             elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 *                 self.reads_faceaway += 1             # <<<<<<<<<<<<<<
 *             if _is_softclipped(b):
 *                 self.reads_softclipped += 1
 */
      __pyx_v_self->reads_faceaway = (__pyx_v_self->reads_faceaway + 1);
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysamstats.pyx":3315
 *             elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 *                 self.reads_faceaway += 1
 *             if _is_softclipped(b):             # <<<<<<<<<<<<<<
 *                 self.reads_softclipped += 1
 * 
 */
    __pyx_t_2 = (__pyx_f_10pysamstats__is_softclipped(__pyx_v_b) != 0);
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3316
 *                 self.reads_faceaway += 1
 *             if _is_softclipped(b):
 *                 self.reads_softclipped += 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_v_self->reads_softclipped = (__pyx_v_self->reads_softclipped + 1);
      goto __pyx_L15;
    }
    __pyx_L15:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":3283
 *         return rec
 * 
 *     cdef recv(self, bam1_t * b):             # <<<<<<<<<<<<<<
 *         cdef uint32_t flag
 *         cdef bint is_unmapped
 */

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

/* "pysamstats.pyx":3319
 * 
 * 
 * def load_coverage_ext_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_ext_binned, dtype_coverage_ext_binned,
 *                        *args, **kwargs)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_123load_coverage_ext_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_122load_coverage_ext_binned[] = "load_coverage_ext_binned(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_123load_coverage_ext_binned = {"load_coverage_ext_binned", (PyCFunction)__pyx_pw_10pysamstats_123load_coverage_ext_binned, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_122load_coverage_ext_binned};
static PyObject *__pyx_pw_10pysamstats_123load_coverage_ext_binned(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("load_coverage_ext_binned (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_coverage_ext_binned", 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_122load_coverage_ext_binned(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_122load_coverage_ext_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_coverage_ext_binned", 0);

  /* "pysamstats.pyx":3320
 * 
 * def load_coverage_ext_binned(*args, **kwargs):
 *     return _load_stats(stat_coverage_ext_binned, dtype_coverage_ext_binned,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_coverage_ext_binned); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage_ext_binned); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":3321
 * def load_coverage_ext_binned(*args, **kwargs):
 *     return _load_stats(stat_coverage_ext_binned, dtype_coverage_ext_binned,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":3320
 * 
 * def load_coverage_ext_binned(*args, **kwargs):
 *     return _load_stats(stat_coverage_ext_binned, dtype_coverage_ext_binned,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3320; __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_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3321
 * def load_coverage_ext_binned(*args, **kwargs):
 *     return _load_stats(stat_coverage_ext_binned, dtype_coverage_ext_binned,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":3320
 * 
 * def load_coverage_ext_binned(*args, **kwargs):
 *     return _load_stats(stat_coverage_ext_binned, dtype_coverage_ext_binned,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":3319
 * 
 * 
 * def load_coverage_ext_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_ext_binned, dtype_coverage_ext_binned,
 *                        *args, **kwargs)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_coverage_ext_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3341
 * 
 * 
 * def stat_mapq_binned(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned mapping quality statistics.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_125stat_mapq_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_124stat_mapq_binned[] = "stat_mapq_binned(alignmentfile, **kwargs)\nGenerate binned mapping quality statistics.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n    window_size : int\n        size of surrounding window in base pairs\n    window_offset :\n        distance from window start to record position\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_125stat_mapq_binned = {"stat_mapq_binned", (PyCFunction)__pyx_pw_10pysamstats_125stat_mapq_binned, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_124stat_mapq_binned};
static PyObject *__pyx_pw_10pysamstats_125stat_mapq_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_mapq_binned (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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_mapq_binned") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_mapq_binned", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_mapq_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_124stat_mapq_binned(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_124stat_mapq_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats__MapqBinned *__pyx_v_stat = 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("stat_mapq_binned", 0);

  /* "pysamstats.pyx":3376
 *     """
 * 
 *     stat = _MapqBinned()             # <<<<<<<<<<<<<<
 *     return _iter_binned(stat, alignmentfile=alignmentfile, **kwargs)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_10pysamstats__MapqBinned)), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_stat = ((struct __pyx_obj_10pysamstats__MapqBinned *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3377
 * 
 *     stat = _MapqBinned()
 *     return _iter_binned(stat, alignmentfile=alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_binned); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_stat));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_stat));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_stat));
  __pyx_t_3 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_alignmentfile))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_alignmentfile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_alignmentfile, __pyx_v_alignmentfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":3341
 * 
 * 
 * def stat_mapq_binned(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned mapping quality statistics.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_mapq_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_stat);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3385
 *     cdef uint64_t mapq, mapq_squared_sum
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.reads_all = self.reads_mapq0 = self.mapq_squared_sum = 0
 * 
 */

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

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

static int __pyx_pf_10pysamstats_11_MapqBinned___cinit__(struct __pyx_obj_10pysamstats__MapqBinned *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "pysamstats.pyx":3386
 * 
 *     def __cinit__(self):
 *         self.reads_all = self.reads_mapq0 = self.mapq_squared_sum = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):
 */
  __pyx_v_self->reads_all = 0;
  __pyx_v_self->reads_mapq0 = 0;
  __pyx_v_self->mapq_squared_sum = 0;

  /* "pysamstats.pyx":3385
 *     cdef uint64_t mapq, mapq_squared_sum
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.reads_all = self.reads_mapq0 = self.mapq_squared_sum = 0
 * 
 */

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

/* "pysamstats.pyx":3388
 *         self.reads_all = self.reads_mapq0 = self.mapq_squared_sum = 0
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):             # <<<<<<<<<<<<<<
 * 
 *         # make record for bin
 */

static PyObject *__pyx_f_10pysamstats_11_MapqBinned_rec(struct __pyx_obj_10pysamstats__MapqBinned *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_chrom, CYTHON_UNUSED PyObject *__pyx_v_bin_start, CYTHON_UNUSED PyObject *__pyx_v_bin_end, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile) {
  PyObject *__pyx_v_rec = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("rec", 0);

  /* "pysamstats.pyx":3391
 * 
 *         # make record for bin
 *         rec = {'reads_all': self.reads_all,             # <<<<<<<<<<<<<<
 *                'reads_mapq0': self.reads_mapq0,
 *                'rms_mapq': _rootmean(self.mapq_squared_sum, self.reads_all)}
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->reads_all); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3392
 *         # make record for bin
 *         rec = {'reads_all': self.reads_all,
 *                'reads_mapq0': self.reads_mapq0,             # <<<<<<<<<<<<<<
 *                'rms_mapq': _rootmean(self.mapq_squared_sum, self.reads_all)}
 * 
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->reads_mapq0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_mapq0, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3393
 *         rec = {'reads_all': self.reads_all,
 *                'reads_mapq0': self.reads_mapq0,
 *                'rms_mapq': _rootmean(self.mapq_squared_sum, self.reads_all)}             # <<<<<<<<<<<<<<
 * 
 *         # reset counters
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_f_10pysamstats__rootmean(__pyx_v_self->mapq_squared_sum, __pyx_v_self->reads_all)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_mapq, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_rec = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3396
 * 
 *         # reset counters
 *         self.reads_all = self.reads_mapq0 = self.mapq_squared_sum = 0             # <<<<<<<<<<<<<<
 * 
 *         return rec
 */
  __pyx_v_self->reads_all = 0;
  __pyx_v_self->reads_mapq0 = 0;
  __pyx_v_self->mapq_squared_sum = 0;

  /* "pysamstats.pyx":3398
 *         self.reads_all = self.reads_mapq0 = self.mapq_squared_sum = 0
 * 
 *         return rec             # <<<<<<<<<<<<<<
 * 
 *     cdef recv(self, bam1_t * b):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_rec);
  __pyx_r = __pyx_v_rec;
  goto __pyx_L0;

  /* "pysamstats.pyx":3388
 *         self.reads_all = self.reads_mapq0 = self.mapq_squared_sum = 0
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):             # <<<<<<<<<<<<<<
 * 
 *         # make record for bin
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._MapqBinned.rec", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3400
 *         return rec
 * 
 *     cdef recv(self, bam1_t * b):             # <<<<<<<<<<<<<<
 *         cdef uint32_t flag
 *         cdef bint is_unmapped
 */

static PyObject *__pyx_f_10pysamstats_11_MapqBinned_recv(struct __pyx_obj_10pysamstats__MapqBinned *__pyx_v_self, bam1_t *__pyx_v_b) {
  uint32_t __pyx_v_flag;
  int __pyx_v_is_unmapped;
  uint64_t __pyx_v_mapq;
  uint64_t __pyx_v_mapq_squared;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_t_2;
  uint8_t __pyx_t_3;
  __Pyx_RefNannySetupContext("recv", 0);

  /* "pysamstats.pyx":3405
 *         cdef uint64_t mapq
 *         cdef uint64_t mapq_squared
 *         flag = b.core.flag             # <<<<<<<<<<<<<<
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:
 */
  __pyx_t_1 = __pyx_v_b->core.flag;
  __pyx_v_flag = __pyx_t_1;

  /* "pysamstats.pyx":3406
 *         cdef uint64_t mapq_squared
 *         flag = b.core.flag
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)             # <<<<<<<<<<<<<<
 *         if not is_unmapped:
 *             self.reads_all += 1
 */
  __pyx_v_is_unmapped = ((__pyx_v_flag & 4) != 0);

  /* "pysamstats.pyx":3407
 *         flag = b.core.flag
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:             # <<<<<<<<<<<<<<
 *             self.reads_all += 1
 *             mapq = b.core.qual
 */
  __pyx_t_2 = ((!(__pyx_v_is_unmapped != 0)) != 0);
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3408
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:
 *             self.reads_all += 1             # <<<<<<<<<<<<<<
 *             mapq = b.core.qual
 *             mapq_squared = mapq**2
 */
    __pyx_v_self->reads_all = (__pyx_v_self->reads_all + 1);

    /* "pysamstats.pyx":3409
 *         if not is_unmapped:
 *             self.reads_all += 1
 *             mapq = b.core.qual             # <<<<<<<<<<<<<<
 *             mapq_squared = mapq**2
 *             self.mapq_squared_sum += mapq_squared
 */
    __pyx_t_3 = __pyx_v_b->core.qual;
    __pyx_v_mapq = __pyx_t_3;

    /* "pysamstats.pyx":3410
 *             self.reads_all += 1
 *             mapq = b.core.qual
 *             mapq_squared = mapq**2             # <<<<<<<<<<<<<<
 *             self.mapq_squared_sum += mapq_squared
 *             if mapq == 0:
 */
    __pyx_v_mapq_squared = __Pyx_pow_uint64_t(__pyx_v_mapq, 2);

    /* "pysamstats.pyx":3411
 *             mapq = b.core.qual
 *             mapq_squared = mapq**2
 *             self.mapq_squared_sum += mapq_squared             # <<<<<<<<<<<<<<
 *             if mapq == 0:
 *                 self.reads_mapq0 += 1
 */
    __pyx_v_self->mapq_squared_sum = (__pyx_v_self->mapq_squared_sum + __pyx_v_mapq_squared);

    /* "pysamstats.pyx":3412
 *             mapq_squared = mapq**2
 *             self.mapq_squared_sum += mapq_squared
 *             if mapq == 0:             # <<<<<<<<<<<<<<
 *                 self.reads_mapq0 += 1
 * 
 */
    __pyx_t_2 = ((__pyx_v_mapq == 0) != 0);
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3413
 *             self.mapq_squared_sum += mapq_squared
 *             if mapq == 0:
 *                 self.reads_mapq0 += 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_v_self->reads_mapq0 = (__pyx_v_self->reads_mapq0 + 1);
      goto __pyx_L4;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":3400
 *         return rec
 * 
 *     cdef recv(self, bam1_t * b):             # <<<<<<<<<<<<<<
 *         cdef uint32_t flag
 *         cdef bint is_unmapped
 */

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

/* "pysamstats.pyx":3416
 * 
 * 
 * def load_mapq_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_mapq_binned, dtype_mapq_binned, *args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_127load_mapq_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_126load_mapq_binned[] = "load_mapq_binned(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_127load_mapq_binned = {"load_mapq_binned", (PyCFunction)__pyx_pw_10pysamstats_127load_mapq_binned, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_126load_mapq_binned};
static PyObject *__pyx_pw_10pysamstats_127load_mapq_binned(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("load_mapq_binned (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_mapq_binned", 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_126load_mapq_binned(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_126load_mapq_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_mapq_binned", 0);

  /* "pysamstats.pyx":3417
 * 
 * def load_mapq_binned(*args, **kwargs):
 *     return _load_stats(stat_mapq_binned, dtype_mapq_binned, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_mapq_binned); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_mapq_binned); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":3416
 * 
 * 
 * def load_mapq_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_mapq_binned, dtype_mapq_binned, *args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_mapq_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3445
 * 
 * 
 * def stat_alignment_binned(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned alignment statistics.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_129stat_alignment_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_128stat_alignment_binned[] = "stat_alignment_binned(alignmentfile, **kwargs)\nGenerate binned alignment statistics.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    fafile : pysam.FastaFile or string\n        FASTA file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n    window_size : int\n        size of surrounding window in base pairs\n    window_offset :\n        distance from window start to record position\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_129stat_alignment_binned = {"stat_alignment_binned", (PyCFunction)__pyx_pw_10pysamstats_129stat_alignment_binned, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_128stat_alignment_binned};
static PyObject *__pyx_pw_10pysamstats_129stat_alignment_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_alignment_binned (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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_alignment_binned") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3445; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_alignment_binned", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3445; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_alignment_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_128stat_alignment_binned(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_128stat_alignment_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats__AlignmentBinned *__pyx_v_stat = 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("stat_alignment_binned", 0);

  /* "pysamstats.pyx":3482
 *     """
 * 
 *     stat = _AlignmentBinned()             # <<<<<<<<<<<<<<
 *     return _iter_binned(stat, alignmentfile=alignmentfile, **kwargs)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_10pysamstats__AlignmentBinned)), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_stat = ((struct __pyx_obj_10pysamstats__AlignmentBinned *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3483
 * 
 *     stat = _AlignmentBinned()
 *     return _iter_binned(stat, alignmentfile=alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_binned); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_stat));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_stat));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_stat));
  __pyx_t_3 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_alignmentfile))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_alignmentfile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_alignmentfile, __pyx_v_alignmentfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":3445
 * 
 * 
 * def stat_alignment_binned(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned alignment statistics.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_alignment_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_stat);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3490
 *     cdef int reads_all, M, I, D, N, S, H, P, EQ, X
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.reads_all = self.M = self.I = self.D = self.N = self.S = self.H\
 *             = self.P = self.EQ = self.X = 0
 */

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

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

static int __pyx_pf_10pysamstats_16_AlignmentBinned___cinit__(struct __pyx_obj_10pysamstats__AlignmentBinned *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "pysamstats.pyx":3491
 * 
 *     def __cinit__(self):
 *         self.reads_all = self.M = self.I = self.D = self.N = self.S = self.H\             # <<<<<<<<<<<<<<
 *             = self.P = self.EQ = self.X = 0
 * 
 */
  __pyx_v_self->reads_all = 0;
  __pyx_v_self->M = 0;
  __pyx_v_self->I = 0;
  __pyx_v_self->D = 0;
  __pyx_v_self->N = 0;
  __pyx_v_self->S = 0;
  __pyx_v_self->H = 0;

  /* "pysamstats.pyx":3492
 *     def __cinit__(self):
 *         self.reads_all = self.M = self.I = self.D = self.N = self.S = self.H\
 *             = self.P = self.EQ = self.X = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):
 */
  __pyx_v_self->P = 0;
  __pyx_v_self->EQ = 0;
  __pyx_v_self->X = 0;

  /* "pysamstats.pyx":3490
 *     cdef int reads_all, M, I, D, N, S, H, P, EQ, X
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.reads_all = self.M = self.I = self.D = self.N = self.S = self.H\
 *             = self.P = self.EQ = self.X = 0
 */

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

/* "pysamstats.pyx":3494
 *             = self.P = self.EQ = self.X = 0
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):             # <<<<<<<<<<<<<<
 * 
 *         # make record for bin
 */

static PyObject *__pyx_f_10pysamstats_16_AlignmentBinned_rec(struct __pyx_obj_10pysamstats__AlignmentBinned *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_chrom, CYTHON_UNUSED PyObject *__pyx_v_bin_start, CYTHON_UNUSED PyObject *__pyx_v_bin_end, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile) {
  PyObject *__pyx_v_rec = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("rec", 0);

  /* "pysamstats.pyx":3497
 * 
 *         # make record for bin
 *         rec = {'reads_all': self.reads_all,             # <<<<<<<<<<<<<<
 *                'M': self.M, 'I': self.I, 'D': self.D, 'N': self.N, 'S': self.S,
 *                'H': self.H, 'P': self.P, '=': self.EQ, 'X': self.X,
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->reads_all); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3498
 *         # make record for bin
 *         rec = {'reads_all': self.reads_all,
 *                'M': self.M, 'I': self.I, 'D': self.D, 'N': self.N, 'S': self.S,             # <<<<<<<<<<<<<<
 *                'H': self.H, 'P': self.P, '=': self.EQ, 'X': self.X,
 *                'bases_all': self.M + self.I + self.S + self.EQ + self.X}
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->M); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_M, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->I); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_I, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->D); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_D, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_N, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->S); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_S, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3499
 *         rec = {'reads_all': self.reads_all,
 *                'M': self.M, 'I': self.I, 'D': self.D, 'N': self.N, 'S': self.S,
 *                'H': self.H, 'P': self.P, '=': self.EQ, 'X': self.X,             # <<<<<<<<<<<<<<
 *                'bases_all': self.M + self.I + self.S + self.EQ + self.X}
 * 
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->H); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_H, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->P); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_P, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_kp_s__5, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->X); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_X, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3500
 *                'M': self.M, 'I': self.I, 'D': self.D, 'N': self.N, 'S': self.S,
 *                'H': self.H, 'P': self.P, '=': self.EQ, 'X': self.X,
 *                'bases_all': self.M + self.I + self.S + self.EQ + self.X}             # <<<<<<<<<<<<<<
 * 
 *         # reset counters
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(((((__pyx_v_self->M + __pyx_v_self->I) + __pyx_v_self->S) + __pyx_v_self->EQ) + __pyx_v_self->X)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_bases_all, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_rec = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3503
 * 
 *         # reset counters
 *         self.reads_all = self.M = self.I = self.D = self.N = self.S = self.H\             # <<<<<<<<<<<<<<
 *             = self.P = self.EQ = self.X = 0
 * 
 */
  __pyx_v_self->reads_all = 0;
  __pyx_v_self->M = 0;
  __pyx_v_self->I = 0;
  __pyx_v_self->D = 0;
  __pyx_v_self->N = 0;
  __pyx_v_self->S = 0;
  __pyx_v_self->H = 0;

  /* "pysamstats.pyx":3504
 *         # reset counters
 *         self.reads_all = self.M = self.I = self.D = self.N = self.S = self.H\
 *             = self.P = self.EQ = self.X = 0             # <<<<<<<<<<<<<<
 * 
 *         return rec
 */
  __pyx_v_self->P = 0;
  __pyx_v_self->EQ = 0;
  __pyx_v_self->X = 0;

  /* "pysamstats.pyx":3506
 *             = self.P = self.EQ = self.X = 0
 * 
 *         return rec             # <<<<<<<<<<<<<<
 * 
 *     cdef recv(self, bam1_t * b):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_rec);
  __pyx_r = __pyx_v_rec;
  goto __pyx_L0;

  /* "pysamstats.pyx":3494
 *             = self.P = self.EQ = self.X = 0
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):             # <<<<<<<<<<<<<<
 * 
 *         # make record for bin
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._AlignmentBinned.rec", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3508
 *         return rec
 * 
 *     cdef recv(self, bam1_t * b):             # <<<<<<<<<<<<<<
 *         cdef uint32_t flag
 *         cdef bint is_unmapped
 */

static PyObject *__pyx_f_10pysamstats_16_AlignmentBinned_recv(struct __pyx_obj_10pysamstats__AlignmentBinned *__pyx_v_self, bam1_t *__pyx_v_b) {
  uint32_t __pyx_v_flag;
  int __pyx_v_is_unmapped;
  int __pyx_v_k;
  int __pyx_v_op;
  int __pyx_v_l;
  uint32_t *__pyx_v_cigar_p;
  PyObject *__pyx_v_cigar = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("recv", 0);

  /* "pysamstats.pyx":3512
 *         cdef bint is_unmapped
 *         cdef int k, op, l
 *         flag = b.core.flag             # <<<<<<<<<<<<<<
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:
 */
  __pyx_t_1 = __pyx_v_b->core.flag;
  __pyx_v_flag = __pyx_t_1;

  /* "pysamstats.pyx":3513
 *         cdef int k, op, l
 *         flag = b.core.flag
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)             # <<<<<<<<<<<<<<
 *         if not is_unmapped:
 *             cigar_p = pysam_bam_get_cigar(b)
 */
  __pyx_v_is_unmapped = ((__pyx_v_flag & 4) != 0);

  /* "pysamstats.pyx":3514
 *         flag = b.core.flag
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:             # <<<<<<<<<<<<<<
 *             cigar_p = pysam_bam_get_cigar(b)
 *             cigar = list()
 */
  __pyx_t_2 = ((!(__pyx_v_is_unmapped != 0)) != 0);
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3515
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:
 *             cigar_p = pysam_bam_get_cigar(b)             # <<<<<<<<<<<<<<
 *             cigar = list()
 *             for k in range(b.core.n_cigar):
 */
    __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_b);

    /* "pysamstats.pyx":3516
 *         if not is_unmapped:
 *             cigar_p = pysam_bam_get_cigar(b)
 *             cigar = list()             # <<<<<<<<<<<<<<
 *             for k in range(b.core.n_cigar):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 */
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_cigar = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":3517
 *             cigar_p = pysam_bam_get_cigar(b)
 *             cigar = list()
 *             for k in range(b.core.n_cigar):             # <<<<<<<<<<<<<<
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
    __pyx_t_1 = __pyx_v_b->core.n_cigar;
    for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_1; __pyx_t_4+=1) {
      __pyx_v_k = __pyx_t_4;

      /* "pysamstats.pyx":3518
 *             cigar = list()
 *             for k in range(b.core.n_cigar):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))
 */
      __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);

      /* "pysamstats.pyx":3519
 *             for k in range(b.core.n_cigar):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *                 cigar.append((op, l))
 *                 if op == BAM_CMATCH:
 */
      __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> 4);

      /* "pysamstats.pyx":3520
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))             # <<<<<<<<<<<<<<
 *                 if op == BAM_CMATCH:
 *                     self.M += l
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_op); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_l); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3520; __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 = 3520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_3 = 0;
      __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_cigar, __pyx_t_6); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "pysamstats.pyx":3537
 *                 elif op == BAM_CEQUAL:
 *                     self.EQ += l
 *                 elif op == BAM_CDIFF:             # <<<<<<<<<<<<<<
 *                     self.X += l
 *             self.reads_all += 1
 */
      switch (__pyx_v_op) {

        /* "pysamstats.pyx":3521
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))
 *                 if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                     self.M += l
 *                 elif op == BAM_CINS:
 */
        case 0:

        /* "pysamstats.pyx":3522
 *                 cigar.append((op, l))
 *                 if op == BAM_CMATCH:
 *                     self.M += l             # <<<<<<<<<<<<<<
 *                 elif op == BAM_CINS:
 *                     self.I += l
 */
        __pyx_v_self->M = (__pyx_v_self->M + __pyx_v_l);
        break;

        /* "pysamstats.pyx":3523
 *                 if op == BAM_CMATCH:
 *                     self.M += l
 *                 elif op == BAM_CINS:             # <<<<<<<<<<<<<<
 *                     self.I += l
 *                 elif op == BAM_CDEL:
 */
        case 1:

        /* "pysamstats.pyx":3524
 *                     self.M += l
 *                 elif op == BAM_CINS:
 *                     self.I += l             # <<<<<<<<<<<<<<
 *                 elif op == BAM_CDEL:
 *                     self.D += l
 */
        __pyx_v_self->I = (__pyx_v_self->I + __pyx_v_l);
        break;

        /* "pysamstats.pyx":3525
 *                 elif op == BAM_CINS:
 *                     self.I += l
 *                 elif op == BAM_CDEL:             # <<<<<<<<<<<<<<
 *                     self.D += l
 *                 elif op == BAM_CREF_SKIP:
 */
        case 2:

        /* "pysamstats.pyx":3526
 *                     self.I += l
 *                 elif op == BAM_CDEL:
 *                     self.D += l             # <<<<<<<<<<<<<<
 *                 elif op == BAM_CREF_SKIP:
 *                     self.N += l
 */
        __pyx_v_self->D = (__pyx_v_self->D + __pyx_v_l);
        break;

        /* "pysamstats.pyx":3527
 *                 elif op == BAM_CDEL:
 *                     self.D += l
 *                 elif op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                     self.N += l
 *                 elif op == BAM_CSOFT_CLIP:
 */
        case 3:

        /* "pysamstats.pyx":3528
 *                     self.D += l
 *                 elif op == BAM_CREF_SKIP:
 *                     self.N += l             # <<<<<<<<<<<<<<
 *                 elif op == BAM_CSOFT_CLIP:
 *                     self.S += l
 */
        __pyx_v_self->N = (__pyx_v_self->N + __pyx_v_l);
        break;

        /* "pysamstats.pyx":3529
 *                 elif op == BAM_CREF_SKIP:
 *                     self.N += l
 *                 elif op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                     self.S += l
 *                 elif op == BAM_CHARD_CLIP:
 */
        case 4:

        /* "pysamstats.pyx":3530
 *                     self.N += l
 *                 elif op == BAM_CSOFT_CLIP:
 *                     self.S += l             # <<<<<<<<<<<<<<
 *                 elif op == BAM_CHARD_CLIP:
 *                     self.H += l
 */
        __pyx_v_self->S = (__pyx_v_self->S + __pyx_v_l);
        break;

        /* "pysamstats.pyx":3531
 *                 elif op == BAM_CSOFT_CLIP:
 *                     self.S += l
 *                 elif op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *                     self.H += l
 *                 elif op == BAM_CPAD:
 */
        case 5:

        /* "pysamstats.pyx":3532
 *                     self.S += l
 *                 elif op == BAM_CHARD_CLIP:
 *                     self.H += l             # <<<<<<<<<<<<<<
 *                 elif op == BAM_CPAD:
 *                     self.P += l
 */
        __pyx_v_self->H = (__pyx_v_self->H + __pyx_v_l);
        break;

        /* "pysamstats.pyx":3533
 *                 elif op == BAM_CHARD_CLIP:
 *                     self.H += l
 *                 elif op == BAM_CPAD:             # <<<<<<<<<<<<<<
 *                     self.P += l
 *                 elif op == BAM_CEQUAL:
 */
        case 6:

        /* "pysamstats.pyx":3534
 *                     self.H += l
 *                 elif op == BAM_CPAD:
 *                     self.P += l             # <<<<<<<<<<<<<<
 *                 elif op == BAM_CEQUAL:
 *                     self.EQ += l
 */
        __pyx_v_self->P = (__pyx_v_self->P + __pyx_v_l);
        break;

        /* "pysamstats.pyx":3535
 *                 elif op == BAM_CPAD:
 *                     self.P += l
 *                 elif op == BAM_CEQUAL:             # <<<<<<<<<<<<<<
 *                     self.EQ += l
 *                 elif op == BAM_CDIFF:
 */
        case 7:

        /* "pysamstats.pyx":3536
 *                     self.P += l
 *                 elif op == BAM_CEQUAL:
 *                     self.EQ += l             # <<<<<<<<<<<<<<
 *                 elif op == BAM_CDIFF:
 *                     self.X += l
 */
        __pyx_v_self->EQ = (__pyx_v_self->EQ + __pyx_v_l);
        break;

        /* "pysamstats.pyx":3537
 *                 elif op == BAM_CEQUAL:
 *                     self.EQ += l
 *                 elif op == BAM_CDIFF:             # <<<<<<<<<<<<<<
 *                     self.X += l
 *             self.reads_all += 1
 */
        case 8:

        /* "pysamstats.pyx":3538
 *                     self.EQ += l
 *                 elif op == BAM_CDIFF:
 *                     self.X += l             # <<<<<<<<<<<<<<
 *             self.reads_all += 1
 * 
 */
        __pyx_v_self->X = (__pyx_v_self->X + __pyx_v_l);
        break;
        default: break;
      }
    }

    /* "pysamstats.pyx":3539
 *                 elif op == BAM_CDIFF:
 *                     self.X += l
 *             self.reads_all += 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_v_self->reads_all = (__pyx_v_self->reads_all + 1);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":3508
 *         return rec
 * 
 *     cdef recv(self, bam1_t * b):             # <<<<<<<<<<<<<<
 *         cdef uint32_t flag
 *         cdef bint is_unmapped
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._AlignmentBinned.recv", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_cigar);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3542
 * 
 * 
 * def load_alignment_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_alignment_binned, dtype_alignment_binned,
 *                        *args, **kwargs)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_131load_alignment_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_130load_alignment_binned[] = "load_alignment_binned(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_131load_alignment_binned = {"load_alignment_binned", (PyCFunction)__pyx_pw_10pysamstats_131load_alignment_binned, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_130load_alignment_binned};
static PyObject *__pyx_pw_10pysamstats_131load_alignment_binned(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("load_alignment_binned (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_alignment_binned", 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_130load_alignment_binned(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_130load_alignment_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_alignment_binned", 0);

  /* "pysamstats.pyx":3543
 * 
 * def load_alignment_binned(*args, **kwargs):
 *     return _load_stats(stat_alignment_binned, dtype_alignment_binned,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_alignment_binned); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_alignment_binned); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":3544
 * def load_alignment_binned(*args, **kwargs):
 *     return _load_stats(stat_alignment_binned, dtype_alignment_binned,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":3543
 * 
 * def load_alignment_binned(*args, **kwargs):
 *     return _load_stats(stat_alignment_binned, dtype_alignment_binned,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3543; __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_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3544
 * def load_alignment_binned(*args, **kwargs):
 *     return _load_stats(stat_alignment_binned, dtype_alignment_binned,
 *                        *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);

  /* "pysamstats.pyx":3543
 * 
 * def load_alignment_binned(*args, **kwargs):
 *     return _load_stats(stat_alignment_binned, dtype_alignment_binned,             # <<<<<<<<<<<<<<
 *                        *args, **kwargs)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":3542
 * 
 * 
 * def load_alignment_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_alignment_binned, dtype_alignment_binned,
 *                        *args, **kwargs)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_alignment_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3567
 * 
 * 
 * def stat_tlen_binned(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned insert size statistics.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_133stat_tlen_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_132stat_tlen_binned[] = "stat_tlen_binned(alignmentfile, **kwargs)\nGenerate binned insert size statistics.\n\n    Parameters\n    ----------\n\n    alignmentfile : pysam.AlignmentFile or string\n        SAM or BAM file or file path\n    chrom : string\n        chromosome/contig\n    start : int\n        start position\n    end : int\n        end position\n    one_based : bool\n        coordinate system\n    truncate : bool\n        if True, truncate output to selected region\n    pad : bool\n        if True, emit records for every position, even if no reads are aligned\n    max_depth : int\n        maximum depth to allow in pileup column\n    window_size : int\n        size of surrounding window in base pairs\n    window_offset :\n        distance from window start to record position\n\n    Returns\n    -------\n\n    recs : iterator\n        record generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_133stat_tlen_binned = {"stat_tlen_binned", (PyCFunction)__pyx_pw_10pysamstats_133stat_tlen_binned, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_132stat_tlen_binned};
static PyObject *__pyx_pw_10pysamstats_133stat_tlen_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_tlen_binned (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_alignmentfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_tlen_binned") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_alignmentfile = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_tlen_binned", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.stat_tlen_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_132stat_tlen_binned(__pyx_self, __pyx_v_alignmentfile, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_132stat_tlen_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats__TlenBinned *__pyx_v_stat = 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("stat_tlen_binned", 0);

  /* "pysamstats.pyx":3602
 *     """
 * 
 *     stat = _TlenBinned()             # <<<<<<<<<<<<<<
 *     return _iter_binned(stat, alignmentfile=alignmentfile, **kwargs)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_10pysamstats__TlenBinned)), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_stat = ((struct __pyx_obj_10pysamstats__TlenBinned *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3603
 * 
 *     stat = _TlenBinned()
 *     return _iter_binned(stat, alignmentfile=alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_binned); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_stat));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_stat));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_stat));
  __pyx_t_3 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_alignmentfile))) {
    __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_alignmentfile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_alignmentfile, __pyx_v_alignmentfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":3567
 * 
 * 
 * def stat_tlen_binned(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned insert size statistics.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.stat_tlen_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_stat);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3615
 *     cdef int64_t tlen_pp_squared_sum
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.tlen_sum = self.tlen_squared_sum = self.tlen_pp_sum = \
 *             self.tlen_pp_squared_sum = self.reads_all = self.reads_pp = 0
 */

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

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

static int __pyx_pf_10pysamstats_11_TlenBinned___cinit__(struct __pyx_obj_10pysamstats__TlenBinned *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "pysamstats.pyx":3616
 * 
 *     def __cinit__(self):
 *         self.tlen_sum = self.tlen_squared_sum = self.tlen_pp_sum = \             # <<<<<<<<<<<<<<
 *             self.tlen_pp_squared_sum = self.reads_all = self.reads_pp = 0
 * 
 */
  __pyx_v_self->tlen_sum = 0;
  __pyx_v_self->tlen_squared_sum = 0;
  __pyx_v_self->tlen_pp_sum = 0;

  /* "pysamstats.pyx":3617
 *     def __cinit__(self):
 *         self.tlen_sum = self.tlen_squared_sum = self.tlen_pp_sum = \
 *             self.tlen_pp_squared_sum = self.reads_all = self.reads_pp = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):
 */
  __pyx_v_self->tlen_pp_squared_sum = 0;
  __pyx_v_self->reads_all = 0;
  __pyx_v_self->reads_pp = 0;

  /* "pysamstats.pyx":3615
 *     cdef int64_t tlen_pp_squared_sum
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.tlen_sum = self.tlen_squared_sum = self.tlen_pp_sum = \
 *             self.tlen_pp_squared_sum = self.reads_all = self.reads_pp = 0
 */

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

/* "pysamstats.pyx":3619
 *             self.tlen_pp_squared_sum = self.reads_all = self.reads_pp = 0
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):             # <<<<<<<<<<<<<<
 * 
 *         # make record for bin
 */

static PyObject *__pyx_f_10pysamstats_11_TlenBinned_rec(struct __pyx_obj_10pysamstats__TlenBinned *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_chrom, CYTHON_UNUSED PyObject *__pyx_v_bin_start, CYTHON_UNUSED PyObject *__pyx_v_bin_end, CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile) {
  PyObject *__pyx_v_rec = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("rec", 0);

  /* "pysamstats.pyx":3622
 * 
 *         # make record for bin
 *         rec = {'reads_all': self.reads_all, 'reads_pp': self.reads_pp,             # <<<<<<<<<<<<<<
 *                'mean_tlen': _mean(self.tlen_sum, self.reads_all),
 *                'mean_tlen_pp': _mean(self.tlen_pp_sum, self.reads_pp),
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->reads_all); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_all, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->reads_pp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reads_pp, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3623
 *         # make record for bin
 *         rec = {'reads_all': self.reads_all, 'reads_pp': self.reads_pp,
 *                'mean_tlen': _mean(self.tlen_sum, self.reads_all),             # <<<<<<<<<<<<<<
 *                'mean_tlen_pp': _mean(self.tlen_pp_sum, self.reads_pp),
 *                'rms_tlen': _rootmean(self.tlen_squared_sum, self.reads_all),
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_f_10pysamstats__mean(__pyx_v_self->tlen_sum, __pyx_v_self->reads_all)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_mean_tlen, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3624
 *         rec = {'reads_all': self.reads_all, 'reads_pp': self.reads_pp,
 *                'mean_tlen': _mean(self.tlen_sum, self.reads_all),
 *                'mean_tlen_pp': _mean(self.tlen_pp_sum, self.reads_pp),             # <<<<<<<<<<<<<<
 *                'rms_tlen': _rootmean(self.tlen_squared_sum, self.reads_all),
 *                'rms_tlen_pp': _rootmean(self.tlen_pp_squared_sum,
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_f_10pysamstats__mean(__pyx_v_self->tlen_pp_sum, __pyx_v_self->reads_pp)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_mean_tlen_pp, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3625
 *                'mean_tlen': _mean(self.tlen_sum, self.reads_all),
 *                'mean_tlen_pp': _mean(self.tlen_pp_sum, self.reads_pp),
 *                'rms_tlen': _rootmean(self.tlen_squared_sum, self.reads_all),             # <<<<<<<<<<<<<<
 *                'rms_tlen_pp': _rootmean(self.tlen_pp_squared_sum,
 *                                         self.reads_pp)}
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_f_10pysamstats__rootmean(__pyx_v_self->tlen_squared_sum, __pyx_v_self->reads_all)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3626
 *                'mean_tlen_pp': _mean(self.tlen_pp_sum, self.reads_pp),
 *                'rms_tlen': _rootmean(self.tlen_squared_sum, self.reads_all),
 *                'rms_tlen_pp': _rootmean(self.tlen_pp_squared_sum,             # <<<<<<<<<<<<<<
 *                                         self.reads_pp)}
 * 
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_f_10pysamstats__rootmean(__pyx_v_self->tlen_pp_squared_sum, __pyx_v_self->reads_pp)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_rms_tlen_pp, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_rec = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3630
 * 
 *         # reset counters
 *         self.tlen_sum = self.tlen_squared_sum = self.tlen_pp_sum = \             # <<<<<<<<<<<<<<
 *             self.tlen_pp_squared_sum = self.reads_all = self.reads_pp = 0
 * 
 */
  __pyx_v_self->tlen_sum = 0;
  __pyx_v_self->tlen_squared_sum = 0;
  __pyx_v_self->tlen_pp_sum = 0;

  /* "pysamstats.pyx":3631
 *         # reset counters
 *         self.tlen_sum = self.tlen_squared_sum = self.tlen_pp_sum = \
 *             self.tlen_pp_squared_sum = self.reads_all = self.reads_pp = 0             # <<<<<<<<<<<<<<
 * 
 *         return rec
 */
  __pyx_v_self->tlen_pp_squared_sum = 0;
  __pyx_v_self->reads_all = 0;
  __pyx_v_self->reads_pp = 0;

  /* "pysamstats.pyx":3633
 *             self.tlen_pp_squared_sum = self.reads_all = self.reads_pp = 0
 * 
 *         return rec             # <<<<<<<<<<<<<<
 * 
 *     cdef recv(self, bam1_t * b):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_rec);
  __pyx_r = __pyx_v_rec;
  goto __pyx_L0;

  /* "pysamstats.pyx":3619
 *             self.tlen_pp_squared_sum = self.reads_all = self.reads_pp = 0
 * 
 *     cdef dict rec(self, chrom, bin_start, bin_end, FastaFile fafile):             # <<<<<<<<<<<<<<
 * 
 *         # make record for bin
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats._TlenBinned.rec", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3635
 *         return rec
 * 
 *     cdef recv(self, bam1_t * b):             # <<<<<<<<<<<<<<
 *         cdef uint32_t flag
 *         cdef bint is_unmapped
 */

static PyObject *__pyx_f_10pysamstats_11_TlenBinned_recv(struct __pyx_obj_10pysamstats__TlenBinned *__pyx_v_self, bam1_t *__pyx_v_b) {
  uint32_t __pyx_v_flag;
  int __pyx_v_is_unmapped;
  int __pyx_v_is_proper_pair;
  int64_t __pyx_v_tlen;
  int64_t __pyx_v_tlen_squared;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_t_2;
  int32_t __pyx_t_3;
  __Pyx_RefNannySetupContext("recv", 0);

  /* "pysamstats.pyx":3641
 *         cdef int64_t tlen
 *         cdef int64_t tlen_squared
 *         flag = b.core.flag             # <<<<<<<<<<<<<<
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:
 */
  __pyx_t_1 = __pyx_v_b->core.flag;
  __pyx_v_flag = __pyx_t_1;

  /* "pysamstats.pyx":3642
 *         cdef int64_t tlen_squared
 *         flag = b.core.flag
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)             # <<<<<<<<<<<<<<
 *         if not is_unmapped:
 *             self.reads_all += 1
 */
  __pyx_v_is_unmapped = ((__pyx_v_flag & 4) != 0);

  /* "pysamstats.pyx":3643
 *         flag = b.core.flag
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:             # <<<<<<<<<<<<<<
 *             self.reads_all += 1
 *             tlen = b.core.isize
 */
  __pyx_t_2 = ((!(__pyx_v_is_unmapped != 0)) != 0);
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3644
 *         is_unmapped = <bint>(flag & BAM_FUNMAP)
 *         if not is_unmapped:
 *             self.reads_all += 1             # <<<<<<<<<<<<<<
 *             tlen = b.core.isize
 *             self.tlen_sum += tlen
 */
    __pyx_v_self->reads_all = (__pyx_v_self->reads_all + 1);

    /* "pysamstats.pyx":3645
 *         if not is_unmapped:
 *             self.reads_all += 1
 *             tlen = b.core.isize             # <<<<<<<<<<<<<<
 *             self.tlen_sum += tlen
 *             tlen_squared = tlen**2
 */
    __pyx_t_3 = __pyx_v_b->core.isize;
    __pyx_v_tlen = __pyx_t_3;

    /* "pysamstats.pyx":3646
 *             self.reads_all += 1
 *             tlen = b.core.isize
 *             self.tlen_sum += tlen             # <<<<<<<<<<<<<<
 *             tlen_squared = tlen**2
 *             self.tlen_squared_sum += tlen_squared
 */
    __pyx_v_self->tlen_sum = (__pyx_v_self->tlen_sum + __pyx_v_tlen);

    /* "pysamstats.pyx":3647
 *             tlen = b.core.isize
 *             self.tlen_sum += tlen
 *             tlen_squared = tlen**2             # <<<<<<<<<<<<<<
 *             self.tlen_squared_sum += tlen_squared
 *             is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_v_tlen_squared = __Pyx_pow_long(((long)__pyx_v_tlen), 2);

    /* "pysamstats.pyx":3648
 *             self.tlen_sum += tlen
 *             tlen_squared = tlen**2
 *             self.tlen_squared_sum += tlen_squared             # <<<<<<<<<<<<<<
 *             is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *             if is_proper_pair:
 */
    __pyx_v_self->tlen_squared_sum = (__pyx_v_self->tlen_squared_sum + __pyx_v_tlen_squared);

    /* "pysamstats.pyx":3649
 *             tlen_squared = tlen**2
 *             self.tlen_squared_sum += tlen_squared
 *             is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *             if is_proper_pair:
 *                 self.reads_pp += 1
 */
    __pyx_v_is_proper_pair = ((__pyx_v_flag & 2) != 0);

    /* "pysamstats.pyx":3650
 *             self.tlen_squared_sum += tlen_squared
 *             is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 self.reads_pp += 1
 *                 self.tlen_pp_sum += tlen
 */
    __pyx_t_2 = (__pyx_v_is_proper_pair != 0);
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3651
 *             is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *             if is_proper_pair:
 *                 self.reads_pp += 1             # <<<<<<<<<<<<<<
 *                 self.tlen_pp_sum += tlen
 *                 self.tlen_pp_squared_sum += tlen_squared
 */
      __pyx_v_self->reads_pp = (__pyx_v_self->reads_pp + 1);

      /* "pysamstats.pyx":3652
 *             if is_proper_pair:
 *                 self.reads_pp += 1
 *                 self.tlen_pp_sum += tlen             # <<<<<<<<<<<<<<
 *                 self.tlen_pp_squared_sum += tlen_squared
 * 
 */
      __pyx_v_self->tlen_pp_sum = (__pyx_v_self->tlen_pp_sum + __pyx_v_tlen);

      /* "pysamstats.pyx":3653
 *                 self.reads_pp += 1
 *                 self.tlen_pp_sum += tlen
 *                 self.tlen_pp_squared_sum += tlen_squared             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_v_self->tlen_pp_squared_sum = (__pyx_v_self->tlen_pp_squared_sum + __pyx_v_tlen_squared);
      goto __pyx_L4;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":3635
 *         return rec
 * 
 *     cdef recv(self, bam1_t * b):             # <<<<<<<<<<<<<<
 *         cdef uint32_t flag
 *         cdef bint is_unmapped
 */

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

/* "pysamstats.pyx":3656
 * 
 * 
 * def load_tlen_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_tlen_binned, dtype_tlen_binned, *args, **kwargs)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_135load_tlen_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_134load_tlen_binned[] = "load_tlen_binned(*args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_135load_tlen_binned = {"load_tlen_binned", (PyCFunction)__pyx_pw_10pysamstats_135load_tlen_binned, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_134load_tlen_binned};
static PyObject *__pyx_pw_10pysamstats_135load_tlen_binned(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("load_tlen_binned (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "load_tlen_binned", 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_134load_tlen_binned(__pyx_self, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_134load_tlen_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("load_tlen_binned", 0);

  /* "pysamstats.pyx":3657
 * 
 * def load_tlen_binned(*args, **kwargs):
 *     return _load_stats(stat_tlen_binned, dtype_tlen_binned, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_load_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_stat_tlen_binned); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_tlen_binned); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3657; __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_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":3656
 * 
 * 
 * def load_tlen_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_tlen_binned, dtype_tlen_binned, *args, **kwargs)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.load_tlen_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3665
 * 
 * 
 * def _iter_pileup(frec, fpad, alignmentfile, fafile=None, chrom=None, start=None,             # <<<<<<<<<<<<<<
 *                  end=None, one_based=False, truncate=False, pad=False,
 *                  max_depth=8000, **kwargs):
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_137_iter_pileup(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_136_iter_pileup[] = "_iter_pileup(frec, fpad, alignmentfile, fafile=None, chrom=None, start=None, end=None, one_based=False, truncate=False, pad=False, max_depth=8000, **kwargs)\nGeneral purpose function to generate statistics, where one record is\n    generated for each genome position in the selected range, based on a\n    pileup column.\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_137_iter_pileup = {"_iter_pileup", (PyCFunction)__pyx_pw_10pysamstats_137_iter_pileup, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_136_iter_pileup};
static PyObject *__pyx_pw_10pysamstats_137_iter_pileup(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_frec = 0;
  PyObject *__pyx_v_fpad = 0;
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__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_truncate = 0;
  PyObject *__pyx_v_pad = 0;
  PyObject *__pyx_v_max_depth = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_iter_pileup (wrapper)", 0);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frec,&__pyx_n_s_fpad,&__pyx_n_s_alignmentfile,&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_one_based,&__pyx_n_s_truncate,&__pyx_n_s_pad,&__pyx_n_s_max_depth,0};
    PyObject* values[11] = {0,0,0,0,0,0,0,0,0,0,0};
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    values[5] = ((PyObject *)Py_None);

    /* "pysamstats.pyx":3666
 * 
 * def _iter_pileup(frec, fpad, alignmentfile, fafile=None, chrom=None, start=None,
 *                  end=None, one_based=False, truncate=False, pad=False,             # <<<<<<<<<<<<<<
 *                  max_depth=8000, **kwargs):
 *     """General purpose function to generate statistics, where one record is
 */
    values[6] = ((PyObject *)Py_None);
    values[7] = ((PyObject *)Py_False);
    values[8] = ((PyObject *)Py_False);
    values[9] = ((PyObject *)Py_False);
    values[10] = ((PyObject *)__pyx_int_8000);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_frec)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fpad)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_pileup", 0, 3, 11, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_pileup", 0, 3, 11, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fafile);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_one_based);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_truncate);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pad);
          if (value) { values[9] = value; kw_args--; }
        }
        case 10:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_depth);
          if (value) { values[10] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "_iter_pileup") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_frec = values[0];
    __pyx_v_fpad = values[1];
    __pyx_v_alignmentfile = values[2];
    __pyx_v_fafile = values[3];
    __pyx_v_chrom = values[4];
    __pyx_v_start = values[5];
    __pyx_v_end = values[6];
    __pyx_v_one_based = values[7];
    __pyx_v_truncate = values[8];
    __pyx_v_pad = values[9];
    __pyx_v_max_depth = values[10];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_iter_pileup", 0, 3, 11, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats._iter_pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_136_iter_pileup(__pyx_self, __pyx_v_frec, __pyx_v_fpad, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_truncate, __pyx_v_pad, __pyx_v_max_depth, __pyx_v_kwargs);

  /* "pysamstats.pyx":3665
 * 
 * 
 * def _iter_pileup(frec, fpad, alignmentfile, fafile=None, chrom=None, start=None,             # <<<<<<<<<<<<<<
 *                  end=None, one_based=False, truncate=False, pad=False,
 *                  max_depth=8000, **kwargs):
 */

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

static PyObject *__pyx_pf_10pysamstats_136_iter_pileup(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_frec, PyObject *__pyx_v_fpad, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_truncate, PyObject *__pyx_v_pad, PyObject *__pyx_v_max_depth, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_iter_pileup", 0);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  __Pyx_INCREF(__pyx_v_fafile);

  /* "pysamstats.pyx":3674
 *     """
 * 
 *     if isinstance(alignmentfile, _string_types):             # <<<<<<<<<<<<<<
 *         alignmentfile = AlignmentFile(alignmentfile)
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_string_types); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_IsInstance(__pyx_v_alignmentfile, __pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "pysamstats.pyx":3675
 * 
 *     if isinstance(alignmentfile, _string_types):
 *         alignmentfile = AlignmentFile(alignmentfile)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(fafile, _string_types):
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_alignmentfile);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_alignmentfile);
    __Pyx_GIVEREF(__pyx_v_alignmentfile);
    __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_AlignmentFile)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_alignmentfile, __pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":3677
 *         alignmentfile = AlignmentFile(alignmentfile)
 * 
 *     if isinstance(fafile, _string_types):             # <<<<<<<<<<<<<<
 *         fafile = FastaFile(fafile)
 * 
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_string_types); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_IsInstance(__pyx_v_fafile, __pyx_t_4); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3678
 * 
 *     if isinstance(fafile, _string_types):
 *         fafile = FastaFile(fafile)             # <<<<<<<<<<<<<<
 * 
 *     if pad:
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_fafile);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_fafile);
    __Pyx_GIVEREF(__pyx_v_fafile);
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6cfaidx_FastaFile)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_fafile, __pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "pysamstats.pyx":3680
 *         fafile = FastaFile(fafile)
 * 
 *     if pad:             # <<<<<<<<<<<<<<
 *         return _iter_pileup_padded(frec, fpad, alignmentfile,
 *                                    fafile=fafile, chrom=chrom,
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_pad); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3681
 * 
 *     if pad:
 *         return _iter_pileup_padded(frec, fpad, alignmentfile,             # <<<<<<<<<<<<<<
 *                                    fafile=fafile, chrom=chrom,
 *                                    start=start, end=end, one_based=one_based,
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup_padded); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_frec);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_frec);
    __Pyx_GIVEREF(__pyx_v_frec);
    __Pyx_INCREF(__pyx_v_fpad);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_fpad);
    __Pyx_GIVEREF(__pyx_v_fpad);
    __Pyx_INCREF(__pyx_v_alignmentfile);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
    __Pyx_GIVEREF(__pyx_v_alignmentfile);

    /* "pysamstats.pyx":3685
 *                                    start=start, end=end, one_based=one_based,
 *                                    truncate=truncate, max_depth=max_depth,
 *                                    **kwargs)             # <<<<<<<<<<<<<<
 *     else:
 *         return _iter_pileup_default(frec, alignmentfile, fafile=fafile, chrom=chrom,
 */
    __pyx_t_5 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);

    /* "pysamstats.pyx":3682
 *     if pad:
 *         return _iter_pileup_padded(frec, fpad, alignmentfile,
 *                                    fafile=fafile, chrom=chrom,             # <<<<<<<<<<<<<<
 *                                    start=start, end=end, one_based=one_based,
 *                                    truncate=truncate, max_depth=max_depth,
 */
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_fafile))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_fafile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_chrom))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_chrom); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3683
 *         return _iter_pileup_padded(frec, fpad, alignmentfile,
 *                                    fafile=fafile, chrom=chrom,
 *                                    start=start, end=end, one_based=one_based,             # <<<<<<<<<<<<<<
 *                                    truncate=truncate, max_depth=max_depth,
 *                                    **kwargs)
 */
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_start))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_start); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_start, __pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_end))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_end); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_end, __pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_one_based))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_one_based); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_one_based, __pyx_v_one_based) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3684
 *                                    fafile=fafile, chrom=chrom,
 *                                    start=start, end=end, one_based=one_based,
 *                                    truncate=truncate, max_depth=max_depth,             # <<<<<<<<<<<<<<
 *                                    **kwargs)
 *     else:
 */
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_truncate))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_truncate); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_truncate, __pyx_v_truncate) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_max_depth))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_max_depth); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_max_depth, __pyx_v_max_depth) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3681
 * 
 *     if pad:
 *         return _iter_pileup_padded(frec, fpad, alignmentfile,             # <<<<<<<<<<<<<<
 *                                    fafile=fafile, chrom=chrom,
 *                                    start=start, end=end, one_based=one_based,
 */
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysamstats.pyx":3687
 *                                    **kwargs)
 *     else:
 *         return _iter_pileup_default(frec, alignmentfile, fafile=fafile, chrom=chrom,             # <<<<<<<<<<<<<<
 *                                     start=start, end=end, one_based=one_based,
 *                                     truncate=truncate, max_depth=max_depth,
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup_default); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_frec);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_frec);
    __Pyx_GIVEREF(__pyx_v_frec);
    __Pyx_INCREF(__pyx_v_alignmentfile);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_alignmentfile);
    __Pyx_GIVEREF(__pyx_v_alignmentfile);

    /* "pysamstats.pyx":3690
 *                                     start=start, end=end, one_based=one_based,
 *                                     truncate=truncate, max_depth=max_depth,
 *                                     **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_4 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);

    /* "pysamstats.pyx":3687
 *                                    **kwargs)
 *     else:
 *         return _iter_pileup_default(frec, alignmentfile, fafile=fafile, chrom=chrom,             # <<<<<<<<<<<<<<
 *                                     start=start, end=end, one_based=one_based,
 *                                     truncate=truncate, max_depth=max_depth,
 */
    if (unlikely(PyDict_GetItem(__pyx_t_4, __pyx_n_s_fafile))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_fafile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_4, __pyx_n_s_chrom))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_chrom); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3688
 *     else:
 *         return _iter_pileup_default(frec, alignmentfile, fafile=fafile, chrom=chrom,
 *                                     start=start, end=end, one_based=one_based,             # <<<<<<<<<<<<<<
 *                                     truncate=truncate, max_depth=max_depth,
 *                                     **kwargs)
 */
    if (unlikely(PyDict_GetItem(__pyx_t_4, __pyx_n_s_start))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_start); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_start, __pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_4, __pyx_n_s_end))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_end); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_end, __pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_4, __pyx_n_s_one_based))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_one_based); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_one_based, __pyx_v_one_based) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3689
 *         return _iter_pileup_default(frec, alignmentfile, fafile=fafile, chrom=chrom,
 *                                     start=start, end=end, one_based=one_based,
 *                                     truncate=truncate, max_depth=max_depth,             # <<<<<<<<<<<<<<
 *                                     **kwargs)
 * 
 */
    if (unlikely(PyDict_GetItem(__pyx_t_4, __pyx_n_s_truncate))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_truncate); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_truncate, __pyx_v_truncate) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_4, __pyx_n_s_max_depth))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_max_depth); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_max_depth, __pyx_v_max_depth) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3687
 *                                    **kwargs)
 *     else:
 *         return _iter_pileup_default(frec, alignmentfile, fafile=fafile, chrom=chrom,             # <<<<<<<<<<<<<<
 *                                     start=start, end=end, one_based=one_based,
 *                                     truncate=truncate, max_depth=max_depth,
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }

  /* "pysamstats.pyx":3665
 * 
 * 
 * def _iter_pileup(frec, fpad, alignmentfile, fafile=None, chrom=None, start=None,             # <<<<<<<<<<<<<<
 *                  end=None, one_based=False, truncate=False, pad=False,
 *                  max_depth=8000, **kwargs):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysamstats._iter_pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_alignmentfile);
  __Pyx_XDECREF(__pyx_v_fafile);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_140generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysamstats.pyx":3693
 * 
 * 
 * def _iter_pileup_default(frec, alignmentfile, fafile=None,             # <<<<<<<<<<<<<<
 *                          chrom=None, start=None, end=None,
 *                          one_based=False, truncate=False,
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_139_iter_pileup_default(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_138_iter_pileup_default[] = "_iter_pileup_default(frec, alignmentfile, fafile=None, chrom=None, start=None, end=None, one_based=False, truncate=False, max_depth=8000, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_139_iter_pileup_default = {"_iter_pileup_default", (PyCFunction)__pyx_pw_10pysamstats_139_iter_pileup_default, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_138_iter_pileup_default};
static PyObject *__pyx_pw_10pysamstats_139_iter_pileup_default(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_frec = 0;
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__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_truncate = 0;
  PyObject *__pyx_v_max_depth = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_iter_pileup_default (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_frec,&__pyx_n_s_alignmentfile,&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_one_based,&__pyx_n_s_truncate,&__pyx_n_s_max_depth,0};
    PyObject* values[9] = {0,0,0,0,0,0,0,0,0};
    values[2] = ((PyObject *)Py_None);

    /* "pysamstats.pyx":3694
 * 
 * def _iter_pileup_default(frec, alignmentfile, fafile=None,
 *                          chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                          one_based=False, truncate=False,
 *                          max_depth=8000, **kwargs):
 */
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    values[5] = ((PyObject *)Py_None);

    /* "pysamstats.pyx":3695
 * def _iter_pileup_default(frec, alignmentfile, fafile=None,
 *                          chrom=None, start=None, end=None,
 *                          one_based=False, truncate=False,             # <<<<<<<<<<<<<<
 *                          max_depth=8000, **kwargs):
 *     start, end = _normalise_coords(alignmentfile, chrom, start, end, one_based)
 */
    values[6] = ((PyObject *)Py_False);
    values[7] = ((PyObject *)Py_False);
    values[8] = ((PyObject *)__pyx_int_8000);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        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_frec)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_pileup_default", 0, 2, 9, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3693; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fafile);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_one_based);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_truncate);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_depth);
          if (value) { values[8] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "_iter_pileup_default") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3693; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        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);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_frec = values[0];
    __pyx_v_alignmentfile = values[1];
    __pyx_v_fafile = values[2];
    __pyx_v_chrom = values[3];
    __pyx_v_start = values[4];
    __pyx_v_end = values[5];
    __pyx_v_one_based = values[6];
    __pyx_v_truncate = values[7];
    __pyx_v_max_depth = values[8];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_iter_pileup_default", 0, 2, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3693; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats._iter_pileup_default", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_138_iter_pileup_default(__pyx_self, __pyx_v_frec, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_truncate, __pyx_v_max_depth, __pyx_v_kwargs);

  /* "pysamstats.pyx":3693
 * 
 * 
 * def _iter_pileup_default(frec, alignmentfile, fafile=None,             # <<<<<<<<<<<<<<
 *                          chrom=None, start=None, end=None,
 *                          one_based=False, truncate=False,
 */

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

static PyObject *__pyx_pf_10pysamstats_138_iter_pileup_default(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_frec, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_truncate, PyObject *__pyx_v_max_depth, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_iter_pileup_default", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default *)__pyx_tp_new_10pysamstats___pyx_scope_struct_1__iter_pileup_default(__pyx_ptype_10pysamstats___pyx_scope_struct_1__iter_pileup_default, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_frec = __pyx_v_frec;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_frec);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_frec);
  __pyx_cur_scope->__pyx_v_alignmentfile = __pyx_v_alignmentfile;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_alignmentfile);
  __pyx_cur_scope->__pyx_v_fafile = __pyx_v_fafile;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fafile);
  __Pyx_GIVEREF(__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_truncate = __pyx_v_truncate;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_truncate);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_truncate);
  __pyx_cur_scope->__pyx_v_max_depth = __pyx_v_max_depth;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_depth);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_depth);
  __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_140generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter_pileup_default, __pyx_n_s_iter_pileup_default); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

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

static PyObject *__pyx_gb_10pysamstats_140generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default *)__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 = NULL;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *(*__pyx_t_7)(PyObject *);
  Py_ssize_t __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_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 = 3693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3697
 *                          one_based=False, truncate=False,
 *                          max_depth=8000, **kwargs):
 *     start, end = _normalise_coords(alignmentfile, chrom, start, end, one_based)             # <<<<<<<<<<<<<<
 *     it = alignmentfile.pileup(reference=chrom, start=start, end=end,
 *                         truncate=truncate, max_depth=max_depth)
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_normalise_coords); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  __pyx_t_5 = PyTuple_New(5+__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (__pyx_t_3) {
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
  }
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_cur_scope->__pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_alignmentfile);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __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_5, 2+__pyx_t_4, __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_5, 3+__pyx_t_4, __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_5, 4+__pyx_t_4, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
    PyObject* sequence = __pyx_t_1;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3697; __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_5 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_5);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_6(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_5 = __pyx_t_6(__pyx_t_3); if (unlikely(!__pyx_t_5)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_5);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_3), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = NULL;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_start, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_end, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pysamstats.pyx":3698
 *                          max_depth=8000, **kwargs):
 *     start, end = _normalise_coords(alignmentfile, chrom, start, end, one_based)
 *     it = alignmentfile.pileup(reference=chrom, start=start, end=end,             # <<<<<<<<<<<<<<
 *                         truncate=truncate, max_depth=max_depth)
 *     for col in it:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_alignmentfile, __pyx_n_s_pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_reference, __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_start, __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_end, __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3699
 *     start, end = _normalise_coords(alignmentfile, chrom, start, end, one_based)
 *     it = alignmentfile.pileup(reference=chrom, start=start, end=end,
 *                         truncate=truncate, max_depth=max_depth)             # <<<<<<<<<<<<<<
 *     for col in it:
 *         yield frec(alignmentfile, fafile, col, one_based)
 */
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_truncate, __pyx_cur_scope->__pyx_v_truncate) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_max_depth, __pyx_cur_scope->__pyx_v_max_depth) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3698
 *                          max_depth=8000, **kwargs):
 *     start, end = _normalise_coords(alignmentfile, chrom, start, end, one_based)
 *     it = alignmentfile.pileup(reference=chrom, start=start, end=end,             # <<<<<<<<<<<<<<
 *                         truncate=truncate, max_depth=max_depth)
 *     for col in it:
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_it = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":3700
 *     it = alignmentfile.pileup(reference=chrom, start=start, end=end,
 *                         truncate=truncate, max_depth=max_depth)
 *     for col in it:             # <<<<<<<<<<<<<<
 *         yield frec(alignmentfile, fafile, col, one_based)
 * 
 */
  if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_it)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_it)) {
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_it; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_it); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_5); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_5); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_7(__pyx_t_2);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_col, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_5 = 0;

    /* "pysamstats.pyx":3701
 *                         truncate=truncate, max_depth=max_depth)
 *     for col in it:
 *         yield frec(alignmentfile, fafile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_frec);
    __pyx_t_1 = __pyx_cur_scope->__pyx_v_frec; __pyx_t_3 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_8 = 1;
      }
    }
    __pyx_t_9 = PyTuple_New(4+__pyx_t_8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    if (__pyx_t_3) {
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_alignmentfile);
    PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_cur_scope->__pyx_v_alignmentfile);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_alignmentfile);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fafile);
    PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_cur_scope->__pyx_v_fafile);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fafile);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_col);
    PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_8, __pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
    PyTuple_SET_ITEM(__pyx_t_9, 3+__pyx_t_8, __pyx_cur_scope->__pyx_v_one_based);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 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_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_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_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3700
 *     it = alignmentfile.pileup(reference=chrom, start=start, end=end,
 *                         truncate=truncate, max_depth=max_depth)
 *     for col in it:             # <<<<<<<<<<<<<<
 *         yield frec(alignmentfile, fafile, col, one_based)
 * 
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3693
 * 
 * 
 * def _iter_pileup_default(frec, alignmentfile, fafile=None,             # <<<<<<<<<<<<<<
 *                          chrom=None, start=None, end=None,
 *                          one_based=False, truncate=False,
 */

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("_iter_pileup_default", __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":3704
 * 
 * 
 * def _iter_pileup_padded(frec, fpad, alignmentfile, fafile=None, chrom=None,             # <<<<<<<<<<<<<<
 *                         start=None, end=None, one_based=False,
 *                         truncate=False, max_depth=8000, **kwargs):
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_142_iter_pileup_padded(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_141_iter_pileup_padded[] = "_iter_pileup_padded(frec, fpad, alignmentfile, fafile=None, chrom=None, start=None, end=None, one_based=False, truncate=False, max_depth=8000, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_142_iter_pileup_padded = {"_iter_pileup_padded", (PyCFunction)__pyx_pw_10pysamstats_142_iter_pileup_padded, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_141_iter_pileup_padded};
static PyObject *__pyx_pw_10pysamstats_142_iter_pileup_padded(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_frec = 0;
  PyObject *__pyx_v_fpad = 0;
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__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_truncate = 0;
  PyObject *__pyx_v_max_depth = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_iter_pileup_padded (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_frec,&__pyx_n_s_fpad,&__pyx_n_s_alignmentfile,&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_one_based,&__pyx_n_s_truncate,&__pyx_n_s_max_depth,0};
    PyObject* values[10] = {0,0,0,0,0,0,0,0,0,0};
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);

    /* "pysamstats.pyx":3705
 * 
 * def _iter_pileup_padded(frec, fpad, alignmentfile, fafile=None, chrom=None,
 *                         start=None, end=None, one_based=False,             # <<<<<<<<<<<<<<
 *                         truncate=False, max_depth=8000, **kwargs):
 * 
 */
    values[5] = ((PyObject *)Py_None);
    values[6] = ((PyObject *)Py_None);
    values[7] = ((PyObject *)Py_False);

    /* "pysamstats.pyx":3706
 * def _iter_pileup_padded(frec, fpad, alignmentfile, fafile=None, chrom=None,
 *                         start=None, end=None, one_based=False,
 *                         truncate=False, max_depth=8000, **kwargs):             # <<<<<<<<<<<<<<
 * 
 *     if chrom is not None:
 */
    values[8] = ((PyObject *)Py_False);
    values[9] = ((PyObject *)__pyx_int_8000);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        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_frec)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fpad)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_pileup_padded", 0, 3, 10, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3704; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_pileup_padded", 0, 3, 10, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3704; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fafile);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_one_based);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_truncate);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_depth);
          if (value) { values[9] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "_iter_pileup_padded") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3704; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        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);
        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_frec = values[0];
    __pyx_v_fpad = values[1];
    __pyx_v_alignmentfile = values[2];
    __pyx_v_fafile = values[3];
    __pyx_v_chrom = values[4];
    __pyx_v_start = values[5];
    __pyx_v_end = values[6];
    __pyx_v_one_based = values[7];
    __pyx_v_truncate = values[8];
    __pyx_v_max_depth = values[9];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_iter_pileup_padded", 0, 3, 10, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3704; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats._iter_pileup_padded", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_141_iter_pileup_padded(__pyx_self, __pyx_v_frec, __pyx_v_fpad, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_truncate, __pyx_v_max_depth, __pyx_v_kwargs);

  /* "pysamstats.pyx":3704
 * 
 * 
 * def _iter_pileup_padded(frec, fpad, alignmentfile, fafile=None, chrom=None,             # <<<<<<<<<<<<<<
 *                         start=None, end=None, one_based=False,
 *                         truncate=False, max_depth=8000, **kwargs):
 */

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

static PyObject *__pyx_pf_10pysamstats_141_iter_pileup_padded(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_frec, PyObject *__pyx_v_fpad, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_truncate, PyObject *__pyx_v_max_depth, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_it = NULL;
  PyObject *__pyx_v_its = NULL;
  PyObject *__pyx_v_itc = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_iter_pileup_padded", 0);
  __Pyx_INCREF(__pyx_v_chrom);

  /* "pysamstats.pyx":3708
 *                         truncate=False, max_depth=8000, **kwargs):
 * 
 *     if chrom is not None:             # <<<<<<<<<<<<<<
 *         it = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,
 *                                        chrom=chrom, start=start, end=end,
 */
  __pyx_t_1 = (__pyx_v_chrom != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3709
 * 
 *     if chrom is not None:
 *         it = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,             # <<<<<<<<<<<<<<
 *                                        chrom=chrom, start=start, end=end,
 *                                        one_based=one_based,
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup_padded_chrom); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __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 = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_frec);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_frec);
    __Pyx_GIVEREF(__pyx_v_frec);
    __Pyx_INCREF(__pyx_v_fpad);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_fpad);
    __Pyx_GIVEREF(__pyx_v_fpad);
    __Pyx_INCREF(__pyx_v_alignmentfile);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
    __Pyx_GIVEREF(__pyx_v_alignmentfile);

    /* "pysamstats.pyx":3713
 *                                        one_based=one_based,
 *                                        truncate=truncate,
 *                                        max_depth=max_depth, **kwargs)             # <<<<<<<<<<<<<<
 *     else:
 *         its = list()
 */
    __pyx_t_5 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);

    /* "pysamstats.pyx":3709
 * 
 *     if chrom is not None:
 *         it = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,             # <<<<<<<<<<<<<<
 *                                        chrom=chrom, start=start, end=end,
 *                                        one_based=one_based,
 */
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_fafile))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_fafile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3710
 *     if chrom is not None:
 *         it = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,
 *                                        chrom=chrom, start=start, end=end,             # <<<<<<<<<<<<<<
 *                                        one_based=one_based,
 *                                        truncate=truncate,
 */
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_chrom))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_chrom); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_start))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_start); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_start, __pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_end))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_end); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_end, __pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3711
 *         it = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,
 *                                        chrom=chrom, start=start, end=end,
 *                                        one_based=one_based,             # <<<<<<<<<<<<<<
 *                                        truncate=truncate,
 *                                        max_depth=max_depth, **kwargs)
 */
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_one_based))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_one_based); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_one_based, __pyx_v_one_based) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3712
 *                                        chrom=chrom, start=start, end=end,
 *                                        one_based=one_based,
 *                                        truncate=truncate,             # <<<<<<<<<<<<<<
 *                                        max_depth=max_depth, **kwargs)
 *     else:
 */
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_truncate))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_truncate); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_truncate, __pyx_v_truncate) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3713
 *                                        one_based=one_based,
 *                                        truncate=truncate,
 *                                        max_depth=max_depth, **kwargs)             # <<<<<<<<<<<<<<
 *     else:
 *         its = list()
 */
    if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_max_depth))) {
      __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_max_depth); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_max_depth, __pyx_v_max_depth) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3709
 * 
 *     if chrom is not None:
 *         it = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,             # <<<<<<<<<<<<<<
 *                                        chrom=chrom, start=start, end=end,
 *                                        one_based=one_based,
 */
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_it = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysamstats.pyx":3715
 *                                        max_depth=max_depth, **kwargs)
 *     else:
 *         its = list()             # <<<<<<<<<<<<<<
 *         for chrom in alignmentfile.references:
 *             itc = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,
 */
    __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_v_its = ((PyObject*)__pyx_t_6);
    __pyx_t_6 = 0;

    /* "pysamstats.pyx":3716
 *     else:
 *         its = list()
 *         for chrom in alignmentfile.references:             # <<<<<<<<<<<<<<
 *             itc = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,
 *                                             chrom=chrom, start=None,
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignmentfile, __pyx_n_s_references); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
      __pyx_t_5 = __pyx_t_6; __Pyx_INCREF(__pyx_t_5); __pyx_t_7 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_8 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_5))) {
          if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_5)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_8(__pyx_t_5);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_DECREF_SET(__pyx_v_chrom, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "pysamstats.pyx":3717
 *         its = list()
 *         for chrom in alignmentfile.references:
 *             itc = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,             # <<<<<<<<<<<<<<
 *                                             chrom=chrom, start=None,
 *                                             end=None,
 */
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_pileup_padded_chrom); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_v_frec);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_frec);
      __Pyx_GIVEREF(__pyx_v_frec);
      __Pyx_INCREF(__pyx_v_fpad);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_fpad);
      __Pyx_GIVEREF(__pyx_v_fpad);
      __Pyx_INCREF(__pyx_v_alignmentfile);
      PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_alignmentfile);
      __Pyx_GIVEREF(__pyx_v_alignmentfile);

      /* "pysamstats.pyx":3723
 *                                             truncate=truncate,
 *                                             max_depth=max_depth,
 *                                             **kwargs)             # <<<<<<<<<<<<<<
 *             its.append(itc)
 *         it = _itertools.chain(*its)
 */
      __pyx_t_3 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);

      /* "pysamstats.pyx":3717
 *         its = list()
 *         for chrom in alignmentfile.references:
 *             itc = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,             # <<<<<<<<<<<<<<
 *                                             chrom=chrom, start=None,
 *                                             end=None,
 */
      if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_fafile))) {
        __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_fafile); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3718
 *         for chrom in alignmentfile.references:
 *             itc = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,
 *                                             chrom=chrom, start=None,             # <<<<<<<<<<<<<<
 *                                             end=None,
 *                                             one_based=one_based,
 */
      if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_chrom))) {
        __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_chrom); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_start))) {
        __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_start); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_start, Py_None) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3719
 *             itc = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,
 *                                             chrom=chrom, start=None,
 *                                             end=None,             # <<<<<<<<<<<<<<
 *                                             one_based=one_based,
 *                                             truncate=truncate,
 */
      if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_end))) {
        __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_end); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_end, Py_None) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3720
 *                                             chrom=chrom, start=None,
 *                                             end=None,
 *                                             one_based=one_based,             # <<<<<<<<<<<<<<
 *                                             truncate=truncate,
 *                                             max_depth=max_depth,
 */
      if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_one_based))) {
        __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_one_based); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_one_based, __pyx_v_one_based) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3721
 *                                             end=None,
 *                                             one_based=one_based,
 *                                             truncate=truncate,             # <<<<<<<<<<<<<<
 *                                             max_depth=max_depth,
 *                                             **kwargs)
 */
      if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_truncate))) {
        __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_truncate); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_truncate, __pyx_v_truncate) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3722
 *                                             one_based=one_based,
 *                                             truncate=truncate,
 *                                             max_depth=max_depth,             # <<<<<<<<<<<<<<
 *                                             **kwargs)
 *             its.append(itc)
 */
      if (unlikely(PyDict_GetItem(__pyx_t_3, __pyx_n_s_max_depth))) {
        __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_max_depth); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_max_depth, __pyx_v_max_depth) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3717
 *         its = list()
 *         for chrom in alignmentfile.references:
 *             itc = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,             # <<<<<<<<<<<<<<
 *                                             chrom=chrom, start=None,
 *                                             end=None,
 */
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_v_itc, __pyx_t_9);
      __pyx_t_9 = 0;

      /* "pysamstats.pyx":3724
 *                                             max_depth=max_depth,
 *                                             **kwargs)
 *             its.append(itc)             # <<<<<<<<<<<<<<
 *         it = _itertools.chain(*its)
 *     return it
 */
      __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_its, __pyx_v_itc); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3716
 *     else:
 *         its = list()
 *         for chrom in alignmentfile.references:             # <<<<<<<<<<<<<<
 *             itc = _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile=fafile,
 *                                             chrom=chrom, start=None,
 */
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pysamstats.pyx":3725
 *                                             **kwargs)
 *             its.append(itc)
 *         it = _itertools.chain(*its)             # <<<<<<<<<<<<<<
 *     return it
 * 
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_itertools); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_chain); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PySequence_Tuple(__pyx_v_its); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_it = __pyx_t_3;
    __pyx_t_3 = 0;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":3726
 *             its.append(itc)
 *         it = _itertools.chain(*its)
 *     return it             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_it);
  __pyx_r = __pyx_v_it;
  goto __pyx_L0;

  /* "pysamstats.pyx":3704
 * 
 * 
 * def _iter_pileup_padded(frec, fpad, alignmentfile, fafile=None, chrom=None,             # <<<<<<<<<<<<<<
 *                         start=None, end=None, one_based=False,
 *                         truncate=False, max_depth=8000, **kwargs):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysamstats._iter_pileup_padded", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_it);
  __Pyx_XDECREF(__pyx_v_its);
  __Pyx_XDECREF(__pyx_v_itc);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_145generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysamstats.pyx":3729
 * 
 * 
 * def _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile, chrom, start=None,             # <<<<<<<<<<<<<<
 *                               end=None, one_based=False, truncate=False,
 *                               max_depth=8000, **kwargs):
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_144_iter_pileup_padded_chrom(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_143_iter_pileup_padded_chrom[] = "_iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile, chrom, start=None, end=None, one_based=False, truncate=False, max_depth=8000, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_144_iter_pileup_padded_chrom = {"_iter_pileup_padded_chrom", (PyCFunction)__pyx_pw_10pysamstats_144_iter_pileup_padded_chrom, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_143_iter_pileup_padded_chrom};
static PyObject *__pyx_pw_10pysamstats_144_iter_pileup_padded_chrom(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_frec = 0;
  PyObject *__pyx_v_fpad = 0;
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__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_truncate = 0;
  PyObject *__pyx_v_max_depth = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_iter_pileup_padded_chrom (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_frec,&__pyx_n_s_fpad,&__pyx_n_s_alignmentfile,&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_one_based,&__pyx_n_s_truncate,&__pyx_n_s_max_depth,0};
    PyObject* values[10] = {0,0,0,0,0,0,0,0,0,0};
    values[5] = ((PyObject *)Py_None);

    /* "pysamstats.pyx":3730
 * 
 * def _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile, chrom, start=None,
 *                               end=None, one_based=False, truncate=False,             # <<<<<<<<<<<<<<
 *                               max_depth=8000, **kwargs):
 *     cdef PileupColumn col
 */
    values[6] = ((PyObject *)Py_None);
    values[7] = ((PyObject *)Py_False);
    values[8] = ((PyObject *)Py_False);
    values[9] = ((PyObject *)__pyx_int_8000);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        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_frec)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fpad)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_pileup_padded_chrom", 0, 5, 10, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_pileup_padded_chrom", 0, 5, 10, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fafile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_pileup_padded_chrom", 0, 5, 10, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  4:
        if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_pileup_padded_chrom", 0, 5, 10, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_one_based);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_truncate);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_depth);
          if (value) { values[9] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "_iter_pileup_padded_chrom") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        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);
        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_frec = values[0];
    __pyx_v_fpad = values[1];
    __pyx_v_alignmentfile = values[2];
    __pyx_v_fafile = values[3];
    __pyx_v_chrom = values[4];
    __pyx_v_start = values[5];
    __pyx_v_end = values[6];
    __pyx_v_one_based = values[7];
    __pyx_v_truncate = values[8];
    __pyx_v_max_depth = values[9];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_iter_pileup_padded_chrom", 0, 5, 10, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats._iter_pileup_padded_chrom", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_143_iter_pileup_padded_chrom(__pyx_self, __pyx_v_frec, __pyx_v_fpad, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_truncate, __pyx_v_max_depth, __pyx_v_kwargs);

  /* "pysamstats.pyx":3729
 * 
 * 
 * def _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile, chrom, start=None,             # <<<<<<<<<<<<<<
 *                               end=None, one_based=False, truncate=False,
 *                               max_depth=8000, **kwargs):
 */

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

static PyObject *__pyx_pf_10pysamstats_143_iter_pileup_padded_chrom(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_frec, PyObject *__pyx_v_fpad, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_truncate, PyObject *__pyx_v_max_depth, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_iter_pileup_padded_chrom", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom *)__pyx_tp_new_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom(__pyx_ptype_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_frec = __pyx_v_frec;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_frec);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_frec);
  __pyx_cur_scope->__pyx_v_fpad = __pyx_v_fpad;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fpad);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fpad);
  __pyx_cur_scope->__pyx_v_alignmentfile = __pyx_v_alignmentfile;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_alignmentfile);
  __pyx_cur_scope->__pyx_v_fafile = __pyx_v_fafile;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fafile);
  __Pyx_GIVEREF(__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_truncate = __pyx_v_truncate;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_truncate);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_truncate);
  __pyx_cur_scope->__pyx_v_max_depth = __pyx_v_max_depth;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_depth);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_depth);
  __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_145generator1, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter_pileup_padded_chrom, __pyx_n_s_iter_pileup_padded_chrom); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

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

static PyObject *__pyx_gb_10pysamstats_145generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  PyObject *(*__pyx_t_9)(PyObject *);
  PyObject *__pyx_t_10 = NULL;
  Py_ssize_t __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L10_resume_from_yield;
    case 2: goto __pyx_L11_resume_from_yield;
    case 3: goto __pyx_L14_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 = 3729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3734
 *     cdef PileupColumn col
 *     cdef int curpos
 *     assert chrom is not None, 'chromosome is None'             # <<<<<<<<<<<<<<
 *     start, end = _normalise_coords(alignmentfile, chrom, start, end, one_based)
 *     it = alignmentfile.pileup(reference=chrom, start=start, end=end,
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    __pyx_t_1 = (__pyx_cur_scope->__pyx_v_chrom != Py_None);
    if (unlikely(!(__pyx_t_1 != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_chromosome_is_None);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif

  /* "pysamstats.pyx":3735
 *     cdef int curpos
 *     assert chrom is not None, 'chromosome is None'
 *     start, end = _normalise_coords(alignmentfile, chrom, start, end, one_based)             # <<<<<<<<<<<<<<
 *     it = alignmentfile.pileup(reference=chrom, start=start, end=end,
 *                         truncate=truncate, max_depth=max_depth)
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_normalise_coords); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  __pyx_t_6 = PyTuple_New(5+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (__pyx_t_4) {
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
  }
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_cur_scope->__pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_alignmentfile);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __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_6, 2+__pyx_t_5, __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_6, 3+__pyx_t_5, __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_6, 4+__pyx_t_5, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
    PyObject* sequence = __pyx_t_2;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_6);
    #else
    __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    #endif
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_3 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    index = 1; __pyx_t_6 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_6);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = 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_7 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_start, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_end, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  __pyx_t_6 = 0;

  /* "pysamstats.pyx":3736
 *     assert chrom is not None, 'chromosome is None'
 *     start, end = _normalise_coords(alignmentfile, chrom, start, end, one_based)
 *     it = alignmentfile.pileup(reference=chrom, start=start, end=end,             # <<<<<<<<<<<<<<
 *                         truncate=truncate, max_depth=max_depth)
 *     curpos = start
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_alignmentfile, __pyx_n_s_pileup); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reference, __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_start, __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_end, __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3737
 *     start, end = _normalise_coords(alignmentfile, chrom, start, end, one_based)
 *     it = alignmentfile.pileup(reference=chrom, start=start, end=end,
 *                         truncate=truncate, max_depth=max_depth)             # <<<<<<<<<<<<<<
 *     curpos = start
 *     for col in it:
 */
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_truncate, __pyx_cur_scope->__pyx_v_truncate) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_max_depth, __pyx_cur_scope->__pyx_v_max_depth) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3736
 *     assert chrom is not None, 'chromosome is None'
 *     start, end = _normalise_coords(alignmentfile, chrom, start, end, one_based)
 *     it = alignmentfile.pileup(reference=chrom, start=start, end=end,             # <<<<<<<<<<<<<<
 *                         truncate=truncate, max_depth=max_depth)
 *     curpos = start
 */
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_cur_scope->__pyx_v_it = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":3738
 *     it = alignmentfile.pileup(reference=chrom, start=start, end=end,
 *                         truncate=truncate, max_depth=max_depth)
 *     curpos = start             # <<<<<<<<<<<<<<
 *     for col in it:
 *         while curpos < col.pos:
 */
  __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_cur_scope->__pyx_v_start); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_cur_scope->__pyx_v_curpos = __pyx_t_8;

  /* "pysamstats.pyx":3739
 *                         truncate=truncate, max_depth=max_depth)
 *     curpos = start
 *     for col in it:             # <<<<<<<<<<<<<<
 *         while curpos < col.pos:
 *             yield fpad(fafile, chrom, curpos, one_based)
 */
  if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_it)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_it)) {
    __pyx_t_3 = __pyx_cur_scope->__pyx_v_it; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
    __pyx_t_9 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_it); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_9 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_9)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_6 = __pyx_t_9(__pyx_t_3);
      if (unlikely(!__pyx_t_6)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_6);
    }
    if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5pysam_14calignmentfile_PileupColumn))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_col));
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_col, ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_t_6));
    __Pyx_GIVEREF(__pyx_t_6);
    __pyx_t_6 = 0;

    /* "pysamstats.pyx":3740
 *     curpos = start
 *     for col in it:
 *         while curpos < col.pos:             # <<<<<<<<<<<<<<
 *             yield fpad(fafile, chrom, curpos, one_based)
 *             curpos += 1
 */
    while (1) {
      __pyx_t_1 = ((__pyx_cur_scope->__pyx_v_curpos < __pyx_cur_scope->__pyx_v_col->pos) != 0);
      if (!__pyx_t_1) break;

      /* "pysamstats.pyx":3741
 *     for col in it:
 *         while curpos < col.pos:
 *             yield fpad(fafile, chrom, curpos, one_based)             # <<<<<<<<<<<<<<
 *             curpos += 1
 *         yield frec(alignmentfile, fafile, col, one_based)
 */
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_curpos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fpad);
      __pyx_t_4 = __pyx_cur_scope->__pyx_v_fpad; __pyx_t_10 = NULL;
      __pyx_t_11 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
          __pyx_t_11 = 1;
        }
      }
      __pyx_t_12 = PyTuple_New(4+__pyx_t_11); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_12);
      if (__pyx_t_10) {
        PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); __pyx_t_10 = NULL;
      }
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fafile);
      PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_cur_scope->__pyx_v_fafile);
      __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fafile);
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
      PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_cur_scope->__pyx_v_chrom);
      __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
      PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_11, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
      PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_11, __pyx_cur_scope->__pyx_v_one_based);
      __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
      __pyx_t_2 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_r = __pyx_t_6;
      __pyx_t_6 = 0;
      __Pyx_XGIVEREF(__pyx_t_3);
      __pyx_cur_scope->__pyx_t_0 = __pyx_t_3;
      __pyx_cur_scope->__pyx_t_1 = __pyx_t_5;
      __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_L10_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_5 = __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 = 3741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3742
 *         while curpos < col.pos:
 *             yield fpad(fafile, chrom, curpos, one_based)
 *             curpos += 1             # <<<<<<<<<<<<<<
 *         yield frec(alignmentfile, fafile, col, one_based)
 *         curpos = col.pos + 1
 */
      __pyx_cur_scope->__pyx_v_curpos = (__pyx_cur_scope->__pyx_v_curpos + 1);
    }

    /* "pysamstats.pyx":3743
 *             yield fpad(fafile, chrom, curpos, one_based)
 *             curpos += 1
 *         yield frec(alignmentfile, fafile, col, one_based)             # <<<<<<<<<<<<<<
 *         curpos = col.pos + 1
 *     while curpos < end:
 */
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_frec);
    __pyx_t_4 = __pyx_cur_scope->__pyx_v_frec; __pyx_t_12 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_12)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_12);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_11 = 1;
      }
    }
    __pyx_t_2 = PyTuple_New(4+__pyx_t_11); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if (__pyx_t_12) {
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_12); __Pyx_GIVEREF(__pyx_t_12); __pyx_t_12 = NULL;
    }
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_alignmentfile);
    PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_cur_scope->__pyx_v_alignmentfile);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_alignmentfile);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fafile);
    PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_cur_scope->__pyx_v_fafile);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fafile);
    __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_col));
    PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_11, ((PyObject *)__pyx_cur_scope->__pyx_v_col));
    __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_col));
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
    PyTuple_SET_ITEM(__pyx_t_2, 3+__pyx_t_11, __pyx_cur_scope->__pyx_v_one_based);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    __Pyx_XGIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_3;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_5;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_9;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 2;
    return __pyx_r;
    __pyx_L11_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_5 = __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 = 3743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3744
 *             curpos += 1
 *         yield frec(alignmentfile, fafile, col, one_based)
 *         curpos = col.pos + 1             # <<<<<<<<<<<<<<
 *     while curpos < end:
 *         yield fpad(fafile, chrom, curpos, one_based)
 */
    __pyx_cur_scope->__pyx_v_curpos = (__pyx_cur_scope->__pyx_v_col->pos + 1);

    /* "pysamstats.pyx":3739
 *                         truncate=truncate, max_depth=max_depth)
 *     curpos = start
 *     for col in it:             # <<<<<<<<<<<<<<
 *         while curpos < col.pos:
 *             yield fpad(fafile, chrom, curpos, one_based)
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":3745
 *         yield frec(alignmentfile, fafile, col, one_based)
 *         curpos = col.pos + 1
 *     while curpos < end:             # <<<<<<<<<<<<<<
 *         yield fpad(fafile, chrom, curpos, one_based)
 *         curpos += 1
 */
  while (1) {
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_curpos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_3, __pyx_cur_scope->__pyx_v_end, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!__pyx_t_1) break;

    /* "pysamstats.pyx":3746
 *         curpos = col.pos + 1
 *     while curpos < end:
 *         yield fpad(fafile, chrom, curpos, one_based)             # <<<<<<<<<<<<<<
 *         curpos += 1
 * 
 */
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_curpos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fpad);
    __pyx_t_4 = __pyx_cur_scope->__pyx_v_fpad; __pyx_t_2 = NULL;
    __pyx_t_5 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_5 = 1;
      }
    }
    __pyx_t_12 = PyTuple_New(4+__pyx_t_5); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    if (__pyx_t_2) {
      PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = NULL;
    }
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fafile);
    PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_5, __pyx_cur_scope->__pyx_v_fafile);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fafile);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
    PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_5, __pyx_cur_scope->__pyx_v_chrom);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
    PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_5, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
    PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_5, __pyx_cur_scope->__pyx_v_one_based);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
    __pyx_t_3 = 0;
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 3;
    return __pyx_r;
    __pyx_L14_resume_from_yield:;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3747
 *     while curpos < end:
 *         yield fpad(fafile, chrom, curpos, one_based)
 *         curpos += 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_cur_scope->__pyx_v_curpos = (__pyx_cur_scope->__pyx_v_curpos + 1);
  }

  /* "pysamstats.pyx":3729
 * 
 * 
 * def _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile, chrom, start=None,             # <<<<<<<<<<<<<<
 *                               end=None, one_based=False, truncate=False,
 *                               max_depth=8000, **kwargs):
 */

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("_iter_pileup_padded_chrom", __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":3750
 * 
 * 
 * def _iter_binned(stat, alignmentfile, fafile=None, chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                  one_based=False, window_size=300, window_offset=None,
 *                  **kwargs):
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_147_iter_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_146_iter_binned[] = "_iter_binned(stat, alignmentfile, fafile=None, chrom=None, start=None, end=None, one_based=False, window_size=300, window_offset=None, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_147_iter_binned = {"_iter_binned", (PyCFunction)__pyx_pw_10pysamstats_147_iter_binned, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_146_iter_binned};
static PyObject *__pyx_pw_10pysamstats_147_iter_binned(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_stat = 0;
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__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_window_size = 0;
  PyObject *__pyx_v_window_offset = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_iter_binned (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_stat,&__pyx_n_s_alignmentfile,&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_one_based,&__pyx_n_s_window_size,&__pyx_n_s_window_offset,0};
    PyObject* values[9] = {0,0,0,0,0,0,0,0,0};
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    values[5] = ((PyObject *)Py_None);

    /* "pysamstats.pyx":3751
 * 
 * def _iter_binned(stat, alignmentfile, fafile=None, chrom=None, start=None, end=None,
 *                  one_based=False, window_size=300, window_offset=None,             # <<<<<<<<<<<<<<
 *                  **kwargs):
 * 
 */
    values[6] = ((PyObject *)Py_False);
    values[7] = ((PyObject *)__pyx_int_300);
    values[8] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        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_stat)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_binned", 0, 2, 9, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3750; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fafile);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_one_based);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_window_size);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_window_offset);
          if (value) { values[8] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "_iter_binned") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3750; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        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);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_stat = values[0];
    __pyx_v_alignmentfile = values[1];
    __pyx_v_fafile = values[2];
    __pyx_v_chrom = values[3];
    __pyx_v_start = values[4];
    __pyx_v_end = values[5];
    __pyx_v_one_based = values[6];
    __pyx_v_window_size = values[7];
    __pyx_v_window_offset = values[8];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_iter_binned", 0, 2, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3750; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats._iter_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_146_iter_binned(__pyx_self, __pyx_v_stat, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_window_size, __pyx_v_window_offset, __pyx_v_kwargs);

  /* "pysamstats.pyx":3750
 * 
 * 
 * def _iter_binned(stat, alignmentfile, fafile=None, chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                  one_based=False, window_size=300, window_offset=None,
 *                  **kwargs):
 */

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

static PyObject *__pyx_pf_10pysamstats_146_iter_binned(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stat, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_window_size, PyObject *__pyx_v_window_offset, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_its = NULL;
  PyObject *__pyx_v_itc = NULL;
  PyObject *__pyx_v_it = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_iter_binned", 0);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  __Pyx_INCREF(__pyx_v_fafile);
  __Pyx_INCREF(__pyx_v_chrom);
  __Pyx_INCREF(__pyx_v_window_offset);

  /* "pysamstats.pyx":3754
 *                  **kwargs):
 * 
 *     if isinstance(alignmentfile, _string_types):             # <<<<<<<<<<<<<<
 *         alignmentfile = AlignmentFile(alignmentfile)
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_string_types); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_IsInstance(__pyx_v_alignmentfile, __pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "pysamstats.pyx":3755
 * 
 *     if isinstance(alignmentfile, _string_types):
 *         alignmentfile = AlignmentFile(alignmentfile)             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(fafile, _string_types):
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_alignmentfile);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_alignmentfile);
    __Pyx_GIVEREF(__pyx_v_alignmentfile);
    __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_AlignmentFile)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_alignmentfile, __pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":3757
 *         alignmentfile = AlignmentFile(alignmentfile)
 * 
 *     if isinstance(fafile, _string_types):             # <<<<<<<<<<<<<<
 *         fafile = FastaFile(fafile)
 * 
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_string_types); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_IsInstance(__pyx_v_fafile, __pyx_t_4); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3758
 * 
 *     if isinstance(fafile, _string_types):
 *         fafile = FastaFile(fafile)             # <<<<<<<<<<<<<<
 * 
 *     if window_offset is None:
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_fafile);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_fafile);
    __Pyx_GIVEREF(__pyx_v_fafile);
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6cfaidx_FastaFile)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_fafile, __pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "pysamstats.pyx":3760
 *         fafile = FastaFile(fafile)
 * 
 *     if window_offset is None:             # <<<<<<<<<<<<<<
 *         window_offset = window_size / 2
 * 
 */
  __pyx_t_2 = (__pyx_v_window_offset == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "pysamstats.pyx":3761
 * 
 *     if window_offset is None:
 *         window_offset = window_size / 2             # <<<<<<<<<<<<<<
 * 
 *     if chrom is None:
 */
    __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_window_size, __pyx_int_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_window_offset, __pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "pysamstats.pyx":3763
 *         window_offset = window_size / 2
 * 
 *     if chrom is None:             # <<<<<<<<<<<<<<
 *         its = list()
 *         for chrom in alignmentfile.references:
 */
  __pyx_t_3 = (__pyx_v_chrom == Py_None);
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3764
 * 
 *     if chrom is None:
 *         its = list()             # <<<<<<<<<<<<<<
 *         for chrom in alignmentfile.references:
 *             itc = _iter_binned_chrom(stat, alignmentfile=alignmentfile,
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_its = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysamstats.pyx":3765
 *     if chrom is None:
 *         its = list()
 *         for chrom in alignmentfile.references:             # <<<<<<<<<<<<<<
 *             itc = _iter_binned_chrom(stat, alignmentfile=alignmentfile,
 *                                      fafile=fafile, chrom=chrom, start=None,
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignmentfile, __pyx_n_s_references); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_6)) {
        if (likely(PyList_CheckExact(__pyx_t_4))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_6(__pyx_t_4);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_DECREF_SET(__pyx_v_chrom, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysamstats.pyx":3766
 *         its = list()
 *         for chrom in alignmentfile.references:
 *             itc = _iter_binned_chrom(stat, alignmentfile=alignmentfile,             # <<<<<<<<<<<<<<
 *                                      fafile=fafile, chrom=chrom, start=None,
 *                                      end=None, one_based=one_based,
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_binned_chrom); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_v_stat);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_stat);
      __Pyx_GIVEREF(__pyx_v_stat);
      __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_alignmentfile, __pyx_v_alignmentfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3767
 *         for chrom in alignmentfile.references:
 *             itc = _iter_binned_chrom(stat, alignmentfile=alignmentfile,
 *                                      fafile=fafile, chrom=chrom, start=None,             # <<<<<<<<<<<<<<
 *                                      end=None, one_based=one_based,
 *                                      window_size=window_size,
 */
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_start, Py_None) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3768
 *             itc = _iter_binned_chrom(stat, alignmentfile=alignmentfile,
 *                                      fafile=fafile, chrom=chrom, start=None,
 *                                      end=None, one_based=one_based,             # <<<<<<<<<<<<<<
 *                                      window_size=window_size,
 *                                      window_offset=window_offset)
 */
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_end, Py_None) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_one_based, __pyx_v_one_based) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3769
 *                                      fafile=fafile, chrom=chrom, start=None,
 *                                      end=None, one_based=one_based,
 *                                      window_size=window_size,             # <<<<<<<<<<<<<<
 *                                      window_offset=window_offset)
 *             its.append(itc)
 */
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_window_size, __pyx_v_window_size) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3770
 *                                      end=None, one_based=one_based,
 *                                      window_size=window_size,
 *                                      window_offset=window_offset)             # <<<<<<<<<<<<<<
 *             its.append(itc)
 *         it = _itertools.chain(*its)
 */
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_window_offset, __pyx_v_window_offset) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3766
 *         its = list()
 *         for chrom in alignmentfile.references:
 *             itc = _iter_binned_chrom(stat, alignmentfile=alignmentfile,             # <<<<<<<<<<<<<<
 *                                      fafile=fafile, chrom=chrom, start=None,
 *                                      end=None, one_based=one_based,
 */
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF_SET(__pyx_v_itc, __pyx_t_9);
      __pyx_t_9 = 0;

      /* "pysamstats.pyx":3771
 *                                      window_size=window_size,
 *                                      window_offset=window_offset)
 *             its.append(itc)             # <<<<<<<<<<<<<<
 *         it = _itertools.chain(*its)
 * 
 */
      __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_its, __pyx_v_itc); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3765
 *     if chrom is None:
 *         its = list()
 *         for chrom in alignmentfile.references:             # <<<<<<<<<<<<<<
 *             itc = _iter_binned_chrom(stat, alignmentfile=alignmentfile,
 *                                      fafile=fafile, chrom=chrom, start=None,
 */
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysamstats.pyx":3772
 *                                      window_offset=window_offset)
 *             its.append(itc)
 *         it = _itertools.chain(*its)             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_itertools); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_chain); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PySequence_Tuple(__pyx_v_its); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_4, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_it = __pyx_t_8;
    __pyx_t_8 = 0;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "pysamstats.pyx":3775
 * 
 *     else:
 *         it = _iter_binned_chrom(stat, alignmentfile=alignmentfile, fafile=fafile,             # <<<<<<<<<<<<<<
 *                                 chrom=chrom, start=start, end=end,
 *                                 one_based=one_based, window_size=window_size,
 */
    __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_iter_binned_chrom); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_stat);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_stat);
    __Pyx_GIVEREF(__pyx_v_stat);
    __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_alignmentfile, __pyx_v_alignmentfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_fafile, __pyx_v_fafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3776
 *     else:
 *         it = _iter_binned_chrom(stat, alignmentfile=alignmentfile, fafile=fafile,
 *                                 chrom=chrom, start=start, end=end,             # <<<<<<<<<<<<<<
 *                                 one_based=one_based, window_size=window_size,
 *                                 window_offset=window_offset)
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_chrom, __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_start, __pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_end, __pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3777
 *         it = _iter_binned_chrom(stat, alignmentfile=alignmentfile, fafile=fafile,
 *                                 chrom=chrom, start=start, end=end,
 *                                 one_based=one_based, window_size=window_size,             # <<<<<<<<<<<<<<
 *                                 window_offset=window_offset)
 * 
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_one_based, __pyx_v_one_based) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_window_size, __pyx_v_window_size) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3778
 *                                 chrom=chrom, start=start, end=end,
 *                                 one_based=one_based, window_size=window_size,
 *                                 window_offset=window_offset)             # <<<<<<<<<<<<<<
 * 
 *     return it
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_window_offset, __pyx_v_window_offset) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":3775
 * 
 *     else:
 *         it = _iter_binned_chrom(stat, alignmentfile=alignmentfile, fafile=fafile,             # <<<<<<<<<<<<<<
 *                                 chrom=chrom, start=start, end=end,
 *                                 one_based=one_based, window_size=window_size,
 */
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_4, __pyx_t_9); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_it = __pyx_t_7;
    __pyx_t_7 = 0;
  }
  __pyx_L6:;

  /* "pysamstats.pyx":3780
 *                                 window_offset=window_offset)
 * 
 *     return it             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_it);
  __pyx_r = __pyx_v_it;
  goto __pyx_L0;

  /* "pysamstats.pyx":3750
 * 
 * 
 * def _iter_binned(stat, alignmentfile, fafile=None, chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                  one_based=False, window_size=300, window_offset=None,
 *                  **kwargs):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysamstats._iter_binned", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_its);
  __Pyx_XDECREF(__pyx_v_itc);
  __Pyx_XDECREF(__pyx_v_it);
  __Pyx_XDECREF(__pyx_v_alignmentfile);
  __Pyx_XDECREF(__pyx_v_fafile);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_window_offset);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_150generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysamstats.pyx":3783
 * 
 * 
 * def _iter_binned_chrom(_StatBinned stat, AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                        chrom, start=None, end=None, one_based=False,
 *                        int window_size=300, int window_offset=150, **kwargs):
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_149_iter_binned_chrom(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_148_iter_binned_chrom[] = "_iter_binned_chrom(_StatBinned stat, AlignmentFile alignmentfile, FastaFile fafile, chrom, start=None, end=None, one_based=False, int window_size=300, int window_offset=150, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_149_iter_binned_chrom = {"_iter_binned_chrom", (PyCFunction)__pyx_pw_10pysamstats_149_iter_binned_chrom, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_148_iter_binned_chrom};
static PyObject *__pyx_pw_10pysamstats_149_iter_binned_chrom(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_10pysamstats__StatBinned *__pyx_v_stat = 0;
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  struct __pyx_obj_5pysam_6cfaidx_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;
  int __pyx_v_window_size;
  int __pyx_v_window_offset;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_iter_binned_chrom (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_stat,&__pyx_n_s_alignmentfile,&__pyx_n_s_fafile,&__pyx_n_s_chrom,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_one_based,&__pyx_n_s_window_size,&__pyx_n_s_window_offset,0};
    PyObject* values[9] = {0,0,0,0,0,0,0,0,0};

    /* "pysamstats.pyx":3784
 * 
 * def _iter_binned_chrom(_StatBinned stat, AlignmentFile alignmentfile, FastaFile fafile,
 *                        chrom, start=None, end=None, one_based=False,             # <<<<<<<<<<<<<<
 *                        int window_size=300, int window_offset=150, **kwargs):
 * 
 */
    values[4] = ((PyObject *)Py_None);
    values[5] = ((PyObject *)Py_None);
    values[6] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  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_stat)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_binned_chrom", 0, 4, 9, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fafile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_binned_chrom", 0, 4, 9, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_iter_binned_chrom", 0, 4, 9, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_one_based);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_window_size);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_window_offset);
          if (value) { values[8] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "_iter_binned_chrom") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        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_stat = ((struct __pyx_obj_10pysamstats__StatBinned *)values[0]);
    __pyx_v_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[1]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)values[2]);
    __pyx_v_chrom = values[3];
    __pyx_v_start = values[4];
    __pyx_v_end = values[5];
    __pyx_v_one_based = values[6];
    if (values[7]) {
      __pyx_v_window_size = __Pyx_PyInt_As_int(values[7]); if (unlikely((__pyx_v_window_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3785; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_window_size = ((int)300);
    }
    if (values[8]) {
      __pyx_v_window_offset = __Pyx_PyInt_As_int(values[8]); if (unlikely((__pyx_v_window_offset == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3785; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_window_offset = ((int)150);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_iter_binned_chrom", 0, 4, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats._iter_binned_chrom", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_stat), __pyx_ptype_10pysamstats__StatBinned, 1, "stat", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_6cfaidx_FastaFile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_148_iter_binned_chrom(__pyx_self, __pyx_v_stat, __pyx_v_alignmentfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_window_size, __pyx_v_window_offset, __pyx_v_kwargs);

  /* "pysamstats.pyx":3783
 * 
 * 
 * def _iter_binned_chrom(_StatBinned stat, AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                        chrom, start=None, end=None, one_based=False,
 *                        int window_size=300, int window_offset=150, **kwargs):
 */

  /* function exit code */
  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_148_iter_binned_chrom(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_10pysamstats__StatBinned *__pyx_v_stat, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, int __pyx_v_window_size, int __pyx_v_window_offset, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_iter_binned_chrom", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom *)__pyx_tp_new_10pysamstats___pyx_scope_struct_3__iter_binned_chrom(__pyx_ptype_10pysamstats___pyx_scope_struct_3__iter_binned_chrom, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_stat = __pyx_v_stat;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_stat);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_stat);
  __pyx_cur_scope->__pyx_v_alignmentfile = __pyx_v_alignmentfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_alignmentfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_alignmentfile);
  __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_window_size = __pyx_v_window_size;
  __pyx_cur_scope->__pyx_v_window_offset = __pyx_v_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_150generator2, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter_binned_chrom, __pyx_n_s_iter_binned_chrom); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

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

static PyObject *__pyx_gb_10pysamstats_150generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  bam1_t *__pyx_t_14;
  int __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L13_resume_from_yield;
    case 2: goto __pyx_L15_resume_from_yield;
    case 3: goto __pyx_L20_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 = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3789
 *     # setup
 * 
 *     assert chrom is not None, 'chromosome is None'             # <<<<<<<<<<<<<<
 *     start, end = _normalise_coords(alignmentfile, chrom, start, end, one_based)
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    __pyx_t_1 = (__pyx_cur_scope->__pyx_v_chrom != Py_None);
    if (unlikely(!(__pyx_t_1 != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_chromosome_is_None);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif

  /* "pysamstats.pyx":3790
 * 
 *     assert chrom is not None, 'chromosome is None'
 *     start, end = _normalise_coords(alignmentfile, chrom, start, end, one_based)             # <<<<<<<<<<<<<<
 * 
 *     cdef int rtid, rstart, rend, has_coord, bin_start, bin_end
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_normalise_coords); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  __pyx_t_6 = PyTuple_New(5+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (__pyx_t_4) {
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
  }
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_alignmentfile));
  PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, ((PyObject *)__pyx_cur_scope->__pyx_v_alignmentfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_alignmentfile));
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __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_6, 2+__pyx_t_5, __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_6, 3+__pyx_t_5, __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_6, 4+__pyx_t_5, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
    PyObject* sequence = __pyx_t_2;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_6);
    #else
    __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    #endif
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_3 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    index = 1; __pyx_t_6 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_6);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = 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_7 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_start, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_end, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  __pyx_t_6 = 0;

  /* "pysamstats.pyx":3794
 *     cdef int rtid, rstart, rend, has_coord, bin_start, bin_end
 *     has_coord, rtid, rstart, rend = \
 *         alignmentfile._parseRegion(chrom, start, end, None)             # <<<<<<<<<<<<<<
 * 
 *     cdef IteratorRowRegion it
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_alignmentfile), __pyx_n_s_parseRegion); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
      __pyx_t_5 = 1;
    }
  }
  __pyx_t_4 = PyTuple_New(4+__pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (__pyx_t_3) {
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
  }
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_5, __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_4, 1+__pyx_t_5, __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_4, 2+__pyx_t_5, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(Py_None);
  PyTuple_SET_ITEM(__pyx_t_4, 3+__pyx_t_5, Py_None);
  __Pyx_GIVEREF(Py_None);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3794; __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_6); __pyx_t_6 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
    PyObject* sequence = __pyx_t_2;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_8 = PyTuple_GET_ITEM(sequence, 3); 
    } else {
      __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_8 = PyList_GET_ITEM(sequence, 3); 
    }
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_8);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_6,&__pyx_t_4,&__pyx_t_3,&__pyx_t_8};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    Py_ssize_t index = -1;
    PyObject** temps[4] = {&__pyx_t_6,&__pyx_t_4,&__pyx_t_3,&__pyx_t_8};
    __pyx_t_9 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = Py_TYPE(__pyx_t_9)->tp_iternext;
    for (index=0; index < 4; index++) {
      PyObject* item = __pyx_t_7(__pyx_t_9); if (unlikely(!item)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(item);
      *(temps[index]) = item;
    }
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_9), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = NULL;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    goto __pyx_L7_unpacking_done;
    __pyx_L6_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_7 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L7_unpacking_done:;
  }

  /* "pysamstats.pyx":3793
 * 
 *     cdef int rtid, rstart, rend, has_coord, bin_start, bin_end
 *     has_coord, rtid, rstart, rend = \             # <<<<<<<<<<<<<<
 *         alignmentfile._parseRegion(chrom, start, end, None)
 * 
 */
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_cur_scope->__pyx_v_has_coord = __pyx_t_10;
  __pyx_cur_scope->__pyx_v_rtid = __pyx_t_11;
  __pyx_cur_scope->__pyx_v_rstart = __pyx_t_12;
  __pyx_cur_scope->__pyx_v_rend = __pyx_t_13;

  /* "pysamstats.pyx":3798
 *     cdef IteratorRowRegion it
 *     cdef bam1_t * b
 *     it = IteratorRowRegion(alignmentfile, rtid, rstart, rend,             # <<<<<<<<<<<<<<
 *                            multiple_iterators=False)
 *     b = it.b
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_rtid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_rstart); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_rend); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_alignmentfile));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_cur_scope->__pyx_v_alignmentfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_alignmentfile));
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_8 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysamstats.pyx":3799
 *     cdef bam1_t * b
 *     it = IteratorRowRegion(alignmentfile, rtid, rstart, rend,
 *                            multiple_iterators=False)             # <<<<<<<<<<<<<<
 *     b = it.b
 * 
 */
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, Py_False) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3798
 *     cdef IteratorRowRegion it
 *     cdef bam1_t * b
 *     it = IteratorRowRegion(alignmentfile, rtid, rstart, rend,             # <<<<<<<<<<<<<<
 *                            multiple_iterators=False)
 *     b = it.b
 */
  __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion)), __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_cur_scope->__pyx_v_it = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "pysamstats.pyx":3800
 *     it = IteratorRowRegion(alignmentfile, rtid, rstart, rend,
 *                            multiple_iterators=False)
 *     b = it.b             # <<<<<<<<<<<<<<
 * 
 *     # setup first bin
 */
  __pyx_t_14 = __pyx_cur_scope->__pyx_v_it->__pyx_base.b;
  __pyx_cur_scope->__pyx_v_b = __pyx_t_14;

  /* "pysamstats.pyx":3803
 * 
 *     # setup first bin
 *     bin_start = rstart             # <<<<<<<<<<<<<<
 *     bin_end = bin_start + window_size
 * 
 */
  __pyx_cur_scope->__pyx_v_bin_start = __pyx_cur_scope->__pyx_v_rstart;

  /* "pysamstats.pyx":3804
 *     # setup first bin
 *     bin_start = rstart
 *     bin_end = bin_start + window_size             # <<<<<<<<<<<<<<
 * 
 *     # iterate over reads
 */
  __pyx_cur_scope->__pyx_v_bin_end = (__pyx_cur_scope->__pyx_v_bin_start + __pyx_cur_scope->__pyx_v_window_size);

  /* "pysamstats.pyx":3807
 * 
 *     # iterate over reads
 *     it.cnext()             # <<<<<<<<<<<<<<
 *     while it.retval > 0:
 *         while b.core.pos > bin_end:  # end of bin
 */
  ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_cur_scope->__pyx_v_it->__pyx_vtab)->cnext(__pyx_cur_scope->__pyx_v_it);

  /* "pysamstats.pyx":3808
 *     # iterate over reads
 *     it.cnext()
 *     while it.retval > 0:             # <<<<<<<<<<<<<<
 *         while b.core.pos > bin_end:  # end of bin
 * 
 */
  while (1) {
    __pyx_t_1 = ((__pyx_cur_scope->__pyx_v_it->__pyx_base.retval > 0) != 0);
    if (!__pyx_t_1) break;

    /* "pysamstats.pyx":3809
 *     it.cnext()
 *     while it.retval > 0:
 *         while b.core.pos > bin_end:  # end of bin             # <<<<<<<<<<<<<<
 * 
 *             # yield record for bin
 */
    while (1) {
      __pyx_t_1 = ((__pyx_cur_scope->__pyx_v_b->core.pos > __pyx_cur_scope->__pyx_v_bin_end) != 0);
      if (!__pyx_t_1) break;

      /* "pysamstats.pyx":3812
 * 
 *             # yield record for bin
 *             rec = stat.rec(chrom, bin_start, bin_end, fafile)             # <<<<<<<<<<<<<<
 *             pos = bin_start + window_offset
 *             if one_based:
 */
      __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_bin_start); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_bin_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = ((struct __pyx_vtabstruct_10pysamstats__StatBinned *)__pyx_cur_scope->__pyx_v_stat->__pyx_vtab)->rec(__pyx_cur_scope->__pyx_v_stat, __pyx_cur_scope->__pyx_v_chrom, __pyx_t_8, __pyx_t_3, __pyx_cur_scope->__pyx_v_fafile); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_rec);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_rec, ((PyObject*)__pyx_t_4));
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_4 = 0;

      /* "pysamstats.pyx":3813
 *             # yield record for bin
 *             rec = stat.rec(chrom, bin_start, bin_end, fafile)
 *             pos = bin_start + window_offset             # <<<<<<<<<<<<<<
 *             if one_based:
 *                 pos += 1
 */
      __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_cur_scope->__pyx_v_bin_start + __pyx_cur_scope->__pyx_v_window_offset)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_pos);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_pos, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_4 = 0;

      /* "pysamstats.pyx":3814
 *             rec = stat.rec(chrom, bin_start, bin_end, fafile)
 *             pos = bin_start + window_offset
 *             if one_based:             # <<<<<<<<<<<<<<
 *                 pos += 1
 *             rec['chrom'] = chrom
 */
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_1) {

        /* "pysamstats.pyx":3815
 *             pos = bin_start + window_offset
 *             if one_based:
 *                 pos += 1             # <<<<<<<<<<<<<<
 *             rec['chrom'] = chrom
 *             rec['pos'] = pos
 */
        __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_cur_scope->__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_pos);
        __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_pos, __pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_4);
        __pyx_t_4 = 0;
        goto __pyx_L12;
      }
      __pyx_L12:;

      /* "pysamstats.pyx":3816
 *             if one_based:
 *                 pos += 1
 *             rec['chrom'] = chrom             # <<<<<<<<<<<<<<
 *             rec['pos'] = pos
 *             yield rec
 */
      if (unlikely(__pyx_cur_scope->__pyx_v_rec == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (unlikely(PyDict_SetItem(__pyx_cur_scope->__pyx_v_rec, __pyx_n_s_chrom, __pyx_cur_scope->__pyx_v_chrom) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3817
 *                 pos += 1
 *             rec['chrom'] = chrom
 *             rec['pos'] = pos             # <<<<<<<<<<<<<<
 *             yield rec
 * 
 */
      if (unlikely(__pyx_cur_scope->__pyx_v_rec == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (unlikely(PyDict_SetItem(__pyx_cur_scope->__pyx_v_rec, __pyx_n_s_pos, __pyx_cur_scope->__pyx_v_pos) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3818
 *             rec['chrom'] = chrom
 *             rec['pos'] = pos
 *             yield rec             # <<<<<<<<<<<<<<
 * 
 *             # start new bin
 */
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_rec);
      __pyx_r = __pyx_cur_scope->__pyx_v_rec;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      /* return from generator, yielding value */
      __pyx_generator->resume_label = 1;
      return __pyx_r;
      __pyx_L13_resume_from_yield:;
      if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3821
 * 
 *             # start new bin
 *             bin_start = bin_end             # <<<<<<<<<<<<<<
 *             bin_end = bin_start + window_size
 * 
 */
      __pyx_cur_scope->__pyx_v_bin_start = __pyx_cur_scope->__pyx_v_bin_end;

      /* "pysamstats.pyx":3822
 *             # start new bin
 *             bin_start = bin_end
 *             bin_end = bin_start + window_size             # <<<<<<<<<<<<<<
 * 
 *         # process current read
 */
      __pyx_cur_scope->__pyx_v_bin_end = (__pyx_cur_scope->__pyx_v_bin_start + __pyx_cur_scope->__pyx_v_window_size);
    }

    /* "pysamstats.pyx":3825
 * 
 *         # process current read
 *         stat.recv(b)             # <<<<<<<<<<<<<<
 * 
 *         # move iterator on
 */
    __pyx_t_4 = ((struct __pyx_vtabstruct_10pysamstats__StatBinned *)__pyx_cur_scope->__pyx_v_stat->__pyx_vtab)->recv(__pyx_cur_scope->__pyx_v_stat, __pyx_cur_scope->__pyx_v_b); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysamstats.pyx":3828
 * 
 *         # move iterator on
 *         it.cnext()             # <<<<<<<<<<<<<<
 * 
 *     # deal with last non-empty bin
 */
    ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_cur_scope->__pyx_v_it->__pyx_vtab)->cnext(__pyx_cur_scope->__pyx_v_it);
  }

  /* "pysamstats.pyx":3831
 * 
 *     # deal with last non-empty bin
 *     rec = stat.rec(chrom, bin_start, bin_end, fafile)             # <<<<<<<<<<<<<<
 *     pos = bin_start + window_offset
 *     if one_based:
 */
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_bin_start); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_bin_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = ((struct __pyx_vtabstruct_10pysamstats__StatBinned *)__pyx_cur_scope->__pyx_v_stat->__pyx_vtab)->rec(__pyx_cur_scope->__pyx_v_stat, __pyx_cur_scope->__pyx_v_chrom, __pyx_t_4, __pyx_t_3, __pyx_cur_scope->__pyx_v_fafile); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_rec);
  __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_rec, ((PyObject*)__pyx_t_8));
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_8 = 0;

  /* "pysamstats.pyx":3832
 *     # deal with last non-empty bin
 *     rec = stat.rec(chrom, bin_start, bin_end, fafile)
 *     pos = bin_start + window_offset             # <<<<<<<<<<<<<<
 *     if one_based:
 *         pos += 1
 */
  __pyx_t_8 = __Pyx_PyInt_From_int((__pyx_cur_scope->__pyx_v_bin_start + __pyx_cur_scope->__pyx_v_window_offset)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_pos);
  __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_pos, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_8 = 0;

  /* "pysamstats.pyx":3833
 *     rec = stat.rec(chrom, bin_start, bin_end, fafile)
 *     pos = bin_start + window_offset
 *     if one_based:             # <<<<<<<<<<<<<<
 *         pos += 1
 *     rec['chrom'] = chrom
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "pysamstats.pyx":3834
 *     pos = bin_start + window_offset
 *     if one_based:
 *         pos += 1             # <<<<<<<<<<<<<<
 *     rec['chrom'] = chrom
 *     rec['pos'] = pos
 */
    __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_cur_scope->__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_pos);
    __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_pos, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __pyx_t_8 = 0;
    goto __pyx_L14;
  }
  __pyx_L14:;

  /* "pysamstats.pyx":3835
 *     if one_based:
 *         pos += 1
 *     rec['chrom'] = chrom             # <<<<<<<<<<<<<<
 *     rec['pos'] = pos
 *     yield rec
 */
  if (unlikely(__pyx_cur_scope->__pyx_v_rec == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (unlikely(PyDict_SetItem(__pyx_cur_scope->__pyx_v_rec, __pyx_n_s_chrom, __pyx_cur_scope->__pyx_v_chrom) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3836
 *         pos += 1
 *     rec['chrom'] = chrom
 *     rec['pos'] = pos             # <<<<<<<<<<<<<<
 *     yield rec
 * 
 */
  if (unlikely(__pyx_cur_scope->__pyx_v_rec == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (unlikely(PyDict_SetItem(__pyx_cur_scope->__pyx_v_rec, __pyx_n_s_pos, __pyx_cur_scope->__pyx_v_pos) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3837
 *     rec['chrom'] = chrom
 *     rec['pos'] = pos
 *     yield rec             # <<<<<<<<<<<<<<
 * 
 *     # deal with empty bins up to explicit end
 */
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_rec);
  __pyx_r = __pyx_cur_scope->__pyx_v_rec;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  /* return from generator, yielding value */
  __pyx_generator->resume_label = 2;
  return __pyx_r;
  __pyx_L15_resume_from_yield:;
  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3840
 * 
 *     # deal with empty bins up to explicit end
 *     if end is not None:             # <<<<<<<<<<<<<<
 *         while bin_end < end:
 *             # start new bin
 */
  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_end != Py_None);
  __pyx_t_15 = (__pyx_t_1 != 0);
  if (__pyx_t_15) {

    /* "pysamstats.pyx":3841
 *     # deal with empty bins up to explicit end
 *     if end is not None:
 *         while bin_end < end:             # <<<<<<<<<<<<<<
 *             # start new bin
 *             bin_start = bin_end
 */
    while (1) {
      __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_bin_end); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = PyObject_RichCompare(__pyx_t_8, __pyx_cur_scope->__pyx_v_end, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_15 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!__pyx_t_15) break;

      /* "pysamstats.pyx":3843
 *         while bin_end < end:
 *             # start new bin
 *             bin_start = bin_end             # <<<<<<<<<<<<<<
 *             bin_end = bin_start + window_size
 * 
 */
      __pyx_cur_scope->__pyx_v_bin_start = __pyx_cur_scope->__pyx_v_bin_end;

      /* "pysamstats.pyx":3844
 *             # start new bin
 *             bin_start = bin_end
 *             bin_end = bin_start + window_size             # <<<<<<<<<<<<<<
 * 
 *             # yield record
 */
      __pyx_cur_scope->__pyx_v_bin_end = (__pyx_cur_scope->__pyx_v_bin_start + __pyx_cur_scope->__pyx_v_window_size);

      /* "pysamstats.pyx":3847
 * 
 *             # yield record
 *             rec = stat.rec(chrom, bin_start, bin_end, fafile)             # <<<<<<<<<<<<<<
 *             pos = bin_start + window_offset
 *             if one_based:
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_bin_start); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3847; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_bin_end); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3847; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_4 = ((struct __pyx_vtabstruct_10pysamstats__StatBinned *)__pyx_cur_scope->__pyx_v_stat->__pyx_vtab)->rec(__pyx_cur_scope->__pyx_v_stat, __pyx_cur_scope->__pyx_v_chrom, __pyx_t_3, __pyx_t_8, __pyx_cur_scope->__pyx_v_fafile); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3847; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_rec);
      __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_rec, ((PyObject*)__pyx_t_4));
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_4 = 0;

      /* "pysamstats.pyx":3848
 *             # yield record
 *             rec = stat.rec(chrom, bin_start, bin_end, fafile)
 *             pos = bin_start + window_offset             # <<<<<<<<<<<<<<
 *             if one_based:
 *                 pos += 1
 */
      __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_cur_scope->__pyx_v_bin_start + __pyx_cur_scope->__pyx_v_window_offset)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_pos);
      __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_pos, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_4 = 0;

      /* "pysamstats.pyx":3849
 *             rec = stat.rec(chrom, bin_start, bin_end, fafile)
 *             pos = bin_start + window_offset
 *             if one_based:             # <<<<<<<<<<<<<<
 *                 pos += 1
 *             rec['chrom'] = chrom
 */
      __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely(__pyx_t_15 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_15) {

        /* "pysamstats.pyx":3850
 *             pos = bin_start + window_offset
 *             if one_based:
 *                 pos += 1             # <<<<<<<<<<<<<<
 *             rec['chrom'] = chrom
 *             rec['pos'] = pos
 */
        __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_cur_scope->__pyx_v_pos, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_pos);
        __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_pos, __pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_4);
        __pyx_t_4 = 0;
        goto __pyx_L19;
      }
      __pyx_L19:;

      /* "pysamstats.pyx":3851
 *             if one_based:
 *                 pos += 1
 *             rec['chrom'] = chrom             # <<<<<<<<<<<<<<
 *             rec['pos'] = pos
 *             yield rec
 */
      if (unlikely(__pyx_cur_scope->__pyx_v_rec == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (unlikely(PyDict_SetItem(__pyx_cur_scope->__pyx_v_rec, __pyx_n_s_chrom, __pyx_cur_scope->__pyx_v_chrom) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3852
 *                 pos += 1
 *             rec['chrom'] = chrom
 *             rec['pos'] = pos             # <<<<<<<<<<<<<<
 *             yield rec
 * 
 */
      if (unlikely(__pyx_cur_scope->__pyx_v_rec == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (unlikely(PyDict_SetItem(__pyx_cur_scope->__pyx_v_rec, __pyx_n_s_pos, __pyx_cur_scope->__pyx_v_pos) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysamstats.pyx":3853
 *             rec['chrom'] = chrom
 *             rec['pos'] = pos
 *             yield rec             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_rec);
      __pyx_r = __pyx_cur_scope->__pyx_v_rec;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      /* return from generator, yielding value */
      __pyx_generator->resume_label = 3;
      return __pyx_r;
      __pyx_L20_resume_from_yield:;
      if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    goto __pyx_L16;
  }
  __pyx_L16:;

  /* "pysamstats.pyx":3783
 * 
 * 
 * def _iter_binned_chrom(_StatBinned stat, AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                        chrom, start=None, end=None, one_based=False,
 *                        int window_size=300, int window_offset=150, **kwargs):
 */

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("_iter_binned_chrom", __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":3856
 * 
 * 
 * def _normalise_coords(AlignmentFile alignmentfile, chrom, start, end, one_based):             # <<<<<<<<<<<<<<
 *     """Convert to zero-based coordinates and deal with unspecified start
 *     and/or end.
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_152_normalise_coords(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_151_normalise_coords[] = "_normalise_coords(AlignmentFile alignmentfile, chrom, start, end, one_based)\nConvert to zero-based coordinates and deal with unspecified start\n    and/or end.\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_152_normalise_coords = {"_normalise_coords", (PyCFunction)__pyx_pw_10pysamstats_152_normalise_coords, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_151_normalise_coords};
static PyObject *__pyx_pw_10pysamstats_152_normalise_coords(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_normalise_coords (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__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};
    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_alignmentfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_normalise_coords", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3856; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_normalise_coords", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3856; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_normalise_coords", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3856; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  4:
        if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_one_based)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_normalise_coords", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3856; __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 = 3856; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
    }
    __pyx_v_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)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("_normalise_coords", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3856; __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:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_151_normalise_coords(__pyx_self, __pyx_v_alignmentfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based);

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

static PyObject *__pyx_pf_10pysamstats_151_normalise_coords(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based) {
  PyObject *__pyx_v_chrlen = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  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":3862
 *     """
 * 
 *     if chrom is None:             # <<<<<<<<<<<<<<
 *         return None, None
 * 
 */
  __pyx_t_1 = (__pyx_v_chrom == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysamstats.pyx":3863
 * 
 *     if chrom is None:
 *         return None, None             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_tuple__6);
    __pyx_r = __pyx_tuple__6;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysamstats.pyx":3866
 * 
 *     else:
 *         assert chrom in alignmentfile.references, \             # <<<<<<<<<<<<<<
 *             'chromosome not in SAM references: %s' % chrom
 * 
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_references); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = (__Pyx_PySequence_Contains(__pyx_v_chrom, __pyx_t_3, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (unlikely(!(__pyx_t_2 != 0))) {

        /* "pysamstats.pyx":3867
 *     else:
 *         assert chrom in alignmentfile.references, \
 *             'chromosome not in SAM references: %s' % chrom             # <<<<<<<<<<<<<<
 * 
 *         if one_based:
 */
        __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_chromosome_not_in_SAM_references, __pyx_v_chrom); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        PyErr_SetObject(PyExc_AssertionError, __pyx_t_3);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
    }
    #endif

    /* "pysamstats.pyx":3869
 *             'chromosome not in SAM references: %s' % chrom
 * 
 *         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_2 = __Pyx_PyObject_IsTrue(__pyx_v_one_based); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3869; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3870
 * 
 *         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_2 = (__pyx_v_start != Py_None);
      if ((__pyx_t_2 != 0)) {
        __pyx_t_4 = PyNumber_Subtract(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_3 = __pyx_t_4;
        __pyx_t_4 = 0;
      } else {
        __Pyx_INCREF(Py_None);
        __pyx_t_3 = Py_None;
      }
      __Pyx_DECREF_SET(__pyx_v_start, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysamstats.pyx":3871
 *         if one_based:
 *             start = start - 1 if start is not None else None
 *             end = end - 1 if end is not None else None             # <<<<<<<<<<<<<<
 * 
 *         chrlen = alignmentfile.lengths[alignmentfile.references.index(chrom)]
 */
      __pyx_t_2 = (__pyx_v_end != Py_None);
      if ((__pyx_t_2 != 0)) {
        __pyx_t_4 = PyNumber_Subtract(__pyx_v_end, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_3 = __pyx_t_4;
        __pyx_t_4 = 0;
      } else {
        __Pyx_INCREF(Py_None);
        __pyx_t_3 = Py_None;
      }
      __Pyx_DECREF_SET(__pyx_v_end, __pyx_t_3);
      __pyx_t_3 = 0;
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "pysamstats.pyx":3873
 *             end = end - 1 if end is not None else None
 * 
 *         chrlen = alignmentfile.lengths[alignmentfile.references.index(chrom)]             # <<<<<<<<<<<<<<
 *         if start is None:
 *             start = 0
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_lengths); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_references); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_index); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_chrom); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
    } else {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_INCREF(__pyx_v_chrom);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_chrom);
      __Pyx_GIVEREF(__pyx_v_chrom);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyObject_GetItem(__pyx_t_3, __pyx_t_4); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3873; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_chrlen = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "pysamstats.pyx":3874
 * 
 *         chrlen = alignmentfile.lengths[alignmentfile.references.index(chrom)]
 *         if start is None:             # <<<<<<<<<<<<<<
 *             start = 0
 *         if end is None:
 */
    __pyx_t_2 = (__pyx_v_start == Py_None);
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "pysamstats.pyx":3875
 *         chrlen = alignmentfile.lengths[alignmentfile.references.index(chrom)]
 *         if start is None:
 *             start = 0             # <<<<<<<<<<<<<<
 *         if end is None:
 *             end = chrlen
 */
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_DECREF_SET(__pyx_v_start, __pyx_int_0);
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "pysamstats.pyx":3876
 *         if start is None:
 *             start = 0
 *         if end is None:             # <<<<<<<<<<<<<<
 *             end = chrlen
 *         if end > chrlen:
 */
    __pyx_t_1 = (__pyx_v_end == Py_None);
    __pyx_t_2 = (__pyx_t_1 != 0);
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3877
 *             start = 0
 *         if end is None:
 *             end = chrlen             # <<<<<<<<<<<<<<
 *         if end > chrlen:
 *             end = chrlen
 */
      __Pyx_INCREF(__pyx_v_chrlen);
      __Pyx_DECREF_SET(__pyx_v_end, __pyx_v_chrlen);
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysamstats.pyx":3878
 *         if end is None:
 *             end = chrlen
 *         if end > chrlen:             # <<<<<<<<<<<<<<
 *             end = chrlen
 * 
 */
    __pyx_t_6 = PyObject_RichCompare(__pyx_v_end, __pyx_v_chrlen, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_2) {

      /* "pysamstats.pyx":3879
 *             end = chrlen
 *         if end > chrlen:
 *             end = chrlen             # <<<<<<<<<<<<<<
 * 
 *         return start, end
 */
      __Pyx_INCREF(__pyx_v_chrlen);
      __Pyx_DECREF_SET(__pyx_v_end, __pyx_v_chrlen);
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "pysamstats.pyx":3881
 *             end = chrlen
 * 
 *         return start, end             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_start);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_start);
    __Pyx_GIVEREF(__pyx_v_start);
    __Pyx_INCREF(__pyx_v_end);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_end);
    __Pyx_GIVEREF(__pyx_v_end);
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;
  }

  /* "pysamstats.pyx":3856
 * 
 * 
 * def _normalise_coords(AlignmentFile alignmentfile, chrom, start, end, one_based):             # <<<<<<<<<<<<<<
 *     """Convert to zero-based coordinates and deal with unspecified start
 *     and/or end.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysamstats._normalise_coords", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrlen);
  __Pyx_XDECREF(__pyx_v_start);
  __Pyx_XDECREF(__pyx_v_end);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3884
 * 
 * 
 * def write_csv(stats_type, outfile, alignmentfile, fields=None, dialect='excel-tab',             # <<<<<<<<<<<<<<
 *               write_header=True, progress=None, **kwargs):
 *     """Write statistics output to a CSV file.
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_154write_csv(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_153write_csv[] = "write_csv(stats_type, outfile, alignmentfile, fields=None, dialect='excel-tab', write_header=True, progress=None, **kwargs)\nWrite statistics output to a CSV file.\n\n    Parameters\n    ----------\n\n    stats_type : string\n        statistics type, one of 'coverage', 'coverage_ext', ...\n    outfile : file-like\n        output file to write to\n    alignmentfile : pysam.AlignmentFile or string\n        input BAM or SAM file or file path\n    fields : list of strings\n        list of field names to output (all by default)\n    dialect : string\n        CSV dialect\n    write_header : bool\n        if True write a header row\n    progress : int\n        log progress to stderr every N rows\n    **kwargs\n        passed through to the statistics function\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_154write_csv = {"write_csv", (PyCFunction)__pyx_pw_10pysamstats_154write_csv, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_153write_csv};
static PyObject *__pyx_pw_10pysamstats_154write_csv(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_stats_type = 0;
  PyObject *__pyx_v_outfile = 0;
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_dialect = 0;
  PyObject *__pyx_v_write_header = 0;
  PyObject *__pyx_v_progress = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_csv (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_stats_type,&__pyx_n_s_outfile,&__pyx_n_s_alignmentfile,&__pyx_n_s_fields,&__pyx_n_s_dialect,&__pyx_n_s_write_header,&__pyx_n_s_progress,0};
    PyObject* values[7] = {0,0,0,0,0,0,0};
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)__pyx_kp_s_excel_tab);

    /* "pysamstats.pyx":3885
 * 
 * def write_csv(stats_type, outfile, alignmentfile, fields=None, dialect='excel-tab',
 *               write_header=True, progress=None, **kwargs):             # <<<<<<<<<<<<<<
 *     """Write statistics output to a CSV file.
 * 
 */
    values[5] = ((PyObject *)Py_True);
    values[6] = ((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  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_stats_type)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_outfile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("write_csv", 0, 3, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3884; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("write_csv", 0, 3, 7, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3884; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fields);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_dialect);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_write_header);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_progress);
          if (value) { values[6] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "write_csv") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3884; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        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);
        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_stats_type = values[0];
    __pyx_v_outfile = values[1];
    __pyx_v_alignmentfile = values[2];
    __pyx_v_fields = values[3];
    __pyx_v_dialect = values[4];
    __pyx_v_write_header = values[5];
    __pyx_v_progress = values[6];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("write_csv", 0, 3, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3884; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.write_csv", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_153write_csv(__pyx_self, __pyx_v_stats_type, __pyx_v_outfile, __pyx_v_alignmentfile, __pyx_v_fields, __pyx_v_dialect, __pyx_v_write_header, __pyx_v_progress, __pyx_v_kwargs);

  /* "pysamstats.pyx":3884
 * 
 * 
 * def write_csv(stats_type, outfile, alignmentfile, fields=None, dialect='excel-tab',             # <<<<<<<<<<<<<<
 *               write_header=True, progress=None, **kwargs):
 *     """Write statistics output to a CSV file.
 */

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

static PyObject *__pyx_pf_10pysamstats_153write_csv(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stats_type, PyObject *__pyx_v_outfile, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fields, PyObject *__pyx_v_dialect, PyObject *__pyx_v_write_header, PyObject *__pyx_v_progress, PyObject *__pyx_v_kwargs) {
  long __pyx_v_counter;
  long __pyx_v_modulus;
  PyObject *__pyx_v_stats_function = NULL;
  PyObject *__pyx_v_recs = NULL;
  PyObject *__pyx_v_rows = NULL;
  PyObject *__pyx_v_writer = NULL;
  PyObject *__pyx_v_row = NULL;
  PyObject *__pyx_v_before = NULL;
  PyObject *__pyx_v_before_all = NULL;
  PyObject *__pyx_v_after = NULL;
  PyObject *__pyx_v_elapsed = NULL;
  PyObject *__pyx_v_batch_elapsed = NULL;
  PyObject *__pyx_v_msg = 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;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  long __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_csv", 0);
  __Pyx_INCREF(__pyx_v_fields);

  /* "pysamstats.pyx":3913
 * 
 *     # lookup stats function
 *     stats_function = globals()['stat_' + stats_type]             # <<<<<<<<<<<<<<
 * 
 *     # determine field names
 */
  __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3913; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_Add(__pyx_n_s_stat_2, __pyx_v_stats_type); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3913; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3913; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_stats_function = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":3916
 * 
 *     # determine field names
 *     if not fields:             # <<<<<<<<<<<<<<
 *         fields = globals()['fields_' + stats_type]
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_fields); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3916; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {

    /* "pysamstats.pyx":3917
 *     # determine field names
 *     if not fields:
 *         fields = globals()['fields_' + stats_type]             # <<<<<<<<<<<<<<
 * 
 *     # setup record generator
 */
    __pyx_t_3 = __Pyx_Globals(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3917; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyNumber_Add(__pyx_n_s_fields_2, __pyx_v_stats_type); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3917; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_GetItem(__pyx_t_3, __pyx_t_2); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3917; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_fields, __pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":3920
 * 
 *     # setup record generator
 *     recs = stats_function(alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 *     # flatten records to rows
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3920; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_2 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_v_stats_function, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3920; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_recs = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":3923
 * 
 *     # flatten records to rows
 *     rows = flatten(recs, *fields)             # <<<<<<<<<<<<<<
 * 
 *     # initialise writer
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_flatten); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_recs);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_recs);
  __Pyx_GIVEREF(__pyx_v_recs);
  __pyx_t_1 = PySequence_Tuple(__pyx_v_fields); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = PyNumber_Add(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_rows = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":3926
 * 
 *     # initialise writer
 *     writer = _csv.writer(outfile, dialect=dialect)             # <<<<<<<<<<<<<<
 * 
 *     # write header row
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_csv); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_writer); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __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 = 3926; __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_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dialect, __pyx_v_dialect) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_writer = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":3929
 * 
 *     # write header row
 *     if write_header:             # <<<<<<<<<<<<<<
 *         writer.writerow(fields)
 * 
 */
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_write_header); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_5) {

    /* "pysamstats.pyx":3930
 *     # write header row
 *     if write_header:
 *         writer.writerow(fields)             # <<<<<<<<<<<<<<
 * 
 *     if progress is None:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_writer, __pyx_n_s_writerow); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    if (!__pyx_t_1) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_fields); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_INCREF(__pyx_v_fields);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_fields);
      __Pyx_GIVEREF(__pyx_v_fields);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "pysamstats.pyx":3932
 *         writer.writerow(fields)
 * 
 *     if progress is None:             # <<<<<<<<<<<<<<
 *         # N.B., don't use writer.writerows(recs)!
 *         for row in rows:
 */
  __pyx_t_5 = (__pyx_v_progress == Py_None);
  __pyx_t_4 = (__pyx_t_5 != 0);
  if (__pyx_t_4) {

    /* "pysamstats.pyx":3934
 *     if progress is None:
 *         # N.B., don't use writer.writerows(recs)!
 *         for row in rows:             # <<<<<<<<<<<<<<
 *             writer.writerow(row)
 * 
 */
    if (likely(PyList_CheckExact(__pyx_v_rows)) || PyTuple_CheckExact(__pyx_v_rows)) {
      __pyx_t_2 = __pyx_v_rows; __Pyx_INCREF(__pyx_t_2); __pyx_t_7 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_rows); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_3); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_3); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        }
      } else {
        __pyx_t_3 = __pyx_t_8(__pyx_t_2);
        if (unlikely(!__pyx_t_3)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_XDECREF_SET(__pyx_v_row, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysamstats.pyx":3935
 *         # N.B., don't use writer.writerows(recs)!
 *         for row in rows:
 *             writer.writerow(row)             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_writer, __pyx_n_s_writerow); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_row); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
      } else {
        __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = NULL;
        __Pyx_INCREF(__pyx_v_row);
        PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_row);
        __Pyx_GIVEREF(__pyx_v_row);
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "pysamstats.pyx":3934
 *     if progress is None:
 *         # N.B., don't use writer.writerows(recs)!
 *         for row in rows:             # <<<<<<<<<<<<<<
 *             writer.writerow(row)
 * 
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "pysamstats.pyx":3938
 * 
 *     else:
 *         counter = 0             # <<<<<<<<<<<<<<
 *         modulus = progress
 *         before = _time.time()
 */
    __pyx_v_counter = 0;

    /* "pysamstats.pyx":3939
 *     else:
 *         counter = 0
 *         modulus = progress             # <<<<<<<<<<<<<<
 *         before = _time.time()
 *         before_all = before
 */
    __pyx_t_10 = __Pyx_PyInt_As_long(__pyx_v_progress); if (unlikely((__pyx_t_10 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_modulus = __pyx_t_10;

    /* "pysamstats.pyx":3940
 *         counter = 0
 *         modulus = progress
 *         before = _time.time()             # <<<<<<<<<<<<<<
 *         before_all = before
 *         for row in rows:
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_time_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    if (__pyx_t_3) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_before = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":3941
 *         modulus = progress
 *         before = _time.time()
 *         before_all = before             # <<<<<<<<<<<<<<
 *         for row in rows:
 *             counter += 1
 */
    __Pyx_INCREF(__pyx_v_before);
    __pyx_v_before_all = __pyx_v_before;

    /* "pysamstats.pyx":3942
 *         before = _time.time()
 *         before_all = before
 *         for row in rows:             # <<<<<<<<<<<<<<
 *             counter += 1
 *             writer.writerow(row)
 */
    if (likely(PyList_CheckExact(__pyx_v_rows)) || PyTuple_CheckExact(__pyx_v_rows)) {
      __pyx_t_2 = __pyx_v_rows; __Pyx_INCREF(__pyx_t_2); __pyx_t_7 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_rows); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_8(__pyx_t_2);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_XDECREF_SET(__pyx_v_row, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "pysamstats.pyx":3943
 *         before_all = before
 *         for row in rows:
 *             counter += 1             # <<<<<<<<<<<<<<
 *             writer.writerow(row)
 *             if counter % modulus == 0:
 */
      __pyx_v_counter = (__pyx_v_counter + 1);

      /* "pysamstats.pyx":3944
 *         for row in rows:
 *             counter += 1
 *             writer.writerow(row)             # <<<<<<<<<<<<<<
 *             if counter % modulus == 0:
 *                 after = _time.time()
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_writer, __pyx_n_s_writerow); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      if (!__pyx_t_9) {
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_row); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
      } else {
        __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_9 = NULL;
        __Pyx_INCREF(__pyx_v_row);
        PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_v_row);
        __Pyx_GIVEREF(__pyx_v_row);
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "pysamstats.pyx":3945
 *             counter += 1
 *             writer.writerow(row)
 *             if counter % modulus == 0:             # <<<<<<<<<<<<<<
 *                 after = _time.time()
 *                 elapsed = after - before_all
 */
      if (unlikely(__pyx_v_modulus == 0)) {
        #ifdef WITH_THREAD
        PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
        #endif
        PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
        #ifdef WITH_THREAD
        PyGILState_Release(__pyx_gilstate_save);
        #endif
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_4 = ((__Pyx_mod_long(__pyx_v_counter, __pyx_v_modulus) == 0) != 0);
      if (__pyx_t_4) {

        /* "pysamstats.pyx":3946
 *             writer.writerow(row)
 *             if counter % modulus == 0:
 *                 after = _time.time()             # <<<<<<<<<<<<<<
 *                 elapsed = after - before_all
 *                 batch_elapsed = after - before
 */
        __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_time_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_1, function);
          }
        }
        if (__pyx_t_3) {
          __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else {
          __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF_SET(__pyx_v_after, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "pysamstats.pyx":3947
 *             if counter % modulus == 0:
 *                 after = _time.time()
 *                 elapsed = after - before_all             # <<<<<<<<<<<<<<
 *                 batch_elapsed = after - before
 *                 msg = '[pysamstats] %s rows in %.2fs (%d rows/s); batch in ' \
 */
        __pyx_t_6 = PyNumber_Subtract(__pyx_v_after, __pyx_v_before_all); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_XDECREF_SET(__pyx_v_elapsed, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "pysamstats.pyx":3948
 *                 after = _time.time()
 *                 elapsed = after - before_all
 *                 batch_elapsed = after - before             # <<<<<<<<<<<<<<
 *                 msg = '[pysamstats] %s rows in %.2fs (%d rows/s); batch in ' \
 *                       '%.2fs (%d rows/s)' \
 */
        __pyx_t_6 = PyNumber_Subtract(__pyx_v_after, __pyx_v_before); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_XDECREF_SET(__pyx_v_batch_elapsed, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "pysamstats.pyx":3951
 *                 msg = '[pysamstats] %s rows in %.2fs (%d rows/s); batch in ' \
 *                       '%.2fs (%d rows/s)' \
 *                       % (counter, elapsed, counter / elapsed, batch_elapsed,             # <<<<<<<<<<<<<<
 *                          progress / batch_elapsed)
 *                 print(msg, file=_sys.stderr)
 */
        __pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_counter); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_counter); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_v_elapsed); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "pysamstats.pyx":3952
 *                       '%.2fs (%d rows/s)' \
 *                       % (counter, elapsed, counter / elapsed, batch_elapsed,
 *                          progress / batch_elapsed)             # <<<<<<<<<<<<<<
 *                 print(msg, file=_sys.stderr)
 *                 before = after
 */
        __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_progress, __pyx_v_batch_elapsed); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);

        /* "pysamstats.pyx":3951
 *                 msg = '[pysamstats] %s rows in %.2fs (%d rows/s); batch in ' \
 *                       '%.2fs (%d rows/s)' \
 *                       % (counter, elapsed, counter / elapsed, batch_elapsed,             # <<<<<<<<<<<<<<
 *                          progress / batch_elapsed)
 *                 print(msg, file=_sys.stderr)
 */
        __pyx_t_9 = PyTuple_New(5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_v_elapsed);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_elapsed);
        __Pyx_GIVEREF(__pyx_v_elapsed);
        PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_v_batch_elapsed);
        PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_v_batch_elapsed);
        __Pyx_GIVEREF(__pyx_v_batch_elapsed);
        PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_1);
        __pyx_t_6 = 0;
        __pyx_t_3 = 0;
        __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_pysamstats_s_rows_in_2fs_d_rows, __pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_XDECREF_SET(__pyx_v_msg, ((PyObject*)__pyx_t_1));
        __pyx_t_1 = 0;

        /* "pysamstats.pyx":3953
 *                       % (counter, elapsed, counter / elapsed, batch_elapsed,
 *                          progress / batch_elapsed)
 *                 print(msg, file=_sys.stderr)             # <<<<<<<<<<<<<<
 *                 before = after
 *         after_all = _time.time()
 */
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_v_msg);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_msg);
        __Pyx_GIVEREF(__pyx_v_msg);
        __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_stderr); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_file, __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_t_1, __pyx_t_9); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "pysamstats.pyx":3954
 *                          progress / batch_elapsed)
 *                 print(msg, file=_sys.stderr)
 *                 before = after             # <<<<<<<<<<<<<<
 *         after_all = _time.time()
 *         elapsed_all = after_all - before_all
 */
        __Pyx_INCREF(__pyx_v_after);
        __Pyx_DECREF_SET(__pyx_v_before, __pyx_v_after);
        goto __pyx_L10;
      }
      __pyx_L10:;

      /* "pysamstats.pyx":3942
 *         before = _time.time()
 *         before_all = before
 *         for row in rows:             # <<<<<<<<<<<<<<
 *             counter += 1
 *             writer.writerow(row)
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysamstats.pyx":3955
 *                 print(msg, file=_sys.stderr)
 *                 before = after
 *         after_all = _time.time()             # <<<<<<<<<<<<<<
 *         elapsed_all = after_all - before_all
 *         msg = '[pysamstats] %s rows in %.2fs (%d rows/s)' \
 */
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_time_2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    if (__pyx_t_6) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else {
      __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_9); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_after_all = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":3956
 *                 before = after
 *         after_all = _time.time()
 *         elapsed_all = after_all - before_all             # <<<<<<<<<<<<<<
 *         msg = '[pysamstats] %s rows in %.2fs (%d rows/s)' \
 *               % (counter, elapsed_all, counter / elapsed_all)
 */
    __pyx_t_2 = PyNumber_Subtract(__pyx_v_after_all, __pyx_v_before_all); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_elapsed_all = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":3958
 *         elapsed_all = after_all - before_all
 *         msg = '[pysamstats] %s rows in %.2fs (%d rows/s)' \
 *               % (counter, elapsed_all, counter / elapsed_all)             # <<<<<<<<<<<<<<
 *         print(msg, file=_sys.stderr)
 * 
 */
    __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_counter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_v_counter); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_6 = __Pyx_PyNumber_Divide(__pyx_t_9, __pyx_v_elapsed_all); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_elapsed_all);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_elapsed_all);
    __Pyx_GIVEREF(__pyx_v_elapsed_all);
    PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    __pyx_t_2 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_pysamstats_s_rows_in_2fs_d_rows_2, __pyx_t_9); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_XDECREF_SET(__pyx_v_msg, ((PyObject*)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "pysamstats.pyx":3959
 *         msg = '[pysamstats] %s rows in %.2fs (%d rows/s)' \
 *               % (counter, elapsed_all, counter / elapsed_all)
 *         print(msg, file=_sys.stderr)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_stderr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_file, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_t_6, __pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L5:;

  /* "pysamstats.pyx":3884
 * 
 * 
 * def write_csv(stats_type, outfile, alignmentfile, fields=None, dialect='excel-tab',             # <<<<<<<<<<<<<<
 *               write_header=True, progress=None, **kwargs):
 *     """Write statistics output to a CSV file.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysamstats.write_csv", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_stats_function);
  __Pyx_XDECREF(__pyx_v_recs);
  __Pyx_XDECREF(__pyx_v_rows);
  __Pyx_XDECREF(__pyx_v_writer);
  __Pyx_XDECREF(__pyx_v_row);
  __Pyx_XDECREF(__pyx_v_before);
  __Pyx_XDECREF(__pyx_v_before_all);
  __Pyx_XDECREF(__pyx_v_after);
  __Pyx_XDECREF(__pyx_v_elapsed);
  __Pyx_XDECREF(__pyx_v_batch_elapsed);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_after_all);
  __Pyx_XDECREF(__pyx_v_elapsed_all);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":3962
 * 
 * 
 * def write_hdf5(stats_type, outfile, alignmentfile, fields=None, progress=None,             # <<<<<<<<<<<<<<
 *                hdf5_group='/', hdf5_dataset='data', hdf5_complevel=5,
 *                hdf5_complib='zlib', hdf5_shuffle=True,
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_156write_hdf5(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_155write_hdf5[] = "write_hdf5(stats_type, outfile, alignmentfile, fields=None, progress=None, hdf5_group='/', hdf5_dataset='data', hdf5_complevel=5, hdf5_complib='zlib', hdf5_shuffle=True, hdf5_fletcher32=False, hdf5_chunksize=131072, **kwargs)\nWrite statistics output to an HDF5 file. Requires PyTables.\n\n    Parameters\n    ----------\n\n    stats_type : string\n        statistics type, one of 'coverage', 'coverage_ext', ...\n    outfile : string\n        output file path\n    alignmentfile : pysam.AlignmentFile or string\n        input BAM or SAM file or file path\n    fields : list of strings\n        list of field names to output (all by default)\n    progress : int\n        log progress to stderr approximately every N rows\n    hdf5_group : string\n        group to write new dataset to\n    hdf5_dataset : string\n        name of dataset to create\n    hdf5_chunksize : int\n        size of chunks in number of bytes\n    dtype : dict\n        override dtype\n    **kwargs\n        passed through to the statistics function\n\n    Notes\n    -----\n\n    The length of the chunks in number of items is calculated by dividing the\n    chunk size in number of bytes by the size of each row in number of bytes as\n    determined from the dtype.\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_156write_hdf5 = {"write_hdf5", (PyCFunction)__pyx_pw_10pysamstats_156write_hdf5, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_155write_hdf5};
static PyObject *__pyx_pw_10pysamstats_156write_hdf5(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_stats_type = 0;
  PyObject *__pyx_v_outfile = 0;
  PyObject *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_progress = 0;
  PyObject *__pyx_v_hdf5_group = 0;
  PyObject *__pyx_v_hdf5_dataset = 0;
  PyObject *__pyx_v_hdf5_complevel = 0;
  PyObject *__pyx_v_hdf5_complib = 0;
  PyObject *__pyx_v_hdf5_shuffle = 0;
  PyObject *__pyx_v_hdf5_fletcher32 = 0;
  PyObject *__pyx_v_hdf5_chunksize = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_hdf5 (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_stats_type,&__pyx_n_s_outfile,&__pyx_n_s_alignmentfile,&__pyx_n_s_fields,&__pyx_n_s_progress,&__pyx_n_s_hdf5_group,&__pyx_n_s_hdf5_dataset,&__pyx_n_s_hdf5_complevel,&__pyx_n_s_hdf5_complib,&__pyx_n_s_hdf5_shuffle,&__pyx_n_s_hdf5_fletcher32,&__pyx_n_s_hdf5_chunksize,0};
    PyObject* values[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    values[5] = ((PyObject *)__pyx_kp_s__7);
    values[6] = ((PyObject *)__pyx_n_s_data);
    values[7] = ((PyObject *)__pyx_int_5);
    values[8] = ((PyObject *)__pyx_n_s_zlib);

    /* "pysamstats.pyx":3964
 * def write_hdf5(stats_type, outfile, alignmentfile, fields=None, progress=None,
 *                hdf5_group='/', hdf5_dataset='data', hdf5_complevel=5,
 *                hdf5_complib='zlib', hdf5_shuffle=True,             # <<<<<<<<<<<<<<
 *                hdf5_fletcher32=False, hdf5_chunksize=2**17, **kwargs):
 *     """Write statistics output to an HDF5 file. Requires PyTables.
 */
    values[9] = ((PyObject *)Py_True);

    /* "pysamstats.pyx":3965
 *                hdf5_group='/', hdf5_dataset='data', hdf5_complevel=5,
 *                hdf5_complib='zlib', hdf5_shuffle=True,
 *                hdf5_fletcher32=False, hdf5_chunksize=2**17, **kwargs):             # <<<<<<<<<<<<<<
 *     """Write statistics output to an HDF5 file. Requires PyTables.
 * 
 */
    values[10] = ((PyObject *)Py_False);
    values[11] = ((PyObject *)__pyx_int_131072);
    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_stats_type)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_outfile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("write_hdf5", 0, 3, 12, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3962; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("write_hdf5", 0, 3, 12, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3962; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fields);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_progress);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_hdf5_group);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_hdf5_dataset);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_hdf5_complevel);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_hdf5_complib);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_hdf5_shuffle);
          if (value) { values[9] = value; kw_args--; }
        }
        case 10:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_hdf5_fletcher32);
          if (value) { values[10] = value; kw_args--; }
        }
        case 11:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_hdf5_chunksize);
          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_hdf5") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3962; __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);
        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_stats_type = values[0];
    __pyx_v_outfile = values[1];
    __pyx_v_alignmentfile = values[2];
    __pyx_v_fields = values[3];
    __pyx_v_progress = values[4];
    __pyx_v_hdf5_group = values[5];
    __pyx_v_hdf5_dataset = values[6];
    __pyx_v_hdf5_complevel = values[7];
    __pyx_v_hdf5_complib = values[8];
    __pyx_v_hdf5_shuffle = values[9];
    __pyx_v_hdf5_fletcher32 = values[10];
    __pyx_v_hdf5_chunksize = values[11];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("write_hdf5", 0, 3, 12, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3962; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.write_hdf5", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_155write_hdf5(__pyx_self, __pyx_v_stats_type, __pyx_v_outfile, __pyx_v_alignmentfile, __pyx_v_fields, __pyx_v_progress, __pyx_v_hdf5_group, __pyx_v_hdf5_dataset, __pyx_v_hdf5_complevel, __pyx_v_hdf5_complib, __pyx_v_hdf5_shuffle, __pyx_v_hdf5_fletcher32, __pyx_v_hdf5_chunksize, __pyx_v_kwargs);

  /* "pysamstats.pyx":3962
 * 
 * 
 * def write_hdf5(stats_type, outfile, alignmentfile, fields=None, progress=None,             # <<<<<<<<<<<<<<
 *                hdf5_group='/', hdf5_dataset='data', hdf5_complevel=5,
 *                hdf5_complib='zlib', hdf5_shuffle=True,
 */

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

static PyObject *__pyx_pf_10pysamstats_155write_hdf5(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stats_type, PyObject *__pyx_v_outfile, PyObject *__pyx_v_alignmentfile, PyObject *__pyx_v_fields, PyObject *__pyx_v_progress, PyObject *__pyx_v_hdf5_group, PyObject *__pyx_v_hdf5_dataset, PyObject *__pyx_v_hdf5_complevel, PyObject *__pyx_v_hdf5_complib, PyObject *__pyx_v_hdf5_shuffle, PyObject *__pyx_v_hdf5_fletcher32, PyObject *__pyx_v_hdf5_chunksize, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_tables = NULL;
  PyObject *__pyx_v_np = NULL;
  PyObject *__pyx_v_h5file = NULL;
  PyObject *__pyx_v_stats_function = NULL;
  PyObject *__pyx_v_default_dtype = NULL;
  PyObject *__pyx_v_dtype = NULL;
  PyObject *__pyx_v_dtype_overrides = NULL;
  PyObject *__pyx_v_recs = NULL;
  PyObject *__pyx_v_rows = NULL;
  PyObject *__pyx_v_hdf5_chunklen = NULL;
  PyObject *__pyx_v_hdf5_chunkshape = NULL;
  PyObject *__pyx_v_h5table = NULL;
  PyObject *__pyx_v_counter = NULL;
  PyObject *__pyx_v_counter_before = NULL;
  PyObject *__pyx_v_before = NULL;
  PyObject *__pyx_v_before_all = NULL;
  PyObject *__pyx_v_chunk = NULL;
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_v_after = NULL;
  PyObject *__pyx_v_elapsed = NULL;
  PyObject *__pyx_v_batch_elapsed = NULL;
  PyObject *__pyx_v_batch_size = NULL;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_v_after_all = NULL;
  PyObject *__pyx_v_elapsed_all = NULL;
  PyObject *__pyx_v_f = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  int __pyx_t_15;
  int __pyx_t_16;
  char const *__pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_hdf5", 0);
  __Pyx_INCREF(__pyx_v_fields);

  /* "pysamstats.pyx":4001
 *     """
 * 
 *     import tables             # <<<<<<<<<<<<<<
 *     import numpy as np
 *     h5file = None
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_tables, 0, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_tables = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":4002
 * 
 *     import tables
 *     import numpy as np             # <<<<<<<<<<<<<<
 *     h5file = None
 * 
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_np = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":4003
 *     import tables
 *     import numpy as np
 *     h5file = None             # <<<<<<<<<<<<<<
 * 
 *     # lookup stats function
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_h5file = Py_None;

  /* "pysamstats.pyx":4006
 * 
 *     # lookup stats function
 *     stats_function = globals()['stat_' + stats_type]             # <<<<<<<<<<<<<<
 * 
 *     # determine field names
 */
  __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_Add(__pyx_n_s_stat_2, __pyx_v_stats_type); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4006; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_stats_function = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":4009
 * 
 *     # determine field names
 *     if not fields:             # <<<<<<<<<<<<<<
 *         fields = globals()['fields_' + stats_type]
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_fields); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {

    /* "pysamstats.pyx":4010
 *     # determine field names
 *     if not fields:
 *         fields = globals()['fields_' + stats_type]             # <<<<<<<<<<<<<<
 * 
 *     # determine dtype
 */
    __pyx_t_3 = __Pyx_Globals(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyNumber_Add(__pyx_n_s_fields_2, __pyx_v_stats_type); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_GetItem(__pyx_t_3, __pyx_t_2); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4010; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_fields, __pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":4013
 * 
 *     # determine dtype
 *     default_dtype = globals()['dtype_' + stats_type]             # <<<<<<<<<<<<<<
 *     dtype = dict(default_dtype)
 *     dtype_overrides = kwargs.pop('dtype', None)
 */
  __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4013; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_Add(__pyx_n_s_dtype, __pyx_v_stats_type); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4013; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4013; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_default_dtype = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":4014
 *     # determine dtype
 *     default_dtype = globals()['dtype_' + stats_type]
 *     dtype = dict(default_dtype)             # <<<<<<<<<<<<<<
 *     dtype_overrides = kwargs.pop('dtype', None)
 *     if dtype_overrides:
 */
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_default_dtype);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_default_dtype);
  __Pyx_GIVEREF(__pyx_v_default_dtype);
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_dtype = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":4015
 *     default_dtype = globals()['dtype_' + stats_type]
 *     dtype = dict(default_dtype)
 *     dtype_overrides = kwargs.pop('dtype', None)             # <<<<<<<<<<<<<<
 *     if dtype_overrides:
 *         # expect dict
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_kwargs, __pyx_n_s_pop); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_dtype_overrides = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":4016
 *     dtype = dict(default_dtype)
 *     dtype_overrides = kwargs.pop('dtype', None)
 *     if dtype_overrides:             # <<<<<<<<<<<<<<
 *         # expect dict
 *         dtype.update(dtype_overrides)
 */
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_dtype_overrides); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_5) {

    /* "pysamstats.pyx":4018
 *     if dtype_overrides:
 *         # expect dict
 *         dtype.update(dtype_overrides)             # <<<<<<<<<<<<<<
 *     if len(fields) == 1:
 *         dtype = dtype[fields[0]]
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_dtype, __pyx_n_s_update); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    if (!__pyx_t_1) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_dtype_overrides); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_INCREF(__pyx_v_dtype_overrides);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_dtype_overrides);
      __Pyx_GIVEREF(__pyx_v_dtype_overrides);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "pysamstats.pyx":4019
 *         # expect dict
 *         dtype.update(dtype_overrides)
 *     if len(fields) == 1:             # <<<<<<<<<<<<<<
 *         dtype = dtype[fields[0]]
 *     else:
 */
  __pyx_t_7 = PyObject_Length(__pyx_v_fields); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = ((__pyx_t_7 == 1) != 0);
  if (__pyx_t_5) {

    /* "pysamstats.pyx":4020
 *         dtype.update(dtype_overrides)
 *     if len(fields) == 1:
 *         dtype = dtype[fields[0]]             # <<<<<<<<<<<<<<
 *     else:
 *         dtype = [(f, dtype[f]) for f in fields]
 */
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_fields, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4020; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_dtype, __pyx_t_3); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4020; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_dtype, __pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "pysamstats.pyx":4022
 *         dtype = dtype[fields[0]]
 *     else:
 *         dtype = [(f, dtype[f]) for f in fields]             # <<<<<<<<<<<<<<
 *     dtype = np.dtype(dtype)
 * 
 */
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if (likely(PyList_CheckExact(__pyx_v_fields)) || PyTuple_CheckExact(__pyx_v_fields)) {
      __pyx_t_3 = __pyx_v_fields; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_fields); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_3))) {
          if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_8(__pyx_t_3);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_XDECREF_SET(__pyx_v_f, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = PyObject_GetItem(__pyx_v_dtype, __pyx_v_f); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4022; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_f);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_f);
      __Pyx_GIVEREF(__pyx_v_f);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __pyx_t_6 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_dtype, __pyx_t_2);
    __pyx_t_2 = 0;
  }
  __pyx_L5:;

  /* "pysamstats.pyx":4023
 *     else:
 *         dtype = [(f, dtype[f]) for f in fields]
 *     dtype = np.dtype(dtype)             # <<<<<<<<<<<<<<
 * 
 *     # setup record generator
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_np, __pyx_n_s_dtype_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_1) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_dtype); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = NULL;
    __Pyx_INCREF(__pyx_v_dtype);
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_dtype);
    __Pyx_GIVEREF(__pyx_v_dtype);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF_SET(__pyx_v_dtype, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":4026
 * 
 *     # setup record generator
 *     recs = stats_function(alignmentfile, **kwargs)             # <<<<<<<<<<<<<<
 * 
 *     # flatten records to rows
 */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4026; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_alignmentfile);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_alignmentfile);
  __Pyx_GIVEREF(__pyx_v_alignmentfile);
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_v_stats_function, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4026; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_recs = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "pysamstats.pyx":4029
 * 
 *     # flatten records to rows
 *     rows = flatten(recs, *fields)             # <<<<<<<<<<<<<<
 * 
 *     try:
 */
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_flatten); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_recs);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_recs);
  __Pyx_GIVEREF(__pyx_v_recs);
  __pyx_t_2 = PySequence_Tuple(__pyx_v_fields); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_rows = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":4031
 *     rows = flatten(recs, *fields)
 * 
 *     try:             # <<<<<<<<<<<<<<
 * 
 *         # open output file
 */
  /*try:*/ {

    /* "pysamstats.pyx":4034
 * 
 *         # open output file
 *         h5file = tables.open_file(outfile, mode='a')             # <<<<<<<<<<<<<<
 * 
 *         # determine chunk shape
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tables, __pyx_n_s_open_file); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4034; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4034; __pyx_clineno = __LINE__; goto __pyx_L9_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_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4034; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_6);
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mode, __pyx_n_s_a) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4034; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4034; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF_SET(__pyx_v_h5file, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":4037
 * 
 *         # determine chunk shape
 *         hdf5_chunklen = hdf5_chunksize/dtype.itemsize             # <<<<<<<<<<<<<<
 *         hdf5_chunkshape = (hdf5_chunklen,)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dtype, __pyx_n_s_itemsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4037; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyNumber_Divide(__pyx_v_hdf5_chunksize, __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4037; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_hdf5_chunklen = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "pysamstats.pyx":4038
 *         # determine chunk shape
 *         hdf5_chunklen = hdf5_chunksize/dtype.itemsize
 *         hdf5_chunkshape = (hdf5_chunklen,)             # <<<<<<<<<<<<<<
 * 
 *         # replace any existing node at that location
 */
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4038; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_hdf5_chunklen);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_hdf5_chunklen);
    __Pyx_GIVEREF(__pyx_v_hdf5_chunklen);
    __pyx_v_hdf5_chunkshape = ((PyObject*)__pyx_t_6);
    __pyx_t_6 = 0;

    /* "pysamstats.pyx":4041
 * 
 *         # replace any existing node at that location
 *         try:             # <<<<<<<<<<<<<<
 *             h5file.remove_node(hdf5_group, hdf5_dataset)
 *         except tables.NoSuchNodeError:
 */
    {
      __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      __Pyx_XGOTREF(__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_10);
      __Pyx_XGOTREF(__pyx_t_11);
      /*try:*/ {

        /* "pysamstats.pyx":4042
 *         # replace any existing node at that location
 *         try:
 *             h5file.remove_node(hdf5_group, hdf5_dataset)             # <<<<<<<<<<<<<<
 *         except tables.NoSuchNodeError:
 *             pass
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_h5file, __pyx_n_s_remove_node); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4042; __pyx_clineno = __LINE__; goto __pyx_L11_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_1 = NULL;
        __pyx_t_7 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
            __pyx_t_7 = 1;
          }
        }
        __pyx_t_2 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4042; __pyx_clineno = __LINE__; goto __pyx_L11_error;}
        __Pyx_GOTREF(__pyx_t_2);
        if (__pyx_t_1) {
          PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = NULL;
        }
        __Pyx_INCREF(__pyx_v_hdf5_group);
        PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_7, __pyx_v_hdf5_group);
        __Pyx_GIVEREF(__pyx_v_hdf5_group);
        __Pyx_INCREF(__pyx_v_hdf5_dataset);
        PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_7, __pyx_v_hdf5_dataset);
        __Pyx_GIVEREF(__pyx_v_hdf5_dataset);
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4042; __pyx_clineno = __LINE__; goto __pyx_L11_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      goto __pyx_L18_try_end;
      __pyx_L11_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "pysamstats.pyx":4043
 *         try:
 *             h5file.remove_node(hdf5_group, hdf5_dataset)
 *         except tables.NoSuchNodeError:             # <<<<<<<<<<<<<<
 *             pass
 * 
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_tables, __pyx_n_s_NoSuchNodeError); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4043; __pyx_clineno = __LINE__; goto __pyx_L13_except_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_12 = PyErr_ExceptionMatches(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_12) {
        PyErr_Restore(0,0,0);
        goto __pyx_L12_exception_handled;
      }
      goto __pyx_L13_except_error;
      __pyx_L13_except_error:;
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_XGIVEREF(__pyx_t_11);
      __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      goto __pyx_L9_error;
      __pyx_L12_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_XGIVEREF(__pyx_t_11);
      __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      __pyx_L18_try_end:;
    }

    /* "pysamstats.pyx":4047
 * 
 *         # create dataset
 *         h5table = h5file.create_table(             # <<<<<<<<<<<<<<
 *             hdf5_group, hdf5_dataset, dtype,
 *             title=stats_type,
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_h5file, __pyx_n_s_create_table); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4047; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_6);

    /* "pysamstats.pyx":4048
 *         # create dataset
 *         h5table = h5file.create_table(
 *             hdf5_group, hdf5_dataset, dtype,             # <<<<<<<<<<<<<<
 *             title=stats_type,
 *             filters=tables.Filters(complevel=hdf5_complevel,
 */
    __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4047; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_hdf5_group);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_hdf5_group);
    __Pyx_GIVEREF(__pyx_v_hdf5_group);
    __Pyx_INCREF(__pyx_v_hdf5_dataset);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_hdf5_dataset);
    __Pyx_GIVEREF(__pyx_v_hdf5_dataset);
    __Pyx_INCREF(__pyx_v_dtype);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_dtype);
    __Pyx_GIVEREF(__pyx_v_dtype);

    /* "pysamstats.pyx":4047
 * 
 *         # create dataset
 *         h5table = h5file.create_table(             # <<<<<<<<<<<<<<
 *             hdf5_group, hdf5_dataset, dtype,
 *             title=stats_type,
 */
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4047; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_2);

    /* "pysamstats.pyx":4049
 *         h5table = h5file.create_table(
 *             hdf5_group, hdf5_dataset, dtype,
 *             title=stats_type,             # <<<<<<<<<<<<<<
 *             filters=tables.Filters(complevel=hdf5_complevel,
 *                                    complib=hdf5_complib,
 */
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_title, __pyx_v_stats_type) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4047; __pyx_clineno = __LINE__; goto __pyx_L9_error;}

    /* "pysamstats.pyx":4050
 *             hdf5_group, hdf5_dataset, dtype,
 *             title=stats_type,
 *             filters=tables.Filters(complevel=hdf5_complevel,             # <<<<<<<<<<<<<<
 *                                    complib=hdf5_complib,
 *                                    shuffle=hdf5_shuffle,
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tables, __pyx_n_s_Filters); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4050; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_13 = PyDict_New(); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4050; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_13);
    if (PyDict_SetItem(__pyx_t_13, __pyx_n_s_complevel, __pyx_v_hdf5_complevel) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4050; __pyx_clineno = __LINE__; goto __pyx_L9_error;}

    /* "pysamstats.pyx":4051
 *             title=stats_type,
 *             filters=tables.Filters(complevel=hdf5_complevel,
 *                                    complib=hdf5_complib,             # <<<<<<<<<<<<<<
 *                                    shuffle=hdf5_shuffle,
 *                                    fletcher32=hdf5_fletcher32),
 */
    if (PyDict_SetItem(__pyx_t_13, __pyx_n_s_complib, __pyx_v_hdf5_complib) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4050; __pyx_clineno = __LINE__; goto __pyx_L9_error;}

    /* "pysamstats.pyx":4052
 *             filters=tables.Filters(complevel=hdf5_complevel,
 *                                    complib=hdf5_complib,
 *                                    shuffle=hdf5_shuffle,             # <<<<<<<<<<<<<<
 *                                    fletcher32=hdf5_fletcher32),
 *             createparents=True,
 */
    if (PyDict_SetItem(__pyx_t_13, __pyx_n_s_shuffle, __pyx_v_hdf5_shuffle) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4050; __pyx_clineno = __LINE__; goto __pyx_L9_error;}

    /* "pysamstats.pyx":4053
 *                                    complib=hdf5_complib,
 *                                    shuffle=hdf5_shuffle,
 *                                    fletcher32=hdf5_fletcher32),             # <<<<<<<<<<<<<<
 *             createparents=True,
 *             chunkshape=hdf5_chunkshape)
 */
    if (PyDict_SetItem(__pyx_t_13, __pyx_n_s_fletcher32, __pyx_v_hdf5_fletcher32) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4050; __pyx_clineno = __LINE__; goto __pyx_L9_error;}

    /* "pysamstats.pyx":4050
 *             hdf5_group, hdf5_dataset, dtype,
 *             title=stats_type,
 *             filters=tables.Filters(complevel=hdf5_complevel,             # <<<<<<<<<<<<<<
 *                                    complib=hdf5_complib,
 *                                    shuffle=hdf5_shuffle,
 */
    __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_13); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4050; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_filters, __pyx_t_14) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4047; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

    /* "pysamstats.pyx":4054
 *                                    shuffle=hdf5_shuffle,
 *                                    fletcher32=hdf5_fletcher32),
 *             createparents=True,             # <<<<<<<<<<<<<<
 *             chunkshape=hdf5_chunkshape)
 * 
 */
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_createparents, Py_True) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4047; __pyx_clineno = __LINE__; goto __pyx_L9_error;}

    /* "pysamstats.pyx":4055
 *                                    fletcher32=hdf5_fletcher32),
 *             createparents=True,
 *             chunkshape=hdf5_chunkshape)             # <<<<<<<<<<<<<<
 * 
 *         # record initial time
 */
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_chunkshape, __pyx_v_hdf5_chunkshape) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4047; __pyx_clineno = __LINE__; goto __pyx_L9_error;}

    /* "pysamstats.pyx":4047
 * 
 *         # create dataset
 *         h5table = h5file.create_table(             # <<<<<<<<<<<<<<
 *             hdf5_group, hdf5_dataset, dtype,
 *             title=stats_type,
 */
    __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4047; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_h5table = __pyx_t_14;
    __pyx_t_14 = 0;

    /* "pysamstats.pyx":4058
 * 
 *         # record initial time
 *         counter = 0             # <<<<<<<<<<<<<<
 *         counter_before = 0
 *         before = _time.time()
 */
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_counter = __pyx_int_0;

    /* "pysamstats.pyx":4059
 *         # record initial time
 *         counter = 0
 *         counter_before = 0             # <<<<<<<<<<<<<<
 *         before = _time.time()
 *         before_all = before
 */
    __Pyx_INCREF(__pyx_int_0);
    __pyx_v_counter_before = __pyx_int_0;

    /* "pysamstats.pyx":4060
 *         counter = 0
 *         counter_before = 0
 *         before = _time.time()             # <<<<<<<<<<<<<<
 *         before_all = before
 * 
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4060; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4060; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    if (__pyx_t_2) {
      __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4060; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      __pyx_t_14 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4060; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    }
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_before = __pyx_t_14;
    __pyx_t_14 = 0;

    /* "pysamstats.pyx":4061
 *         counter_before = 0
 *         before = _time.time()
 *         before_all = before             # <<<<<<<<<<<<<<
 * 
 *         # load data in batches of size `hdf5_chunklen`
 */
    __Pyx_INCREF(__pyx_v_before);
    __pyx_v_before_all = __pyx_v_before;

    /* "pysamstats.pyx":4064
 * 
 *         # load data in batches of size `hdf5_chunklen`
 *         chunk = list(_itertools.islice(rows, hdf5_chunklen))             # <<<<<<<<<<<<<<
 * 
 *         # load chunk at a time
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_itertools); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4064; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_islice); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4064; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    __pyx_t_7 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_7 = 1;
      }
    }
    __pyx_t_6 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4064; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_6);
    if (__pyx_t_3) {
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(__pyx_v_rows);
    PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_7, __pyx_v_rows);
    __Pyx_GIVEREF(__pyx_v_rows);
    __Pyx_INCREF(__pyx_v_hdf5_chunklen);
    PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_7, __pyx_v_hdf5_chunklen);
    __Pyx_GIVEREF(__pyx_v_hdf5_chunklen);
    __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4064; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __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 = 4064; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14);
    __Pyx_GIVEREF(__pyx_t_14);
    __pyx_t_14 = 0;
    __pyx_t_14 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4064; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_chunk = ((PyObject*)__pyx_t_14);
    __pyx_t_14 = 0;

    /* "pysamstats.pyx":4067
 * 
 *         # load chunk at a time
 *         while chunk:             # <<<<<<<<<<<<<<
 * 
 *             # write chunk
 */
    while (1) {
      __pyx_t_5 = (__pyx_v_chunk != Py_None) && (PyList_GET_SIZE(__pyx_v_chunk) != 0);
      if (!__pyx_t_5) break;

      /* "pysamstats.pyx":4070
 * 
 *             # write chunk
 *             h5table.append(chunk)             # <<<<<<<<<<<<<<
 *             h5table.flush()
 * 
 */
      __pyx_t_15 = __Pyx_PyObject_Append(__pyx_v_h5table, __pyx_v_chunk); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4070; __pyx_clineno = __LINE__; goto __pyx_L9_error;}

      /* "pysamstats.pyx":4071
 *             # write chunk
 *             h5table.append(chunk)
 *             h5table.flush()             # <<<<<<<<<<<<<<
 * 
 *             # keep track of number of records loaded
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_h5table, __pyx_n_s_flush); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4071; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (__pyx_t_6) {
        __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4071; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else {
        __pyx_t_14 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4071; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      }
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

      /* "pysamstats.pyx":4074
 * 
 *             # keep track of number of records loaded
 *             n = len(chunk)  # may be shorter than chunklen if final batch             # <<<<<<<<<<<<<<
 *             counter += n
 * 
 */
      __pyx_t_7 = PyList_GET_SIZE(__pyx_v_chunk); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4074; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __pyx_t_14 = PyInt_FromSsize_t(__pyx_t_7); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4074; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_14);
      __pyx_t_14 = 0;

      /* "pysamstats.pyx":4075
 *             # keep track of number of records loaded
 *             n = len(chunk)  # may be shorter than chunklen if final batch
 *             counter += n             # <<<<<<<<<<<<<<
 * 
 *             # log progress
 */
      __pyx_t_14 = PyNumber_InPlaceAdd(__pyx_v_counter, __pyx_v_n); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4075; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF_SET(__pyx_v_counter, __pyx_t_14);
      __pyx_t_14 = 0;

      /* "pysamstats.pyx":4078
 * 
 *             # log progress
 *             if progress and (counter % progress) < hdf5_chunklen:             # <<<<<<<<<<<<<<
 *                 after = _time.time()
 *                 elapsed = after - before_all
 */
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_progress); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4078; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      if (__pyx_t_4) {
      } else {
        __pyx_t_5 = __pyx_t_4;
        goto __pyx_L22_bool_binop_done;
      }
      __pyx_t_14 = PyNumber_Remainder(__pyx_v_counter, __pyx_v_progress); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4078; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_2 = PyObject_RichCompare(__pyx_t_14, __pyx_v_hdf5_chunklen, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4078; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4078; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_5 = __pyx_t_4;
      __pyx_L22_bool_binop_done:;
      if (__pyx_t_5) {

        /* "pysamstats.pyx":4079
 *             # log progress
 *             if progress and (counter % progress) < hdf5_chunklen:
 *                 after = _time.time()             # <<<<<<<<<<<<<<
 *                 elapsed = after - before_all
 *                 batch_elapsed = after - before
 */
        __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4079; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_time_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4079; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_14 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_14)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_14);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
          }
        }
        if (__pyx_t_14) {
          __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4079; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        } else {
          __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4079; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        }
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF_SET(__pyx_v_after, __pyx_t_2);
        __pyx_t_2 = 0;

        /* "pysamstats.pyx":4080
 *             if progress and (counter % progress) < hdf5_chunklen:
 *                 after = _time.time()
 *                 elapsed = after - before_all             # <<<<<<<<<<<<<<
 *                 batch_elapsed = after - before
 *                 batch_size = counter - counter_before
 */
        __pyx_t_2 = PyNumber_Subtract(__pyx_v_after, __pyx_v_before_all); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4080; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_XDECREF_SET(__pyx_v_elapsed, __pyx_t_2);
        __pyx_t_2 = 0;

        /* "pysamstats.pyx":4081
 *                 after = _time.time()
 *                 elapsed = after - before_all
 *                 batch_elapsed = after - before             # <<<<<<<<<<<<<<
 *                 batch_size = counter - counter_before
 *                 msg = '[pysamstats] %s rows in %.2fs (%d rows/s); last %s ' \
 */
        __pyx_t_2 = PyNumber_Subtract(__pyx_v_after, __pyx_v_before); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4081; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_XDECREF_SET(__pyx_v_batch_elapsed, __pyx_t_2);
        __pyx_t_2 = 0;

        /* "pysamstats.pyx":4082
 *                 elapsed = after - before_all
 *                 batch_elapsed = after - before
 *                 batch_size = counter - counter_before             # <<<<<<<<<<<<<<
 *                 msg = '[pysamstats] %s rows in %.2fs (%d rows/s); last %s ' \
 *                       'rows in %.2fs (%d rows/s)' \
 */
        __pyx_t_2 = PyNumber_Subtract(__pyx_v_counter, __pyx_v_counter_before); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4082; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_XDECREF_SET(__pyx_v_batch_size, __pyx_t_2);
        __pyx_t_2 = 0;

        /* "pysamstats.pyx":4085
 *                 msg = '[pysamstats] %s rows in %.2fs (%d rows/s); last %s ' \
 *                       'rows in %.2fs (%d rows/s)' \
 *                       % (counter, elapsed, counter / elapsed,             # <<<<<<<<<<<<<<
 *                          batch_size, batch_elapsed, batch_size / batch_elapsed)
 *                 print(msg, file=_sys.stderr)
 */
        __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_v_counter, __pyx_v_elapsed); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4085; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_2);

        /* "pysamstats.pyx":4086
 *                       'rows in %.2fs (%d rows/s)' \
 *                       % (counter, elapsed, counter / elapsed,
 *                          batch_size, batch_elapsed, batch_size / batch_elapsed)             # <<<<<<<<<<<<<<
 *                 print(msg, file=_sys.stderr)
 *                 before = after
 */
        __pyx_t_6 = __Pyx_PyNumber_Divide(__pyx_v_batch_size, __pyx_v_batch_elapsed); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4086; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_6);

        /* "pysamstats.pyx":4085
 *                 msg = '[pysamstats] %s rows in %.2fs (%d rows/s); last %s ' \
 *                       'rows in %.2fs (%d rows/s)' \
 *                       % (counter, elapsed, counter / elapsed,             # <<<<<<<<<<<<<<
 *                          batch_size, batch_elapsed, batch_size / batch_elapsed)
 *                 print(msg, file=_sys.stderr)
 */
        __pyx_t_14 = PyTuple_New(6); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4085; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_INCREF(__pyx_v_counter);
        PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_counter);
        __Pyx_GIVEREF(__pyx_v_counter);
        __Pyx_INCREF(__pyx_v_elapsed);
        PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_v_elapsed);
        __Pyx_GIVEREF(__pyx_v_elapsed);
        PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_v_batch_size);
        PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_v_batch_size);
        __Pyx_GIVEREF(__pyx_v_batch_size);
        __Pyx_INCREF(__pyx_v_batch_elapsed);
        PyTuple_SET_ITEM(__pyx_t_14, 4, __pyx_v_batch_elapsed);
        __Pyx_GIVEREF(__pyx_v_batch_elapsed);
        PyTuple_SET_ITEM(__pyx_t_14, 5, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_6);
        __pyx_t_2 = 0;
        __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_pysamstats_s_rows_in_2fs_d_rows_3, __pyx_t_14); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4085; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_XDECREF_SET(__pyx_v_msg, ((PyObject*)__pyx_t_6));
        __pyx_t_6 = 0;

        /* "pysamstats.pyx":4087
 *                       % (counter, elapsed, counter / elapsed,
 *                          batch_size, batch_elapsed, batch_size / batch_elapsed)
 *                 print(msg, file=_sys.stderr)             # <<<<<<<<<<<<<<
 *                 before = after
 *                 counter_before = counter
 */
        __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4087; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_v_msg);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_msg);
        __Pyx_GIVEREF(__pyx_v_msg);
        __pyx_t_14 = PyDict_New(); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4087; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4087; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_stderr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4087; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_file, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4087; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_t_6, __pyx_t_14); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4087; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pysamstats.pyx":4088
 *                          batch_size, batch_elapsed, batch_size / batch_elapsed)
 *                 print(msg, file=_sys.stderr)
 *                 before = after             # <<<<<<<<<<<<<<
 *                 counter_before = counter
 * 
 */
        __Pyx_INCREF(__pyx_v_after);
        __Pyx_DECREF_SET(__pyx_v_before, __pyx_v_after);

        /* "pysamstats.pyx":4089
 *                 print(msg, file=_sys.stderr)
 *                 before = after
 *                 counter_before = counter             # <<<<<<<<<<<<<<
 * 
 *             # load next batch
 */
        __Pyx_INCREF(__pyx_v_counter);
        __Pyx_DECREF_SET(__pyx_v_counter_before, __pyx_v_counter);
        goto __pyx_L21;
      }
      __pyx_L21:;

      /* "pysamstats.pyx":4092
 * 
 *             # load next batch
 *             chunk = list(_itertools.islice(rows, hdf5_chunklen))             # <<<<<<<<<<<<<<
 * 
 *         if progress:
 */
      __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_itertools); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4092; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_islice); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4092; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = NULL;
      __pyx_t_7 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_14)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_14);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
          __pyx_t_7 = 1;
        }
      }
      __pyx_t_2 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4092; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_2);
      if (__pyx_t_14) {
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); __Pyx_GIVEREF(__pyx_t_14); __pyx_t_14 = NULL;
      }
      __Pyx_INCREF(__pyx_v_rows);
      PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_7, __pyx_v_rows);
      __Pyx_GIVEREF(__pyx_v_rows);
      __Pyx_INCREF(__pyx_v_hdf5_chunklen);
      PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_7, __pyx_v_hdf5_chunklen);
      __Pyx_GIVEREF(__pyx_v_hdf5_chunklen);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4092; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4092; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4092; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF_SET(__pyx_v_chunk, ((PyObject*)__pyx_t_3));
      __pyx_t_3 = 0;
    }

    /* "pysamstats.pyx":4094
 *             chunk = list(_itertools.islice(rows, hdf5_chunklen))
 * 
 *         if progress:             # <<<<<<<<<<<<<<
 *             after_all = _time.time()
 *             elapsed_all = after_all - before_all
 */
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_progress); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4094; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
    if (__pyx_t_5) {

      /* "pysamstats.pyx":4095
 * 
 *         if progress:
 *             after_all = _time.time()             # <<<<<<<<<<<<<<
 *             elapsed_all = after_all - before_all
 *             msg = '[pysamstats] %s rows in %.2fs (%d rows/s)' \
 */
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4095; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_time_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4095; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (__pyx_t_6) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4095; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else {
        __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4095; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      }
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_after_all = __pyx_t_3;
      __pyx_t_3 = 0;

      /* "pysamstats.pyx":4096
 *         if progress:
 *             after_all = _time.time()
 *             elapsed_all = after_all - before_all             # <<<<<<<<<<<<<<
 *             msg = '[pysamstats] %s rows in %.2fs (%d rows/s)' \
 *                   % (counter, elapsed_all, counter / elapsed_all)
 */
      __pyx_t_3 = PyNumber_Subtract(__pyx_v_after_all, __pyx_v_before_all); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4096; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_v_elapsed_all = __pyx_t_3;
      __pyx_t_3 = 0;

      /* "pysamstats.pyx":4098
 *             elapsed_all = after_all - before_all
 *             msg = '[pysamstats] %s rows in %.2fs (%d rows/s)' \
 *                   % (counter, elapsed_all, counter / elapsed_all)             # <<<<<<<<<<<<<<
 *             print(msg, file=_sys.stderr)
 * 
 */
      __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_v_counter, __pyx_v_elapsed_all); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4098; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4098; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_v_counter);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_counter);
      __Pyx_GIVEREF(__pyx_v_counter);
      __Pyx_INCREF(__pyx_v_elapsed_all);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_elapsed_all);
      __Pyx_GIVEREF(__pyx_v_elapsed_all);
      PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_pysamstats_s_rows_in_2fs_d_rows_2, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4098; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF_SET(__pyx_v_msg, ((PyObject*)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "pysamstats.pyx":4099
 *             msg = '[pysamstats] %s rows in %.2fs (%d rows/s)' \
 *                   % (counter, elapsed_all, counter / elapsed_all)
 *             print(msg, file=_sys.stderr)             # <<<<<<<<<<<<<<
 * 
 *     finally:
 */
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4099; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_v_msg);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_msg);
      __Pyx_GIVEREF(__pyx_v_msg);
      __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4099; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4099; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_stderr); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4099; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_file, __pyx_t_14) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4099; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4099; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      goto __pyx_L24;
    }
    __pyx_L24:;
  }

  /* "pysamstats.pyx":4102
 * 
 *     finally:
 *         if h5file is not None:             # <<<<<<<<<<<<<<
 *             h5file.close()
 * 
 */
  /*finally:*/ {
    /*normal exit:*/{
      __pyx_t_5 = (__pyx_v_h5file != Py_None);
      __pyx_t_4 = (__pyx_t_5 != 0);
      if (__pyx_t_4) {

        /* "pysamstats.pyx":4103
 *     finally:
 *         if h5file is not None:
 *             h5file.close()             # <<<<<<<<<<<<<<
 * 
 * 
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_h5file, __pyx_n_s_close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
          }
        }
        if (__pyx_t_3) {
          __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else {
          __pyx_t_14 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        goto __pyx_L25;
      }
      __pyx_L25:;
      goto __pyx_L10;
    }
    /*exception exit:*/{
      __pyx_L9_error:;
      __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_9 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9) < 0)) __Pyx_ErrFetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_11);
      __Pyx_XGOTREF(__pyx_t_10);
      __Pyx_XGOTREF(__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_18);
      __Pyx_XGOTREF(__pyx_t_19);
      __Pyx_XGOTREF(__pyx_t_20);
      __pyx_t_12 = __pyx_lineno; __pyx_t_16 = __pyx_clineno; __pyx_t_17 = __pyx_filename;
      {

        /* "pysamstats.pyx":4102
 * 
 *     finally:
 *         if h5file is not None:             # <<<<<<<<<<<<<<
 *             h5file.close()
 * 
 */
        __pyx_t_4 = (__pyx_v_h5file != Py_None);
        __pyx_t_5 = (__pyx_t_4 != 0);
        if (__pyx_t_5) {

          /* "pysamstats.pyx":4103
 *     finally:
 *         if h5file is not None:
 *             h5file.close()             # <<<<<<<<<<<<<<
 * 
 * 
 */
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_h5file, __pyx_n_s_close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4103; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_3 = NULL;
          if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
            __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
            if (likely(__pyx_t_3)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_2, function);
            }
          }
          if (__pyx_t_3) {
            __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4103; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          } else {
            __pyx_t_14 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4103; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
          }
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          goto __pyx_L28;
        }
        __pyx_L28:;
      }
      if (PY_MAJOR_VERSION >= 3) {
        __Pyx_XGIVEREF(__pyx_t_18);
        __Pyx_XGIVEREF(__pyx_t_19);
        __Pyx_XGIVEREF(__pyx_t_20);
        __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20);
      }
      __Pyx_XGIVEREF(__pyx_t_11);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_ErrRestore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
      __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_9 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
      __pyx_lineno = __pyx_t_12; __pyx_clineno = __pyx_t_16; __pyx_filename = __pyx_t_17;
      goto __pyx_L1_error;
      __pyx_L27_error:;
      if (PY_MAJOR_VERSION >= 3) {
        __Pyx_XGIVEREF(__pyx_t_18);
        __Pyx_XGIVEREF(__pyx_t_19);
        __Pyx_XGIVEREF(__pyx_t_20);
        __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20);
      }
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
      goto __pyx_L1_error;
    }
    __pyx_L10:;
  }

  /* "pysamstats.pyx":3962
 * 
 * 
 * def write_hdf5(stats_type, outfile, alignmentfile, fields=None, progress=None,             # <<<<<<<<<<<<<<
 *                hdf5_group='/', hdf5_dataset='data', hdf5_complevel=5,
 *                hdf5_complib='zlib', hdf5_shuffle=True,
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_AddTraceback("pysamstats.write_hdf5", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_tables);
  __Pyx_XDECREF(__pyx_v_np);
  __Pyx_XDECREF(__pyx_v_h5file);
  __Pyx_XDECREF(__pyx_v_stats_function);
  __Pyx_XDECREF(__pyx_v_default_dtype);
  __Pyx_XDECREF(__pyx_v_dtype);
  __Pyx_XDECREF(__pyx_v_dtype_overrides);
  __Pyx_XDECREF(__pyx_v_recs);
  __Pyx_XDECREF(__pyx_v_rows);
  __Pyx_XDECREF(__pyx_v_hdf5_chunklen);
  __Pyx_XDECREF(__pyx_v_hdf5_chunkshape);
  __Pyx_XDECREF(__pyx_v_h5table);
  __Pyx_XDECREF(__pyx_v_counter);
  __Pyx_XDECREF(__pyx_v_counter_before);
  __Pyx_XDECREF(__pyx_v_before);
  __Pyx_XDECREF(__pyx_v_before_all);
  __Pyx_XDECREF(__pyx_v_chunk);
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_after);
  __Pyx_XDECREF(__pyx_v_elapsed);
  __Pyx_XDECREF(__pyx_v_batch_elapsed);
  __Pyx_XDECREF(__pyx_v_batch_size);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_after_all);
  __Pyx_XDECREF(__pyx_v_elapsed_all);
  __Pyx_XDECREF(__pyx_v_f);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":4109
 * 
 * 
 * def flatten(recs, *fields):             # <<<<<<<<<<<<<<
 *     """Convert a record (dict) iterator to a row (tuple) iterator.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_158flatten(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_157flatten[] = "flatten(recs, *fields)\nConvert a record (dict) iterator to a row (tuple) iterator.\n\n    Parameters\n    ----------\n\n    recs : iterator of dicts\n        records generator\n    fields : list of strings\n        names of fields to select\n\n    Returns\n    -------\n\n    rows : iterator of tuples\n        rows generator\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_158flatten = {"flatten", (PyCFunction)__pyx_pw_10pysamstats_158flatten, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_157flatten};
static PyObject *__pyx_pw_10pysamstats_158flatten(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_recs = 0;
  PyObject *__pyx_v_fields = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("flatten (wrapper)", 0);
  if (PyTuple_GET_SIZE(__pyx_args) > 1) {
    __pyx_v_fields = PyTuple_GetSlice(__pyx_args, 1, PyTuple_GET_SIZE(__pyx_args));
    if (unlikely(!__pyx_v_fields)) {
      __Pyx_RefNannyFinishContext();
      return NULL;
    }
    __Pyx_GOTREF(__pyx_v_fields);
  } else {
    __pyx_v_fields = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_recs,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        default:
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_recs)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t used_pos_args = (pos_args < 1) ? pos_args : 1;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "flatten") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4109; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) < 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_recs = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("flatten", 0, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4109; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_fields); __pyx_v_fields = 0;
  __Pyx_AddTraceback("pysamstats.flatten", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_157flatten(__pyx_self, __pyx_v_recs, __pyx_v_fields);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_7flatten_2generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysamstats.pyx":4129
 * 
 *     getter = itemgetter(*fields)
 *     it = (getter(rec) for rec in recs)             # <<<<<<<<<<<<<<
 *     return it
 * 
 */

static PyObject *__pyx_pf_10pysamstats_7flatten_genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_5_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_5_genexpr *)__pyx_tp_new_10pysamstats___pyx_scope_struct_5_genexpr(__pyx_ptype_10pysamstats___pyx_scope_struct_5_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_4_flatten *) __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_7flatten_2generator4, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_flatten_locals_genexpr); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

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

static PyObject *__pyx_gb_10pysamstats_7flatten_2generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_5_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;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L6_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4129; __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 = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
  if (likely(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 = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(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 = 4129; __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 = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        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 = 4129; __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 = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_rec);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_rec, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_getter)) { __Pyx_RaiseClosureNameError("getter"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __Pyx_INCREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_getter);
    __pyx_t_5 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_getter; __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_cur_scope->__pyx_v_rec); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
    } else {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_rec);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_cur_scope->__pyx_v_rec);
      __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_rec);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 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 = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __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":4109
 * 
 * 
 * def flatten(recs, *fields):             # <<<<<<<<<<<<<<
 *     """Convert a record (dict) iterator to a row (tuple) iterator.
 * 
 */

static PyObject *__pyx_pf_10pysamstats_157flatten(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_recs, PyObject *__pyx_v_fields) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten *__pyx_cur_scope;
  PyObject *__pyx_v_it = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("flatten", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten *)__pyx_tp_new_10pysamstats___pyx_scope_struct_4_flatten(__pyx_ptype_10pysamstats___pyx_scope_struct_4_flatten, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_recs = __pyx_v_recs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_recs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_recs);

  /* "pysamstats.pyx":4128
 *     """
 * 
 *     getter = itemgetter(*fields)             # <<<<<<<<<<<<<<
 *     it = (getter(rec) for rec in recs)
 *     return it
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_itemgetter); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PySequence_Tuple(__pyx_v_fields); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_cur_scope->__pyx_v_getter = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":4129
 * 
 *     getter = itemgetter(*fields)
 *     it = (getter(rec) for rec in recs)             # <<<<<<<<<<<<<<
 *     return it
 * 
 */
  __pyx_t_3 = __pyx_pf_10pysamstats_7flatten_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_it = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":4130
 *     getter = itemgetter(*fields)
 *     it = (getter(rec) for rec in recs)
 *     return it             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_it);
  __pyx_r = __pyx_v_it;
  goto __pyx_L0;

  /* "pysamstats.pyx":4109
 * 
 * 
 * def flatten(recs, *fields):             # <<<<<<<<<<<<<<
 *     """Convert a record (dict) iterator to a row (tuple) iterator.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysamstats.flatten", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_it);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":4133
 * 
 * 
 * def tabulate(stat, *args, **kwargs):             # <<<<<<<<<<<<<<
 *     """Tabulate statistics.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_160tabulate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_159tabulate[] = "tabulate(stat, *args, **kwargs)\nTabulate statistics.\n\n    Parameters\n    ----------\n\n    stat : string\n        statistics type\n    *args\n        passed through to statistics function\n    fields : list of strings\n        names of fields to select\n    **args\n        passed through to statistics function\n\n    Returns\n    -------\n\n    table : row container\n\n    ";
static PyMethodDef __pyx_mdef_10pysamstats_160tabulate = {"tabulate", (PyCFunction)__pyx_pw_10pysamstats_160tabulate, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_159tabulate};
static PyObject *__pyx_pw_10pysamstats_160tabulate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_stat = 0;
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("tabulate (wrapper)", 0);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  if (PyTuple_GET_SIZE(__pyx_args) > 1) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 1, PyTuple_GET_SIZE(__pyx_args));
    if (unlikely(!__pyx_v_args)) {
      __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
      __Pyx_RefNannyFinishContext();
      return NULL;
    }
    __Pyx_GOTREF(__pyx_v_args);
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_stat,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        default:
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_stat)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t used_pos_args = (pos_args < 1) ? pos_args : 1;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, used_pos_args, "tabulate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4133; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) < 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_stat = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("tabulate", 0, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4133; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args); __pyx_v_args = 0;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.tabulate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_159tabulate(__pyx_self, __pyx_v_stat, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_159tabulate(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_stat, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  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("tabulate", 0);

  /* "pysamstats.pyx":4155
 *     """
 * 
 *     return _StatsTable(stat, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_StatsTable); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_stat);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_stat);
  __Pyx_GIVEREF(__pyx_v_stat);
  __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":4133
 * 
 * 
 * def tabulate(stat, *args, **kwargs):             # <<<<<<<<<<<<<<
 *     """Tabulate statistics.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.tabulate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":4160
 * class _StatsTable(object):
 * 
 *     def __init__(self, stats_type, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         try:
 *             self.stats_function = globals()['stat_' + stats_type]
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_11_StatsTable_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_11_StatsTable___init__[] = "_StatsTable.__init__(self, stats_type, *args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_11_StatsTable_1__init__ = {"__init__", (PyCFunction)__pyx_pw_10pysamstats_11_StatsTable_1__init__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_11_StatsTable___init__};
static PyObject *__pyx_pw_10pysamstats_11_StatsTable_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_stats_type = 0;
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  if (PyTuple_GET_SIZE(__pyx_args) > 2) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 2, PyTuple_GET_SIZE(__pyx_args));
    if (unlikely(!__pyx_v_args)) {
      __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
      __Pyx_RefNannyFinishContext();
      return NULL;
    }
    __Pyx_GOTREF(__pyx_v_args);
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_stats_type,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        default:
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_stats_type)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4160; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t used_pos_args = (pos_args < 2) ? pos_args : 2;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, used_pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4160; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) < 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_stats_type = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4160; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args); __pyx_v_args = 0;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats._StatsTable.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_11_StatsTable___init__(__pyx_self, __pyx_v_self, __pyx_v_stats_type, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_11_StatsTable___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_stats_type, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "pysamstats.pyx":4161
 * 
 *     def __init__(self, stats_type, *args, **kwargs):
 *         try:             # <<<<<<<<<<<<<<
 *             self.stats_function = globals()['stat_' + stats_type]
 *             self.fields = kwargs.pop('fields', None)
 */
  {
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "pysamstats.pyx":4162
 *     def __init__(self, stats_type, *args, **kwargs):
 *         try:
 *             self.stats_function = globals()['stat_' + stats_type]             # <<<<<<<<<<<<<<
 *             self.fields = kwargs.pop('fields', None)
 *             if self.fields is None:
 */
      __pyx_t_4 = __Pyx_Globals(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4162; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = PyNumber_Add(__pyx_n_s_stat_2, __pyx_v_stats_type); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4162; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyObject_GetItem(__pyx_t_4, __pyx_t_5); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4162; __pyx_clineno = __LINE__; goto __pyx_L3_error;};
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_stats_function, __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4162; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "pysamstats.pyx":4163
 *         try:
 *             self.stats_function = globals()['stat_' + stats_type]
 *             self.fields = kwargs.pop('fields', None)             # <<<<<<<<<<<<<<
 *             if self.fields is None:
 *                 self.fields = globals()['fields_' + stats_type]
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_kwargs, __pyx_n_s_pop); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4163; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4163; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_fields, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4163; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "pysamstats.pyx":4164
 *             self.stats_function = globals()['stat_' + stats_type]
 *             self.fields = kwargs.pop('fields', None)
 *             if self.fields is None:             # <<<<<<<<<<<<<<
 *                 self.fields = globals()['fields_' + stats_type]
 *             self.args = args
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fields); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4164; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = (__pyx_t_5 == Py_None);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_8 = (__pyx_t_7 != 0);
      if (__pyx_t_8) {

        /* "pysamstats.pyx":4165
 *             self.fields = kwargs.pop('fields', None)
 *             if self.fields is None:
 *                 self.fields = globals()['fields_' + stats_type]             # <<<<<<<<<<<<<<
 *             self.args = args
 *             self.kwargs = kwargs
 */
        __pyx_t_5 = __Pyx_Globals(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4165; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = PyNumber_Add(__pyx_n_s_fields_2, __pyx_v_stats_type); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4165; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_4 = PyObject_GetItem(__pyx_t_5, __pyx_t_6); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4165; __pyx_clineno = __LINE__; goto __pyx_L3_error;};
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_fields, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4165; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        goto __pyx_L11;
      }
      __pyx_L11:;

      /* "pysamstats.pyx":4166
 *             if self.fields is None:
 *                 self.fields = globals()['fields_' + stats_type]
 *             self.args = args             # <<<<<<<<<<<<<<
 *             self.kwargs = kwargs
 *         except KeyError:
 */
      if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_args, __pyx_v_args) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4166; __pyx_clineno = __LINE__; goto __pyx_L3_error;}

      /* "pysamstats.pyx":4167
 *                 self.fields = globals()['fields_' + stats_type]
 *             self.args = args
 *             self.kwargs = kwargs             # <<<<<<<<<<<<<<
 *         except KeyError:
 *             raise Exception('statistics type not found: %r' % stats_type)
 */
      if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_kwargs, __pyx_v_kwargs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4167; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L10_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysamstats.pyx":4168
 *             self.args = args
 *             self.kwargs = kwargs
 *         except KeyError:             # <<<<<<<<<<<<<<
 *             raise Exception('statistics type not found: %r' % stats_type)
 * 
 */
    __pyx_t_9 = PyErr_ExceptionMatches(__pyx_builtin_KeyError);
    if (__pyx_t_9) {
      __Pyx_AddTraceback("pysamstats._StatsTable.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4168; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_5);

      /* "pysamstats.pyx":4169
 *             self.kwargs = kwargs
 *         except KeyError:
 *             raise Exception('statistics type not found: %r' % stats_type)             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
      __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_statistics_type_not_found_r, __pyx_v_stats_type); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4169; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4169; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}
      __Pyx_GOTREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_10);
      __pyx_t_10 = 0;
      __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_Exception, __pyx_t_11, NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4169; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_Raise(__pyx_t_10, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4169; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L10_try_end:;
  }

  /* "pysamstats.pyx":4160
 * class _StatsTable(object):
 * 
 *     def __init__(self, stats_type, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         try:
 *             self.stats_function = globals()['stat_' + stats_type]
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("pysamstats._StatsTable.__init__", __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_11_StatsTable_4generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysamstats.pyx":4171
 *             raise Exception('statistics type not found: %r' % stats_type)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         recs = self.stats_function(*self.args, **self.kwargs)
 *         fields = tuple(self.fields)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_11_StatsTable_3__iter__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_10pysamstats_11_StatsTable_2__iter__[] = "_StatsTable.__iter__(self)";
static PyMethodDef __pyx_mdef_10pysamstats_11_StatsTable_3__iter__ = {"__iter__", (PyCFunction)__pyx_pw_10pysamstats_11_StatsTable_3__iter__, METH_O, __pyx_doc_10pysamstats_11_StatsTable_2__iter__};
static PyObject *__pyx_pw_10pysamstats_11_StatsTable_3__iter__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10pysamstats_11_StatsTable_2__iter__(__pyx_self, ((PyObject *)__pyx_v_self));

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

static PyObject *__pyx_pf_10pysamstats_11_StatsTable_2__iter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ *)__pyx_tp_new_10pysamstats___pyx_scope_struct_6___iter__(__pyx_ptype_10pysamstats___pyx_scope_struct_6___iter__, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_11_StatsTable_4generator3, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_StatsTable___iter); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats._StatsTable.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_11_StatsTable_4generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ *)__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;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L4_resume_from_yield;
    case 2: goto __pyx_L7_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 = 4171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":4172
 * 
 *     def __iter__(self):
 *         recs = self.stats_function(*self.args, **self.kwargs)             # <<<<<<<<<<<<<<
 *         fields = tuple(self.fields)
 *         rows = flatten(recs, *fields)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_stats_function); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_kwargs); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (unlikely(__pyx_t_4 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  if (likely(PyDict_Check(__pyx_t_4))) {
    __pyx_t_2 = __pyx_t_4;
    __Pyx_INCREF(__pyx_t_2);
  } else {
    __pyx_t_2 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4172; __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_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__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":4173
 *     def __iter__(self):
 *         recs = self.stats_function(*self.args, **self.kwargs)
 *         fields = tuple(self.fields)             # <<<<<<<<<<<<<<
 *         rows = flatten(recs, *fields)
 *         yield fields
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_fields); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4173; __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 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_cur_scope->__pyx_v_fields = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":4174
 *         recs = self.stats_function(*self.args, **self.kwargs)
 *         fields = tuple(self.fields)
 *         rows = flatten(recs, *fields)             # <<<<<<<<<<<<<<
 *         yield fields
 *         for row in rows:
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_flatten); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_recs);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_recs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_recs);
  __pyx_t_3 = PySequence_Tuple(__pyx_cur_scope->__pyx_v_fields); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_cur_scope->__pyx_v_rows = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":4175
 *         fields = tuple(self.fields)
 *         rows = flatten(recs, *fields)
 *         yield fields             # <<<<<<<<<<<<<<
 *         for row in rows:
 *             yield row
 */
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fields);
  __pyx_r = __pyx_cur_scope->__pyx_v_fields;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  /* return from generator, yielding value */
  __pyx_generator->resume_label = 1;
  return __pyx_r;
  __pyx_L4_resume_from_yield:;
  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":4176
 *         rows = flatten(recs, *fields)
 *         yield fields
 *         for row in rows:             # <<<<<<<<<<<<<<
 *             yield row
 * 
 */
  if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_rows)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_rows)) {
    __pyx_t_3 = __pyx_cur_scope->__pyx_v_rows; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_rows); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_3);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_row);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_row, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysamstats.pyx":4177
 *         yield fields
 *         for row in rows:
 *             yield row             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_row);
    __pyx_r = __pyx_cur_scope->__pyx_v_row;
    __Pyx_XGIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_3;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_5;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_6;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 2;
    return __pyx_r;
    __pyx_L7_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_5 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_6 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":4176
 *         rows = flatten(recs, *fields)
 *         yield fields
 *         for row in rows:             # <<<<<<<<<<<<<<
 *             yield row
 * 
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysamstats.pyx":4171
 *             raise Exception('statistics type not found: %r' % stats_type)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         recs = self.stats_function(*self.args, **self.kwargs)
 *         fields = tuple(self.fields)
 */

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("__iter__", __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":4180
 * 
 * 
 * def _load_stats(statfun, default_dtype, *args, **kwargs):             # <<<<<<<<<<<<<<
 * 
 *     import numpy as np
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_162_load_stats(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_161_load_stats[] = "_load_stats(statfun, default_dtype, *args, **kwargs)";
static PyMethodDef __pyx_mdef_10pysamstats_162_load_stats = {"_load_stats", (PyCFunction)__pyx_pw_10pysamstats_162_load_stats, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_161_load_stats};
static PyObject *__pyx_pw_10pysamstats_162_load_stats(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_statfun = 0;
  PyObject *__pyx_v_default_dtype = 0;
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_load_stats (wrapper)", 0);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  if (PyTuple_GET_SIZE(__pyx_args) > 2) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 2, PyTuple_GET_SIZE(__pyx_args));
    if (unlikely(!__pyx_v_args)) {
      __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
      __Pyx_RefNannyFinishContext();
      return NULL;
    }
    __Pyx_GOTREF(__pyx_v_args);
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_statfun,&__pyx_n_s_default_dtype,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        default:
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
      }
      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_default_dtype)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_load_stats", 0, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t used_pos_args = (pos_args < 2) ? pos_args : 2;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, used_pos_args, "_load_stats") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) < 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_statfun = values[0];
    __pyx_v_default_dtype = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_load_stats", 0, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args); __pyx_v_args = 0;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats._load_stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_161_load_stats(__pyx_self, __pyx_v_statfun, __pyx_v_default_dtype, __pyx_v_args, __pyx_v_kwargs);

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

static PyObject *__pyx_pf_10pysamstats_161_load_stats(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_statfun, PyObject *__pyx_v_default_dtype, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_np = NULL;
  PyObject *__pyx_v_fields = NULL;
  PyObject *__pyx_v_dtype = NULL;
  PyObject *__pyx_v_dtype_overrides = NULL;
  PyObject *__pyx_v_recs = NULL;
  PyObject *__pyx_v_it = NULL;
  PyObject *__pyx_v_a = NULL;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_v_f = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_load_stats", 0);

  /* "pysamstats.pyx":4182
 * def _load_stats(statfun, default_dtype, *args, **kwargs):
 * 
 *     import numpy as np             # <<<<<<<<<<<<<<
 * 
 *     # determine fields to load
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_np = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":4185
 * 
 *     # determine fields to load
 *     fields = kwargs.pop('fields', None)             # <<<<<<<<<<<<<<
 *     if not fields:
 *         fields = [t[0] for t in default_dtype]
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_kwargs, __pyx_n_s_pop); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_fields = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":4186
 *     # determine fields to load
 *     fields = kwargs.pop('fields', None)
 *     if not fields:             # <<<<<<<<<<<<<<
 *         fields = [t[0] for t in default_dtype]
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_fields); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {

    /* "pysamstats.pyx":4187
 *     fields = kwargs.pop('fields', None)
 *     if not fields:
 *         fields = [t[0] for t in default_dtype]             # <<<<<<<<<<<<<<
 * 
 *     # determine dtype
 */
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if (likely(PyList_CheckExact(__pyx_v_default_dtype)) || PyTuple_CheckExact(__pyx_v_default_dtype)) {
      __pyx_t_1 = __pyx_v_default_dtype; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_default_dtype); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    for (;;) {
      if (likely(!__pyx_t_6)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        }
      } else {
        __pyx_t_7 = __pyx_t_6(__pyx_t_1);
        if (unlikely(!__pyx_t_7)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_7);
      }
      __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_t, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4187; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_7);
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_fields, __pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":4190
 * 
 *     # determine dtype
 *     dtype = dict(default_dtype)             # <<<<<<<<<<<<<<
 *     dtype_overrides = kwargs.pop('dtype', None)
 *     if dtype_overrides:
 */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_default_dtype);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_default_dtype);
  __Pyx_GIVEREF(__pyx_v_default_dtype);
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_dtype = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":4191
 *     # determine dtype
 *     dtype = dict(default_dtype)
 *     dtype_overrides = kwargs.pop('dtype', None)             # <<<<<<<<<<<<<<
 *     if dtype_overrides:
 *         # expect dict
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_kwargs, __pyx_n_s_pop); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_dtype_overrides = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":4192
 *     dtype = dict(default_dtype)
 *     dtype_overrides = kwargs.pop('dtype', None)
 *     if dtype_overrides:             # <<<<<<<<<<<<<<
 *         # expect dict
 *         dtype.update(dtype_overrides)
 */
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_dtype_overrides); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_4) {

    /* "pysamstats.pyx":4194
 *     if dtype_overrides:
 *         # expect dict
 *         dtype.update(dtype_overrides)             # <<<<<<<<<<<<<<
 *     if len(fields) == 1:
 *         dtype = dtype[fields[0]]
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dtype, __pyx_n_s_update); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_7) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_dtype_overrides); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __Pyx_GIVEREF(__pyx_t_7); __pyx_t_7 = NULL;
      __Pyx_INCREF(__pyx_v_dtype_overrides);
      PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_dtype_overrides);
      __Pyx_GIVEREF(__pyx_v_dtype_overrides);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "pysamstats.pyx":4195
 *         # expect dict
 *         dtype.update(dtype_overrides)
 *     if len(fields) == 1:             # <<<<<<<<<<<<<<
 *         dtype = dtype[fields[0]]
 *     else:
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_fields); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = ((__pyx_t_5 == 1) != 0);
  if (__pyx_t_4) {

    /* "pysamstats.pyx":4196
 *         dtype.update(dtype_overrides)
 *     if len(fields) == 1:
 *         dtype = dtype[fields[0]]             # <<<<<<<<<<<<<<
 *     else:
 *         dtype = [(f, dtype[f]) for f in fields]
 */
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_fields, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4196; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_dtype, __pyx_t_2); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4196; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_dtype, __pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L7;
  }
  /*else*/ {

    /* "pysamstats.pyx":4198
 *         dtype = dtype[fields[0]]
 *     else:
 *         dtype = [(f, dtype[f]) for f in fields]             # <<<<<<<<<<<<<<
 * 
 *     # setup record generator
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (likely(PyList_CheckExact(__pyx_v_fields)) || PyTuple_CheckExact(__pyx_v_fields)) {
      __pyx_t_2 = __pyx_v_fields; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_fields); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    for (;;) {
      if (likely(!__pyx_t_6)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_8 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_8); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_8); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        }
      } else {
        __pyx_t_8 = __pyx_t_6(__pyx_t_2);
        if (unlikely(!__pyx_t_8)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_8);
      }
      __Pyx_XDECREF_SET(__pyx_v_f, __pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_8 = PyObject_GetItem(__pyx_v_dtype, __pyx_v_f); if (unlikely(__pyx_t_8 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4198; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_v_f);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_f);
      __Pyx_GIVEREF(__pyx_v_f);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      __pyx_t_8 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_dtype, __pyx_t_1);
    __pyx_t_1 = 0;
  }
  __pyx_L7:;

  /* "pysamstats.pyx":4201
 * 
 *     # setup record generator
 *     recs = statfun(*args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 *     # flatten records
 */
  __pyx_t_1 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_v_statfun, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_recs = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "pysamstats.pyx":4204
 * 
 *     # flatten records
 *     it = flatten(recs, *fields)             # <<<<<<<<<<<<<<
 * 
 *     # load into a Numpy array
 */
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_flatten); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_recs);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_recs);
  __Pyx_GIVEREF(__pyx_v_recs);
  __pyx_t_1 = PySequence_Tuple(__pyx_v_fields); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = PyNumber_Add(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_it = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":4207
 * 
 *     # load into a Numpy array
 *     a = np.fromiter(it, dtype=dtype)             # <<<<<<<<<<<<<<
 * 
 *     # view as recarray for convenience
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_np, __pyx_n_s_fromiter); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_INCREF(__pyx_v_it);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_it);
  __Pyx_GIVEREF(__pyx_v_it);
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype_2, __pyx_v_dtype) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_a = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":4210
 * 
 *     # view as recarray for convenience
 *     if len(fields) > 1:             # <<<<<<<<<<<<<<
 *         a = a.view(np.recarray)
 * 
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_fields); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = ((__pyx_t_5 > 1) != 0);
  if (__pyx_t_4) {

    /* "pysamstats.pyx":4211
 *     # view as recarray for convenience
 *     if len(fields) > 1:
 *         a = a.view(np.recarray)             # <<<<<<<<<<<<<<
 * 
 *     return a
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_n_s_view); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_np, __pyx_n_s_recarray); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_1 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (!__pyx_t_1) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = NULL;
      PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF_SET(__pyx_v_a, __pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "pysamstats.pyx":4213
 *         a = a.view(np.recarray)
 * 
 *     return a             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_a);
  __pyx_r = __pyx_v_a;
  goto __pyx_L0;

  /* "pysamstats.pyx":4180
 * 
 * 
 * def _load_stats(statfun, default_dtype, *args, **kwargs):             # <<<<<<<<<<<<<<
 * 
 *     import numpy as np
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysamstats._load_stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_np);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_dtype);
  __Pyx_XDECREF(__pyx_v_dtype_overrides);
  __Pyx_XDECREF(__pyx_v_recs);
  __Pyx_XDECREF(__pyx_v_it);
  __Pyx_XDECREF(__pyx_v_a);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_f);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":4216
 * 
 * 
 * cdef inline bint _is_softclipped(bam1_t * aln):             # <<<<<<<<<<<<<<
 *     cdef int k
 *     cigar_p = pysam_bam_get_cigar(aln)
 */

static CYTHON_INLINE int __pyx_f_10pysamstats__is_softclipped(bam1_t *__pyx_v_aln) {
  int __pyx_v_k;
  uint32_t *__pyx_v_cigar_p;
  long __pyx_v_op;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("_is_softclipped", 0);

  /* "pysamstats.pyx":4218
 * cdef inline bint _is_softclipped(bam1_t * aln):
 *     cdef int k
 *     cigar_p = pysam_bam_get_cigar(aln)             # <<<<<<<<<<<<<<
 *     for k in range(aln.core.n_cigar):
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_aln);

  /* "pysamstats.pyx":4219
 *     cdef int k
 *     cigar_p = pysam_bam_get_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":4220
 *     cigar_p = pysam_bam_get_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":4221
 *     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) != 0);
    if (__pyx_t_3) {

      /* "pysamstats.pyx":4222
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 *         if op == BAM_CSOFT_CLIP:
 *             return 1             # <<<<<<<<<<<<<<
 *     return 0
 * 
 */
      __pyx_r = 1;
      goto __pyx_L0;
    }
  }

  /* "pysamstats.pyx":4223
 *         if op == BAM_CSOFT_CLIP:
 *             return 1
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":4216
 * 
 * 
 * cdef inline bint _is_softclipped(bam1_t * aln):             # <<<<<<<<<<<<<<
 *     cdef int k
 *     cigar_p = pysam_bam_get_cigar(aln)
 */

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

/* "pysamstats.pyx":4226
 * 
 * 
 * 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":4230
 *     cdef char * s
 * 
 *     if not src.core.l_qseq:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = ((!(__pyx_v_src->core.l_qseq != 0)) != 0);
  if (__pyx_t_1) {

    /* "pysamstats.pyx":4231
 * 
 *     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;
  }

  /* "pysamstats.pyx":4233
 *         return None
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, 1)             # <<<<<<<<<<<<<<
 *     s   = <char*>seq
 *     p   = pysam_bam_get_seq(src)
 */
  __pyx_t_2 = PyBytes_FromStringAndSize(NULL, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4233; __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":4234
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, 1)
 *     s   = <char*>seq             # <<<<<<<<<<<<<<
 *     p   = pysam_bam_get_seq(src)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_s = ((char *)__pyx_t_3);

  /* "pysamstats.pyx":4235
 *     seq = PyBytes_FromStringAndSize(NULL, 1)
 *     s   = <char*>seq
 *     p   = pysam_bam_get_seq(src)             # <<<<<<<<<<<<<<
 * 
 *     s[0] = bam_nt16_rev_table[p[k//2] >> 4 * (1 - k%2) & 0xf]
 */
  __pyx_v_p = pysam_bam_get_seq(__pyx_v_src);

  /* "pysamstats.pyx":4237
 *     p   = pysam_bam_get_seq(src)
 * 
 *     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":4239
 *     s[0] = bam_nt16_rev_table[p[k//2] >> 4 * (1 - k%2) & 0xf]
 * 
 *     return seq             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_seq);
  __pyx_r = __pyx_v_seq;
  goto __pyx_L0;

  /* "pysamstats.pyx":4226
 * 
 * 
 * cdef inline object _get_seq_base(bam1_t *src, uint32_t k):             # <<<<<<<<<<<<<<
 *     cdef uint8_t * p
 *     cdef char * s
 */

  /* function exit code */
  __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":4242
 * 
 * 
 * cdef inline int _rootmean(uint64_t sqsum, int count):             # <<<<<<<<<<<<<<
 *     if count > 0:
 *         return int(round(sqrt(sqsum / count)))
 */

static CYTHON_INLINE int __pyx_f_10pysamstats__rootmean(uint64_t __pyx_v_sqsum, int __pyx_v_count) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_rootmean", 0);

  /* "pysamstats.pyx":4243
 * 
 * cdef inline int _rootmean(uint64_t sqsum, int count):
 *     if count > 0:             # <<<<<<<<<<<<<<
 *         return int(round(sqrt(sqsum / count)))
 *     else:
 */
  __pyx_t_1 = ((__pyx_v_count > 0) != 0);
  if (__pyx_t_1) {

    /* "pysamstats.pyx":4244
 * cdef inline int _rootmean(uint64_t sqsum, int count):
 *     if count > 0:
 *         return int(round(sqrt(sqsum / count)))             # <<<<<<<<<<<<<<
 *     else:
 *         return 0
 */
    if (unlikely(__pyx_v_count == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_2 = PyFloat_FromDouble(sqrt((((double)__pyx_v_sqsum) / ((double)__pyx_v_count)))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysamstats.pyx":4246
 *         return int(round(sqrt(sqsum / count)))
 *     else:
 *         return 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_r = 0;
    goto __pyx_L0;
  }

  /* "pysamstats.pyx":4242
 * 
 * 
 * cdef inline int _rootmean(uint64_t sqsum, int count):             # <<<<<<<<<<<<<<
 *     if count > 0:
 *         return int(round(sqrt(sqsum / count)))
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("pysamstats._rootmean", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":4249
 * 
 * 
 * cdef inline int _mean(int64_t total, int count):             # <<<<<<<<<<<<<<
 *     if count > 0:
 *         return int(round(total / count))
 */

static CYTHON_INLINE int __pyx_f_10pysamstats__mean(int64_t __pyx_v_total, int __pyx_v_count) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_mean", 0);

  /* "pysamstats.pyx":4250
 * 
 * cdef inline int _mean(int64_t total, int count):
 *     if count > 0:             # <<<<<<<<<<<<<<
 *         return int(round(total / count))
 *     else:
 */
  __pyx_t_1 = ((__pyx_v_count > 0) != 0);
  if (__pyx_t_1) {

    /* "pysamstats.pyx":4251
 * cdef inline int _mean(int64_t total, int count):
 *     if count > 0:
 *         return int(round(total / count))             # <<<<<<<<<<<<<<
 *     else:
 *         return 0
 */
    if (unlikely(__pyx_v_count == 0)) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_2 = PyFloat_FromDouble((((double)__pyx_v_total) / ((double)__pyx_v_count))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysamstats.pyx":4253
 *         return int(round(total / count))
 *     else:
 *         return 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_r = 0;
    goto __pyx_L0;
  }

  /* "pysamstats.pyx":4249
 * 
 * 
 * cdef inline int _mean(int64_t total, int count):             # <<<<<<<<<<<<<<
 *     if count > 0:
 *         return int(round(total / count))
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("pysamstats._mean", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":4259
 * 
 * 
 * def count_reads(AlignmentFile alignmentfile, chrom=None, start=None, end=None):             # <<<<<<<<<<<<<<
 *     cdef IteratorRowRegion it
 *     cdef int n = 0
 */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_164count_reads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10pysamstats_163count_reads[] = "count_reads(AlignmentFile alignmentfile, chrom=None, start=None, end=None)";
static PyMethodDef __pyx_mdef_10pysamstats_164count_reads = {"count_reads", (PyCFunction)__pyx_pw_10pysamstats_164count_reads, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_163count_reads};
static PyObject *__pyx_pw_10pysamstats_164count_reads(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("count_reads (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_alignmentfile,&__pyx_n_s_chrom,&__pyx_n_s_start,&__pyx_n_s_end,0};
    PyObject* values[4] = {0,0,0,0};
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alignmentfile)) != 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--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count_reads") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4259; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_start = values[2];
    __pyx_v_end = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("count_reads", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4259; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.count_reads", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_alignmentfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "alignmentfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_163count_reads(__pyx_self, __pyx_v_alignmentfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end);

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

static PyObject *__pyx_pf_10pysamstats_163count_reads(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignmentfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end) {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_it = 0;
  int __pyx_v_n;
  CYTHON_UNUSED PyObject *__pyx_v_has_coord = NULL;
  PyObject *__pyx_v_rtid = NULL;
  PyObject *__pyx_v_rstart = NULL;
  PyObject *__pyx_v_rend = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *(*__pyx_t_8)(PyObject *);
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("count_reads", 0);

  /* "pysamstats.pyx":4261
 * def count_reads(AlignmentFile alignmentfile, chrom=None, start=None, end=None):
 *     cdef IteratorRowRegion it
 *     cdef int n = 0             # <<<<<<<<<<<<<<
 *     has_coord, rtid, rstart, rend = alignmentfile._parseRegion(chrom, start,
 *                                                                end,
 */
  __pyx_v_n = 0;

  /* "pysamstats.pyx":4262
 *     cdef IteratorRowRegion it
 *     cdef int n = 0
 *     has_coord, rtid, rstart, rend = alignmentfile._parseRegion(chrom, start,             # <<<<<<<<<<<<<<
 *                                                                end,
 *                                                                None)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alignmentfile), __pyx_n_s_parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysamstats.pyx":4264
 *     has_coord, rtid, rstart, rend = alignmentfile._parseRegion(chrom, start,
 *                                                                end,
 *                                                                None)             # <<<<<<<<<<<<<<
 *     it = IteratorRowRegion(alignmentfile, rtid, rstart, rend,
 *                            multiple_iterators=False)
 */
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (__pyx_t_3) {
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
  }
  __Pyx_INCREF(__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_v_chrom);
  __Pyx_INCREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_end);
  __Pyx_GIVEREF(__pyx_v_end);
  __Pyx_INCREF(Py_None);
  PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, Py_None);
  __Pyx_GIVEREF(Py_None);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
    PyObject* sequence = __pyx_t_1;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __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_5 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_6 = PyTuple_GET_ITEM(sequence, 3); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_6 = PyList_GET_ITEM(sequence, 3); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_6);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_5,&__pyx_t_3,&__pyx_t_6};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    Py_ssize_t index = -1;
    PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_5,&__pyx_t_3,&__pyx_t_6};
    __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
    for (index=0; index < 4; index++) {
      PyObject* item = __pyx_t_8(__pyx_t_7); if (unlikely(!item)) goto __pyx_L3_unpacking_failed;
      __Pyx_GOTREF(item);
      *(temps[index]) = item;
    }
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = NULL;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    goto __pyx_L4_unpacking_done;
    __pyx_L3_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_8 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L4_unpacking_done:;
  }

  /* "pysamstats.pyx":4262
 *     cdef IteratorRowRegion it
 *     cdef int n = 0
 *     has_coord, rtid, rstart, rend = alignmentfile._parseRegion(chrom, start,             # <<<<<<<<<<<<<<
 *                                                                end,
 *                                                                None)
 */
  __pyx_v_has_coord = __pyx_t_2;
  __pyx_t_2 = 0;
  __pyx_v_rtid = __pyx_t_5;
  __pyx_t_5 = 0;
  __pyx_v_rstart = __pyx_t_3;
  __pyx_t_3 = 0;
  __pyx_v_rend = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "pysamstats.pyx":4265
 *                                                                end,
 *                                                                None)
 *     it = IteratorRowRegion(alignmentfile, rtid, rstart, rend,             # <<<<<<<<<<<<<<
 *                            multiple_iterators=False)
 *     while True:
 */
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_alignmentfile));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_alignmentfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alignmentfile));
  __Pyx_INCREF(__pyx_v_rtid);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_rtid);
  __Pyx_GIVEREF(__pyx_v_rtid);
  __Pyx_INCREF(__pyx_v_rstart);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_rstart);
  __Pyx_GIVEREF(__pyx_v_rstart);
  __Pyx_INCREF(__pyx_v_rend);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_rend);
  __Pyx_GIVEREF(__pyx_v_rend);
  __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);

  /* "pysamstats.pyx":4266
 *                                                                None)
 *     it = IteratorRowRegion(alignmentfile, rtid, rstart, rend,
 *                            multiple_iterators=False)             # <<<<<<<<<<<<<<
 *     while True:
 *         it.cnext()
 */
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_multiple_iterators, Py_False) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":4265
 *                                                                end,
 *                                                                None)
 *     it = IteratorRowRegion(alignmentfile, rtid, rstart, rend,             # <<<<<<<<<<<<<<
 *                            multiple_iterators=False)
 *     while True:
 */
  __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion)), __pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_it = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":4267
 *     it = IteratorRowRegion(alignmentfile, rtid, rstart, rend,
 *                            multiple_iterators=False)
 *     while True:             # <<<<<<<<<<<<<<
 *         it.cnext()
 *         if it.retval > 0:
 */
  while (1) {

    /* "pysamstats.pyx":4268
 *                            multiple_iterators=False)
 *     while True:
 *         it.cnext()             # <<<<<<<<<<<<<<
 *         if it.retval > 0:
 *             n += 1
 */
    ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_v_it->__pyx_vtab)->cnext(__pyx_v_it);

    /* "pysamstats.pyx":4269
 *     while True:
 *         it.cnext()
 *         if it.retval > 0:             # <<<<<<<<<<<<<<
 *             n += 1
 *         else:
 */
    __pyx_t_9 = ((__pyx_v_it->__pyx_base.retval > 0) != 0);
    if (__pyx_t_9) {

      /* "pysamstats.pyx":4270
 *         it.cnext()
 *         if it.retval > 0:
 *             n += 1             # <<<<<<<<<<<<<<
 *         else:
 *             break
 */
      __pyx_v_n = (__pyx_v_n + 1);
      goto __pyx_L7;
    }
    /*else*/ {

      /* "pysamstats.pyx":4272
 *             n += 1
 *         else:
 *             break             # <<<<<<<<<<<<<<
 *     return n
 */
      goto __pyx_L6_break;
    }
    __pyx_L7:;
  }
  __pyx_L6_break:;

  /* "pysamstats.pyx":4273
 *         else:
 *             break
 *     return n             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysamstats.pyx":4259
 * 
 * 
 * def count_reads(AlignmentFile alignmentfile, chrom=None, start=None, end=None):             # <<<<<<<<<<<<<<
 *     cdef IteratorRowRegion it
 *     cdef int n = 0
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysamstats.count_reads", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_it);
  __Pyx_XDECREF(__pyx_v_has_coord);
  __Pyx_XDECREF(__pyx_v_rtid);
  __Pyx_XDECREF(__pyx_v_rstart);
  __Pyx_XDECREF(__pyx_v_rend);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_10pysamstats__StatBinned __pyx_vtable_10pysamstats__StatBinned;

static PyObject *__pyx_tp_new_10pysamstats__StatBinned(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats__StatBinned *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_10pysamstats__StatBinned *)o);
  p->__pyx_vtab = __pyx_vtabptr_10pysamstats__StatBinned;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats__StatBinned(PyObject *o) {
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  (*Py_TYPE(o)->tp_free)(o);
}

static PyTypeObject __pyx_type_10pysamstats__StatBinned = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats._StatBinned", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats__StatBinned), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats__StatBinned, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10pysamstats__StatBinned, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_10pysamstats__CoverageBinned __pyx_vtable_10pysamstats__CoverageBinned;

static PyObject *__pyx_tp_new_10pysamstats__CoverageBinned(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_10pysamstats__CoverageBinned *p;
  PyObject *o = __pyx_tp_new_10pysamstats__StatBinned(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_10pysamstats__CoverageBinned *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_10pysamstats__StatBinned*)__pyx_vtabptr_10pysamstats__CoverageBinned;
  if (unlikely(__pyx_pw_10pysamstats_15_CoverageBinned_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static PyMethodDef __pyx_methods_10pysamstats__CoverageBinned[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_10pysamstats__CoverageBinned = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats._CoverageBinned", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats__CoverageBinned), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats__StatBinned, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats__CoverageBinned, /*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__CoverageBinned, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_10pysamstats__CoverageExtBinned __pyx_vtable_10pysamstats__CoverageExtBinned;

static PyObject *__pyx_tp_new_10pysamstats__CoverageExtBinned(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_10pysamstats__CoverageExtBinned *p;
  PyObject *o = __pyx_tp_new_10pysamstats__StatBinned(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_10pysamstats__CoverageExtBinned *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_10pysamstats__StatBinned*)__pyx_vtabptr_10pysamstats__CoverageExtBinned;
  if (unlikely(__pyx_pw_10pysamstats_18_CoverageExtBinned_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static PyMethodDef __pyx_methods_10pysamstats__CoverageExtBinned[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_10pysamstats__CoverageExtBinned = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats._CoverageExtBinned", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats__CoverageExtBinned), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats__StatBinned, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats__CoverageExtBinned, /*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__CoverageExtBinned, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_10pysamstats__MapqBinned __pyx_vtable_10pysamstats__MapqBinned;

static PyObject *__pyx_tp_new_10pysamstats__MapqBinned(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_10pysamstats__MapqBinned *p;
  PyObject *o = __pyx_tp_new_10pysamstats__StatBinned(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_10pysamstats__MapqBinned *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_10pysamstats__StatBinned*)__pyx_vtabptr_10pysamstats__MapqBinned;
  if (unlikely(__pyx_pw_10pysamstats_11_MapqBinned_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static PyMethodDef __pyx_methods_10pysamstats__MapqBinned[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_10pysamstats__MapqBinned = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats._MapqBinned", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats__MapqBinned), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats__StatBinned, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats__MapqBinned, /*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__MapqBinned, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_10pysamstats__AlignmentBinned __pyx_vtable_10pysamstats__AlignmentBinned;

static PyObject *__pyx_tp_new_10pysamstats__AlignmentBinned(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_10pysamstats__AlignmentBinned *p;
  PyObject *o = __pyx_tp_new_10pysamstats__StatBinned(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_10pysamstats__AlignmentBinned *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_10pysamstats__StatBinned*)__pyx_vtabptr_10pysamstats__AlignmentBinned;
  if (unlikely(__pyx_pw_10pysamstats_16_AlignmentBinned_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static PyMethodDef __pyx_methods_10pysamstats__AlignmentBinned[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_10pysamstats__AlignmentBinned = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats._AlignmentBinned", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats__AlignmentBinned), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats__StatBinned, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats__AlignmentBinned, /*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__AlignmentBinned, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_10pysamstats__TlenBinned __pyx_vtable_10pysamstats__TlenBinned;

static PyObject *__pyx_tp_new_10pysamstats__TlenBinned(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_10pysamstats__TlenBinned *p;
  PyObject *o = __pyx_tp_new_10pysamstats__StatBinned(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_10pysamstats__TlenBinned *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_10pysamstats__StatBinned*)__pyx_vtabptr_10pysamstats__TlenBinned;
  if (unlikely(__pyx_pw_10pysamstats_11_TlenBinned_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static PyMethodDef __pyx_methods_10pysamstats__TlenBinned[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_10pysamstats__TlenBinned = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats._TlenBinned", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats__TlenBinned), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats__StatBinned, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats__TlenBinned, /*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__TlenBinned, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *__pyx_freelist_10pysamstats___pyx_scope_struct__stat_coverage_gc[8];
static int __pyx_freecount_10pysamstats___pyx_scope_struct__stat_coverage_gc = 0;

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct__stat_coverage_gc(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_10pysamstats___pyx_scope_struct__stat_coverage_gc > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc)))) {
    o = (PyObject*)__pyx_freelist_10pysamstats___pyx_scope_struct__stat_coverage_gc[--__pyx_freecount_10pysamstats___pyx_scope_struct__stat_coverage_gc];
    memset(o, 0, sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct__stat_coverage_gc(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_window_offset);
  Py_CLEAR(p->__pyx_v_window_size);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_10pysamstats___pyx_scope_struct__stat_coverage_gc < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc)))) {
    __pyx_freelist_10pysamstats___pyx_scope_struct__stat_coverage_gc[__pyx_freecount_10pysamstats___pyx_scope_struct__stat_coverage_gc++] = ((struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct__stat_coverage_gc(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *)o;
  if (p->__pyx_v_window_offset) {
    e = (*v)(p->__pyx_v_window_offset, a); if (e) return e;
  }
  if (p->__pyx_v_window_size) {
    e = (*v)(p->__pyx_v_window_size, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct__stat_coverage_gc(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc *)o;
  tmp = ((PyObject*)p->__pyx_v_window_offset);
  p->__pyx_v_window_offset = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_window_size);
  p->__pyx_v_window_size = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct__stat_coverage_gc = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats.__pyx_scope_struct__stat_coverage_gc", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage_gc), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct__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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct__stat_coverage_gc, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct__stat_coverage_gc, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10pysamstats___pyx_scope_struct__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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default *__pyx_freelist_10pysamstats___pyx_scope_struct_1__iter_pileup_default[8];
static int __pyx_freecount_10pysamstats___pyx_scope_struct_1__iter_pileup_default = 0;

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_1__iter_pileup_default(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_10pysamstats___pyx_scope_struct_1__iter_pileup_default > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default)))) {
    o = (PyObject*)__pyx_freelist_10pysamstats___pyx_scope_struct_1__iter_pileup_default[--__pyx_freecount_10pysamstats___pyx_scope_struct_1__iter_pileup_default];
    memset(o, 0, sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_1__iter_pileup_default(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_alignmentfile);
  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_frec);
  Py_CLEAR(p->__pyx_v_it);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_max_depth);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_v_truncate);
  Py_CLEAR(p->__pyx_t_0);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_10pysamstats___pyx_scope_struct_1__iter_pileup_default < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default)))) {
    __pyx_freelist_10pysamstats___pyx_scope_struct_1__iter_pileup_default[__pyx_freecount_10pysamstats___pyx_scope_struct_1__iter_pileup_default++] = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_1__iter_pileup_default(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default *)o;
  if (p->__pyx_v_alignmentfile) {
    e = (*v)(p->__pyx_v_alignmentfile, 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_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_fafile) {
    e = (*v)(p->__pyx_v_fafile, a); if (e) return e;
  }
  if (p->__pyx_v_frec) {
    e = (*v)(p->__pyx_v_frec, 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_max_depth) {
    e = (*v)(p->__pyx_v_max_depth, 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_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_v_truncate) {
    e = (*v)(p->__pyx_v_truncate, 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__iter_pileup_default(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default *)o;
  tmp = ((PyObject*)p->__pyx_v_alignmentfile);
  p->__pyx_v_alignmentfile = 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_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_fafile);
  p->__pyx_v_fafile = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_frec);
  p->__pyx_v_frec = 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_max_depth);
  p->__pyx_v_max_depth = 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_start);
  p->__pyx_v_start = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_truncate);
  p->__pyx_v_truncate = 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 PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_1__iter_pileup_default = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats.__pyx_scope_struct_1__iter_pileup_default", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_1__iter_pileup_default), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_1__iter_pileup_default, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_1__iter_pileup_default, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_1__iter_pileup_default, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10pysamstats___pyx_scope_struct_1__iter_pileup_default, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom *__pyx_freelist_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom[8];
static int __pyx_freecount_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom = 0;

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom)))) {
    o = (PyObject*)__pyx_freelist_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom[--__pyx_freecount_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom];
    memset(o, 0, sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_alignmentfile);
  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_fpad);
  Py_CLEAR(p->__pyx_v_frec);
  Py_CLEAR(p->__pyx_v_it);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_max_depth);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_v_truncate);
  Py_CLEAR(p->__pyx_t_0);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom)))) {
    __pyx_freelist_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom[__pyx_freecount_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom++] = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom *)o;
  if (p->__pyx_v_alignmentfile) {
    e = (*v)(p->__pyx_v_alignmentfile, 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)(((PyObject*)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)(p->__pyx_v_fafile, a); if (e) return e;
  }
  if (p->__pyx_v_fpad) {
    e = (*v)(p->__pyx_v_fpad, a); if (e) return e;
  }
  if (p->__pyx_v_frec) {
    e = (*v)(p->__pyx_v_frec, 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_max_depth) {
    e = (*v)(p->__pyx_v_max_depth, 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_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_v_truncate) {
    e = (*v)(p->__pyx_v_truncate, 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__iter_pileup_padded_chrom(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom *)o;
  tmp = ((PyObject*)p->__pyx_v_alignmentfile);
  p->__pyx_v_alignmentfile = 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 = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)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 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_fpad);
  p->__pyx_v_fpad = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_frec);
  p->__pyx_v_frec = 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_max_depth);
  p->__pyx_v_max_depth = 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_start);
  p->__pyx_v_start = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_truncate);
  p->__pyx_v_truncate = 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 PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats.__pyx_scope_struct_2__iter_pileup_padded_chrom", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom *__pyx_freelist_10pysamstats___pyx_scope_struct_3__iter_binned_chrom[8];
static int __pyx_freecount_10pysamstats___pyx_scope_struct_3__iter_binned_chrom = 0;

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_3__iter_binned_chrom(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_10pysamstats___pyx_scope_struct_3__iter_binned_chrom > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom)))) {
    o = (PyObject*)__pyx_freelist_10pysamstats___pyx_scope_struct_3__iter_binned_chrom[--__pyx_freecount_10pysamstats___pyx_scope_struct_3__iter_binned_chrom];
    memset(o, 0, sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_3__iter_binned_chrom(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_alignmentfile);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_fafile);
  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_rec);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_v_stat);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_10pysamstats___pyx_scope_struct_3__iter_binned_chrom < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom)))) {
    __pyx_freelist_10pysamstats___pyx_scope_struct_3__iter_binned_chrom[__pyx_freecount_10pysamstats___pyx_scope_struct_3__iter_binned_chrom++] = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_3__iter_binned_chrom(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom *)o;
  if (p->__pyx_v_alignmentfile) {
    e = (*v)(((PyObject*)p->__pyx_v_alignmentfile), 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_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_it) {
    e = (*v)(((PyObject*)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_rec) {
    e = (*v)(p->__pyx_v_rec, a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_v_stat) {
    e = (*v)(((PyObject*)p->__pyx_v_stat), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_3__iter_binned_chrom(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom *)o;
  tmp = ((PyObject*)p->__pyx_v_alignmentfile);
  p->__pyx_v_alignmentfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)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_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_6cfaidx_FastaFile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_it);
  p->__pyx_v_it = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)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_rec);
  p->__pyx_v_rec = ((PyObject*)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_v_stat);
  p->__pyx_v_stat = ((struct __pyx_obj_10pysamstats__StatBinned *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_3__iter_binned_chrom = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats.__pyx_scope_struct_3__iter_binned_chrom", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_3__iter_binned_chrom), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_3__iter_binned_chrom, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_3__iter_binned_chrom, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_3__iter_binned_chrom, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10pysamstats___pyx_scope_struct_3__iter_binned_chrom, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten *__pyx_freelist_10pysamstats___pyx_scope_struct_4_flatten[8];
static int __pyx_freecount_10pysamstats___pyx_scope_struct_4_flatten = 0;

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_4_flatten(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_10pysamstats___pyx_scope_struct_4_flatten > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten)))) {
    o = (PyObject*)__pyx_freelist_10pysamstats___pyx_scope_struct_4_flatten[--__pyx_freecount_10pysamstats___pyx_scope_struct_4_flatten];
    memset(o, 0, sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_4_flatten(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_getter);
  Py_CLEAR(p->__pyx_v_recs);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_10pysamstats___pyx_scope_struct_4_flatten < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten)))) {
    __pyx_freelist_10pysamstats___pyx_scope_struct_4_flatten[__pyx_freecount_10pysamstats___pyx_scope_struct_4_flatten++] = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_4_flatten(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten *)o;
  if (p->__pyx_v_getter) {
    e = (*v)(p->__pyx_v_getter, a); if (e) return e;
  }
  if (p->__pyx_v_recs) {
    e = (*v)(p->__pyx_v_recs, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_4_flatten(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten *)o;
  tmp = ((PyObject*)p->__pyx_v_getter);
  p->__pyx_v_getter = 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);
  return 0;
}

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_4_flatten = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats.__pyx_scope_struct_4_flatten", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_4_flatten, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_4_flatten, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_4_flatten, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10pysamstats___pyx_scope_struct_4_flatten, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr *__pyx_freelist_10pysamstats___pyx_scope_struct_5_genexpr[8];
static int __pyx_freecount_10pysamstats___pyx_scope_struct_5_genexpr = 0;

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_5_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_10pysamstats___pyx_scope_struct_5_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr)))) {
    o = (PyObject*)__pyx_freelist_10pysamstats___pyx_scope_struct_5_genexpr[--__pyx_freecount_10pysamstats___pyx_scope_struct_5_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_5_genexpr(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_rec);
  Py_CLEAR(p->__pyx_t_0);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_10pysamstats___pyx_scope_struct_5_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr)))) {
    __pyx_freelist_10pysamstats___pyx_scope_struct_5_genexpr[__pyx_freecount_10pysamstats___pyx_scope_struct_5_genexpr++] = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_5_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_5_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_5_genexpr(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr *)o;
  tmp = ((PyObject*)p->__pyx_outer_scope);
  p->__pyx_outer_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_4_flatten *)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 PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_5_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats.__pyx_scope_struct_5_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_5_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_5_genexpr, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_5_genexpr, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_5_genexpr, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10pysamstats___pyx_scope_struct_5_genexpr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ *__pyx_freelist_10pysamstats___pyx_scope_struct_6___iter__[8];
static int __pyx_freecount_10pysamstats___pyx_scope_struct_6___iter__ = 0;

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_6___iter__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_10pysamstats___pyx_scope_struct_6___iter__ > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__)))) {
    o = (PyObject*)__pyx_freelist_10pysamstats___pyx_scope_struct_6___iter__[--__pyx_freecount_10pysamstats___pyx_scope_struct_6___iter__];
    memset(o, 0, sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_6___iter__(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_fields);
  Py_CLEAR(p->__pyx_v_recs);
  Py_CLEAR(p->__pyx_v_row);
  Py_CLEAR(p->__pyx_v_rows);
  Py_CLEAR(p->__pyx_v_self);
  Py_CLEAR(p->__pyx_t_0);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_10pysamstats___pyx_scope_struct_6___iter__ < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__)))) {
    __pyx_freelist_10pysamstats___pyx_scope_struct_6___iter__[__pyx_freecount_10pysamstats___pyx_scope_struct_6___iter__++] = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_6___iter__(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ *)o;
  if (p->__pyx_v_fields) {
    e = (*v)(p->__pyx_v_fields, 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_row) {
    e = (*v)(p->__pyx_v_row, a); if (e) return e;
  }
  if (p->__pyx_v_rows) {
    e = (*v)(p->__pyx_v_rows, a); if (e) return e;
  }
  if (p->__pyx_v_self) {
    e = (*v)(p->__pyx_v_self, 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___iter__(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__ *)o;
  tmp = ((PyObject*)p->__pyx_v_fields);
  p->__pyx_v_fields = ((PyObject*)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_row);
  p->__pyx_v_row = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_rows);
  p->__pyx_v_rows = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_self);
  p->__pyx_v_self = 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 PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_6___iter__ = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysamstats.__pyx_scope_struct_6___iter__", /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_6___iter__), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_6___iter__, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_6___iter__, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_6___iter__, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10pysamstats___pyx_scope_struct_6___iter__, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {"_rec_coverage", (PyCFunction)__pyx_pw_10pysamstats_1_rec_coverage, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats__rec_coverage},
  {"_rec_coverage_pad", (PyCFunction)__pyx_pw_10pysamstats_3_rec_coverage_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_2_rec_coverage_pad},
  {"_rec_coverage_strand", (PyCFunction)__pyx_pw_10pysamstats_9_rec_coverage_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_8_rec_coverage_strand},
  {"_rec_coverage_strand_pad", (PyCFunction)__pyx_pw_10pysamstats_11_rec_coverage_strand_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_10_rec_coverage_strand_pad},
  {"_rec_coverage_ext", (PyCFunction)__pyx_pw_10pysamstats_17_rec_coverage_ext, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_16_rec_coverage_ext},
  {"_rec_coverage_ext_pad", (PyCFunction)__pyx_pw_10pysamstats_19_rec_coverage_ext_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_18_rec_coverage_ext_pad},
  {"_rec_coverage_ext_strand", (PyCFunction)__pyx_pw_10pysamstats_25_rec_coverage_ext_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_24_rec_coverage_ext_strand},
  {"_rec_coverage_ext_strand_pad", (PyCFunction)__pyx_pw_10pysamstats_27_rec_coverage_ext_strand_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_26_rec_coverage_ext_strand_pad},
  {"_rec_variation", (PyCFunction)__pyx_pw_10pysamstats_33_rec_variation, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_32_rec_variation},
  {"_rec_variation_pad", (PyCFunction)__pyx_pw_10pysamstats_35_rec_variation_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_34_rec_variation_pad},
  {"_rec_variation_strand", (PyCFunction)__pyx_pw_10pysamstats_41_rec_variation_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_40_rec_variation_strand},
  {"_rec_variation_strand_pad", (PyCFunction)__pyx_pw_10pysamstats_43_rec_variation_strand_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_42_rec_variation_strand_pad},
  {"_rec_tlen", (PyCFunction)__pyx_pw_10pysamstats_49_rec_tlen, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_48_rec_tlen},
  {"_rec_tlen_pad", (PyCFunction)__pyx_pw_10pysamstats_51_rec_tlen_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_50_rec_tlen_pad},
  {"_rec_tlen_strand", (PyCFunction)__pyx_pw_10pysamstats_57_rec_tlen_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_56_rec_tlen_strand},
  {"_rec_tlen_strand_pad", (PyCFunction)__pyx_pw_10pysamstats_59_rec_tlen_strand_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_58_rec_tlen_strand_pad},
  {"_rec_mapq", (PyCFunction)__pyx_pw_10pysamstats_65_rec_mapq, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_64_rec_mapq},
  {"_rec_mapq_pad", (PyCFunction)__pyx_pw_10pysamstats_67_rec_mapq_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_66_rec_mapq_pad},
  {"_rec_mapq_strand", (PyCFunction)__pyx_pw_10pysamstats_73_rec_mapq_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_72_rec_mapq_strand},
  {"_rec_mapq_strand_pad", (PyCFunction)__pyx_pw_10pysamstats_75_rec_mapq_strand_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_74_rec_mapq_strand_pad},
  {"_rec_baseq", (PyCFunction)__pyx_pw_10pysamstats_81_rec_baseq, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_80_rec_baseq},
  {"_rec_baseq_pad", (PyCFunction)__pyx_pw_10pysamstats_83_rec_baseq_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_82_rec_baseq_pad},
  {"_rec_baseq_strand", (PyCFunction)__pyx_pw_10pysamstats_89_rec_baseq_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_88_rec_baseq_strand},
  {"_rec_baseq_strand_pad", (PyCFunction)__pyx_pw_10pysamstats_91_rec_baseq_strand_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_90_rec_baseq_strand_pad},
  {"_rec_baseq_ext", (PyCFunction)__pyx_pw_10pysamstats_97_rec_baseq_ext, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_96_rec_baseq_ext},
  {"_rec_baseq_ext_pad", (PyCFunction)__pyx_pw_10pysamstats_99_rec_baseq_ext_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_98_rec_baseq_ext_pad},
  {"_rec_baseq_ext_strand", (PyCFunction)__pyx_pw_10pysamstats_105_rec_baseq_ext_strand, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_104_rec_baseq_ext_strand},
  {"_rec_baseq_ext_strand_pad", (PyCFunction)__pyx_pw_10pysamstats_107_rec_baseq_ext_strand_pad, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10pysamstats_106_rec_baseq_ext_strand_pad},
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
  #if PY_VERSION_HEX < 0x03020000
    { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
  #else
    PyModuleDef_HEAD_INIT,
  #endif
    "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_kp_s_0_20, __pyx_k_0_20, sizeof(__pyx_k_0_20), 0, 0, 1, 0},
  {&__pyx_n_b_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 0, 1},
  {&__pyx_n_s_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 1, 1},
  {&__pyx_n_s_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_b_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 0, 1},
  {&__pyx_n_s_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 1, 1},
  {&__pyx_n_s_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_D, __pyx_k_D, sizeof(__pyx_k_D), 0, 0, 1, 1},
  {&__pyx_n_s_Exception, __pyx_k_Exception, sizeof(__pyx_k_Exception), 0, 0, 1, 1},
  {&__pyx_n_s_Filters, __pyx_k_Filters, sizeof(__pyx_k_Filters), 0, 0, 1, 1},
  {&__pyx_n_b_G, __pyx_k_G, sizeof(__pyx_k_G), 0, 0, 0, 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_H, __pyx_k_H, sizeof(__pyx_k_H), 0, 0, 1, 1},
  {&__pyx_n_s_I, __pyx_k_I, sizeof(__pyx_k_I), 0, 0, 1, 1},
  {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1},
  {&__pyx_n_s_M, __pyx_k_M, sizeof(__pyx_k_M), 0, 0, 1, 1},
  {&__pyx_n_b_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 0, 0, 1},
  {&__pyx_n_s_N, __pyx_k_N, sizeof(__pyx_k_N), 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_NoSuchNodeError, __pyx_k_NoSuchNodeError, sizeof(__pyx_k_NoSuchNodeError), 0, 0, 1, 1},
  {&__pyx_n_s_P, __pyx_k_P, sizeof(__pyx_k_P), 0, 0, 1, 1},
  {&__pyx_n_s_PY2, __pyx_k_PY2, sizeof(__pyx_k_PY2), 0, 0, 1, 1},
  {&__pyx_n_s_S, __pyx_k_S, sizeof(__pyx_k_S), 0, 0, 1, 1},
  {&__pyx_n_s_StatsTable, __pyx_k_StatsTable, sizeof(__pyx_k_StatsTable), 0, 0, 1, 1},
  {&__pyx_n_s_StatsTable___init, __pyx_k_StatsTable___init, sizeof(__pyx_k_StatsTable___init), 0, 0, 1, 1},
  {&__pyx_n_s_StatsTable___iter, __pyx_k_StatsTable___iter, sizeof(__pyx_k_StatsTable___iter), 0, 0, 1, 1},
  {&__pyx_n_b_T, __pyx_k_T, sizeof(__pyx_k_T), 0, 0, 0, 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_X, __pyx_k_X, sizeof(__pyx_k_X), 0, 0, 1, 1},
  {&__pyx_kp_s__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 0, 1, 0},
  {&__pyx_kp_s__7, __pyx_k__7, sizeof(__pyx_k__7), 0, 0, 1, 0},
  {&__pyx_n_s_a, __pyx_k_a, sizeof(__pyx_k_a), 0, 0, 1, 1},
  {&__pyx_n_s_a1, __pyx_k_a1, sizeof(__pyx_k_a1), 0, 0, 1, 1},
  {&__pyx_n_s_a12, __pyx_k_a12, sizeof(__pyx_k_a12), 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_alignmentfile, __pyx_k_alignmentfile, sizeof(__pyx_k_alignmentfile), 0, 0, 1, 1},
  {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
  {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
  {&__pyx_n_s_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1},
  {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
  {&__pyx_n_s_bases_all, __pyx_k_bases_all, sizeof(__pyx_k_bases_all), 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_batch_size, __pyx_k_batch_size, sizeof(__pyx_k_batch_size), 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_bin_end, __pyx_k_bin_end, sizeof(__pyx_k_bin_end), 0, 0, 1, 1},
  {&__pyx_n_s_bin_start, __pyx_k_bin_start, sizeof(__pyx_k_bin_start), 0, 0, 1, 1},
  {&__pyx_n_s_chain, __pyx_k_chain, sizeof(__pyx_k_chain), 0, 0, 1, 1},
  {&__pyx_n_s_chrlen, __pyx_k_chrlen, sizeof(__pyx_k_chrlen), 0, 0, 1, 1},
  {&__pyx_n_s_chrom, __pyx_k_chrom, sizeof(__pyx_k_chrom), 0, 0, 1, 1},
  {&__pyx_kp_s_chromosome_is_None, __pyx_k_chromosome_is_None, sizeof(__pyx_k_chromosome_is_None), 0, 0, 1, 0},
  {&__pyx_kp_s_chromosome_not_in_SAM_references, __pyx_k_chromosome_not_in_SAM_references, sizeof(__pyx_k_chromosome_not_in_SAM_references), 0, 0, 1, 0},
  {&__pyx_n_s_chunk, __pyx_k_chunk, sizeof(__pyx_k_chunk), 0, 0, 1, 1},
  {&__pyx_n_s_chunkshape, __pyx_k_chunkshape, sizeof(__pyx_k_chunkshape), 0, 0, 1, 1},
  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_n_s_col, __pyx_k_col, sizeof(__pyx_k_col), 0, 0, 1, 1},
  {&__pyx_n_s_complevel, __pyx_k_complevel, sizeof(__pyx_k_complevel), 0, 0, 1, 1},
  {&__pyx_n_s_complib, __pyx_k_complib, sizeof(__pyx_k_complib), 0, 0, 1, 1},
  {&__pyx_n_s_count_reads, __pyx_k_count_reads, sizeof(__pyx_k_count_reads), 0, 0, 1, 1},
  {&__pyx_n_s_counter, __pyx_k_counter, sizeof(__pyx_k_counter), 0, 0, 1, 1},
  {&__pyx_n_s_counter_before, __pyx_k_counter_before, sizeof(__pyx_k_counter_before), 0, 0, 1, 1},
  {&__pyx_n_s_create_table, __pyx_k_create_table, sizeof(__pyx_k_create_table), 0, 0, 1, 1},
  {&__pyx_n_s_createparents, __pyx_k_createparents, sizeof(__pyx_k_createparents), 0, 0, 1, 1},
  {&__pyx_n_s_csv, __pyx_k_csv, sizeof(__pyx_k_csv), 0, 0, 1, 1},
  {&__pyx_n_s_csv_2, __pyx_k_csv_2, sizeof(__pyx_k_csv_2), 0, 0, 1, 1},
  {&__pyx_n_s_curpos, __pyx_k_curpos, sizeof(__pyx_k_curpos), 0, 0, 1, 1},
  {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1},
  {&__pyx_n_s_default_dtype, __pyx_k_default_dtype, sizeof(__pyx_k_default_dtype), 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_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1},
  {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_2, __pyx_k_dtype_2, sizeof(__pyx_k_dtype_2), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_alignment_binned, __pyx_k_dtype_alignment_binned, sizeof(__pyx_k_dtype_alignment_binned), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_baseq, __pyx_k_dtype_baseq, sizeof(__pyx_k_dtype_baseq), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_baseq_ext, __pyx_k_dtype_baseq_ext, sizeof(__pyx_k_dtype_baseq_ext), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_baseq_ext_strand, __pyx_k_dtype_baseq_ext_strand, sizeof(__pyx_k_dtype_baseq_ext_strand), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_baseq_strand, __pyx_k_dtype_baseq_strand, sizeof(__pyx_k_dtype_baseq_strand), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_coverage, __pyx_k_dtype_coverage, sizeof(__pyx_k_dtype_coverage), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_coverage_binned, __pyx_k_dtype_coverage_binned, sizeof(__pyx_k_dtype_coverage_binned), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_coverage_ext, __pyx_k_dtype_coverage_ext, sizeof(__pyx_k_dtype_coverage_ext), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_coverage_ext_binned, __pyx_k_dtype_coverage_ext_binned, sizeof(__pyx_k_dtype_coverage_ext_binned), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_coverage_ext_strand, __pyx_k_dtype_coverage_ext_strand, sizeof(__pyx_k_dtype_coverage_ext_strand), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_coverage_gc, __pyx_k_dtype_coverage_gc, sizeof(__pyx_k_dtype_coverage_gc), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_coverage_strand, __pyx_k_dtype_coverage_strand, sizeof(__pyx_k_dtype_coverage_strand), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_mapq, __pyx_k_dtype_mapq, sizeof(__pyx_k_dtype_mapq), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_mapq_binned, __pyx_k_dtype_mapq_binned, sizeof(__pyx_k_dtype_mapq_binned), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_mapq_strand, __pyx_k_dtype_mapq_strand, sizeof(__pyx_k_dtype_mapq_strand), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_overrides, __pyx_k_dtype_overrides, sizeof(__pyx_k_dtype_overrides), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_tlen, __pyx_k_dtype_tlen, sizeof(__pyx_k_dtype_tlen), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_tlen_binned, __pyx_k_dtype_tlen_binned, sizeof(__pyx_k_dtype_tlen_binned), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_tlen_strand, __pyx_k_dtype_tlen_strand, sizeof(__pyx_k_dtype_tlen_strand), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_variation, __pyx_k_dtype_variation, sizeof(__pyx_k_dtype_variation), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_variation_strand, __pyx_k_dtype_variation_strand, sizeof(__pyx_k_dtype_variation_strand), 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_kp_s_excel_tab, __pyx_k_excel_tab, sizeof(__pyx_k_excel_tab), 0, 0, 1, 0},
  {&__pyx_n_s_f, __pyx_k_f, sizeof(__pyx_k_f), 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_fields, __pyx_k_fields, sizeof(__pyx_k_fields), 0, 0, 1, 1},
  {&__pyx_n_s_fields_2, __pyx_k_fields_2, sizeof(__pyx_k_fields_2), 0, 0, 1, 1},
  {&__pyx_n_s_fields_alignment_binned, __pyx_k_fields_alignment_binned, sizeof(__pyx_k_fields_alignment_binned), 0, 0, 1, 1},
  {&__pyx_n_s_fields_baseq, __pyx_k_fields_baseq, sizeof(__pyx_k_fields_baseq), 0, 0, 1, 1},
  {&__pyx_n_s_fields_baseq_ext, __pyx_k_fields_baseq_ext, sizeof(__pyx_k_fields_baseq_ext), 0, 0, 1, 1},
  {&__pyx_n_s_fields_baseq_ext_strand, __pyx_k_fields_baseq_ext_strand, sizeof(__pyx_k_fields_baseq_ext_strand), 0, 0, 1, 1},
  {&__pyx_n_s_fields_baseq_strand, __pyx_k_fields_baseq_strand, sizeof(__pyx_k_fields_baseq_strand), 0, 0, 1, 1},
  {&__pyx_n_s_fields_coverage, __pyx_k_fields_coverage, sizeof(__pyx_k_fields_coverage), 0, 0, 1, 1},
  {&__pyx_n_s_fields_coverage_binned, __pyx_k_fields_coverage_binned, sizeof(__pyx_k_fields_coverage_binned), 0, 0, 1, 1},
  {&__pyx_n_s_fields_coverage_ext, __pyx_k_fields_coverage_ext, sizeof(__pyx_k_fields_coverage_ext), 0, 0, 1, 1},
  {&__pyx_n_s_fields_coverage_ext_binned, __pyx_k_fields_coverage_ext_binned, sizeof(__pyx_k_fields_coverage_ext_binned), 0, 0, 1, 1},
  {&__pyx_n_s_fields_coverage_ext_strand, __pyx_k_fields_coverage_ext_strand, sizeof(__pyx_k_fields_coverage_ext_strand), 0, 0, 1, 1},
  {&__pyx_n_s_fields_coverage_gc, __pyx_k_fields_coverage_gc, sizeof(__pyx_k_fields_coverage_gc), 0, 0, 1, 1},
  {&__pyx_n_s_fields_coverage_strand, __pyx_k_fields_coverage_strand, sizeof(__pyx_k_fields_coverage_strand), 0, 0, 1, 1},
  {&__pyx_n_s_fields_mapq, __pyx_k_fields_mapq, sizeof(__pyx_k_fields_mapq), 0, 0, 1, 1},
  {&__pyx_n_s_fields_mapq_binned, __pyx_k_fields_mapq_binned, sizeof(__pyx_k_fields_mapq_binned), 0, 0, 1, 1},
  {&__pyx_n_s_fields_mapq_strand, __pyx_k_fields_mapq_strand, sizeof(__pyx_k_fields_mapq_strand), 0, 0, 1, 1},
  {&__pyx_n_s_fields_tlen, __pyx_k_fields_tlen, sizeof(__pyx_k_fields_tlen), 0, 0, 1, 1},
  {&__pyx_n_s_fields_tlen_binned, __pyx_k_fields_tlen_binned, sizeof(__pyx_k_fields_tlen_binned), 0, 0, 1, 1},
  {&__pyx_n_s_fields_tlen_strand, __pyx_k_fields_tlen_strand, sizeof(__pyx_k_fields_tlen_strand), 0, 0, 1, 1},
  {&__pyx_n_s_fields_variation, __pyx_k_fields_variation, sizeof(__pyx_k_fields_variation), 0, 0, 1, 1},
  {&__pyx_n_s_fields_variation_strand, __pyx_k_fields_variation_strand, sizeof(__pyx_k_fields_variation_strand), 0, 0, 1, 1},
  {&__pyx_n_s_file, __pyx_k_file, sizeof(__pyx_k_file), 0, 0, 1, 1},
  {&__pyx_n_s_filters, __pyx_k_filters, sizeof(__pyx_k_filters), 0, 0, 1, 1},
  {&__pyx_n_s_flatten, __pyx_k_flatten, sizeof(__pyx_k_flatten), 0, 0, 1, 1},
  {&__pyx_n_s_flatten_locals_genexpr, __pyx_k_flatten_locals_genexpr, sizeof(__pyx_k_flatten_locals_genexpr), 0, 0, 1, 1},
  {&__pyx_n_s_fletcher32, __pyx_k_fletcher32, sizeof(__pyx_k_fletcher32), 0, 0, 1, 1},
  {&__pyx_n_s_flush, __pyx_k_flush, sizeof(__pyx_k_flush), 0, 0, 1, 1},
  {&__pyx_n_s_fpad, __pyx_k_fpad, sizeof(__pyx_k_fpad), 0, 0, 1, 1},
  {&__pyx_n_s_frec, __pyx_k_frec, sizeof(__pyx_k_frec), 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_percent, __pyx_k_gc_percent, sizeof(__pyx_k_gc_percent), 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_getter, __pyx_k_getter, sizeof(__pyx_k_getter), 0, 0, 1, 1},
  {&__pyx_n_s_h5file, __pyx_k_h5file, sizeof(__pyx_k_h5file), 0, 0, 1, 1},
  {&__pyx_n_s_h5table, __pyx_k_h5table, sizeof(__pyx_k_h5table), 0, 0, 1, 1},
  {&__pyx_n_s_has_coord, __pyx_k_has_coord, sizeof(__pyx_k_has_coord), 0, 0, 1, 1},
  {&__pyx_n_s_hdf5_chunklen, __pyx_k_hdf5_chunklen, sizeof(__pyx_k_hdf5_chunklen), 0, 0, 1, 1},
  {&__pyx_n_s_hdf5_chunkshape, __pyx_k_hdf5_chunkshape, sizeof(__pyx_k_hdf5_chunkshape), 0, 0, 1, 1},
  {&__pyx_n_s_hdf5_chunksize, __pyx_k_hdf5_chunksize, sizeof(__pyx_k_hdf5_chunksize), 0, 0, 1, 1},
  {&__pyx_n_s_hdf5_complevel, __pyx_k_hdf5_complevel, sizeof(__pyx_k_hdf5_complevel), 0, 0, 1, 1},
  {&__pyx_n_s_hdf5_complib, __pyx_k_hdf5_complib, sizeof(__pyx_k_hdf5_complib), 0, 0, 1, 1},
  {&__pyx_n_s_hdf5_dataset, __pyx_k_hdf5_dataset, sizeof(__pyx_k_hdf5_dataset), 0, 0, 1, 1},
  {&__pyx_n_s_hdf5_fletcher32, __pyx_k_hdf5_fletcher32, sizeof(__pyx_k_hdf5_fletcher32), 0, 0, 1, 1},
  {&__pyx_n_s_hdf5_group, __pyx_k_hdf5_group, sizeof(__pyx_k_hdf5_group), 0, 0, 1, 1},
  {&__pyx_n_s_hdf5_shuffle, __pyx_k_hdf5_shuffle, sizeof(__pyx_k_hdf5_shuffle), 0, 0, 1, 1},
  {&__pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_k_home_aliman_src_github_alimanfo, sizeof(__pyx_k_home_aliman_src_github_alimanfo), 0, 0, 1, 0},
  {&__pyx_n_s_i4, __pyx_k_i4, sizeof(__pyx_k_i4), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_index, __pyx_k_index, sizeof(__pyx_k_index), 0, 0, 1, 1},
  {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 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_islice, __pyx_k_islice, sizeof(__pyx_k_islice), 0, 0, 1, 1},
  {&__pyx_n_s_it, __pyx_k_it, sizeof(__pyx_k_it), 0, 0, 1, 1},
  {&__pyx_n_s_itc, __pyx_k_itc, sizeof(__pyx_k_itc), 0, 0, 1, 1},
  {&__pyx_n_s_itemgetter, __pyx_k_itemgetter, sizeof(__pyx_k_itemgetter), 0, 0, 1, 1},
  {&__pyx_n_s_itemsize, __pyx_k_itemsize, sizeof(__pyx_k_itemsize), 0, 0, 1, 1},
  {&__pyx_n_s_iter, __pyx_k_iter, sizeof(__pyx_k_iter), 0, 0, 1, 1},
  {&__pyx_n_s_iter_binned, __pyx_k_iter_binned, sizeof(__pyx_k_iter_binned), 0, 0, 1, 1},
  {&__pyx_n_s_iter_binned_chrom, __pyx_k_iter_binned_chrom, sizeof(__pyx_k_iter_binned_chrom), 0, 0, 1, 1},
  {&__pyx_n_s_iter_pileup, __pyx_k_iter_pileup, sizeof(__pyx_k_iter_pileup), 0, 0, 1, 1},
  {&__pyx_n_s_iter_pileup_default, __pyx_k_iter_pileup_default, sizeof(__pyx_k_iter_pileup_default), 0, 0, 1, 1},
  {&__pyx_n_s_iter_pileup_padded, __pyx_k_iter_pileup_padded, sizeof(__pyx_k_iter_pileup_padded), 0, 0, 1, 1},
  {&__pyx_n_s_iter_pileup_padded_chrom, __pyx_k_iter_pileup_padded_chrom, sizeof(__pyx_k_iter_pileup_padded_chrom), 0, 0, 1, 1},
  {&__pyx_n_s_itertools, __pyx_k_itertools, sizeof(__pyx_k_itertools), 0, 0, 1, 1},
  {&__pyx_n_s_itertools_2, __pyx_k_itertools_2, sizeof(__pyx_k_itertools_2), 0, 0, 1, 1},
  {&__pyx_n_s_its, __pyx_k_its, sizeof(__pyx_k_its), 0, 0, 1, 1},
  {&__pyx_n_s_kwargs, __pyx_k_kwargs, sizeof(__pyx_k_kwargs), 0, 0, 1, 1},
  {&__pyx_n_s_lengths, __pyx_k_lengths, sizeof(__pyx_k_lengths), 0, 0, 1, 1},
  {&__pyx_n_s_load_alignment_binned, __pyx_k_load_alignment_binned, sizeof(__pyx_k_load_alignment_binned), 0, 0, 1, 1},
  {&__pyx_n_s_load_baseq, __pyx_k_load_baseq, sizeof(__pyx_k_load_baseq), 0, 0, 1, 1},
  {&__pyx_n_s_load_baseq_ext, __pyx_k_load_baseq_ext, sizeof(__pyx_k_load_baseq_ext), 0, 0, 1, 1},
  {&__pyx_n_s_load_baseq_ext_strand, __pyx_k_load_baseq_ext_strand, sizeof(__pyx_k_load_baseq_ext_strand), 0, 0, 1, 1},
  {&__pyx_n_s_load_baseq_strand, __pyx_k_load_baseq_strand, sizeof(__pyx_k_load_baseq_strand), 0, 0, 1, 1},
  {&__pyx_n_s_load_coverage, __pyx_k_load_coverage, sizeof(__pyx_k_load_coverage), 0, 0, 1, 1},
  {&__pyx_n_s_load_coverage_binned, __pyx_k_load_coverage_binned, sizeof(__pyx_k_load_coverage_binned), 0, 0, 1, 1},
  {&__pyx_n_s_load_coverage_ext, __pyx_k_load_coverage_ext, sizeof(__pyx_k_load_coverage_ext), 0, 0, 1, 1},
  {&__pyx_n_s_load_coverage_ext_binned, __pyx_k_load_coverage_ext_binned, sizeof(__pyx_k_load_coverage_ext_binned), 0, 0, 1, 1},
  {&__pyx_n_s_load_coverage_ext_strand, __pyx_k_load_coverage_ext_strand, sizeof(__pyx_k_load_coverage_ext_strand), 0, 0, 1, 1},
  {&__pyx_n_s_load_coverage_gc, __pyx_k_load_coverage_gc, sizeof(__pyx_k_load_coverage_gc), 0, 0, 1, 1},
  {&__pyx_n_s_load_coverage_strand, __pyx_k_load_coverage_strand, sizeof(__pyx_k_load_coverage_strand), 0, 0, 1, 1},
  {&__pyx_n_s_load_mapq, __pyx_k_load_mapq, sizeof(__pyx_k_load_mapq), 0, 0, 1, 1},
  {&__pyx_n_s_load_mapq_binned, __pyx_k_load_mapq_binned, sizeof(__pyx_k_load_mapq_binned), 0, 0, 1, 1},
  {&__pyx_n_s_load_mapq_strand, __pyx_k_load_mapq_strand, sizeof(__pyx_k_load_mapq_strand), 0, 0, 1, 1},
  {&__pyx_n_s_load_stats, __pyx_k_load_stats, sizeof(__pyx_k_load_stats), 0, 0, 1, 1},
  {&__pyx_n_s_load_tlen, __pyx_k_load_tlen, sizeof(__pyx_k_load_tlen), 0, 0, 1, 1},
  {&__pyx_n_s_load_tlen_binned, __pyx_k_load_tlen_binned, sizeof(__pyx_k_load_tlen_binned), 0, 0, 1, 1},
  {&__pyx_n_s_load_tlen_strand, __pyx_k_load_tlen_strand, sizeof(__pyx_k_load_tlen_strand), 0, 0, 1, 1},
  {&__pyx_n_s_load_variation, __pyx_k_load_variation, sizeof(__pyx_k_load_variation), 0, 0, 1, 1},
  {&__pyx_n_s_load_variation_strand, __pyx_k_load_variation_strand, sizeof(__pyx_k_load_variation_strand), 0, 0, 1, 1},
  {&__pyx_n_s_lower, __pyx_k_lower, sizeof(__pyx_k_lower), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 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_depth, __pyx_k_max_depth, sizeof(__pyx_k_max_depth), 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_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_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 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_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1},
  {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1},
  {&__pyx_n_s_modulus, __pyx_k_modulus, sizeof(__pyx_k_modulus), 0, 0, 1, 1},
  {&__pyx_n_s_msg, __pyx_k_msg, sizeof(__pyx_k_msg), 0, 0, 1, 1},
  {&__pyx_n_s_multiple_iterators, __pyx_k_multiple_iterators, sizeof(__pyx_k_multiple_iterators), 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_object, __pyx_k_object, sizeof(__pyx_k_object), 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_open_file, __pyx_k_open_file, sizeof(__pyx_k_open_file), 0, 0, 1, 1},
  {&__pyx_n_s_operator, __pyx_k_operator, sizeof(__pyx_k_operator), 0, 0, 1, 1},
  {&__pyx_n_s_outfile, __pyx_k_outfile, sizeof(__pyx_k_outfile), 0, 0, 1, 1},
  {&__pyx_n_s_pad, __pyx_k_pad, sizeof(__pyx_k_pad), 0, 0, 1, 1},
  {&__pyx_n_s_parseRegion, __pyx_k_parseRegion, sizeof(__pyx_k_parseRegion), 0, 0, 1, 1},
  {&__pyx_n_s_pileup, __pyx_k_pileup, sizeof(__pyx_k_pileup), 0, 0, 1, 1},
  {&__pyx_n_s_pop, __pyx_k_pop, sizeof(__pyx_k_pop), 0, 0, 1, 1},
  {&__pyx_n_s_pos, __pyx_k_pos, sizeof(__pyx_k_pos), 0, 0, 1, 1},
  {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1},
  {&__pyx_n_s_print, __pyx_k_print, sizeof(__pyx_k_print), 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_kp_s_pysamstats_s_rows_in_2fs_d_rows, __pyx_k_pysamstats_s_rows_in_2fs_d_rows, sizeof(__pyx_k_pysamstats_s_rows_in_2fs_d_rows), 0, 0, 1, 0},
  {&__pyx_kp_s_pysamstats_s_rows_in_2fs_d_rows_2, __pyx_k_pysamstats_s_rows_in_2fs_d_rows_2, sizeof(__pyx_k_pysamstats_s_rows_in_2fs_d_rows_2), 0, 0, 1, 0},
  {&__pyx_kp_s_pysamstats_s_rows_in_2fs_d_rows_3, __pyx_k_pysamstats_s_rows_in_2fs_d_rows_3, sizeof(__pyx_k_pysamstats_s_rows_in_2fs_d_rows_3), 0, 0, 1, 0},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 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_other_chr, __pyx_k_reads_mate_other_chr, sizeof(__pyx_k_reads_mate_other_chr), 0, 0, 1, 1},
  {&__pyx_n_s_reads_mate_other_chr_fwd, __pyx_k_reads_mate_other_chr_fwd, sizeof(__pyx_k_reads_mate_other_chr_fwd), 0, 0, 1, 1},
  {&__pyx_n_s_reads_mate_other_chr_rev, __pyx_k_reads_mate_other_chr_rev, sizeof(__pyx_k_reads_mate_other_chr_rev), 0, 0, 1, 1},
  {&__pyx_n_s_reads_mate_same_strand, __pyx_k_reads_mate_same_strand, sizeof(__pyx_k_reads_mate_same_strand), 0, 0, 1, 1},
  {&__pyx_n_s_reads_mate_same_strand_fwd, __pyx_k_reads_mate_same_strand_fwd, sizeof(__pyx_k_reads_mate_same_strand_fwd), 0, 0, 1, 1},
  {&__pyx_n_s_reads_mate_same_strand_rev, __pyx_k_reads_mate_same_strand_rev, sizeof(__pyx_k_reads_mate_same_strand_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_mate_unmapped_fwd, __pyx_k_reads_mate_unmapped_fwd, sizeof(__pyx_k_reads_mate_unmapped_fwd), 0, 0, 1, 1},
  {&__pyx_n_s_reads_mate_unmapped_rev, __pyx_k_reads_mate_unmapped_rev, sizeof(__pyx_k_reads_mate_unmapped_rev), 0, 0, 1, 1},
  {&__pyx_n_s_reads_paired, __pyx_k_reads_paired, sizeof(__pyx_k_reads_paired), 0, 0, 1, 1},
  {&__pyx_n_s_reads_paired_fwd, __pyx_k_reads_paired_fwd, sizeof(__pyx_k_reads_paired_fwd), 0, 0, 1, 1},
  {&__pyx_n_s_reads_paired_rev, __pyx_k_reads_paired_rev, sizeof(__pyx_k_reads_paired_rev), 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_reads_softclipped_fwd, __pyx_k_reads_softclipped_fwd, sizeof(__pyx_k_reads_softclipped_fwd), 0, 0, 1, 1},
  {&__pyx_n_s_reads_softclipped_rev, __pyx_k_reads_softclipped_rev, sizeof(__pyx_k_reads_softclipped_rev), 0, 0, 1, 1},
  {&__pyx_n_s_rec, __pyx_k_rec, sizeof(__pyx_k_rec), 0, 0, 1, 1},
  {&__pyx_n_s_rec_baseq, __pyx_k_rec_baseq, sizeof(__pyx_k_rec_baseq), 0, 0, 1, 1},
  {&__pyx_n_s_rec_baseq_ext, __pyx_k_rec_baseq_ext, sizeof(__pyx_k_rec_baseq_ext), 0, 0, 1, 1},
  {&__pyx_n_s_rec_baseq_ext_pad, __pyx_k_rec_baseq_ext_pad, sizeof(__pyx_k_rec_baseq_ext_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_baseq_ext_strand, __pyx_k_rec_baseq_ext_strand, sizeof(__pyx_k_rec_baseq_ext_strand), 0, 0, 1, 1},
  {&__pyx_n_s_rec_baseq_ext_strand_pad, __pyx_k_rec_baseq_ext_strand_pad, sizeof(__pyx_k_rec_baseq_ext_strand_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_baseq_pad, __pyx_k_rec_baseq_pad, sizeof(__pyx_k_rec_baseq_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_baseq_strand, __pyx_k_rec_baseq_strand, sizeof(__pyx_k_rec_baseq_strand), 0, 0, 1, 1},
  {&__pyx_n_s_rec_baseq_strand_pad, __pyx_k_rec_baseq_strand_pad, sizeof(__pyx_k_rec_baseq_strand_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_coverage, __pyx_k_rec_coverage, sizeof(__pyx_k_rec_coverage), 0, 0, 1, 1},
  {&__pyx_n_s_rec_coverage_ext, __pyx_k_rec_coverage_ext, sizeof(__pyx_k_rec_coverage_ext), 0, 0, 1, 1},
  {&__pyx_n_s_rec_coverage_ext_pad, __pyx_k_rec_coverage_ext_pad, sizeof(__pyx_k_rec_coverage_ext_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_coverage_ext_strand, __pyx_k_rec_coverage_ext_strand, sizeof(__pyx_k_rec_coverage_ext_strand), 0, 0, 1, 1},
  {&__pyx_n_s_rec_coverage_ext_strand_pad, __pyx_k_rec_coverage_ext_strand_pad, sizeof(__pyx_k_rec_coverage_ext_strand_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_coverage_gc, __pyx_k_rec_coverage_gc, sizeof(__pyx_k_rec_coverage_gc), 0, 0, 1, 1},
  {&__pyx_n_s_rec_coverage_gc_pad, __pyx_k_rec_coverage_gc_pad, sizeof(__pyx_k_rec_coverage_gc_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_coverage_pad, __pyx_k_rec_coverage_pad, sizeof(__pyx_k_rec_coverage_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_coverage_strand, __pyx_k_rec_coverage_strand, sizeof(__pyx_k_rec_coverage_strand), 0, 0, 1, 1},
  {&__pyx_n_s_rec_coverage_strand_pad, __pyx_k_rec_coverage_strand_pad, sizeof(__pyx_k_rec_coverage_strand_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_mapq, __pyx_k_rec_mapq, sizeof(__pyx_k_rec_mapq), 0, 0, 1, 1},
  {&__pyx_n_s_rec_mapq_pad, __pyx_k_rec_mapq_pad, sizeof(__pyx_k_rec_mapq_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_mapq_strand, __pyx_k_rec_mapq_strand, sizeof(__pyx_k_rec_mapq_strand), 0, 0, 1, 1},
  {&__pyx_n_s_rec_mapq_strand_pad, __pyx_k_rec_mapq_strand_pad, sizeof(__pyx_k_rec_mapq_strand_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_tlen, __pyx_k_rec_tlen, sizeof(__pyx_k_rec_tlen), 0, 0, 1, 1},
  {&__pyx_n_s_rec_tlen_pad, __pyx_k_rec_tlen_pad, sizeof(__pyx_k_rec_tlen_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_tlen_strand, __pyx_k_rec_tlen_strand, sizeof(__pyx_k_rec_tlen_strand), 0, 0, 1, 1},
  {&__pyx_n_s_rec_tlen_strand_pad, __pyx_k_rec_tlen_strand_pad, sizeof(__pyx_k_rec_tlen_strand_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_variation, __pyx_k_rec_variation, sizeof(__pyx_k_rec_variation), 0, 0, 1, 1},
  {&__pyx_n_s_rec_variation_pad, __pyx_k_rec_variation_pad, sizeof(__pyx_k_rec_variation_pad), 0, 0, 1, 1},
  {&__pyx_n_s_rec_variation_strand, __pyx_k_rec_variation_strand, sizeof(__pyx_k_rec_variation_strand), 0, 0, 1, 1},
  {&__pyx_n_s_rec_variation_strand_pad, __pyx_k_rec_variation_strand_pad, sizeof(__pyx_k_rec_variation_strand_pad), 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_references, __pyx_k_references, sizeof(__pyx_k_references), 0, 0, 1, 1},
  {&__pyx_n_s_remove_node, __pyx_k_remove_node, sizeof(__pyx_k_remove_node), 0, 0, 1, 1},
  {&__pyx_n_s_rend, __pyx_k_rend, sizeof(__pyx_k_rend), 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_matches_fwd, __pyx_k_rms_baseq_matches_fwd, sizeof(__pyx_k_rms_baseq_matches_fwd), 0, 0, 1, 1},
  {&__pyx_n_s_rms_baseq_matches_pp, __pyx_k_rms_baseq_matches_pp, sizeof(__pyx_k_rms_baseq_matches_pp), 0, 0, 1, 1},
  {&__pyx_n_s_rms_baseq_matches_pp_fwd, __pyx_k_rms_baseq_matches_pp_fwd, sizeof(__pyx_k_rms_baseq_matches_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s_rms_baseq_matches_pp_rev, __pyx_k_rms_baseq_matches_pp_rev, sizeof(__pyx_k_rms_baseq_matches_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s_rms_baseq_matches_rev, __pyx_k_rms_baseq_matches_rev, sizeof(__pyx_k_rms_baseq_matches_rev), 0, 0, 1, 1},
  {&__pyx_n_s_rms_baseq_mismatches, __pyx_k_rms_baseq_mismatches, sizeof(__pyx_k_rms_baseq_mismatches), 0, 0, 1, 1},
  {&__pyx_n_s_rms_baseq_mismatches_fwd, __pyx_k_rms_baseq_mismatches_fwd, sizeof(__pyx_k_rms_baseq_mismatches_fwd), 0, 0, 1, 1},
  {&__pyx_n_s_rms_baseq_mismatches_pp, __pyx_k_rms_baseq_mismatches_pp, sizeof(__pyx_k_rms_baseq_mismatches_pp), 0, 0, 1, 1},
  {&__pyx_n_s_rms_baseq_mismatches_pp_fwd, __pyx_k_rms_baseq_mismatches_pp_fwd, sizeof(__pyx_k_rms_baseq_mismatches_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s_rms_baseq_mismatches_pp_rev, __pyx_k_rms_baseq_mismatches_pp_rev, sizeof(__pyx_k_rms_baseq_mismatches_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s_rms_baseq_mismatches_rev, __pyx_k_rms_baseq_mismatches_rev, sizeof(__pyx_k_rms_baseq_mismatches_rev), 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_row, __pyx_k_row, sizeof(__pyx_k_row), 0, 0, 1, 1},
  {&__pyx_n_s_rows, __pyx_k_rows, sizeof(__pyx_k_rows), 0, 0, 1, 1},
  {&__pyx_n_s_rstart, __pyx_k_rstart, sizeof(__pyx_k_rstart), 0, 0, 1, 1},
  {&__pyx_n_s_rtid, __pyx_k_rtid, sizeof(__pyx_k_rtid), 0, 0, 1, 1},
  {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1},
  {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1},
  {&__pyx_n_s_shuffle, __pyx_k_shuffle, sizeof(__pyx_k_shuffle), 0, 0, 1, 1},
  {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
  {&__pyx_n_s_stat, __pyx_k_stat, sizeof(__pyx_k_stat), 0, 0, 1, 1},
  {&__pyx_n_s_stat_2, __pyx_k_stat_2, sizeof(__pyx_k_stat_2), 0, 0, 1, 1},
  {&__pyx_n_s_stat_alignment_binned, __pyx_k_stat_alignment_binned, sizeof(__pyx_k_stat_alignment_binned), 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_ext_strand, __pyx_k_stat_baseq_ext_strand, sizeof(__pyx_k_stat_baseq_ext_strand), 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_binned, __pyx_k_stat_coverage_binned, sizeof(__pyx_k_stat_coverage_binned), 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_ext_binned, __pyx_k_stat_coverage_ext_binned, sizeof(__pyx_k_stat_coverage_ext_binned), 0, 0, 1, 1},
  {&__pyx_n_s_stat_coverage_ext_strand, __pyx_k_stat_coverage_ext_strand, sizeof(__pyx_k_stat_coverage_ext_strand), 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_coverage_gc_locals__rec_cov, __pyx_k_stat_coverage_gc_locals__rec_cov, sizeof(__pyx_k_stat_coverage_gc_locals__rec_cov), 0, 0, 1, 1},
  {&__pyx_n_s_stat_coverage_gc_locals__rec_cov_2, __pyx_k_stat_coverage_gc_locals__rec_cov_2, sizeof(__pyx_k_stat_coverage_gc_locals__rec_cov_2), 0, 0, 1, 1},
  {&__pyx_n_s_stat_coverage_strand, __pyx_k_stat_coverage_strand, sizeof(__pyx_k_stat_coverage_strand), 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_binned, __pyx_k_stat_mapq_binned, sizeof(__pyx_k_stat_mapq_binned), 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_binned, __pyx_k_stat_tlen_binned, sizeof(__pyx_k_stat_tlen_binned), 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_stat_variation_strand, __pyx_k_stat_variation_strand, sizeof(__pyx_k_stat_variation_strand), 0, 0, 1, 1},
  {&__pyx_n_s_statfun, __pyx_k_statfun, sizeof(__pyx_k_statfun), 0, 0, 1, 1},
  {&__pyx_kp_s_statistics_type_not_found_r, __pyx_k_statistics_type_not_found_r, sizeof(__pyx_k_statistics_type_not_found_r), 0, 0, 1, 0},
  {&__pyx_n_s_stats_function, __pyx_k_stats_function, sizeof(__pyx_k_stats_function), 0, 0, 1, 1},
  {&__pyx_n_s_stats_type, __pyx_k_stats_type, sizeof(__pyx_k_stats_type), 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_string_types, __pyx_k_string_types, sizeof(__pyx_k_string_types), 0, 0, 1, 1},
  {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1},
  {&__pyx_n_s_sys_2, __pyx_k_sys_2, sizeof(__pyx_k_sys_2), 0, 0, 1, 1},
  {&__pyx_n_s_t, __pyx_k_t, sizeof(__pyx_k_t), 0, 0, 1, 1},
  {&__pyx_n_s_tables, __pyx_k_tables, sizeof(__pyx_k_tables), 0, 0, 1, 1},
  {&__pyx_n_s_tabulate, __pyx_k_tabulate, sizeof(__pyx_k_tabulate), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1},
  {&__pyx_n_s_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 0, 1, 1},
  {&__pyx_n_s_time_2, __pyx_k_time_2, sizeof(__pyx_k_time_2), 0, 0, 1, 1},
  {&__pyx_n_s_title, __pyx_k_title, sizeof(__pyx_k_title), 0, 0, 1, 1},
  {&__pyx_n_s_truncate, __pyx_k_truncate, sizeof(__pyx_k_truncate), 0, 0, 1, 1},
  {&__pyx_n_s_u1, __pyx_k_u1, sizeof(__pyx_k_u1), 0, 0, 1, 1},
  {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1},
  {&__pyx_n_s_upper, __pyx_k_upper, sizeof(__pyx_k_upper), 0, 0, 1, 1},
  {&__pyx_n_s_version, __pyx_k_version, sizeof(__pyx_k_version), 0, 0, 1, 1},
  {&__pyx_n_s_version_info, __pyx_k_version_info, sizeof(__pyx_k_version_info), 0, 0, 1, 1},
  {&__pyx_n_s_view, __pyx_k_view, sizeof(__pyx_k_view), 0, 0, 1, 1},
  {&__pyx_n_s_window_offset, __pyx_k_window_offset, sizeof(__pyx_k_window_offset), 0, 0, 1, 1},
  {&__pyx_n_s_window_size, __pyx_k_window_size, sizeof(__pyx_k_window_size), 0, 0, 1, 1},
  {&__pyx_n_s_write_csv, __pyx_k_write_csv, sizeof(__pyx_k_write_csv), 0, 0, 1, 1},
  {&__pyx_n_s_write_hdf5, __pyx_k_write_hdf5, sizeof(__pyx_k_write_hdf5), 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_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_zlib, __pyx_k_zlib, sizeof(__pyx_k_zlib), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_round = __Pyx_GetBuiltinName(__pyx_n_s_round); if (!__pyx_builtin_round) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_print = __Pyx_GetBuiltinName(__pyx_n_s_print); if (!__pyx_builtin_print) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_Exception = __Pyx_GetBuiltinName(__pyx_n_s_Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4169; __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":3014
 *         window_offset = window_size / 2
 * 
 *     def _rec_coverage_gc(AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                          PileupColumn col, bint one_based):
 *         chrom = alignmentfile.getrname(col.tid)
 */
  __pyx_tuple_ = PyTuple_Pack(10, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_col, __pyx_n_s_one_based, __pyx_n_s_chrom, __pyx_n_s_ref_window_start, __pyx_n_s_ref_window_end, __pyx_n_s_ref_window, __pyx_n_s_gc_percent, __pyx_n_s_rec); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);
  __pyx_codeobj__2 = (PyObject*)__Pyx_PyCode_New(4, 0, 10, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple_, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_rec_coverage_gc, 3014, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3034
 *         return rec
 * 
 *     def _rec_coverage_gc_pad(FastaFile fafile, chrom, pos,             # <<<<<<<<<<<<<<
 *                              bint one_based):
 *         ref_window_start = pos - window_offset
 */
  __pyx_tuple__3 = PyTuple_Pack(9, __pyx_n_s_fafile, __pyx_n_s_chrom, __pyx_n_s_pos, __pyx_n_s_one_based, __pyx_n_s_ref_window_start, __pyx_n_s_ref_window_end, __pyx_n_s_ref_window, __pyx_n_s_gc_percent, __pyx_n_s_rec); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);
  __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(4, 0, 9, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__3, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_rec_coverage_gc_pad, 3034, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3863
 * 
 *     if chrom is None:
 *         return None, None             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
  __pyx_tuple__6 = PyTuple_Pack(2, Py_None, Py_None); if (unlikely(!__pyx_tuple__6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);

  /* "pysamstats.pyx":4015
 *     default_dtype = globals()['dtype_' + stats_type]
 *     dtype = dict(default_dtype)
 *     dtype_overrides = kwargs.pop('dtype', None)             # <<<<<<<<<<<<<<
 *     if dtype_overrides:
 *         # expect dict
 */
  __pyx_tuple__8 = PyTuple_Pack(2, __pyx_n_s_dtype_2, Py_None); if (unlikely(!__pyx_tuple__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);

  /* "pysamstats.pyx":4163
 *         try:
 *             self.stats_function = globals()['stat_' + stats_type]
 *             self.fields = kwargs.pop('fields', None)             # <<<<<<<<<<<<<<
 *             if self.fields is None:
 *                 self.fields = globals()['fields_' + stats_type]
 */
  __pyx_tuple__9 = PyTuple_Pack(2, __pyx_n_s_fields, Py_None); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__9);
  __Pyx_GIVEREF(__pyx_tuple__9);

  /* "pysamstats.pyx":4185
 * 
 *     # determine fields to load
 *     fields = kwargs.pop('fields', None)             # <<<<<<<<<<<<<<
 *     if not fields:
 *         fields = [t[0] for t in default_dtype]
 */
  __pyx_tuple__10 = PyTuple_Pack(2, __pyx_n_s_fields, Py_None); if (unlikely(!__pyx_tuple__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "pysamstats.pyx":4191
 *     # determine dtype
 *     dtype = dict(default_dtype)
 *     dtype_overrides = kwargs.pop('dtype', None)             # <<<<<<<<<<<<<<
 *     if dtype_overrides:
 *         # expect dict
 */
  __pyx_tuple__11 = PyTuple_Pack(2, __pyx_n_s_dtype_2, Py_None); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);

  /* "pysamstats.pyx":81
 * 
 * 
 * dtype_coverage = [('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *                   ('pos', 'i4'),
 *                   ('reads_all', 'i4'),
 */
  __pyx_tuple__12 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "pysamstats.pyx":82
 * 
 * dtype_coverage = [('chrom', 'a12'),
 *                   ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *                   ('reads_all', 'i4'),
 *                   ('reads_pp', 'i4')]
 */
  __pyx_tuple__13 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);

  /* "pysamstats.pyx":83
 * dtype_coverage = [('chrom', 'a12'),
 *                   ('pos', 'i4'),
 *                   ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *                   ('reads_pp', 'i4')]
 * 
 */
  __pyx_tuple__14 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__14);
  __Pyx_GIVEREF(__pyx_tuple__14);

  /* "pysamstats.pyx":84
 *                   ('pos', 'i4'),
 *                   ('reads_all', 'i4'),
 *                   ('reads_pp', 'i4')]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__15 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);

  /* "pysamstats.pyx":137
 * 
 * 
 * def stat_coverage(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate coverage statistics per genome position.
 * 
 */
  __pyx_tuple__16 = PyTuple_Pack(2, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);
  __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__16, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_coverage, 137, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":172
 * 
 * 
 * def load_coverage(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage, dtype_coverage, *args, **kwargs)
 * 
 */
  __pyx_tuple__18 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);
  __pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_coverage, 172, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":182
 * 
 * dtype_coverage_strand = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__20 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);

  /* "pysamstats.pyx":183
 * dtype_coverage_strand = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 */
  __pyx_tuple__21 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "pysamstats.pyx":184
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 */
  __pyx_tuple__22 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "pysamstats.pyx":185
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__23 = PyTuple_Pack(2, __pyx_n_s_reads_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "pysamstats.pyx":186
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 */
  __pyx_tuple__24 = PyTuple_Pack(2, __pyx_n_s_reads_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "pysamstats.pyx":187
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 */
  __pyx_tuple__25 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__25);
  __Pyx_GIVEREF(__pyx_tuple__25);

  /* "pysamstats.pyx":188
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_rev', 'i4'),
 * ]
 */
  __pyx_tuple__26 = PyTuple_Pack(2, __pyx_n_s_reads_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);

  /* "pysamstats.pyx":189
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__27 = PyTuple_Pack(2, __pyx_n_s_reads_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__27);
  __Pyx_GIVEREF(__pyx_tuple__27);

  /* "pysamstats.pyx":265
 * 
 * 
 * def stat_coverage_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate coverage statistics by strand per genome position.
 * 
 */
  __pyx_tuple__28 = PyTuple_Pack(2, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);
  __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_coverage_strand, 265, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":301
 * 
 * 
 * def load_coverage_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_strand, dtype_coverage_strand,
 *                       *args, **kwargs)
 */
  __pyx_tuple__30 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);
  __pyx_codeobj__31 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_coverage_strand, 301, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":312
 * 
 * dtype_coverage_ext = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__32 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);

  /* "pysamstats.pyx":313
 * dtype_coverage_ext = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__33 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);

  /* "pysamstats.pyx":314
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('reads_mate_unmapped', 'i4'),
 */
  __pyx_tuple__34 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__34)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);

  /* "pysamstats.pyx":315
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mate_unmapped', 'i4'),
 *     ('reads_mate_other_chr', 'i4'),
 */
  __pyx_tuple__35 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);

  /* "pysamstats.pyx":316
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('reads_mate_unmapped', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mate_other_chr', 'i4'),
 *     ('reads_mate_same_strand', 'i4'),
 */
  __pyx_tuple__36 = PyTuple_Pack(2, __pyx_n_s_reads_mate_unmapped, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__36)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);

  /* "pysamstats.pyx":317
 *     ('reads_pp', 'i4'),
 *     ('reads_mate_unmapped', 'i4'),
 *     ('reads_mate_other_chr', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mate_same_strand', 'i4'),
 *     ('reads_faceaway', 'i4'),
 */
  __pyx_tuple__37 = PyTuple_Pack(2, __pyx_n_s_reads_mate_other_chr, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);

  /* "pysamstats.pyx":318
 *     ('reads_mate_unmapped', 'i4'),
 *     ('reads_mate_other_chr', 'i4'),
 *     ('reads_mate_same_strand', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_faceaway', 'i4'),
 *     ('reads_softclipped', 'i4'),
 */
  __pyx_tuple__38 = PyTuple_Pack(2, __pyx_n_s_reads_mate_same_strand, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);

  /* "pysamstats.pyx":319
 *     ('reads_mate_other_chr', 'i4'),
 *     ('reads_mate_same_strand', 'i4'),
 *     ('reads_faceaway', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_softclipped', 'i4'),
 *     ('reads_duplicate', 'i4')
 */
  __pyx_tuple__39 = PyTuple_Pack(2, __pyx_n_s_reads_faceaway, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__39)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);

  /* "pysamstats.pyx":320
 *     ('reads_mate_same_strand', 'i4'),
 *     ('reads_faceaway', 'i4'),
 *     ('reads_softclipped', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_duplicate', 'i4')
 * ]
 */
  __pyx_tuple__40 = PyTuple_Pack(2, __pyx_n_s_reads_softclipped, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__40)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);

  /* "pysamstats.pyx":321
 *     ('reads_faceaway', 'i4'),
 *     ('reads_softclipped', 'i4'),
 *     ('reads_duplicate', 'i4')             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__41 = PyTuple_Pack(2, __pyx_n_s_reads_duplicate, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__41)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);

  /* "pysamstats.pyx":415
 * 
 * 
 * def stat_coverage_ext(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended coverage statistics per genome position.
 * 
 */
  __pyx_tuple__42 = PyTuple_Pack(2, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);
  __pyx_codeobj__43 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__42, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_coverage_ext, 415, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__43)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":450
 * 
 * 
 * def load_coverage_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_ext, dtype_coverage_ext, *args, **kwargs)
 * 
 */
  __pyx_tuple__44 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__44)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);
  __pyx_codeobj__45 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__44, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_coverage_ext, 450, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":460
 * 
 * dtype_coverage_ext_strand = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__46 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__46)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__46);
  __Pyx_GIVEREF(__pyx_tuple__46);

  /* "pysamstats.pyx":461
 * dtype_coverage_ext_strand = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 */
  __pyx_tuple__47 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__47);
  __Pyx_GIVEREF(__pyx_tuple__47);

  /* "pysamstats.pyx":462
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 */
  __pyx_tuple__48 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__48)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);

  /* "pysamstats.pyx":463
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__49 = PyTuple_Pack(2, __pyx_n_s_reads_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__49)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__49);
  __Pyx_GIVEREF(__pyx_tuple__49);

  /* "pysamstats.pyx":464
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 */
  __pyx_tuple__50 = PyTuple_Pack(2, __pyx_n_s_reads_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__50)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__50);
  __Pyx_GIVEREF(__pyx_tuple__50);

  /* "pysamstats.pyx":465
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 */
  __pyx_tuple__51 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);

  /* "pysamstats.pyx":466
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_rev', 'i4'),
 *     ('reads_mate_unmapped', 'i4'),
 */
  __pyx_tuple__52 = PyTuple_Pack(2, __pyx_n_s_reads_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__52);
  __Pyx_GIVEREF(__pyx_tuple__52);

  /* "pysamstats.pyx":467
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mate_unmapped', 'i4'),
 *     ('reads_mate_unmapped_fwd', 'i4'),
 */
  __pyx_tuple__53 = PyTuple_Pack(2, __pyx_n_s_reads_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__53)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);

  /* "pysamstats.pyx":468
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 *     ('reads_mate_unmapped', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mate_unmapped_fwd', 'i4'),
 *     ('reads_mate_unmapped_rev', 'i4'),
 */
  __pyx_tuple__54 = PyTuple_Pack(2, __pyx_n_s_reads_mate_unmapped, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__54)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__54);
  __Pyx_GIVEREF(__pyx_tuple__54);

  /* "pysamstats.pyx":469
 *     ('reads_pp_rev', 'i4'),
 *     ('reads_mate_unmapped', 'i4'),
 *     ('reads_mate_unmapped_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mate_unmapped_rev', 'i4'),
 *     ('reads_mate_other_chr', 'i4'),
 */
  __pyx_tuple__55 = PyTuple_Pack(2, __pyx_n_s_reads_mate_unmapped_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);

  /* "pysamstats.pyx":470
 *     ('reads_mate_unmapped', 'i4'),
 *     ('reads_mate_unmapped_fwd', 'i4'),
 *     ('reads_mate_unmapped_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mate_other_chr', 'i4'),
 *     ('reads_mate_other_chr_fwd', 'i4'),
 */
  __pyx_tuple__56 = PyTuple_Pack(2, __pyx_n_s_reads_mate_unmapped_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__56)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__56);
  __Pyx_GIVEREF(__pyx_tuple__56);

  /* "pysamstats.pyx":471
 *     ('reads_mate_unmapped_fwd', 'i4'),
 *     ('reads_mate_unmapped_rev', 'i4'),
 *     ('reads_mate_other_chr', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mate_other_chr_fwd', 'i4'),
 *     ('reads_mate_other_chr_rev', 'i4'),
 */
  __pyx_tuple__57 = PyTuple_Pack(2, __pyx_n_s_reads_mate_other_chr, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__57)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__57);
  __Pyx_GIVEREF(__pyx_tuple__57);

  /* "pysamstats.pyx":472
 *     ('reads_mate_unmapped_rev', 'i4'),
 *     ('reads_mate_other_chr', 'i4'),
 *     ('reads_mate_other_chr_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mate_other_chr_rev', 'i4'),
 *     ('reads_mate_same_strand', 'i4'),
 */
  __pyx_tuple__58 = PyTuple_Pack(2, __pyx_n_s_reads_mate_other_chr_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__58)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__58);
  __Pyx_GIVEREF(__pyx_tuple__58);

  /* "pysamstats.pyx":473
 *     ('reads_mate_other_chr', 'i4'),
 *     ('reads_mate_other_chr_fwd', 'i4'),
 *     ('reads_mate_other_chr_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mate_same_strand', 'i4'),
 *     ('reads_mate_same_strand_fwd', 'i4'),
 */
  __pyx_tuple__59 = PyTuple_Pack(2, __pyx_n_s_reads_mate_other_chr_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__59)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);

  /* "pysamstats.pyx":474
 *     ('reads_mate_other_chr_fwd', 'i4'),
 *     ('reads_mate_other_chr_rev', 'i4'),
 *     ('reads_mate_same_strand', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mate_same_strand_fwd', 'i4'),
 *     ('reads_mate_same_strand_rev', 'i4'),
 */
  __pyx_tuple__60 = PyTuple_Pack(2, __pyx_n_s_reads_mate_same_strand, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__60);
  __Pyx_GIVEREF(__pyx_tuple__60);

  /* "pysamstats.pyx":475
 *     ('reads_mate_other_chr_rev', 'i4'),
 *     ('reads_mate_same_strand', 'i4'),
 *     ('reads_mate_same_strand_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mate_same_strand_rev', 'i4'),
 *     ('reads_faceaway', 'i4'),
 */
  __pyx_tuple__61 = PyTuple_Pack(2, __pyx_n_s_reads_mate_same_strand_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__61)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__61);
  __Pyx_GIVEREF(__pyx_tuple__61);

  /* "pysamstats.pyx":476
 *     ('reads_mate_same_strand', 'i4'),
 *     ('reads_mate_same_strand_fwd', 'i4'),
 *     ('reads_mate_same_strand_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_faceaway', 'i4'),
 *     ('reads_faceaway_fwd', 'i4'),
 */
  __pyx_tuple__62 = PyTuple_Pack(2, __pyx_n_s_reads_mate_same_strand_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__62)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__62);
  __Pyx_GIVEREF(__pyx_tuple__62);

  /* "pysamstats.pyx":477
 *     ('reads_mate_same_strand_fwd', 'i4'),
 *     ('reads_mate_same_strand_rev', 'i4'),
 *     ('reads_faceaway', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_faceaway_fwd', 'i4'),
 *     ('reads_faceaway_rev', 'i4'),
 */
  __pyx_tuple__63 = PyTuple_Pack(2, __pyx_n_s_reads_faceaway, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__63);
  __Pyx_GIVEREF(__pyx_tuple__63);

  /* "pysamstats.pyx":478
 *     ('reads_mate_same_strand_rev', 'i4'),
 *     ('reads_faceaway', 'i4'),
 *     ('reads_faceaway_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_faceaway_rev', 'i4'),
 *     ('reads_softclipped', 'i4'),
 */
  __pyx_tuple__64 = PyTuple_Pack(2, __pyx_n_s_reads_faceaway_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__64)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__64);
  __Pyx_GIVEREF(__pyx_tuple__64);

  /* "pysamstats.pyx":479
 *     ('reads_faceaway', 'i4'),
 *     ('reads_faceaway_fwd', 'i4'),
 *     ('reads_faceaway_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_softclipped', 'i4'),
 *     ('reads_softclipped_fwd', 'i4'),
 */
  __pyx_tuple__65 = PyTuple_Pack(2, __pyx_n_s_reads_faceaway_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__65)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__65);
  __Pyx_GIVEREF(__pyx_tuple__65);

  /* "pysamstats.pyx":480
 *     ('reads_faceaway_fwd', 'i4'),
 *     ('reads_faceaway_rev', 'i4'),
 *     ('reads_softclipped', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_softclipped_fwd', 'i4'),
 *     ('reads_softclipped_rev', 'i4'),
 */
  __pyx_tuple__66 = PyTuple_Pack(2, __pyx_n_s_reads_softclipped, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__66)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__66);
  __Pyx_GIVEREF(__pyx_tuple__66);

  /* "pysamstats.pyx":481
 *     ('reads_faceaway_rev', 'i4'),
 *     ('reads_softclipped', 'i4'),
 *     ('reads_softclipped_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_softclipped_rev', 'i4'),
 *     ('reads_duplicate', 'i4'),
 */
  __pyx_tuple__67 = PyTuple_Pack(2, __pyx_n_s_reads_softclipped_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__67)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__67);
  __Pyx_GIVEREF(__pyx_tuple__67);

  /* "pysamstats.pyx":482
 *     ('reads_softclipped', 'i4'),
 *     ('reads_softclipped_fwd', 'i4'),
 *     ('reads_softclipped_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_duplicate', 'i4'),
 *     ('reads_duplicate_fwd', 'i4'),
 */
  __pyx_tuple__68 = PyTuple_Pack(2, __pyx_n_s_reads_softclipped_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__68)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__68);
  __Pyx_GIVEREF(__pyx_tuple__68);

  /* "pysamstats.pyx":483
 *     ('reads_softclipped_fwd', 'i4'),
 *     ('reads_softclipped_rev', 'i4'),
 *     ('reads_duplicate', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_duplicate_fwd', 'i4'),
 *     ('reads_duplicate_rev', 'i4'),
 */
  __pyx_tuple__69 = PyTuple_Pack(2, __pyx_n_s_reads_duplicate, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__69)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__69);
  __Pyx_GIVEREF(__pyx_tuple__69);

  /* "pysamstats.pyx":484
 *     ('reads_softclipped_rev', 'i4'),
 *     ('reads_duplicate', 'i4'),
 *     ('reads_duplicate_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_duplicate_rev', 'i4'),
 * ]
 */
  __pyx_tuple__70 = PyTuple_Pack(2, __pyx_n_s_reads_duplicate_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__70)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__70);
  __Pyx_GIVEREF(__pyx_tuple__70);

  /* "pysamstats.pyx":485
 *     ('reads_duplicate', 'i4'),
 *     ('reads_duplicate_fwd', 'i4'),
 *     ('reads_duplicate_rev', 'i4'),             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__71 = PyTuple_Pack(2, __pyx_n_s_reads_duplicate_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__71)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__71);
  __Pyx_GIVEREF(__pyx_tuple__71);

  /* "pysamstats.pyx":660
 * 
 * 
 * def stat_coverage_ext_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended coverage statistics by strand per genome position.
 * 
 */
  __pyx_tuple__72 = PyTuple_Pack(2, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__72)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__72);
  __Pyx_GIVEREF(__pyx_tuple__72);
  __pyx_codeobj__73 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__72, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_coverage_ext_strand, 660, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__73)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":695
 * 
 * 
 * def load_coverage_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_ext_strand, dtype_coverage_ext_strand,
 *                        *args, **kwargs)
 */
  __pyx_tuple__74 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__74)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__74);
  __Pyx_GIVEREF(__pyx_tuple__74);
  __pyx_codeobj__75 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__74, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_coverage_ext_strand, 695, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__75)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":706
 * 
 * dtype_variation = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('ref', 'a1'),
 */
  __pyx_tuple__76 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__76)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__76);
  __Pyx_GIVEREF(__pyx_tuple__76);

  /* "pysamstats.pyx":707
 * dtype_variation = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('ref', 'a1'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__77 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__77)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__77);
  __Pyx_GIVEREF(__pyx_tuple__77);

  /* "pysamstats.pyx":708
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('ref', 'a1'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__78 = PyTuple_Pack(2, __pyx_n_s_ref, __pyx_n_s_a1); if (unlikely(!__pyx_tuple__78)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__78);
  __Pyx_GIVEREF(__pyx_tuple__78);

  /* "pysamstats.pyx":709
 *     ('pos', 'i4'),
 *     ('ref', 'a1'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('matches', 'i4'),
 */
  __pyx_tuple__79 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__79)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__79);
  __Pyx_GIVEREF(__pyx_tuple__79);

  /* "pysamstats.pyx":710
 *     ('ref', 'a1'),
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches', 'i4'),
 *     ('matches_pp', 'i4'),
 */
  __pyx_tuple__80 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__80)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__80);
  __Pyx_GIVEREF(__pyx_tuple__80);

  /* "pysamstats.pyx":711
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('matches', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches_pp', 'i4'),
 *     ('mismatches', 'i4'),
 */
  __pyx_tuple__81 = PyTuple_Pack(2, __pyx_n_s_matches, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__81)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__81);
  __Pyx_GIVEREF(__pyx_tuple__81);

  /* "pysamstats.pyx":712
 *     ('reads_pp', 'i4'),
 *     ('matches', 'i4'),
 *     ('matches_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches', 'i4'),
 *     ('mismatches_pp', 'i4'),
 */
  __pyx_tuple__82 = PyTuple_Pack(2, __pyx_n_s_matches_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__82)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__82);
  __Pyx_GIVEREF(__pyx_tuple__82);

  /* "pysamstats.pyx":713
 *     ('matches', 'i4'),
 *     ('matches_pp', 'i4'),
 *     ('mismatches', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches_pp', 'i4'),
 *     ('deletions', 'i4'),
 */
  __pyx_tuple__83 = PyTuple_Pack(2, __pyx_n_s_mismatches, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__83)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__83);
  __Pyx_GIVEREF(__pyx_tuple__83);

  /* "pysamstats.pyx":714
 *     ('matches_pp', 'i4'),
 *     ('mismatches', 'i4'),
 *     ('mismatches_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('deletions', 'i4'),
 *     ('deletions_pp', 'i4'),
 */
  __pyx_tuple__84 = PyTuple_Pack(2, __pyx_n_s_mismatches_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__84)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__84);
  __Pyx_GIVEREF(__pyx_tuple__84);

  /* "pysamstats.pyx":715
 *     ('mismatches', 'i4'),
 *     ('mismatches_pp', 'i4'),
 *     ('deletions', 'i4'),             # <<<<<<<<<<<<<<
 *     ('deletions_pp', 'i4'),
 *     ('insertions', 'i4'),
 */
  __pyx_tuple__85 = PyTuple_Pack(2, __pyx_n_s_deletions, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__85)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__85);
  __Pyx_GIVEREF(__pyx_tuple__85);

  /* "pysamstats.pyx":716
 *     ('mismatches_pp', 'i4'),
 *     ('deletions', 'i4'),
 *     ('deletions_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('insertions', 'i4'),
 *     ('insertions_pp', 'i4'),
 */
  __pyx_tuple__86 = PyTuple_Pack(2, __pyx_n_s_deletions_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__86)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__86);
  __Pyx_GIVEREF(__pyx_tuple__86);

  /* "pysamstats.pyx":717
 *     ('deletions', 'i4'),
 *     ('deletions_pp', 'i4'),
 *     ('insertions', 'i4'),             # <<<<<<<<<<<<<<
 *     ('insertions_pp', 'i4'),
 *     ('A', 'i4'),
 */
  __pyx_tuple__87 = PyTuple_Pack(2, __pyx_n_s_insertions, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__87)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__87);
  __Pyx_GIVEREF(__pyx_tuple__87);

  /* "pysamstats.pyx":718
 *     ('deletions_pp', 'i4'),
 *     ('insertions', 'i4'),
 *     ('insertions_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('A', 'i4'),
 *     ('A_pp', 'i4'),
 */
  __pyx_tuple__88 = PyTuple_Pack(2, __pyx_n_s_insertions_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__88)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__88);
  __Pyx_GIVEREF(__pyx_tuple__88);

  /* "pysamstats.pyx":719
 *     ('insertions', 'i4'),
 *     ('insertions_pp', 'i4'),
 *     ('A', 'i4'),             # <<<<<<<<<<<<<<
 *     ('A_pp', 'i4'),
 *     ('C', 'i4'),
 */
  __pyx_tuple__89 = PyTuple_Pack(2, __pyx_n_s_A, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__89)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__89);
  __Pyx_GIVEREF(__pyx_tuple__89);

  /* "pysamstats.pyx":720
 *     ('insertions_pp', 'i4'),
 *     ('A', 'i4'),
 *     ('A_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('C', 'i4'),
 *     ('C_pp', 'i4'),
 */
  __pyx_tuple__90 = PyTuple_Pack(2, __pyx_n_s_A_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__90)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__90);
  __Pyx_GIVEREF(__pyx_tuple__90);

  /* "pysamstats.pyx":721
 *     ('A', 'i4'),
 *     ('A_pp', 'i4'),
 *     ('C', 'i4'),             # <<<<<<<<<<<<<<
 *     ('C_pp', 'i4'),
 *     ('T', 'i4'),
 */
  __pyx_tuple__91 = PyTuple_Pack(2, __pyx_n_s_C, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__91)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__91);
  __Pyx_GIVEREF(__pyx_tuple__91);

  /* "pysamstats.pyx":722
 *     ('A_pp', 'i4'),
 *     ('C', 'i4'),
 *     ('C_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('T', 'i4'),
 *     ('T_pp', 'i4'),
 */
  __pyx_tuple__92 = PyTuple_Pack(2, __pyx_n_s_C_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__92)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 722; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__92);
  __Pyx_GIVEREF(__pyx_tuple__92);

  /* "pysamstats.pyx":723
 *     ('C', 'i4'),
 *     ('C_pp', 'i4'),
 *     ('T', 'i4'),             # <<<<<<<<<<<<<<
 *     ('T_pp', 'i4'),
 *     ('G', 'i4'),
 */
  __pyx_tuple__93 = PyTuple_Pack(2, __pyx_n_s_T, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__93)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__93);
  __Pyx_GIVEREF(__pyx_tuple__93);

  /* "pysamstats.pyx":724
 *     ('C_pp', 'i4'),
 *     ('T', 'i4'),
 *     ('T_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('G', 'i4'),
 *     ('G_pp', 'i4'),
 */
  __pyx_tuple__94 = PyTuple_Pack(2, __pyx_n_s_T_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__94)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__94);
  __Pyx_GIVEREF(__pyx_tuple__94);

  /* "pysamstats.pyx":725
 *     ('T', 'i4'),
 *     ('T_pp', 'i4'),
 *     ('G', 'i4'),             # <<<<<<<<<<<<<<
 *     ('G_pp', 'i4'),
 *     ('N', 'i4'),
 */
  __pyx_tuple__95 = PyTuple_Pack(2, __pyx_n_s_G, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__95)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__95);
  __Pyx_GIVEREF(__pyx_tuple__95);

  /* "pysamstats.pyx":726
 *     ('T_pp', 'i4'),
 *     ('G', 'i4'),
 *     ('G_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('N', 'i4'),
 *     ('N_pp', 'i4')
 */
  __pyx_tuple__96 = PyTuple_Pack(2, __pyx_n_s_G_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__96)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__96);
  __Pyx_GIVEREF(__pyx_tuple__96);

  /* "pysamstats.pyx":727
 *     ('G', 'i4'),
 *     ('G_pp', 'i4'),
 *     ('N', 'i4'),             # <<<<<<<<<<<<<<
 *     ('N_pp', 'i4')
 * ]
 */
  __pyx_tuple__97 = PyTuple_Pack(2, __pyx_n_s_N, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__97)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__97);
  __Pyx_GIVEREF(__pyx_tuple__97);

  /* "pysamstats.pyx":728
 *     ('G_pp', 'i4'),
 *     ('N', 'i4'),
 *     ('N_pp', 'i4')             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__98 = PyTuple_Pack(2, __pyx_n_s_N_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__98)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__98);
  __Pyx_GIVEREF(__pyx_tuple__98);

  /* "pysamstats.pyx":874
 * 
 * 
 * def stat_variation(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate variation statistics per genome position.
 * 
 */
  __pyx_tuple__99 = PyTuple_Pack(3, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__99)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__99);
  __Pyx_GIVEREF(__pyx_tuple__99);
  __pyx_codeobj__100 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__99, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_variation, 874, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__100)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":911
 * 
 * 
 * def load_variation(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_variation, dtype_variation, *args, **kwargs)
 * 
 */
  __pyx_tuple__101 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__101)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__101);
  __Pyx_GIVEREF(__pyx_tuple__101);
  __pyx_codeobj__102 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__101, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_variation, 911, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__102)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":921
 * 
 * dtype_variation_strand = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('ref', 'a1'),
 */
  __pyx_tuple__103 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__103)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__103);
  __Pyx_GIVEREF(__pyx_tuple__103);

  /* "pysamstats.pyx":922
 * dtype_variation_strand = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('ref', 'a1'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__104 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__104)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__104);
  __Pyx_GIVEREF(__pyx_tuple__104);

  /* "pysamstats.pyx":923
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('ref', 'a1'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 */
  __pyx_tuple__105 = PyTuple_Pack(2, __pyx_n_s_ref, __pyx_n_s_a1); if (unlikely(!__pyx_tuple__105)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__105);
  __Pyx_GIVEREF(__pyx_tuple__105);

  /* "pysamstats.pyx":924
 *     ('pos', 'i4'),
 *     ('ref', 'a1'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 */
  __pyx_tuple__106 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__106)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__106);
  __Pyx_GIVEREF(__pyx_tuple__106);

  /* "pysamstats.pyx":925
 *     ('ref', 'a1'),
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__107 = PyTuple_Pack(2, __pyx_n_s_reads_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__107)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__107);
  __Pyx_GIVEREF(__pyx_tuple__107);

  /* "pysamstats.pyx":926
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 */
  __pyx_tuple__108 = PyTuple_Pack(2, __pyx_n_s_reads_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__108)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__108);
  __Pyx_GIVEREF(__pyx_tuple__108);

  /* "pysamstats.pyx":927
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 */
  __pyx_tuple__109 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__109)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__109);
  __Pyx_GIVEREF(__pyx_tuple__109);

  /* "pysamstats.pyx":928
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_rev', 'i4'),
 *     ('matches', 'i4'),
 */
  __pyx_tuple__110 = PyTuple_Pack(2, __pyx_n_s_reads_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__110)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 928; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__110);
  __Pyx_GIVEREF(__pyx_tuple__110);

  /* "pysamstats.pyx":929
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches', 'i4'),
 *     ('matches_fwd', 'i4'),
 */
  __pyx_tuple__111 = PyTuple_Pack(2, __pyx_n_s_reads_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__111)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__111);
  __Pyx_GIVEREF(__pyx_tuple__111);

  /* "pysamstats.pyx":930
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 *     ('matches', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches_fwd', 'i4'),
 *     ('matches_rev', 'i4'),
 */
  __pyx_tuple__112 = PyTuple_Pack(2, __pyx_n_s_matches, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__112)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__112);
  __Pyx_GIVEREF(__pyx_tuple__112);

  /* "pysamstats.pyx":931
 *     ('reads_pp_rev', 'i4'),
 *     ('matches', 'i4'),
 *     ('matches_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches_rev', 'i4'),
 *     ('matches_pp', 'i4'),
 */
  __pyx_tuple__113 = PyTuple_Pack(2, __pyx_n_s_matches_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__113)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__113);
  __Pyx_GIVEREF(__pyx_tuple__113);

  /* "pysamstats.pyx":932
 *     ('matches', 'i4'),
 *     ('matches_fwd', 'i4'),
 *     ('matches_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches_pp', 'i4'),
 *     ('matches_pp_fwd', 'i4'),
 */
  __pyx_tuple__114 = PyTuple_Pack(2, __pyx_n_s_matches_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__114)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__114);
  __Pyx_GIVEREF(__pyx_tuple__114);

  /* "pysamstats.pyx":933
 *     ('matches_fwd', 'i4'),
 *     ('matches_rev', 'i4'),
 *     ('matches_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches_pp_fwd', 'i4'),
 *     ('matches_pp_rev', 'i4'),
 */
  __pyx_tuple__115 = PyTuple_Pack(2, __pyx_n_s_matches_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__115)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 933; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__115);
  __Pyx_GIVEREF(__pyx_tuple__115);

  /* "pysamstats.pyx":934
 *     ('matches_rev', 'i4'),
 *     ('matches_pp', 'i4'),
 *     ('matches_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches_pp_rev', 'i4'),
 *     ('mismatches', 'i4'),
 */
  __pyx_tuple__116 = PyTuple_Pack(2, __pyx_n_s_matches_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__116)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__116);
  __Pyx_GIVEREF(__pyx_tuple__116);

  /* "pysamstats.pyx":935
 *     ('matches_pp', 'i4'),
 *     ('matches_pp_fwd', 'i4'),
 *     ('matches_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches', 'i4'),
 *     ('mismatches_fwd', 'i4'),
 */
  __pyx_tuple__117 = PyTuple_Pack(2, __pyx_n_s_matches_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__117)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__117);
  __Pyx_GIVEREF(__pyx_tuple__117);

  /* "pysamstats.pyx":936
 *     ('matches_pp_fwd', 'i4'),
 *     ('matches_pp_rev', 'i4'),
 *     ('mismatches', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches_fwd', 'i4'),
 *     ('mismatches_rev', 'i4'),
 */
  __pyx_tuple__118 = PyTuple_Pack(2, __pyx_n_s_mismatches, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__118)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__118);
  __Pyx_GIVEREF(__pyx_tuple__118);

  /* "pysamstats.pyx":937
 *     ('matches_pp_rev', 'i4'),
 *     ('mismatches', 'i4'),
 *     ('mismatches_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches_rev', 'i4'),
 *     ('mismatches_pp', 'i4'),
 */
  __pyx_tuple__119 = PyTuple_Pack(2, __pyx_n_s_mismatches_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__119)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__119);
  __Pyx_GIVEREF(__pyx_tuple__119);

  /* "pysamstats.pyx":938
 *     ('mismatches', 'i4'),
 *     ('mismatches_fwd', 'i4'),
 *     ('mismatches_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches_pp', 'i4'),
 *     ('mismatches_pp_fwd', 'i4'),
 */
  __pyx_tuple__120 = PyTuple_Pack(2, __pyx_n_s_mismatches_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__120)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__120);
  __Pyx_GIVEREF(__pyx_tuple__120);

  /* "pysamstats.pyx":939
 *     ('mismatches_fwd', 'i4'),
 *     ('mismatches_rev', 'i4'),
 *     ('mismatches_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches_pp_fwd', 'i4'),
 *     ('mismatches_pp_rev', 'i4'),
 */
  __pyx_tuple__121 = PyTuple_Pack(2, __pyx_n_s_mismatches_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__121)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__121);
  __Pyx_GIVEREF(__pyx_tuple__121);

  /* "pysamstats.pyx":940
 *     ('mismatches_rev', 'i4'),
 *     ('mismatches_pp', 'i4'),
 *     ('mismatches_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches_pp_rev', 'i4'),
 *     ('deletions', 'i4'),
 */
  __pyx_tuple__122 = PyTuple_Pack(2, __pyx_n_s_mismatches_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__122)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__122);
  __Pyx_GIVEREF(__pyx_tuple__122);

  /* "pysamstats.pyx":941
 *     ('mismatches_pp', 'i4'),
 *     ('mismatches_pp_fwd', 'i4'),
 *     ('mismatches_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('deletions', 'i4'),
 *     ('deletions_fwd', 'i4'),
 */
  __pyx_tuple__123 = PyTuple_Pack(2, __pyx_n_s_mismatches_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__123)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__123);
  __Pyx_GIVEREF(__pyx_tuple__123);

  /* "pysamstats.pyx":942
 *     ('mismatches_pp_fwd', 'i4'),
 *     ('mismatches_pp_rev', 'i4'),
 *     ('deletions', 'i4'),             # <<<<<<<<<<<<<<
 *     ('deletions_fwd', 'i4'),
 *     ('deletions_rev', 'i4'),
 */
  __pyx_tuple__124 = PyTuple_Pack(2, __pyx_n_s_deletions, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__124)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__124);
  __Pyx_GIVEREF(__pyx_tuple__124);

  /* "pysamstats.pyx":943
 *     ('mismatches_pp_rev', 'i4'),
 *     ('deletions', 'i4'),
 *     ('deletions_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('deletions_rev', 'i4'),
 *     ('deletions_pp', 'i4'),
 */
  __pyx_tuple__125 = PyTuple_Pack(2, __pyx_n_s_deletions_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__125)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__125);
  __Pyx_GIVEREF(__pyx_tuple__125);

  /* "pysamstats.pyx":944
 *     ('deletions', 'i4'),
 *     ('deletions_fwd', 'i4'),
 *     ('deletions_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('deletions_pp', 'i4'),
 *     ('deletions_pp_fwd', 'i4'),
 */
  __pyx_tuple__126 = PyTuple_Pack(2, __pyx_n_s_deletions_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__126)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__126);
  __Pyx_GIVEREF(__pyx_tuple__126);

  /* "pysamstats.pyx":945
 *     ('deletions_fwd', 'i4'),
 *     ('deletions_rev', 'i4'),
 *     ('deletions_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('deletions_pp_fwd', 'i4'),
 *     ('deletions_pp_rev', 'i4'),
 */
  __pyx_tuple__127 = PyTuple_Pack(2, __pyx_n_s_deletions_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__127)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__127);
  __Pyx_GIVEREF(__pyx_tuple__127);

  /* "pysamstats.pyx":946
 *     ('deletions_rev', 'i4'),
 *     ('deletions_pp', 'i4'),
 *     ('deletions_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('deletions_pp_rev', 'i4'),
 *     ('insertions', 'i4'),
 */
  __pyx_tuple__128 = PyTuple_Pack(2, __pyx_n_s_deletions_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__128)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__128);
  __Pyx_GIVEREF(__pyx_tuple__128);

  /* "pysamstats.pyx":947
 *     ('deletions_pp', 'i4'),
 *     ('deletions_pp_fwd', 'i4'),
 *     ('deletions_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('insertions', 'i4'),
 *     ('insertions_fwd', 'i4'),
 */
  __pyx_tuple__129 = PyTuple_Pack(2, __pyx_n_s_deletions_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__129)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__129);
  __Pyx_GIVEREF(__pyx_tuple__129);

  /* "pysamstats.pyx":948
 *     ('deletions_pp_fwd', 'i4'),
 *     ('deletions_pp_rev', 'i4'),
 *     ('insertions', 'i4'),             # <<<<<<<<<<<<<<
 *     ('insertions_fwd', 'i4'),
 *     ('insertions_rev', 'i4'),
 */
  __pyx_tuple__130 = PyTuple_Pack(2, __pyx_n_s_insertions, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__130)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__130);
  __Pyx_GIVEREF(__pyx_tuple__130);

  /* "pysamstats.pyx":949
 *     ('deletions_pp_rev', 'i4'),
 *     ('insertions', 'i4'),
 *     ('insertions_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('insertions_rev', 'i4'),
 *     ('insertions_pp', 'i4'),
 */
  __pyx_tuple__131 = PyTuple_Pack(2, __pyx_n_s_insertions_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__131)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__131);
  __Pyx_GIVEREF(__pyx_tuple__131);

  /* "pysamstats.pyx":950
 *     ('insertions', 'i4'),
 *     ('insertions_fwd', 'i4'),
 *     ('insertions_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('insertions_pp', 'i4'),
 *     ('insertions_pp_fwd', 'i4'),
 */
  __pyx_tuple__132 = PyTuple_Pack(2, __pyx_n_s_insertions_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__132)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__132);
  __Pyx_GIVEREF(__pyx_tuple__132);

  /* "pysamstats.pyx":951
 *     ('insertions_fwd', 'i4'),
 *     ('insertions_rev', 'i4'),
 *     ('insertions_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('insertions_pp_fwd', 'i4'),
 *     ('insertions_pp_rev', 'i4'),
 */
  __pyx_tuple__133 = PyTuple_Pack(2, __pyx_n_s_insertions_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__133)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__133);
  __Pyx_GIVEREF(__pyx_tuple__133);

  /* "pysamstats.pyx":952
 *     ('insertions_rev', 'i4'),
 *     ('insertions_pp', 'i4'),
 *     ('insertions_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('insertions_pp_rev', 'i4'),
 *     ('A', 'i4'), ('A_fwd', 'i4'), ('A_rev', 'i4'),
 */
  __pyx_tuple__134 = PyTuple_Pack(2, __pyx_n_s_insertions_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__134)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__134);
  __Pyx_GIVEREF(__pyx_tuple__134);

  /* "pysamstats.pyx":953
 *     ('insertions_pp', 'i4'),
 *     ('insertions_pp_fwd', 'i4'),
 *     ('insertions_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('A', 'i4'), ('A_fwd', 'i4'), ('A_rev', 'i4'),
 *     ('A_pp', 'i4'), ('A_pp_fwd', 'i4'), ('A_pp_rev', 'i4'),
 */
  __pyx_tuple__135 = PyTuple_Pack(2, __pyx_n_s_insertions_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__135)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__135);
  __Pyx_GIVEREF(__pyx_tuple__135);

  /* "pysamstats.pyx":954
 *     ('insertions_pp_fwd', 'i4'),
 *     ('insertions_pp_rev', 'i4'),
 *     ('A', 'i4'), ('A_fwd', 'i4'), ('A_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('A_pp', 'i4'), ('A_pp_fwd', 'i4'), ('A_pp_rev', 'i4'),
 *     ('C', 'i4'), ('C_fwd', 'i4'), ('C_rev', 'i4'),
 */
  __pyx_tuple__136 = PyTuple_Pack(2, __pyx_n_s_A, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__136)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__136);
  __Pyx_GIVEREF(__pyx_tuple__136);
  __pyx_tuple__137 = PyTuple_Pack(2, __pyx_n_s_A_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__137)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__137);
  __Pyx_GIVEREF(__pyx_tuple__137);
  __pyx_tuple__138 = PyTuple_Pack(2, __pyx_n_s_A_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__138)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__138);
  __Pyx_GIVEREF(__pyx_tuple__138);

  /* "pysamstats.pyx":955
 *     ('insertions_pp_rev', 'i4'),
 *     ('A', 'i4'), ('A_fwd', 'i4'), ('A_rev', 'i4'),
 *     ('A_pp', 'i4'), ('A_pp_fwd', 'i4'), ('A_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('C', 'i4'), ('C_fwd', 'i4'), ('C_rev', 'i4'),
 *     ('C_pp', 'i4'), ('C_pp_fwd', 'i4'), ('C_pp_rev', 'i4'),
 */
  __pyx_tuple__139 = PyTuple_Pack(2, __pyx_n_s_A_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__139)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__139);
  __Pyx_GIVEREF(__pyx_tuple__139);
  __pyx_tuple__140 = PyTuple_Pack(2, __pyx_n_s_A_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__140)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__140);
  __Pyx_GIVEREF(__pyx_tuple__140);
  __pyx_tuple__141 = PyTuple_Pack(2, __pyx_n_s_A_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__141)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__141);
  __Pyx_GIVEREF(__pyx_tuple__141);

  /* "pysamstats.pyx":956
 *     ('A', 'i4'), ('A_fwd', 'i4'), ('A_rev', 'i4'),
 *     ('A_pp', 'i4'), ('A_pp_fwd', 'i4'), ('A_pp_rev', 'i4'),
 *     ('C', 'i4'), ('C_fwd', 'i4'), ('C_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('C_pp', 'i4'), ('C_pp_fwd', 'i4'), ('C_pp_rev', 'i4'),
 *     ('T', 'i4'), ('T_fwd', 'i4'), ('T_rev', 'i4'),
 */
  __pyx_tuple__142 = PyTuple_Pack(2, __pyx_n_s_C, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__142)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__142);
  __Pyx_GIVEREF(__pyx_tuple__142);
  __pyx_tuple__143 = PyTuple_Pack(2, __pyx_n_s_C_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__143)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__143);
  __Pyx_GIVEREF(__pyx_tuple__143);
  __pyx_tuple__144 = PyTuple_Pack(2, __pyx_n_s_C_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__144)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__144);
  __Pyx_GIVEREF(__pyx_tuple__144);

  /* "pysamstats.pyx":957
 *     ('A_pp', 'i4'), ('A_pp_fwd', 'i4'), ('A_pp_rev', 'i4'),
 *     ('C', 'i4'), ('C_fwd', 'i4'), ('C_rev', 'i4'),
 *     ('C_pp', 'i4'), ('C_pp_fwd', 'i4'), ('C_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('T', 'i4'), ('T_fwd', 'i4'), ('T_rev', 'i4'),
 *     ('T_pp', 'i4'), ('T_pp_fwd', 'i4'), ('T_pp_rev', 'i4'),
 */
  __pyx_tuple__145 = PyTuple_Pack(2, __pyx_n_s_C_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__145)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__145);
  __Pyx_GIVEREF(__pyx_tuple__145);
  __pyx_tuple__146 = PyTuple_Pack(2, __pyx_n_s_C_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__146)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__146);
  __Pyx_GIVEREF(__pyx_tuple__146);
  __pyx_tuple__147 = PyTuple_Pack(2, __pyx_n_s_C_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__147)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__147);
  __Pyx_GIVEREF(__pyx_tuple__147);

  /* "pysamstats.pyx":958
 *     ('C', 'i4'), ('C_fwd', 'i4'), ('C_rev', 'i4'),
 *     ('C_pp', 'i4'), ('C_pp_fwd', 'i4'), ('C_pp_rev', 'i4'),
 *     ('T', 'i4'), ('T_fwd', 'i4'), ('T_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('T_pp', 'i4'), ('T_pp_fwd', 'i4'), ('T_pp_rev', 'i4'),
 *     ('G', 'i4'), ('G_fwd', 'i4'), ('G_rev', 'i4'),
 */
  __pyx_tuple__148 = PyTuple_Pack(2, __pyx_n_s_T, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__148)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__148);
  __Pyx_GIVEREF(__pyx_tuple__148);
  __pyx_tuple__149 = PyTuple_Pack(2, __pyx_n_s_T_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__149)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__149);
  __Pyx_GIVEREF(__pyx_tuple__149);
  __pyx_tuple__150 = PyTuple_Pack(2, __pyx_n_s_T_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__150)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__150);
  __Pyx_GIVEREF(__pyx_tuple__150);

  /* "pysamstats.pyx":959
 *     ('C_pp', 'i4'), ('C_pp_fwd', 'i4'), ('C_pp_rev', 'i4'),
 *     ('T', 'i4'), ('T_fwd', 'i4'), ('T_rev', 'i4'),
 *     ('T_pp', 'i4'), ('T_pp_fwd', 'i4'), ('T_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('G', 'i4'), ('G_fwd', 'i4'), ('G_rev', 'i4'),
 *     ('G_pp', 'i4'), ('G_pp_fwd', 'i4'), ('G_pp_rev', 'i4'),
 */
  __pyx_tuple__151 = PyTuple_Pack(2, __pyx_n_s_T_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__151)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__151);
  __Pyx_GIVEREF(__pyx_tuple__151);
  __pyx_tuple__152 = PyTuple_Pack(2, __pyx_n_s_T_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__152)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__152);
  __Pyx_GIVEREF(__pyx_tuple__152);
  __pyx_tuple__153 = PyTuple_Pack(2, __pyx_n_s_T_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__153)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__153);
  __Pyx_GIVEREF(__pyx_tuple__153);

  /* "pysamstats.pyx":960
 *     ('T', 'i4'), ('T_fwd', 'i4'), ('T_rev', 'i4'),
 *     ('T_pp', 'i4'), ('T_pp_fwd', 'i4'), ('T_pp_rev', 'i4'),
 *     ('G', 'i4'), ('G_fwd', 'i4'), ('G_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('G_pp', 'i4'), ('G_pp_fwd', 'i4'), ('G_pp_rev', 'i4'),
 *     ('N', 'i4'), ('N_fwd', 'i4'), ('N_rev', 'i4'),
 */
  __pyx_tuple__154 = PyTuple_Pack(2, __pyx_n_s_G, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__154)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__154);
  __Pyx_GIVEREF(__pyx_tuple__154);
  __pyx_tuple__155 = PyTuple_Pack(2, __pyx_n_s_G_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__155)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__155);
  __Pyx_GIVEREF(__pyx_tuple__155);
  __pyx_tuple__156 = PyTuple_Pack(2, __pyx_n_s_G_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__156)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__156);
  __Pyx_GIVEREF(__pyx_tuple__156);

  /* "pysamstats.pyx":961
 *     ('T_pp', 'i4'), ('T_pp_fwd', 'i4'), ('T_pp_rev', 'i4'),
 *     ('G', 'i4'), ('G_fwd', 'i4'), ('G_rev', 'i4'),
 *     ('G_pp', 'i4'), ('G_pp_fwd', 'i4'), ('G_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('N', 'i4'), ('N_fwd', 'i4'), ('N_rev', 'i4'),
 *     ('N_pp', 'i4'), ('N_pp_fwd', 'i4'), ('N_pp_rev', 'i4')
 */
  __pyx_tuple__157 = PyTuple_Pack(2, __pyx_n_s_G_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__157)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__157);
  __Pyx_GIVEREF(__pyx_tuple__157);
  __pyx_tuple__158 = PyTuple_Pack(2, __pyx_n_s_G_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__158)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__158);
  __Pyx_GIVEREF(__pyx_tuple__158);
  __pyx_tuple__159 = PyTuple_Pack(2, __pyx_n_s_G_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__159)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__159);
  __Pyx_GIVEREF(__pyx_tuple__159);

  /* "pysamstats.pyx":962
 *     ('G', 'i4'), ('G_fwd', 'i4'), ('G_rev', 'i4'),
 *     ('G_pp', 'i4'), ('G_pp_fwd', 'i4'), ('G_pp_rev', 'i4'),
 *     ('N', 'i4'), ('N_fwd', 'i4'), ('N_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('N_pp', 'i4'), ('N_pp_fwd', 'i4'), ('N_pp_rev', 'i4')
 * ]
 */
  __pyx_tuple__160 = PyTuple_Pack(2, __pyx_n_s_N, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__160)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__160);
  __Pyx_GIVEREF(__pyx_tuple__160);
  __pyx_tuple__161 = PyTuple_Pack(2, __pyx_n_s_N_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__161)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__161);
  __Pyx_GIVEREF(__pyx_tuple__161);
  __pyx_tuple__162 = PyTuple_Pack(2, __pyx_n_s_N_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__162)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__162);
  __Pyx_GIVEREF(__pyx_tuple__162);

  /* "pysamstats.pyx":963
 *     ('G_pp', 'i4'), ('G_pp_fwd', 'i4'), ('G_pp_rev', 'i4'),
 *     ('N', 'i4'), ('N_fwd', 'i4'), ('N_rev', 'i4'),
 *     ('N_pp', 'i4'), ('N_pp_fwd', 'i4'), ('N_pp_rev', 'i4')             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__163 = PyTuple_Pack(2, __pyx_n_s_N_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__163)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__163);
  __Pyx_GIVEREF(__pyx_tuple__163);
  __pyx_tuple__164 = PyTuple_Pack(2, __pyx_n_s_N_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__164)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__164);
  __Pyx_GIVEREF(__pyx_tuple__164);
  __pyx_tuple__165 = PyTuple_Pack(2, __pyx_n_s_N_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__165)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__165);
  __Pyx_GIVEREF(__pyx_tuple__165);

  /* "pysamstats.pyx":1113
 * 
 * 
 * def stat_variation_strand(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate variation statistics by strand per genome position.
 * 
 */
  __pyx_tuple__166 = PyTuple_Pack(3, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__166)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__166);
  __Pyx_GIVEREF(__pyx_tuple__166);
  __pyx_codeobj__167 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__166, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_variation_strand, 1113, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__167)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1151
 * 
 * 
 * def load_variation_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_variation_strand, dtype_variation_strand,
 *                        *args, **kwargs)
 */
  __pyx_tuple__168 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__168)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__168);
  __Pyx_GIVEREF(__pyx_tuple__168);
  __pyx_codeobj__169 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__168, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_variation_strand, 1151, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__169)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1162
 * 
 * dtype_tlen = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__170 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__170)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__170);
  __Pyx_GIVEREF(__pyx_tuple__170);

  /* "pysamstats.pyx":1163
 * dtype_tlen = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_paired', 'i4'),
 */
  __pyx_tuple__171 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__171)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__171);
  __Pyx_GIVEREF(__pyx_tuple__171);

  /* "pysamstats.pyx":1164
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_paired', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__172 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__172)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__172);
  __Pyx_GIVEREF(__pyx_tuple__172);

  /* "pysamstats.pyx":1165
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 *     ('reads_paired', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('mean_tlen', 'i4'),
 */
  __pyx_tuple__173 = PyTuple_Pack(2, __pyx_n_s_reads_paired, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__173)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__173);
  __Pyx_GIVEREF(__pyx_tuple__173);

  /* "pysamstats.pyx":1166
 *     ('reads_all', 'i4'),
 *     ('reads_paired', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mean_tlen', 'i4'),
 *     ('mean_tlen_pp', 'i4'),
 */
  __pyx_tuple__174 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__174)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__174);
  __Pyx_GIVEREF(__pyx_tuple__174);

  /* "pysamstats.pyx":1167
 *     ('reads_paired', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('mean_tlen', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mean_tlen_pp', 'i4'),
 *     ('rms_tlen', 'i4'),
 */
  __pyx_tuple__175 = PyTuple_Pack(2, __pyx_n_s_mean_tlen, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__175)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__175);
  __Pyx_GIVEREF(__pyx_tuple__175);

  /* "pysamstats.pyx":1168
 *     ('reads_pp', 'i4'),
 *     ('mean_tlen', 'i4'),
 *     ('mean_tlen_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_tlen', 'i4'),
 *     ('rms_tlen_pp', 'i4'),
 */
  __pyx_tuple__176 = PyTuple_Pack(2, __pyx_n_s_mean_tlen_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__176)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__176);
  __Pyx_GIVEREF(__pyx_tuple__176);

  /* "pysamstats.pyx":1169
 *     ('mean_tlen', 'i4'),
 *     ('mean_tlen_pp', 'i4'),
 *     ('rms_tlen', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_tlen_pp', 'i4'),
 *     ('std_tlen', 'i4'),
 */
  __pyx_tuple__177 = PyTuple_Pack(2, __pyx_n_s_rms_tlen, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__177)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__177);
  __Pyx_GIVEREF(__pyx_tuple__177);

  /* "pysamstats.pyx":1170
 *     ('mean_tlen_pp', 'i4'),
 *     ('rms_tlen', 'i4'),
 *     ('rms_tlen_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('std_tlen', 'i4'),
 *     ('std_tlen_pp', 'i4')
 */
  __pyx_tuple__178 = PyTuple_Pack(2, __pyx_n_s_rms_tlen_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__178)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__178);
  __Pyx_GIVEREF(__pyx_tuple__178);

  /* "pysamstats.pyx":1171
 *     ('rms_tlen', 'i4'),
 *     ('rms_tlen_pp', 'i4'),
 *     ('std_tlen', 'i4'),             # <<<<<<<<<<<<<<
 *     ('std_tlen_pp', 'i4')
 * ]
 */
  __pyx_tuple__179 = PyTuple_Pack(2, __pyx_n_s_std_tlen, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__179)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__179);
  __Pyx_GIVEREF(__pyx_tuple__179);

  /* "pysamstats.pyx":1172
 *     ('rms_tlen_pp', 'i4'),
 *     ('std_tlen', 'i4'),
 *     ('std_tlen_pp', 'i4')             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__180 = PyTuple_Pack(2, __pyx_n_s_std_tlen_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__180)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__180);
  __Pyx_GIVEREF(__pyx_tuple__180);

  /* "pysamstats.pyx":1315
 * 
 * 
 * def stat_tlen(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate insert size statistics per genome position.
 * 
 */
  __pyx_tuple__181 = PyTuple_Pack(2, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__181)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__181);
  __Pyx_GIVEREF(__pyx_tuple__181);
  __pyx_codeobj__182 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__181, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_tlen, 1315, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__182)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1349
 * 
 * 
 * def load_tlen(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_tlen, dtype_tlen, *args, **kwargs)
 * 
 */
  __pyx_tuple__183 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__183)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__183);
  __Pyx_GIVEREF(__pyx_tuple__183);
  __pyx_codeobj__184 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__183, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_tlen, 1349, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__184)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1359
 * 
 * dtype_tlen_strand = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__185 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__185)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__185);
  __Pyx_GIVEREF(__pyx_tuple__185);

  /* "pysamstats.pyx":1360
 * dtype_tlen_strand = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 */
  __pyx_tuple__186 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__186)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__186);
  __Pyx_GIVEREF(__pyx_tuple__186);

  /* "pysamstats.pyx":1361
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 */
  __pyx_tuple__187 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__187)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__187);
  __Pyx_GIVEREF(__pyx_tuple__187);

  /* "pysamstats.pyx":1362
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_rev', 'i4'),
 *     ('reads_paired', 'i4'),
 */
  __pyx_tuple__188 = PyTuple_Pack(2, __pyx_n_s_reads_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__188)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__188);
  __Pyx_GIVEREF(__pyx_tuple__188);

  /* "pysamstats.pyx":1363
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_paired', 'i4'),
 *     ('reads_paired_fwd', 'i4'),
 */
  __pyx_tuple__189 = PyTuple_Pack(2, __pyx_n_s_reads_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__189)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__189);
  __Pyx_GIVEREF(__pyx_tuple__189);

  /* "pysamstats.pyx":1364
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 *     ('reads_paired', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_paired_fwd', 'i4'),
 *     ('reads_paired_rev', 'i4'),
 */
  __pyx_tuple__190 = PyTuple_Pack(2, __pyx_n_s_reads_paired, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__190)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__190);
  __Pyx_GIVEREF(__pyx_tuple__190);

  /* "pysamstats.pyx":1365
 *     ('reads_rev', 'i4'),
 *     ('reads_paired', 'i4'),
 *     ('reads_paired_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_paired_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__191 = PyTuple_Pack(2, __pyx_n_s_reads_paired_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__191)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__191);
  __Pyx_GIVEREF(__pyx_tuple__191);

  /* "pysamstats.pyx":1366
 *     ('reads_paired', 'i4'),
 *     ('reads_paired_fwd', 'i4'),
 *     ('reads_paired_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 */
  __pyx_tuple__192 = PyTuple_Pack(2, __pyx_n_s_reads_paired_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__192)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__192);
  __Pyx_GIVEREF(__pyx_tuple__192);

  /* "pysamstats.pyx":1367
 *     ('reads_paired_fwd', 'i4'),
 *     ('reads_paired_rev', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 */
  __pyx_tuple__193 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__193)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__193);
  __Pyx_GIVEREF(__pyx_tuple__193);

  /* "pysamstats.pyx":1368
 *     ('reads_paired_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_rev', 'i4'),
 *     ('mean_tlen', 'i4'),
 */
  __pyx_tuple__194 = PyTuple_Pack(2, __pyx_n_s_reads_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__194)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__194);
  __Pyx_GIVEREF(__pyx_tuple__194);

  /* "pysamstats.pyx":1369
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mean_tlen', 'i4'),
 *     ('mean_tlen_fwd', 'i4'),
 */
  __pyx_tuple__195 = PyTuple_Pack(2, __pyx_n_s_reads_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__195)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__195);
  __Pyx_GIVEREF(__pyx_tuple__195);

  /* "pysamstats.pyx":1370
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 *     ('mean_tlen', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mean_tlen_fwd', 'i4'),
 *     ('mean_tlen_rev', 'i4'),
 */
  __pyx_tuple__196 = PyTuple_Pack(2, __pyx_n_s_mean_tlen, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__196)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__196);
  __Pyx_GIVEREF(__pyx_tuple__196);

  /* "pysamstats.pyx":1371
 *     ('reads_pp_rev', 'i4'),
 *     ('mean_tlen', 'i4'),
 *     ('mean_tlen_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mean_tlen_rev', 'i4'),
 *     ('mean_tlen_pp', 'i4'),
 */
  __pyx_tuple__197 = PyTuple_Pack(2, __pyx_n_s_mean_tlen_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__197)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__197);
  __Pyx_GIVEREF(__pyx_tuple__197);

  /* "pysamstats.pyx":1372
 *     ('mean_tlen', 'i4'),
 *     ('mean_tlen_fwd', 'i4'),
 *     ('mean_tlen_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mean_tlen_pp', 'i4'),
 *     ('mean_tlen_pp_fwd', 'i4'),
 */
  __pyx_tuple__198 = PyTuple_Pack(2, __pyx_n_s_mean_tlen_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__198)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__198);
  __Pyx_GIVEREF(__pyx_tuple__198);

  /* "pysamstats.pyx":1373
 *     ('mean_tlen_fwd', 'i4'),
 *     ('mean_tlen_rev', 'i4'),
 *     ('mean_tlen_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mean_tlen_pp_fwd', 'i4'),
 *     ('mean_tlen_pp_rev', 'i4'),
 */
  __pyx_tuple__199 = PyTuple_Pack(2, __pyx_n_s_mean_tlen_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__199)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__199);
  __Pyx_GIVEREF(__pyx_tuple__199);

  /* "pysamstats.pyx":1374
 *     ('mean_tlen_rev', 'i4'),
 *     ('mean_tlen_pp', 'i4'),
 *     ('mean_tlen_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mean_tlen_pp_rev', 'i4'),
 *     ('rms_tlen', 'i4'),
 */
  __pyx_tuple__200 = PyTuple_Pack(2, __pyx_n_s_mean_tlen_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__200)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__200);
  __Pyx_GIVEREF(__pyx_tuple__200);

  /* "pysamstats.pyx":1375
 *     ('mean_tlen_pp', 'i4'),
 *     ('mean_tlen_pp_fwd', 'i4'),
 *     ('mean_tlen_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_tlen', 'i4'),
 *     ('rms_tlen_fwd', 'i4'),
 */
  __pyx_tuple__201 = PyTuple_Pack(2, __pyx_n_s_mean_tlen_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__201)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__201);
  __Pyx_GIVEREF(__pyx_tuple__201);

  /* "pysamstats.pyx":1376
 *     ('mean_tlen_pp_fwd', 'i4'),
 *     ('mean_tlen_pp_rev', 'i4'),
 *     ('rms_tlen', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_tlen_fwd', 'i4'),
 *     ('rms_tlen_rev', 'i4'),
 */
  __pyx_tuple__202 = PyTuple_Pack(2, __pyx_n_s_rms_tlen, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__202)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__202);
  __Pyx_GIVEREF(__pyx_tuple__202);

  /* "pysamstats.pyx":1377
 *     ('mean_tlen_pp_rev', 'i4'),
 *     ('rms_tlen', 'i4'),
 *     ('rms_tlen_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_tlen_rev', 'i4'),
 *     ('rms_tlen_pp', 'i4'),
 */
  __pyx_tuple__203 = PyTuple_Pack(2, __pyx_n_s_rms_tlen_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__203)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__203);
  __Pyx_GIVEREF(__pyx_tuple__203);

  /* "pysamstats.pyx":1378
 *     ('rms_tlen', 'i4'),
 *     ('rms_tlen_fwd', 'i4'),
 *     ('rms_tlen_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_tlen_pp', 'i4'),
 *     ('rms_tlen_pp_fwd', 'i4'),
 */
  __pyx_tuple__204 = PyTuple_Pack(2, __pyx_n_s_rms_tlen_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__204)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__204);
  __Pyx_GIVEREF(__pyx_tuple__204);

  /* "pysamstats.pyx":1379
 *     ('rms_tlen_fwd', 'i4'),
 *     ('rms_tlen_rev', 'i4'),
 *     ('rms_tlen_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_tlen_pp_fwd', 'i4'),
 *     ('rms_tlen_pp_rev', 'i4'),
 */
  __pyx_tuple__205 = PyTuple_Pack(2, __pyx_n_s_rms_tlen_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__205)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__205);
  __Pyx_GIVEREF(__pyx_tuple__205);

  /* "pysamstats.pyx":1380
 *     ('rms_tlen_rev', 'i4'),
 *     ('rms_tlen_pp', 'i4'),
 *     ('rms_tlen_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_tlen_pp_rev', 'i4'),
 *     ('std_tlen', 'i4'),
 */
  __pyx_tuple__206 = PyTuple_Pack(2, __pyx_n_s_rms_tlen_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__206)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__206);
  __Pyx_GIVEREF(__pyx_tuple__206);

  /* "pysamstats.pyx":1381
 *     ('rms_tlen_pp', 'i4'),
 *     ('rms_tlen_pp_fwd', 'i4'),
 *     ('rms_tlen_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('std_tlen', 'i4'),
 *     ('std_tlen_fwd', 'i4'),
 */
  __pyx_tuple__207 = PyTuple_Pack(2, __pyx_n_s_rms_tlen_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__207)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__207);
  __Pyx_GIVEREF(__pyx_tuple__207);

  /* "pysamstats.pyx":1382
 *     ('rms_tlen_pp_fwd', 'i4'),
 *     ('rms_tlen_pp_rev', 'i4'),
 *     ('std_tlen', 'i4'),             # <<<<<<<<<<<<<<
 *     ('std_tlen_fwd', 'i4'),
 *     ('std_tlen_rev', 'i4'),
 */
  __pyx_tuple__208 = PyTuple_Pack(2, __pyx_n_s_std_tlen, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__208)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__208);
  __Pyx_GIVEREF(__pyx_tuple__208);

  /* "pysamstats.pyx":1383
 *     ('rms_tlen_pp_rev', 'i4'),
 *     ('std_tlen', 'i4'),
 *     ('std_tlen_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('std_tlen_rev', 'i4'),
 *     ('std_tlen_pp', 'i4'),
 */
  __pyx_tuple__209 = PyTuple_Pack(2, __pyx_n_s_std_tlen_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__209)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__209);
  __Pyx_GIVEREF(__pyx_tuple__209);

  /* "pysamstats.pyx":1384
 *     ('std_tlen', 'i4'),
 *     ('std_tlen_fwd', 'i4'),
 *     ('std_tlen_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('std_tlen_pp', 'i4'),
 *     ('std_tlen_pp_fwd', 'i4'),
 */
  __pyx_tuple__210 = PyTuple_Pack(2, __pyx_n_s_std_tlen_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__210)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__210);
  __Pyx_GIVEREF(__pyx_tuple__210);

  /* "pysamstats.pyx":1385
 *     ('std_tlen_fwd', 'i4'),
 *     ('std_tlen_rev', 'i4'),
 *     ('std_tlen_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('std_tlen_pp_fwd', 'i4'),
 *     ('std_tlen_pp_rev', 'i4')
 */
  __pyx_tuple__211 = PyTuple_Pack(2, __pyx_n_s_std_tlen_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__211)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1385; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__211);
  __Pyx_GIVEREF(__pyx_tuple__211);

  /* "pysamstats.pyx":1386
 *     ('std_tlen_rev', 'i4'),
 *     ('std_tlen_pp', 'i4'),
 *     ('std_tlen_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('std_tlen_pp_rev', 'i4')
 * ]
 */
  __pyx_tuple__212 = PyTuple_Pack(2, __pyx_n_s_std_tlen_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__212)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__212);
  __Pyx_GIVEREF(__pyx_tuple__212);

  /* "pysamstats.pyx":1387
 *     ('std_tlen_pp', 'i4'),
 *     ('std_tlen_pp_fwd', 'i4'),
 *     ('std_tlen_pp_rev', 'i4')             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__213 = PyTuple_Pack(2, __pyx_n_s_std_tlen_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__213)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__213);
  __Pyx_GIVEREF(__pyx_tuple__213);

  /* "pysamstats.pyx":1673
 * 
 * 
 * def stat_tlen_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate insert size statistics by strand per genome position.
 * 
 */
  __pyx_tuple__214 = PyTuple_Pack(2, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__214)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__214);
  __Pyx_GIVEREF(__pyx_tuple__214);
  __pyx_codeobj__215 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__214, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_tlen_strand, 1673, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__215)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1708
 * 
 * 
 * def load_tlen_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_tlen_strand, dtype_tlen_strand, *args, **kwargs)
 * 
 */
  __pyx_tuple__216 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__216)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__216);
  __Pyx_GIVEREF(__pyx_tuple__216);
  __pyx_codeobj__217 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__216, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_tlen_strand, 1708, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__217)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1718
 * 
 * dtype_mapq = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__218 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__218)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__218);
  __Pyx_GIVEREF(__pyx_tuple__218);

  /* "pysamstats.pyx":1719
 * dtype_mapq = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__219 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__219)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1719; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__219);
  __Pyx_GIVEREF(__pyx_tuple__219);

  /* "pysamstats.pyx":1720
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('reads_mapq0', 'i4'),
 */
  __pyx_tuple__220 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__220)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__220);
  __Pyx_GIVEREF(__pyx_tuple__220);

  /* "pysamstats.pyx":1721
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mapq0', 'i4'),
 *     ('reads_mapq0_pp', 'i4'),
 */
  __pyx_tuple__221 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__221)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__221);
  __Pyx_GIVEREF(__pyx_tuple__221);

  /* "pysamstats.pyx":1722
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('reads_mapq0', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mapq0_pp', 'i4'),
 *     ('rms_mapq', 'i4'),
 */
  __pyx_tuple__222 = PyTuple_Pack(2, __pyx_n_s_reads_mapq0, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__222)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1722; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__222);
  __Pyx_GIVEREF(__pyx_tuple__222);

  /* "pysamstats.pyx":1723
 *     ('reads_pp', 'i4'),
 *     ('reads_mapq0', 'i4'),
 *     ('reads_mapq0_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_mapq', 'i4'),
 *     ('rms_mapq_pp', 'i4'),
 */
  __pyx_tuple__223 = PyTuple_Pack(2, __pyx_n_s_reads_mapq0_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__223)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__223);
  __Pyx_GIVEREF(__pyx_tuple__223);

  /* "pysamstats.pyx":1724
 *     ('reads_mapq0', 'i4'),
 *     ('reads_mapq0_pp', 'i4'),
 *     ('rms_mapq', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_mapq_pp', 'i4'),
 *     ('max_mapq', 'i4'),
 */
  __pyx_tuple__224 = PyTuple_Pack(2, __pyx_n_s_rms_mapq, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__224)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__224);
  __Pyx_GIVEREF(__pyx_tuple__224);

  /* "pysamstats.pyx":1725
 *     ('reads_mapq0_pp', 'i4'),
 *     ('rms_mapq', 'i4'),
 *     ('rms_mapq_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('max_mapq', 'i4'),
 *     ('max_mapq_pp', 'i4')
 */
  __pyx_tuple__225 = PyTuple_Pack(2, __pyx_n_s_rms_mapq_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__225)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__225);
  __Pyx_GIVEREF(__pyx_tuple__225);

  /* "pysamstats.pyx":1726
 *     ('rms_mapq', 'i4'),
 *     ('rms_mapq_pp', 'i4'),
 *     ('max_mapq', 'i4'),             # <<<<<<<<<<<<<<
 *     ('max_mapq_pp', 'i4')
 * ]
 */
  __pyx_tuple__226 = PyTuple_Pack(2, __pyx_n_s_max_mapq, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__226)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__226);
  __Pyx_GIVEREF(__pyx_tuple__226);

  /* "pysamstats.pyx":1727
 *     ('rms_mapq_pp', 'i4'),
 *     ('max_mapq', 'i4'),
 *     ('max_mapq_pp', 'i4')             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__227 = PyTuple_Pack(2, __pyx_n_s_max_mapq_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__227)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__227);
  __Pyx_GIVEREF(__pyx_tuple__227);

  /* "pysamstats.pyx":1822
 * 
 * 
 * def stat_mapq(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate mapping quality statistics per genome position.
 * 
 */
  __pyx_tuple__228 = PyTuple_Pack(2, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__228)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__228);
  __Pyx_GIVEREF(__pyx_tuple__228);
  __pyx_codeobj__229 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__228, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_mapq, 1822, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__229)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1856
 * 
 * 
 * def load_mapq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_mapq, dtype_mapq, *args, **kwargs)
 * 
 */
  __pyx_tuple__230 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__230)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__230);
  __Pyx_GIVEREF(__pyx_tuple__230);
  __pyx_codeobj__231 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__230, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_mapq, 1856, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__231)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1866
 * 
 * dtype_mapq_strand = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__232 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__232)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__232);
  __Pyx_GIVEREF(__pyx_tuple__232);

  /* "pysamstats.pyx":1867
 * dtype_mapq_strand = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 */
  __pyx_tuple__233 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__233)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__233);
  __Pyx_GIVEREF(__pyx_tuple__233);

  /* "pysamstats.pyx":1868
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 */
  __pyx_tuple__234 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__234)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__234);
  __Pyx_GIVEREF(__pyx_tuple__234);

  /* "pysamstats.pyx":1869
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__235 = PyTuple_Pack(2, __pyx_n_s_reads_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__235)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1869; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__235);
  __Pyx_GIVEREF(__pyx_tuple__235);

  /* "pysamstats.pyx":1870
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 */
  __pyx_tuple__236 = PyTuple_Pack(2, __pyx_n_s_reads_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__236)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__236);
  __Pyx_GIVEREF(__pyx_tuple__236);

  /* "pysamstats.pyx":1871
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 */
  __pyx_tuple__237 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__237)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__237);
  __Pyx_GIVEREF(__pyx_tuple__237);

  /* "pysamstats.pyx":1872
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_rev', 'i4'),
 *     ('reads_mapq0', 'i4'),
 */
  __pyx_tuple__238 = PyTuple_Pack(2, __pyx_n_s_reads_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__238)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__238);
  __Pyx_GIVEREF(__pyx_tuple__238);

  /* "pysamstats.pyx":1873
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mapq0', 'i4'),
 *     ('reads_mapq0_fwd', 'i4'),
 */
  __pyx_tuple__239 = PyTuple_Pack(2, __pyx_n_s_reads_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__239)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__239);
  __Pyx_GIVEREF(__pyx_tuple__239);

  /* "pysamstats.pyx":1874
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 *     ('reads_mapq0', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mapq0_fwd', 'i4'),
 *     ('reads_mapq0_rev', 'i4'),
 */
  __pyx_tuple__240 = PyTuple_Pack(2, __pyx_n_s_reads_mapq0, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__240)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__240);
  __Pyx_GIVEREF(__pyx_tuple__240);

  /* "pysamstats.pyx":1875
 *     ('reads_pp_rev', 'i4'),
 *     ('reads_mapq0', 'i4'),
 *     ('reads_mapq0_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mapq0_rev', 'i4'),
 *     ('reads_mapq0_pp', 'i4'),
 */
  __pyx_tuple__241 = PyTuple_Pack(2, __pyx_n_s_reads_mapq0_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__241)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__241);
  __Pyx_GIVEREF(__pyx_tuple__241);

  /* "pysamstats.pyx":1876
 *     ('reads_mapq0', 'i4'),
 *     ('reads_mapq0_fwd', 'i4'),
 *     ('reads_mapq0_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mapq0_pp', 'i4'),
 *     ('reads_mapq0_pp_fwd', 'i4'),
 */
  __pyx_tuple__242 = PyTuple_Pack(2, __pyx_n_s_reads_mapq0_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__242)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__242);
  __Pyx_GIVEREF(__pyx_tuple__242);

  /* "pysamstats.pyx":1877
 *     ('reads_mapq0_fwd', 'i4'),
 *     ('reads_mapq0_rev', 'i4'),
 *     ('reads_mapq0_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mapq0_pp_fwd', 'i4'),
 *     ('reads_mapq0_pp_rev', 'i4'),
 */
  __pyx_tuple__243 = PyTuple_Pack(2, __pyx_n_s_reads_mapq0_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__243)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__243);
  __Pyx_GIVEREF(__pyx_tuple__243);

  /* "pysamstats.pyx":1878
 *     ('reads_mapq0_rev', 'i4'),
 *     ('reads_mapq0_pp', 'i4'),
 *     ('reads_mapq0_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mapq0_pp_rev', 'i4'),
 *     ('rms_mapq', 'i4'),
 */
  __pyx_tuple__244 = PyTuple_Pack(2, __pyx_n_s_reads_mapq0_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__244)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__244);
  __Pyx_GIVEREF(__pyx_tuple__244);

  /* "pysamstats.pyx":1879
 *     ('reads_mapq0_pp', 'i4'),
 *     ('reads_mapq0_pp_fwd', 'i4'),
 *     ('reads_mapq0_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_mapq', 'i4'),
 *     ('rms_mapq_fwd', 'i4'),
 */
  __pyx_tuple__245 = PyTuple_Pack(2, __pyx_n_s_reads_mapq0_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__245)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__245);
  __Pyx_GIVEREF(__pyx_tuple__245);

  /* "pysamstats.pyx":1880
 *     ('reads_mapq0_pp_fwd', 'i4'),
 *     ('reads_mapq0_pp_rev', 'i4'),
 *     ('rms_mapq', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_mapq_fwd', 'i4'),
 *     ('rms_mapq_rev', 'i4'),
 */
  __pyx_tuple__246 = PyTuple_Pack(2, __pyx_n_s_rms_mapq, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__246)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__246);
  __Pyx_GIVEREF(__pyx_tuple__246);

  /* "pysamstats.pyx":1881
 *     ('reads_mapq0_pp_rev', 'i4'),
 *     ('rms_mapq', 'i4'),
 *     ('rms_mapq_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_mapq_rev', 'i4'),
 *     ('rms_mapq_pp', 'i4'),
 */
  __pyx_tuple__247 = PyTuple_Pack(2, __pyx_n_s_rms_mapq_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__247)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__247);
  __Pyx_GIVEREF(__pyx_tuple__247);

  /* "pysamstats.pyx":1882
 *     ('rms_mapq', 'i4'),
 *     ('rms_mapq_fwd', 'i4'),
 *     ('rms_mapq_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_mapq_pp', 'i4'),
 *     ('rms_mapq_pp_fwd', 'i4'),
 */
  __pyx_tuple__248 = PyTuple_Pack(2, __pyx_n_s_rms_mapq_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__248)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__248);
  __Pyx_GIVEREF(__pyx_tuple__248);

  /* "pysamstats.pyx":1883
 *     ('rms_mapq_fwd', 'i4'),
 *     ('rms_mapq_rev', 'i4'),
 *     ('rms_mapq_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_mapq_pp_fwd', 'i4'),
 *     ('rms_mapq_pp_rev', 'i4'),
 */
  __pyx_tuple__249 = PyTuple_Pack(2, __pyx_n_s_rms_mapq_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__249)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__249);
  __Pyx_GIVEREF(__pyx_tuple__249);

  /* "pysamstats.pyx":1884
 *     ('rms_mapq_rev', 'i4'),
 *     ('rms_mapq_pp', 'i4'),
 *     ('rms_mapq_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_mapq_pp_rev', 'i4'),
 *     ('max_mapq', 'i4'),
 */
  __pyx_tuple__250 = PyTuple_Pack(2, __pyx_n_s_rms_mapq_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__250)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__250);
  __Pyx_GIVEREF(__pyx_tuple__250);

  /* "pysamstats.pyx":1885
 *     ('rms_mapq_pp', 'i4'),
 *     ('rms_mapq_pp_fwd', 'i4'),
 *     ('rms_mapq_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('max_mapq', 'i4'),
 *     ('max_mapq_fwd', 'i4'),
 */
  __pyx_tuple__251 = PyTuple_Pack(2, __pyx_n_s_rms_mapq_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__251)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__251);
  __Pyx_GIVEREF(__pyx_tuple__251);

  /* "pysamstats.pyx":1886
 *     ('rms_mapq_pp_fwd', 'i4'),
 *     ('rms_mapq_pp_rev', 'i4'),
 *     ('max_mapq', 'i4'),             # <<<<<<<<<<<<<<
 *     ('max_mapq_fwd', 'i4'),
 *     ('max_mapq_rev', 'i4'),
 */
  __pyx_tuple__252 = PyTuple_Pack(2, __pyx_n_s_max_mapq, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__252)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__252);
  __Pyx_GIVEREF(__pyx_tuple__252);

  /* "pysamstats.pyx":1887
 *     ('rms_mapq_pp_rev', 'i4'),
 *     ('max_mapq', 'i4'),
 *     ('max_mapq_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('max_mapq_rev', 'i4'),
 *     ('max_mapq_pp', 'i4'),
 */
  __pyx_tuple__253 = PyTuple_Pack(2, __pyx_n_s_max_mapq_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__253)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__253);
  __Pyx_GIVEREF(__pyx_tuple__253);

  /* "pysamstats.pyx":1888
 *     ('max_mapq', 'i4'),
 *     ('max_mapq_fwd', 'i4'),
 *     ('max_mapq_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('max_mapq_pp', 'i4'),
 *     ('max_mapq_pp_fwd', 'i4'),
 */
  __pyx_tuple__254 = PyTuple_Pack(2, __pyx_n_s_max_mapq_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__254)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__254);
  __Pyx_GIVEREF(__pyx_tuple__254);

  /* "pysamstats.pyx":1889
 *     ('max_mapq_fwd', 'i4'),
 *     ('max_mapq_rev', 'i4'),
 *     ('max_mapq_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('max_mapq_pp_fwd', 'i4'),
 *     ('max_mapq_pp_rev', 'i4'),
 */
  __pyx_tuple__255 = PyTuple_Pack(2, __pyx_n_s_max_mapq_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__255)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__255);
  __Pyx_GIVEREF(__pyx_tuple__255);

  /* "pysamstats.pyx":1890
 *     ('max_mapq_rev', 'i4'),
 *     ('max_mapq_pp', 'i4'),
 *     ('max_mapq_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('max_mapq_pp_rev', 'i4'),
 * ]
 */
  __pyx_tuple__256 = PyTuple_Pack(2, __pyx_n_s_max_mapq_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__256)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__256);
  __Pyx_GIVEREF(__pyx_tuple__256);

  /* "pysamstats.pyx":1891
 *     ('max_mapq_pp', 'i4'),
 *     ('max_mapq_pp_fwd', 'i4'),
 *     ('max_mapq_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__257 = PyTuple_Pack(2, __pyx_n_s_max_mapq_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__257)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__257);
  __Pyx_GIVEREF(__pyx_tuple__257);

  /* "pysamstats.pyx":2092
 * 
 * 
 * def stat_mapq_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate mapping quality statistics by strand per genome position.
 * 
 */
  __pyx_tuple__258 = PyTuple_Pack(2, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__258)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__258);
  __Pyx_GIVEREF(__pyx_tuple__258);
  __pyx_codeobj__259 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__258, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_mapq_strand, 2092, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__259)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2127
 * 
 * 
 * def load_mapq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_mapq_strand, dtype_mapq_strand, *args, **kwargs)
 * 
 */
  __pyx_tuple__260 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__260)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__260);
  __Pyx_GIVEREF(__pyx_tuple__260);
  __pyx_codeobj__261 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__260, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_mapq_strand, 2127, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__261)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2137
 * 
 * dtype_baseq = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__262 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__262)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__262);
  __Pyx_GIVEREF(__pyx_tuple__262);

  /* "pysamstats.pyx":2138
 * dtype_baseq = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__263 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__263)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__263);
  __Pyx_GIVEREF(__pyx_tuple__263);

  /* "pysamstats.pyx":2139
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('rms_baseq', 'i4'),
 */
  __pyx_tuple__264 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__264)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__264);
  __Pyx_GIVEREF(__pyx_tuple__264);

  /* "pysamstats.pyx":2140
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq', 'i4'),
 *     ('rms_baseq_pp', 'i4'),
 */
  __pyx_tuple__265 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__265)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__265);
  __Pyx_GIVEREF(__pyx_tuple__265);

  /* "pysamstats.pyx":2141
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('rms_baseq', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_pp', 'i4'),
 * ]
 */
  __pyx_tuple__266 = PyTuple_Pack(2, __pyx_n_s_rms_baseq, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__266)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__266);
  __Pyx_GIVEREF(__pyx_tuple__266);

  /* "pysamstats.pyx":2142
 *     ('reads_pp', 'i4'),
 *     ('rms_baseq', 'i4'),
 *     ('rms_baseq_pp', 'i4'),             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__267 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__267)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__267);
  __Pyx_GIVEREF(__pyx_tuple__267);

  /* "pysamstats.pyx":2219
 * 
 * 
 * def stat_baseq(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate base quality statistics per genome position.
 * 
 */
  __pyx_tuple__268 = PyTuple_Pack(2, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__268)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__268);
  __Pyx_GIVEREF(__pyx_tuple__268);
  __pyx_codeobj__269 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__268, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_baseq, 2219, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__269)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2253
 * 
 * 
 * def load_baseq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq, dtype_baseq, *args, **kwargs)
 * 
 */
  __pyx_tuple__270 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__270)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__270);
  __Pyx_GIVEREF(__pyx_tuple__270);
  __pyx_codeobj__271 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__270, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_baseq, 2253, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__271)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2263
 * 
 * dtype_baseq_strand = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__272 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__272)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__272);
  __Pyx_GIVEREF(__pyx_tuple__272);

  /* "pysamstats.pyx":2264
 * dtype_baseq_strand = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 */
  __pyx_tuple__273 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__273)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__273);
  __Pyx_GIVEREF(__pyx_tuple__273);

  /* "pysamstats.pyx":2265
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 */
  __pyx_tuple__274 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__274)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__274);
  __Pyx_GIVEREF(__pyx_tuple__274);

  /* "pysamstats.pyx":2266
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__275 = PyTuple_Pack(2, __pyx_n_s_reads_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__275)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__275);
  __Pyx_GIVEREF(__pyx_tuple__275);

  /* "pysamstats.pyx":2267
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 */
  __pyx_tuple__276 = PyTuple_Pack(2, __pyx_n_s_reads_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__276)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__276);
  __Pyx_GIVEREF(__pyx_tuple__276);

  /* "pysamstats.pyx":2268
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 */
  __pyx_tuple__277 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__277)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__277);
  __Pyx_GIVEREF(__pyx_tuple__277);

  /* "pysamstats.pyx":2269
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_rev', 'i4'),
 *     ('rms_baseq', 'i4'),
 */
  __pyx_tuple__278 = PyTuple_Pack(2, __pyx_n_s_reads_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__278)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__278);
  __Pyx_GIVEREF(__pyx_tuple__278);

  /* "pysamstats.pyx":2270
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq', 'i4'),
 *     ('rms_baseq_fwd', 'i4'),
 */
  __pyx_tuple__279 = PyTuple_Pack(2, __pyx_n_s_reads_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__279)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__279);
  __Pyx_GIVEREF(__pyx_tuple__279);

  /* "pysamstats.pyx":2271
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 *     ('rms_baseq', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_fwd', 'i4'),
 *     ('rms_baseq_rev', 'i4'),
 */
  __pyx_tuple__280 = PyTuple_Pack(2, __pyx_n_s_rms_baseq, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__280)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__280);
  __Pyx_GIVEREF(__pyx_tuple__280);

  /* "pysamstats.pyx":2272
 *     ('reads_pp_rev', 'i4'),
 *     ('rms_baseq', 'i4'),
 *     ('rms_baseq_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_rev', 'i4'),
 *     ('rms_baseq_pp', 'i4'),
 */
  __pyx_tuple__281 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__281)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__281);
  __Pyx_GIVEREF(__pyx_tuple__281);

  /* "pysamstats.pyx":2273
 *     ('rms_baseq', 'i4'),
 *     ('rms_baseq_fwd', 'i4'),
 *     ('rms_baseq_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_pp', 'i4'),
 *     ('rms_baseq_pp_fwd', 'i4'),
 */
  __pyx_tuple__282 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__282)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__282);
  __Pyx_GIVEREF(__pyx_tuple__282);

  /* "pysamstats.pyx":2274
 *     ('rms_baseq_fwd', 'i4'),
 *     ('rms_baseq_rev', 'i4'),
 *     ('rms_baseq_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_pp_fwd', 'i4'),
 *     ('rms_baseq_pp_rev', 'i4'),
 */
  __pyx_tuple__283 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__283)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__283);
  __Pyx_GIVEREF(__pyx_tuple__283);

  /* "pysamstats.pyx":2275
 *     ('rms_baseq_rev', 'i4'),
 *     ('rms_baseq_pp', 'i4'),
 *     ('rms_baseq_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_pp_rev', 'i4'),
 * ]
 */
  __pyx_tuple__284 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__284)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__284);
  __Pyx_GIVEREF(__pyx_tuple__284);

  /* "pysamstats.pyx":2276
 *     ('rms_baseq_pp', 'i4'),
 *     ('rms_baseq_pp_fwd', 'i4'),
 *     ('rms_baseq_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__285 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__285)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__285);
  __Pyx_GIVEREF(__pyx_tuple__285);

  /* "pysamstats.pyx":2414
 * 
 * 
 * def stat_baseq_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate base quality statistics by strand per genome position.
 * 
 */
  __pyx_tuple__286 = PyTuple_Pack(2, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__286)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__286);
  __Pyx_GIVEREF(__pyx_tuple__286);
  __pyx_codeobj__287 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__286, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_baseq_strand, 2414, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__287)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2449
 * 
 * 
 * def load_baseq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq_strand, dtype_baseq_strand,
 *                        *args, **kwargs)
 */
  __pyx_tuple__288 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__288)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__288);
  __Pyx_GIVEREF(__pyx_tuple__288);
  __pyx_codeobj__289 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__288, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_baseq_strand, 2449, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__289)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2460
 * 
 * dtype_baseq_ext = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('ref', 'a1'),
 */
  __pyx_tuple__290 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__290)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__290);
  __Pyx_GIVEREF(__pyx_tuple__290);

  /* "pysamstats.pyx":2461
 * dtype_baseq_ext = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('ref', 'a1'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__291 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__291)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__291);
  __Pyx_GIVEREF(__pyx_tuple__291);

  /* "pysamstats.pyx":2462
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('ref', 'a1'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__292 = PyTuple_Pack(2, __pyx_n_s_ref, __pyx_n_s_a1); if (unlikely(!__pyx_tuple__292)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__292);
  __Pyx_GIVEREF(__pyx_tuple__292);

  /* "pysamstats.pyx":2463
 *     ('pos', 'i4'),
 *     ('ref', 'a1'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('matches', 'i4'),
 */
  __pyx_tuple__293 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__293)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__293);
  __Pyx_GIVEREF(__pyx_tuple__293);

  /* "pysamstats.pyx":2464
 *     ('ref', 'a1'),
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches', 'i4'),
 *     ('matches_pp', 'i4'),
 */
  __pyx_tuple__294 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__294)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__294);
  __Pyx_GIVEREF(__pyx_tuple__294);

  /* "pysamstats.pyx":2465
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('matches', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches_pp', 'i4'),
 *     ('mismatches', 'i4'),
 */
  __pyx_tuple__295 = PyTuple_Pack(2, __pyx_n_s_matches, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__295)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__295);
  __Pyx_GIVEREF(__pyx_tuple__295);

  /* "pysamstats.pyx":2466
 *     ('reads_pp', 'i4'),
 *     ('matches', 'i4'),
 *     ('matches_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches', 'i4'),
 *     ('mismatches_pp', 'i4'),
 */
  __pyx_tuple__296 = PyTuple_Pack(2, __pyx_n_s_matches_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__296)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__296);
  __Pyx_GIVEREF(__pyx_tuple__296);

  /* "pysamstats.pyx":2467
 *     ('matches', 'i4'),
 *     ('matches_pp', 'i4'),
 *     ('mismatches', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches_pp', 'i4'),
 *     ('rms_baseq', 'i4'),
 */
  __pyx_tuple__297 = PyTuple_Pack(2, __pyx_n_s_mismatches, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__297)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__297);
  __Pyx_GIVEREF(__pyx_tuple__297);

  /* "pysamstats.pyx":2468
 *     ('matches_pp', 'i4'),
 *     ('mismatches', 'i4'),
 *     ('mismatches_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq', 'i4'),
 *     ('rms_baseq_pp', 'i4'),
 */
  __pyx_tuple__298 = PyTuple_Pack(2, __pyx_n_s_mismatches_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__298)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__298);
  __Pyx_GIVEREF(__pyx_tuple__298);

  /* "pysamstats.pyx":2469
 *     ('mismatches', 'i4'),
 *     ('mismatches_pp', 'i4'),
 *     ('rms_baseq', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_pp', 'i4'),
 *     ('rms_baseq_matches', 'i4'),
 */
  __pyx_tuple__299 = PyTuple_Pack(2, __pyx_n_s_rms_baseq, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__299)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__299);
  __Pyx_GIVEREF(__pyx_tuple__299);

  /* "pysamstats.pyx":2470
 *     ('mismatches_pp', 'i4'),
 *     ('rms_baseq', 'i4'),
 *     ('rms_baseq_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_matches', 'i4'),
 *     ('rms_baseq_matches_pp', 'i4'),
 */
  __pyx_tuple__300 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__300)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__300);
  __Pyx_GIVEREF(__pyx_tuple__300);

  /* "pysamstats.pyx":2471
 *     ('rms_baseq', 'i4'),
 *     ('rms_baseq_pp', 'i4'),
 *     ('rms_baseq_matches', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_matches_pp', 'i4'),
 *     ('rms_baseq_mismatches', 'i4'),
 */
  __pyx_tuple__301 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_matches, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__301)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__301);
  __Pyx_GIVEREF(__pyx_tuple__301);

  /* "pysamstats.pyx":2472
 *     ('rms_baseq_pp', 'i4'),
 *     ('rms_baseq_matches', 'i4'),
 *     ('rms_baseq_matches_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_mismatches', 'i4'),
 *     ('rms_baseq_mismatches_pp', 'i4'),
 */
  __pyx_tuple__302 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_matches_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__302)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__302);
  __Pyx_GIVEREF(__pyx_tuple__302);

  /* "pysamstats.pyx":2473
 *     ('rms_baseq_matches', 'i4'),
 *     ('rms_baseq_matches_pp', 'i4'),
 *     ('rms_baseq_mismatches', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_mismatches_pp', 'i4'),
 * ]
 */
  __pyx_tuple__303 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_mismatches, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__303)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__303);
  __Pyx_GIVEREF(__pyx_tuple__303);

  /* "pysamstats.pyx":2474
 *     ('rms_baseq_matches_pp', 'i4'),
 *     ('rms_baseq_mismatches', 'i4'),
 *     ('rms_baseq_mismatches_pp', 'i4'),             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__304 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_mismatches_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__304)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__304);
  __Pyx_GIVEREF(__pyx_tuple__304);

  /* "pysamstats.pyx":2601
 * 
 * 
 * def stat_baseq_ext(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended base quality statistics per genome position.
 * 
 */
  __pyx_tuple__305 = PyTuple_Pack(3, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__305)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__305);
  __Pyx_GIVEREF(__pyx_tuple__305);
  __pyx_codeobj__306 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__305, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_baseq_ext, 2601, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__306)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2638
 * 
 * 
 * def load_baseq_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq_ext, dtype_baseq_ext, *args, **kwargs)
 * 
 */
  __pyx_tuple__307 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__307)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__307);
  __Pyx_GIVEREF(__pyx_tuple__307);
  __pyx_codeobj__308 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__307, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_baseq_ext, 2638, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__308)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2648
 * 
 * dtype_baseq_ext_strand = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('ref', 'a1'),
 */
  __pyx_tuple__309 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__309)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2648; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__309);
  __Pyx_GIVEREF(__pyx_tuple__309);

  /* "pysamstats.pyx":2649
 * dtype_baseq_ext_strand = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('ref', 'a1'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__310 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__310)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__310);
  __Pyx_GIVEREF(__pyx_tuple__310);

  /* "pysamstats.pyx":2650
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('ref', 'a1'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 */
  __pyx_tuple__311 = PyTuple_Pack(2, __pyx_n_s_ref, __pyx_n_s_a1); if (unlikely(!__pyx_tuple__311)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__311);
  __Pyx_GIVEREF(__pyx_tuple__311);

  /* "pysamstats.pyx":2651
 *     ('pos', 'i4'),
 *     ('ref', 'a1'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 */
  __pyx_tuple__312 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__312)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__312);
  __Pyx_GIVEREF(__pyx_tuple__312);

  /* "pysamstats.pyx":2652
 *     ('ref', 'a1'),
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__313 = PyTuple_Pack(2, __pyx_n_s_reads_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__313)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__313);
  __Pyx_GIVEREF(__pyx_tuple__313);

  /* "pysamstats.pyx":2653
 *     ('reads_all', 'i4'),
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 */
  __pyx_tuple__314 = PyTuple_Pack(2, __pyx_n_s_reads_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__314)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__314);
  __Pyx_GIVEREF(__pyx_tuple__314);

  /* "pysamstats.pyx":2654
 *     ('reads_fwd', 'i4'),
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 */
  __pyx_tuple__315 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__315)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2654; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__315);
  __Pyx_GIVEREF(__pyx_tuple__315);

  /* "pysamstats.pyx":2655
 *     ('reads_rev', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp_rev', 'i4'),
 *     ('matches', 'i4'),
 */
  __pyx_tuple__316 = PyTuple_Pack(2, __pyx_n_s_reads_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__316)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__316);
  __Pyx_GIVEREF(__pyx_tuple__316);

  /* "pysamstats.pyx":2656
 *     ('reads_pp', 'i4'),
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches', 'i4'),
 *     ('matches_fwd', 'i4'),
 */
  __pyx_tuple__317 = PyTuple_Pack(2, __pyx_n_s_reads_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__317)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__317);
  __Pyx_GIVEREF(__pyx_tuple__317);

  /* "pysamstats.pyx":2657
 *     ('reads_pp_fwd', 'i4'),
 *     ('reads_pp_rev', 'i4'),
 *     ('matches', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches_fwd', 'i4'),
 *     ('matches_rev', 'i4'),
 */
  __pyx_tuple__318 = PyTuple_Pack(2, __pyx_n_s_matches, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__318)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__318);
  __Pyx_GIVEREF(__pyx_tuple__318);

  /* "pysamstats.pyx":2658
 *     ('reads_pp_rev', 'i4'),
 *     ('matches', 'i4'),
 *     ('matches_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches_rev', 'i4'),
 *     ('matches_pp', 'i4'),
 */
  __pyx_tuple__319 = PyTuple_Pack(2, __pyx_n_s_matches_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__319)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2658; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__319);
  __Pyx_GIVEREF(__pyx_tuple__319);

  /* "pysamstats.pyx":2659
 *     ('matches', 'i4'),
 *     ('matches_fwd', 'i4'),
 *     ('matches_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches_pp', 'i4'),
 *     ('matches_pp_fwd', 'i4'),
 */
  __pyx_tuple__320 = PyTuple_Pack(2, __pyx_n_s_matches_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__320)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__320);
  __Pyx_GIVEREF(__pyx_tuple__320);

  /* "pysamstats.pyx":2660
 *     ('matches_fwd', 'i4'),
 *     ('matches_rev', 'i4'),
 *     ('matches_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches_pp_fwd', 'i4'),
 *     ('matches_pp_rev', 'i4'),
 */
  __pyx_tuple__321 = PyTuple_Pack(2, __pyx_n_s_matches_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__321)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__321);
  __Pyx_GIVEREF(__pyx_tuple__321);

  /* "pysamstats.pyx":2661
 *     ('matches_rev', 'i4'),
 *     ('matches_pp', 'i4'),
 *     ('matches_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('matches_pp_rev', 'i4'),
 *     ('mismatches', 'i4'),
 */
  __pyx_tuple__322 = PyTuple_Pack(2, __pyx_n_s_matches_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__322)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__322);
  __Pyx_GIVEREF(__pyx_tuple__322);

  /* "pysamstats.pyx":2662
 *     ('matches_pp', 'i4'),
 *     ('matches_pp_fwd', 'i4'),
 *     ('matches_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches', 'i4'),
 *     ('mismatches_fwd', 'i4'),
 */
  __pyx_tuple__323 = PyTuple_Pack(2, __pyx_n_s_matches_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__323)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2662; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__323);
  __Pyx_GIVEREF(__pyx_tuple__323);

  /* "pysamstats.pyx":2663
 *     ('matches_pp_fwd', 'i4'),
 *     ('matches_pp_rev', 'i4'),
 *     ('mismatches', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches_fwd', 'i4'),
 *     ('mismatches_rev', 'i4'),
 */
  __pyx_tuple__324 = PyTuple_Pack(2, __pyx_n_s_mismatches, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__324)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__324);
  __Pyx_GIVEREF(__pyx_tuple__324);

  /* "pysamstats.pyx":2664
 *     ('matches_pp_rev', 'i4'),
 *     ('mismatches', 'i4'),
 *     ('mismatches_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches_rev', 'i4'),
 *     ('mismatches_pp', 'i4'),
 */
  __pyx_tuple__325 = PyTuple_Pack(2, __pyx_n_s_mismatches_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__325)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__325);
  __Pyx_GIVEREF(__pyx_tuple__325);

  /* "pysamstats.pyx":2665
 *     ('mismatches', 'i4'),
 *     ('mismatches_fwd', 'i4'),
 *     ('mismatches_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches_pp', 'i4'),
 *     ('mismatches_pp_fwd', 'i4'),
 */
  __pyx_tuple__326 = PyTuple_Pack(2, __pyx_n_s_mismatches_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__326)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__326);
  __Pyx_GIVEREF(__pyx_tuple__326);

  /* "pysamstats.pyx":2666
 *     ('mismatches_fwd', 'i4'),
 *     ('mismatches_rev', 'i4'),
 *     ('mismatches_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches_pp_fwd', 'i4'),
 *     ('mismatches_pp_rev', 'i4'),
 */
  __pyx_tuple__327 = PyTuple_Pack(2, __pyx_n_s_mismatches_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__327)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__327);
  __Pyx_GIVEREF(__pyx_tuple__327);

  /* "pysamstats.pyx":2667
 *     ('mismatches_rev', 'i4'),
 *     ('mismatches_pp', 'i4'),
 *     ('mismatches_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mismatches_pp_rev', 'i4'),
 *     ('rms_baseq', 'i4'),
 */
  __pyx_tuple__328 = PyTuple_Pack(2, __pyx_n_s_mismatches_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__328)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__328);
  __Pyx_GIVEREF(__pyx_tuple__328);

  /* "pysamstats.pyx":2668
 *     ('mismatches_pp', 'i4'),
 *     ('mismatches_pp_fwd', 'i4'),
 *     ('mismatches_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq', 'i4'),
 *     ('rms_baseq_fwd', 'i4'),
 */
  __pyx_tuple__329 = PyTuple_Pack(2, __pyx_n_s_mismatches_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__329)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__329);
  __Pyx_GIVEREF(__pyx_tuple__329);

  /* "pysamstats.pyx":2669
 *     ('mismatches_pp_fwd', 'i4'),
 *     ('mismatches_pp_rev', 'i4'),
 *     ('rms_baseq', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_fwd', 'i4'),
 *     ('rms_baseq_rev', 'i4'),
 */
  __pyx_tuple__330 = PyTuple_Pack(2, __pyx_n_s_rms_baseq, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__330)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__330);
  __Pyx_GIVEREF(__pyx_tuple__330);

  /* "pysamstats.pyx":2670
 *     ('mismatches_pp_rev', 'i4'),
 *     ('rms_baseq', 'i4'),
 *     ('rms_baseq_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_rev', 'i4'),
 *     ('rms_baseq_pp', 'i4'),
 */
  __pyx_tuple__331 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__331)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2670; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__331);
  __Pyx_GIVEREF(__pyx_tuple__331);

  /* "pysamstats.pyx":2671
 *     ('rms_baseq', 'i4'),
 *     ('rms_baseq_fwd', 'i4'),
 *     ('rms_baseq_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_pp', 'i4'),
 *     ('rms_baseq_pp_fwd', 'i4'),
 */
  __pyx_tuple__332 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__332)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__332);
  __Pyx_GIVEREF(__pyx_tuple__332);

  /* "pysamstats.pyx":2672
 *     ('rms_baseq_fwd', 'i4'),
 *     ('rms_baseq_rev', 'i4'),
 *     ('rms_baseq_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_pp_fwd', 'i4'),
 *     ('rms_baseq_pp_rev', 'i4'),
 */
  __pyx_tuple__333 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__333)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2672; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__333);
  __Pyx_GIVEREF(__pyx_tuple__333);

  /* "pysamstats.pyx":2673
 *     ('rms_baseq_rev', 'i4'),
 *     ('rms_baseq_pp', 'i4'),
 *     ('rms_baseq_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_pp_rev', 'i4'),
 *     ('rms_baseq_matches', 'i4'),
 */
  __pyx_tuple__334 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__334)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__334);
  __Pyx_GIVEREF(__pyx_tuple__334);

  /* "pysamstats.pyx":2674
 *     ('rms_baseq_pp', 'i4'),
 *     ('rms_baseq_pp_fwd', 'i4'),
 *     ('rms_baseq_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_matches', 'i4'),
 *     ('rms_baseq_matches_fwd', 'i4'),
 */
  __pyx_tuple__335 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__335)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__335);
  __Pyx_GIVEREF(__pyx_tuple__335);

  /* "pysamstats.pyx":2675
 *     ('rms_baseq_pp_fwd', 'i4'),
 *     ('rms_baseq_pp_rev', 'i4'),
 *     ('rms_baseq_matches', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_matches_fwd', 'i4'),
 *     ('rms_baseq_matches_rev', 'i4'),
 */
  __pyx_tuple__336 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_matches, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__336)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__336);
  __Pyx_GIVEREF(__pyx_tuple__336);

  /* "pysamstats.pyx":2676
 *     ('rms_baseq_pp_rev', 'i4'),
 *     ('rms_baseq_matches', 'i4'),
 *     ('rms_baseq_matches_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_matches_rev', 'i4'),
 *     ('rms_baseq_matches_pp', 'i4'),
 */
  __pyx_tuple__337 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_matches_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__337)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__337);
  __Pyx_GIVEREF(__pyx_tuple__337);

  /* "pysamstats.pyx":2677
 *     ('rms_baseq_matches', 'i4'),
 *     ('rms_baseq_matches_fwd', 'i4'),
 *     ('rms_baseq_matches_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_matches_pp', 'i4'),
 *     ('rms_baseq_matches_pp_fwd', 'i4'),
 */
  __pyx_tuple__338 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_matches_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__338)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__338);
  __Pyx_GIVEREF(__pyx_tuple__338);

  /* "pysamstats.pyx":2678
 *     ('rms_baseq_matches_fwd', 'i4'),
 *     ('rms_baseq_matches_rev', 'i4'),
 *     ('rms_baseq_matches_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_matches_pp_fwd', 'i4'),
 *     ('rms_baseq_matches_pp_rev', 'i4'),
 */
  __pyx_tuple__339 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_matches_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__339)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__339);
  __Pyx_GIVEREF(__pyx_tuple__339);

  /* "pysamstats.pyx":2679
 *     ('rms_baseq_matches_rev', 'i4'),
 *     ('rms_baseq_matches_pp', 'i4'),
 *     ('rms_baseq_matches_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_matches_pp_rev', 'i4'),
 *     ('rms_baseq_mismatches', 'i4'),
 */
  __pyx_tuple__340 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_matches_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__340)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__340);
  __Pyx_GIVEREF(__pyx_tuple__340);

  /* "pysamstats.pyx":2680
 *     ('rms_baseq_matches_pp', 'i4'),
 *     ('rms_baseq_matches_pp_fwd', 'i4'),
 *     ('rms_baseq_matches_pp_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_mismatches', 'i4'),
 *     ('rms_baseq_mismatches_fwd', 'i4'),
 */
  __pyx_tuple__341 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_matches_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__341)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__341);
  __Pyx_GIVEREF(__pyx_tuple__341);

  /* "pysamstats.pyx":2681
 *     ('rms_baseq_matches_pp_fwd', 'i4'),
 *     ('rms_baseq_matches_pp_rev', 'i4'),
 *     ('rms_baseq_mismatches', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_mismatches_fwd', 'i4'),
 *     ('rms_baseq_mismatches_rev', 'i4'),
 */
  __pyx_tuple__342 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_mismatches, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__342)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__342);
  __Pyx_GIVEREF(__pyx_tuple__342);

  /* "pysamstats.pyx":2682
 *     ('rms_baseq_matches_pp_rev', 'i4'),
 *     ('rms_baseq_mismatches', 'i4'),
 *     ('rms_baseq_mismatches_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_mismatches_rev', 'i4'),
 *     ('rms_baseq_mismatches_pp', 'i4'),
 */
  __pyx_tuple__343 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_mismatches_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__343)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__343);
  __Pyx_GIVEREF(__pyx_tuple__343);

  /* "pysamstats.pyx":2683
 *     ('rms_baseq_mismatches', 'i4'),
 *     ('rms_baseq_mismatches_fwd', 'i4'),
 *     ('rms_baseq_mismatches_rev', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_mismatches_pp', 'i4'),
 *     ('rms_baseq_mismatches_pp_fwd', 'i4'),
 */
  __pyx_tuple__344 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_mismatches_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__344)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__344);
  __Pyx_GIVEREF(__pyx_tuple__344);

  /* "pysamstats.pyx":2684
 *     ('rms_baseq_mismatches_fwd', 'i4'),
 *     ('rms_baseq_mismatches_rev', 'i4'),
 *     ('rms_baseq_mismatches_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_mismatches_pp_fwd', 'i4'),
 *     ('rms_baseq_mismatches_pp_rev', 'i4')
 */
  __pyx_tuple__345 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_mismatches_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__345)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__345);
  __Pyx_GIVEREF(__pyx_tuple__345);

  /* "pysamstats.pyx":2685
 *     ('rms_baseq_mismatches_rev', 'i4'),
 *     ('rms_baseq_mismatches_pp', 'i4'),
 *     ('rms_baseq_mismatches_pp_fwd', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_baseq_mismatches_pp_rev', 'i4')
 * ]
 */
  __pyx_tuple__346 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_mismatches_pp_fwd, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__346)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__346);
  __Pyx_GIVEREF(__pyx_tuple__346);

  /* "pysamstats.pyx":2686
 *     ('rms_baseq_mismatches_pp', 'i4'),
 *     ('rms_baseq_mismatches_pp_fwd', 'i4'),
 *     ('rms_baseq_mismatches_pp_rev', 'i4')             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__347 = PyTuple_Pack(2, __pyx_n_s_rms_baseq_mismatches_pp_rev, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__347)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__347);
  __Pyx_GIVEREF(__pyx_tuple__347);

  /* "pysamstats.pyx":2913
 * 
 * 
 * def stat_baseq_ext_strand(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended base quality statistics by strand per genome position.
 * 
 */
  __pyx_tuple__348 = PyTuple_Pack(3, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__348)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2913; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__348);
  __Pyx_GIVEREF(__pyx_tuple__348);
  __pyx_codeobj__349 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__348, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_baseq_ext_strand, 2913, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__349)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2913; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2950
 * 
 * 
 * def load_baseq_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq_ext_strand, dtype_baseq_ext_strand,
 *                        *args, **kwargs)
 */
  __pyx_tuple__350 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__350)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__350);
  __Pyx_GIVEREF(__pyx_tuple__350);
  __pyx_codeobj__351 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__350, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_baseq_ext_strand, 2950, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__351)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2960
 * 
 * 
 * dtype_coverage_gc = [('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *                      ('pos', 'i4'),
 *                      ('gc', 'u1'),
 */
  __pyx_tuple__352 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__352)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__352);
  __Pyx_GIVEREF(__pyx_tuple__352);

  /* "pysamstats.pyx":2961
 * 
 * dtype_coverage_gc = [('chrom', 'a12'),
 *                      ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *                      ('gc', 'u1'),
 *                      ('reads_all', 'i4'),
 */
  __pyx_tuple__353 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__353)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__353);
  __Pyx_GIVEREF(__pyx_tuple__353);

  /* "pysamstats.pyx":2962
 * dtype_coverage_gc = [('chrom', 'a12'),
 *                      ('pos', 'i4'),
 *                      ('gc', 'u1'),             # <<<<<<<<<<<<<<
 *                      ('reads_all', 'i4'),
 *                      ('reads_pp', 'i4')]
 */
  __pyx_tuple__354 = PyTuple_Pack(2, __pyx_n_s_gc, __pyx_n_s_u1); if (unlikely(!__pyx_tuple__354)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__354);
  __Pyx_GIVEREF(__pyx_tuple__354);

  /* "pysamstats.pyx":2963
 *                      ('pos', 'i4'),
 *                      ('gc', 'u1'),
 *                      ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *                      ('reads_pp', 'i4')]
 * 
 */
  __pyx_tuple__355 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__355)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__355);
  __Pyx_GIVEREF(__pyx_tuple__355);

  /* "pysamstats.pyx":2964
 *                      ('gc', 'u1'),
 *                      ('reads_all', 'i4'),
 *                      ('reads_pp', 'i4')]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__356 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__356)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2964; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__356);
  __Pyx_GIVEREF(__pyx_tuple__356);

  /* "pysamstats.pyx":2970
 * 
 * 
 * def stat_coverage_gc(alignmentfile, fafile, chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                      one_based=False, truncate=False, pad=False, max_depth=8000,
 *                      window_size=300, window_offset=None, **kwargs):
 */
  __pyx_tuple__357 = PyTuple_Pack(16, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_chrom, __pyx_n_s_start, __pyx_n_s_end, __pyx_n_s_one_based, __pyx_n_s_truncate, __pyx_n_s_pad, __pyx_n_s_max_depth, __pyx_n_s_window_size, __pyx_n_s_window_offset, __pyx_n_s_kwargs, __pyx_n_s_rec_coverage_gc, __pyx_n_s_rec_coverage_gc, __pyx_n_s_rec_coverage_gc_pad, __pyx_n_s_rec_coverage_gc_pad); if (unlikely(!__pyx_tuple__357)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__357);
  __Pyx_GIVEREF(__pyx_tuple__357);
  __pyx_codeobj__358 = (PyObject*)__Pyx_PyCode_New(11, 0, 16, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__357, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_coverage_gc, 2970, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__358)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3060
 * 
 * 
 * def load_coverage_gc(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_gc, dtype_coverage_gc, *args, **kwargs)
 * 
 */
  __pyx_tuple__359 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__359)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__359);
  __Pyx_GIVEREF(__pyx_tuple__359);
  __pyx_codeobj__360 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__359, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_coverage_gc, 3060, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__360)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3069
 * 
 * 
 * dtype_coverage_binned = [('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *                          ('pos', 'i4'),
 *                          ('gc', 'u1'),
 */
  __pyx_tuple__361 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__361)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__361);
  __Pyx_GIVEREF(__pyx_tuple__361);

  /* "pysamstats.pyx":3070
 * 
 * dtype_coverage_binned = [('chrom', 'a12'),
 *                          ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *                          ('gc', 'u1'),
 *                          ('reads_all', 'i4'),
 */
  __pyx_tuple__362 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__362)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__362);
  __Pyx_GIVEREF(__pyx_tuple__362);

  /* "pysamstats.pyx":3071
 * dtype_coverage_binned = [('chrom', 'a12'),
 *                          ('pos', 'i4'),
 *                          ('gc', 'u1'),             # <<<<<<<<<<<<<<
 *                          ('reads_all', 'i4'),
 *                          ('reads_pp', 'i4')]
 */
  __pyx_tuple__363 = PyTuple_Pack(2, __pyx_n_s_gc, __pyx_n_s_u1); if (unlikely(!__pyx_tuple__363)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__363);
  __Pyx_GIVEREF(__pyx_tuple__363);

  /* "pysamstats.pyx":3072
 *                          ('pos', 'i4'),
 *                          ('gc', 'u1'),
 *                          ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *                          ('reads_pp', 'i4')]
 * 
 */
  __pyx_tuple__364 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__364)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3072; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__364);
  __Pyx_GIVEREF(__pyx_tuple__364);

  /* "pysamstats.pyx":3073
 *                          ('gc', 'u1'),
 *                          ('reads_all', 'i4'),
 *                          ('reads_pp', 'i4')]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__365 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__365)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__365);
  __Pyx_GIVEREF(__pyx_tuple__365);

  /* "pysamstats.pyx":3079
 * 
 * 
 * def stat_coverage_binned(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned coverage statistics.
 * 
 */
  __pyx_tuple__366 = PyTuple_Pack(4, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_kwargs, __pyx_n_s_stat); if (unlikely(!__pyx_tuple__366)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__366);
  __Pyx_GIVEREF(__pyx_tuple__366);
  __pyx_codeobj__367 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__366, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_coverage_binned, 3079, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__367)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3178
 * 
 * 
 * def load_coverage_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_binned, dtype_coverage_binned,
 *                        *args, **kwargs)
 */
  __pyx_tuple__368 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__368)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__368);
  __Pyx_GIVEREF(__pyx_tuple__368);
  __pyx_codeobj__369 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__368, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_coverage_binned, 3178, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__369)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3188
 * 
 * 
 * dtype_coverage_ext_binned = [('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *                              ('pos', 'i4'),
 *                              ('gc', 'u1'),
 */
  __pyx_tuple__370 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__370)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__370);
  __Pyx_GIVEREF(__pyx_tuple__370);

  /* "pysamstats.pyx":3189
 * 
 * dtype_coverage_ext_binned = [('chrom', 'a12'),
 *                              ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *                              ('gc', 'u1'),
 *                              ('reads_all', 'i4'),
 */
  __pyx_tuple__371 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__371)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__371);
  __Pyx_GIVEREF(__pyx_tuple__371);

  /* "pysamstats.pyx":3190
 * dtype_coverage_ext_binned = [('chrom', 'a12'),
 *                              ('pos', 'i4'),
 *                              ('gc', 'u1'),             # <<<<<<<<<<<<<<
 *                              ('reads_all', 'i4'),
 *                              ('reads_pp', 'i4'),
 */
  __pyx_tuple__372 = PyTuple_Pack(2, __pyx_n_s_gc, __pyx_n_s_u1); if (unlikely(!__pyx_tuple__372)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__372);
  __Pyx_GIVEREF(__pyx_tuple__372);

  /* "pysamstats.pyx":3191
 *                              ('pos', 'i4'),
 *                              ('gc', 'u1'),
 *                              ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *                              ('reads_pp', 'i4'),
 *                              ('reads_mate_unmapped', 'i4'),
 */
  __pyx_tuple__373 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__373)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__373);
  __Pyx_GIVEREF(__pyx_tuple__373);

  /* "pysamstats.pyx":3192
 *                              ('gc', 'u1'),
 *                              ('reads_all', 'i4'),
 *                              ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *                              ('reads_mate_unmapped', 'i4'),
 *                              ('reads_mate_other_chr', 'i4'),
 */
  __pyx_tuple__374 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__374)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__374);
  __Pyx_GIVEREF(__pyx_tuple__374);

  /* "pysamstats.pyx":3193
 *                              ('reads_all', 'i4'),
 *                              ('reads_pp', 'i4'),
 *                              ('reads_mate_unmapped', 'i4'),             # <<<<<<<<<<<<<<
 *                              ('reads_mate_other_chr', 'i4'),
 *                              ('reads_mate_same_strand', 'i4'),
 */
  __pyx_tuple__375 = PyTuple_Pack(2, __pyx_n_s_reads_mate_unmapped, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__375)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__375);
  __Pyx_GIVEREF(__pyx_tuple__375);

  /* "pysamstats.pyx":3194
 *                              ('reads_pp', 'i4'),
 *                              ('reads_mate_unmapped', 'i4'),
 *                              ('reads_mate_other_chr', 'i4'),             # <<<<<<<<<<<<<<
 *                              ('reads_mate_same_strand', 'i4'),
 *                              ('reads_faceaway', 'i4'),
 */
  __pyx_tuple__376 = PyTuple_Pack(2, __pyx_n_s_reads_mate_other_chr, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__376)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__376);
  __Pyx_GIVEREF(__pyx_tuple__376);

  /* "pysamstats.pyx":3195
 *                              ('reads_mate_unmapped', 'i4'),
 *                              ('reads_mate_other_chr', 'i4'),
 *                              ('reads_mate_same_strand', 'i4'),             # <<<<<<<<<<<<<<
 *                              ('reads_faceaway', 'i4'),
 *                              ('reads_softclipped', 'i4'),
 */
  __pyx_tuple__377 = PyTuple_Pack(2, __pyx_n_s_reads_mate_same_strand, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__377)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__377);
  __Pyx_GIVEREF(__pyx_tuple__377);

  /* "pysamstats.pyx":3196
 *                              ('reads_mate_other_chr', 'i4'),
 *                              ('reads_mate_same_strand', 'i4'),
 *                              ('reads_faceaway', 'i4'),             # <<<<<<<<<<<<<<
 *                              ('reads_softclipped', 'i4'),
 *                              ('reads_duplicate', 'i4')]
 */
  __pyx_tuple__378 = PyTuple_Pack(2, __pyx_n_s_reads_faceaway, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__378)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__378);
  __Pyx_GIVEREF(__pyx_tuple__378);

  /* "pysamstats.pyx":3197
 *                              ('reads_mate_same_strand', 'i4'),
 *                              ('reads_faceaway', 'i4'),
 *                              ('reads_softclipped', 'i4'),             # <<<<<<<<<<<<<<
 *                              ('reads_duplicate', 'i4')]
 * 
 */
  __pyx_tuple__379 = PyTuple_Pack(2, __pyx_n_s_reads_softclipped, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__379)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__379);
  __Pyx_GIVEREF(__pyx_tuple__379);

  /* "pysamstats.pyx":3198
 *                              ('reads_faceaway', 'i4'),
 *                              ('reads_softclipped', 'i4'),
 *                              ('reads_duplicate', 'i4')]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__380 = PyTuple_Pack(2, __pyx_n_s_reads_duplicate, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__380)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__380);
  __Pyx_GIVEREF(__pyx_tuple__380);

  /* "pysamstats.pyx":3204
 * 
 * 
 * def stat_coverage_ext_binned(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned extended coverage statistics.
 * 
 */
  __pyx_tuple__381 = PyTuple_Pack(4, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_kwargs, __pyx_n_s_stat); if (unlikely(!__pyx_tuple__381)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__381);
  __Pyx_GIVEREF(__pyx_tuple__381);
  __pyx_codeobj__382 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__381, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_coverage_ext_binned, 3204, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__382)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3319
 * 
 * 
 * def load_coverage_ext_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_ext_binned, dtype_coverage_ext_binned,
 *                        *args, **kwargs)
 */
  __pyx_tuple__383 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__383)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__383);
  __Pyx_GIVEREF(__pyx_tuple__383);
  __pyx_codeobj__384 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__383, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_coverage_ext_binned, 3319, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__384)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3330
 * 
 * dtype_mapq_binned = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__385 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__385)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__385);
  __Pyx_GIVEREF(__pyx_tuple__385);

  /* "pysamstats.pyx":3331
 * dtype_mapq_binned = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_mapq0', 'i4'),
 */
  __pyx_tuple__386 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__386)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__386);
  __Pyx_GIVEREF(__pyx_tuple__386);

  /* "pysamstats.pyx":3332
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_mapq0', 'i4'),
 *     ('rms_mapq', 'i4'),
 */
  __pyx_tuple__387 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__387)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__387);
  __Pyx_GIVEREF(__pyx_tuple__387);

  /* "pysamstats.pyx":3333
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 *     ('reads_mapq0', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_mapq', 'i4'),
 * ]
 */
  __pyx_tuple__388 = PyTuple_Pack(2, __pyx_n_s_reads_mapq0, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__388)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__388);
  __Pyx_GIVEREF(__pyx_tuple__388);

  /* "pysamstats.pyx":3334
 *     ('reads_all', 'i4'),
 *     ('reads_mapq0', 'i4'),
 *     ('rms_mapq', 'i4'),             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__389 = PyTuple_Pack(2, __pyx_n_s_rms_mapq, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__389)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__389);
  __Pyx_GIVEREF(__pyx_tuple__389);

  /* "pysamstats.pyx":3341
 * 
 * 
 * def stat_mapq_binned(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned mapping quality statistics.
 * 
 */
  __pyx_tuple__390 = PyTuple_Pack(3, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs, __pyx_n_s_stat); if (unlikely(!__pyx_tuple__390)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__390);
  __Pyx_GIVEREF(__pyx_tuple__390);
  __pyx_codeobj__391 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__390, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_mapq_binned, 3341, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__391)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3416
 * 
 * 
 * def load_mapq_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_mapq_binned, dtype_mapq_binned, *args, **kwargs)
 * 
 */
  __pyx_tuple__392 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__392)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__392);
  __Pyx_GIVEREF(__pyx_tuple__392);
  __pyx_codeobj__393 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__392, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_mapq_binned, 3416, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__393)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3426
 * 
 * dtype_alignment_binned = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__394 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__394)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__394);
  __Pyx_GIVEREF(__pyx_tuple__394);

  /* "pysamstats.pyx":3427
 * dtype_alignment_binned = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('bases_all', 'i4'),
 */
  __pyx_tuple__395 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__395)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__395);
  __Pyx_GIVEREF(__pyx_tuple__395);

  /* "pysamstats.pyx":3428
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('bases_all', 'i4'),
 *     ('M', 'i4'),
 */
  __pyx_tuple__396 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__396)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__396);
  __Pyx_GIVEREF(__pyx_tuple__396);

  /* "pysamstats.pyx":3429
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 *     ('bases_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('M', 'i4'),
 *     ('I', 'i4'),
 */
  __pyx_tuple__397 = PyTuple_Pack(2, __pyx_n_s_bases_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__397)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__397);
  __Pyx_GIVEREF(__pyx_tuple__397);

  /* "pysamstats.pyx":3430
 *     ('reads_all', 'i4'),
 *     ('bases_all', 'i4'),
 *     ('M', 'i4'),             # <<<<<<<<<<<<<<
 *     ('I', 'i4'),
 *     ('D', 'i4'),
 */
  __pyx_tuple__398 = PyTuple_Pack(2, __pyx_n_s_M, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__398)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__398);
  __Pyx_GIVEREF(__pyx_tuple__398);

  /* "pysamstats.pyx":3431
 *     ('bases_all', 'i4'),
 *     ('M', 'i4'),
 *     ('I', 'i4'),             # <<<<<<<<<<<<<<
 *     ('D', 'i4'),
 *     ('N', 'i4'),
 */
  __pyx_tuple__399 = PyTuple_Pack(2, __pyx_n_s_I, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__399)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__399);
  __Pyx_GIVEREF(__pyx_tuple__399);

  /* "pysamstats.pyx":3432
 *     ('M', 'i4'),
 *     ('I', 'i4'),
 *     ('D', 'i4'),             # <<<<<<<<<<<<<<
 *     ('N', 'i4'),
 *     ('S', 'i4'),
 */
  __pyx_tuple__400 = PyTuple_Pack(2, __pyx_n_s_D, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__400)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__400);
  __Pyx_GIVEREF(__pyx_tuple__400);

  /* "pysamstats.pyx":3433
 *     ('I', 'i4'),
 *     ('D', 'i4'),
 *     ('N', 'i4'),             # <<<<<<<<<<<<<<
 *     ('S', 'i4'),
 *     ('H', 'i4'),
 */
  __pyx_tuple__401 = PyTuple_Pack(2, __pyx_n_s_N, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__401)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__401);
  __Pyx_GIVEREF(__pyx_tuple__401);

  /* "pysamstats.pyx":3434
 *     ('D', 'i4'),
 *     ('N', 'i4'),
 *     ('S', 'i4'),             # <<<<<<<<<<<<<<
 *     ('H', 'i4'),
 *     ('P', 'i4'),
 */
  __pyx_tuple__402 = PyTuple_Pack(2, __pyx_n_s_S, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__402)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__402);
  __Pyx_GIVEREF(__pyx_tuple__402);

  /* "pysamstats.pyx":3435
 *     ('N', 'i4'),
 *     ('S', 'i4'),
 *     ('H', 'i4'),             # <<<<<<<<<<<<<<
 *     ('P', 'i4'),
 *     ('=', 'i4'),
 */
  __pyx_tuple__403 = PyTuple_Pack(2, __pyx_n_s_H, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__403)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__403);
  __Pyx_GIVEREF(__pyx_tuple__403);

  /* "pysamstats.pyx":3436
 *     ('S', 'i4'),
 *     ('H', 'i4'),
 *     ('P', 'i4'),             # <<<<<<<<<<<<<<
 *     ('=', 'i4'),
 *     ('X', 'i4')
 */
  __pyx_tuple__404 = PyTuple_Pack(2, __pyx_n_s_P, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__404)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__404);
  __Pyx_GIVEREF(__pyx_tuple__404);

  /* "pysamstats.pyx":3437
 *     ('H', 'i4'),
 *     ('P', 'i4'),
 *     ('=', 'i4'),             # <<<<<<<<<<<<<<
 *     ('X', 'i4')
 * ]
 */
  __pyx_tuple__405 = PyTuple_Pack(2, __pyx_kp_s__5, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__405)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__405);
  __Pyx_GIVEREF(__pyx_tuple__405);

  /* "pysamstats.pyx":3438
 *     ('P', 'i4'),
 *     ('=', 'i4'),
 *     ('X', 'i4')             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__406 = PyTuple_Pack(2, __pyx_n_s_X, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__406)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__406);
  __Pyx_GIVEREF(__pyx_tuple__406);

  /* "pysamstats.pyx":3445
 * 
 * 
 * def stat_alignment_binned(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned alignment statistics.
 * 
 */
  __pyx_tuple__407 = PyTuple_Pack(3, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs, __pyx_n_s_stat); if (unlikely(!__pyx_tuple__407)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__407);
  __Pyx_GIVEREF(__pyx_tuple__407);
  __pyx_codeobj__408 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__407, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_alignment_binned, 3445, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__408)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3542
 * 
 * 
 * def load_alignment_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_alignment_binned, dtype_alignment_binned,
 *                        *args, **kwargs)
 */
  __pyx_tuple__409 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__409)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__409);
  __Pyx_GIVEREF(__pyx_tuple__409);
  __pyx_codeobj__410 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__409, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_alignment_binned, 3542, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__410)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3553
 * 
 * dtype_tlen_binned = [
 *     ('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 */
  __pyx_tuple__411 = PyTuple_Pack(2, __pyx_n_s_chrom, __pyx_n_s_a12); if (unlikely(!__pyx_tuple__411)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__411);
  __Pyx_GIVEREF(__pyx_tuple__411);

  /* "pysamstats.pyx":3554
 * dtype_tlen_binned = [
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),
 */
  __pyx_tuple__412 = PyTuple_Pack(2, __pyx_n_s_pos, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__412)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3554; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__412);
  __Pyx_GIVEREF(__pyx_tuple__412);

  /* "pysamstats.pyx":3555
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),             # <<<<<<<<<<<<<<
 *     ('reads_pp', 'i4'),
 *     ('mean_tlen', 'i4'),
 */
  __pyx_tuple__413 = PyTuple_Pack(2, __pyx_n_s_reads_all, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__413)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__413);
  __Pyx_GIVEREF(__pyx_tuple__413);

  /* "pysamstats.pyx":3556
 *     ('pos', 'i4'),
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mean_tlen', 'i4'),
 *     ('mean_tlen_pp', 'i4'),
 */
  __pyx_tuple__414 = PyTuple_Pack(2, __pyx_n_s_reads_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__414)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__414);
  __Pyx_GIVEREF(__pyx_tuple__414);

  /* "pysamstats.pyx":3557
 *     ('reads_all', 'i4'),
 *     ('reads_pp', 'i4'),
 *     ('mean_tlen', 'i4'),             # <<<<<<<<<<<<<<
 *     ('mean_tlen_pp', 'i4'),
 *     ('rms_tlen', 'i4'),
 */
  __pyx_tuple__415 = PyTuple_Pack(2, __pyx_n_s_mean_tlen, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__415)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__415);
  __Pyx_GIVEREF(__pyx_tuple__415);

  /* "pysamstats.pyx":3558
 *     ('reads_pp', 'i4'),
 *     ('mean_tlen', 'i4'),
 *     ('mean_tlen_pp', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_tlen', 'i4'),
 *     ('rms_tlen_pp', 'i4'),
 */
  __pyx_tuple__416 = PyTuple_Pack(2, __pyx_n_s_mean_tlen_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__416)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__416);
  __Pyx_GIVEREF(__pyx_tuple__416);

  /* "pysamstats.pyx":3559
 *     ('mean_tlen', 'i4'),
 *     ('mean_tlen_pp', 'i4'),
 *     ('rms_tlen', 'i4'),             # <<<<<<<<<<<<<<
 *     ('rms_tlen_pp', 'i4'),
 * ]
 */
  __pyx_tuple__417 = PyTuple_Pack(2, __pyx_n_s_rms_tlen, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__417)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__417);
  __Pyx_GIVEREF(__pyx_tuple__417);

  /* "pysamstats.pyx":3560
 *     ('mean_tlen_pp', 'i4'),
 *     ('rms_tlen', 'i4'),
 *     ('rms_tlen_pp', 'i4'),             # <<<<<<<<<<<<<<
 * ]
 * 
 */
  __pyx_tuple__418 = PyTuple_Pack(2, __pyx_n_s_rms_tlen_pp, __pyx_n_s_i4); if (unlikely(!__pyx_tuple__418)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__418);
  __Pyx_GIVEREF(__pyx_tuple__418);

  /* "pysamstats.pyx":3567
 * 
 * 
 * def stat_tlen_binned(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned insert size statistics.
 * 
 */
  __pyx_tuple__419 = PyTuple_Pack(3, __pyx_n_s_alignmentfile, __pyx_n_s_kwargs, __pyx_n_s_stat); if (unlikely(!__pyx_tuple__419)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__419);
  __Pyx_GIVEREF(__pyx_tuple__419);
  __pyx_codeobj__420 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__419, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_stat_tlen_binned, 3567, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__420)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3656
 * 
 * 
 * def load_tlen_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_tlen_binned, dtype_tlen_binned, *args, **kwargs)
 * 
 */
  __pyx_tuple__421 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__421)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__421);
  __Pyx_GIVEREF(__pyx_tuple__421);
  __pyx_codeobj__422 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__421, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_tlen_binned, 3656, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__422)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3665
 * 
 * 
 * def _iter_pileup(frec, fpad, alignmentfile, fafile=None, chrom=None, start=None,             # <<<<<<<<<<<<<<
 *                  end=None, one_based=False, truncate=False, pad=False,
 *                  max_depth=8000, **kwargs):
 */
  __pyx_tuple__423 = PyTuple_Pack(12, __pyx_n_s_frec, __pyx_n_s_fpad, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_chrom, __pyx_n_s_start, __pyx_n_s_end, __pyx_n_s_one_based, __pyx_n_s_truncate, __pyx_n_s_pad, __pyx_n_s_max_depth, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__423)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__423);
  __Pyx_GIVEREF(__pyx_tuple__423);
  __pyx_codeobj__424 = (PyObject*)__Pyx_PyCode_New(11, 0, 12, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__423, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_iter_pileup, 3665, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__424)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3693
 * 
 * 
 * def _iter_pileup_default(frec, alignmentfile, fafile=None,             # <<<<<<<<<<<<<<
 *                          chrom=None, start=None, end=None,
 *                          one_based=False, truncate=False,
 */
  __pyx_tuple__425 = PyTuple_Pack(12, __pyx_n_s_frec, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_chrom, __pyx_n_s_start, __pyx_n_s_end, __pyx_n_s_one_based, __pyx_n_s_truncate, __pyx_n_s_max_depth, __pyx_n_s_kwargs, __pyx_n_s_it, __pyx_n_s_col); if (unlikely(!__pyx_tuple__425)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__425);
  __Pyx_GIVEREF(__pyx_tuple__425);
  __pyx_codeobj__426 = (PyObject*)__Pyx_PyCode_New(9, 0, 12, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__425, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_iter_pileup_default, 3693, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__426)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3704
 * 
 * 
 * def _iter_pileup_padded(frec, fpad, alignmentfile, fafile=None, chrom=None,             # <<<<<<<<<<<<<<
 *                         start=None, end=None, one_based=False,
 *                         truncate=False, max_depth=8000, **kwargs):
 */
  __pyx_tuple__427 = PyTuple_Pack(14, __pyx_n_s_frec, __pyx_n_s_fpad, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_chrom, __pyx_n_s_start, __pyx_n_s_end, __pyx_n_s_one_based, __pyx_n_s_truncate, __pyx_n_s_max_depth, __pyx_n_s_kwargs, __pyx_n_s_it, __pyx_n_s_its, __pyx_n_s_itc); if (unlikely(!__pyx_tuple__427)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__427);
  __Pyx_GIVEREF(__pyx_tuple__427);
  __pyx_codeobj__428 = (PyObject*)__Pyx_PyCode_New(10, 0, 14, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__427, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_iter_pileup_padded, 3704, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__428)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3729
 * 
 * 
 * def _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile, chrom, start=None,             # <<<<<<<<<<<<<<
 *                               end=None, one_based=False, truncate=False,
 *                               max_depth=8000, **kwargs):
 */
  __pyx_tuple__429 = PyTuple_Pack(14, __pyx_n_s_frec, __pyx_n_s_fpad, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_chrom, __pyx_n_s_start, __pyx_n_s_end, __pyx_n_s_one_based, __pyx_n_s_truncate, __pyx_n_s_max_depth, __pyx_n_s_kwargs, __pyx_n_s_col, __pyx_n_s_curpos, __pyx_n_s_it); if (unlikely(!__pyx_tuple__429)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__429);
  __Pyx_GIVEREF(__pyx_tuple__429);
  __pyx_codeobj__430 = (PyObject*)__Pyx_PyCode_New(10, 0, 14, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__429, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_iter_pileup_padded_chrom, 3729, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__430)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3750
 * 
 * 
 * def _iter_binned(stat, alignmentfile, fafile=None, chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                  one_based=False, window_size=300, window_offset=None,
 *                  **kwargs):
 */
  __pyx_tuple__431 = PyTuple_Pack(13, __pyx_n_s_stat, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_chrom, __pyx_n_s_start, __pyx_n_s_end, __pyx_n_s_one_based, __pyx_n_s_window_size, __pyx_n_s_window_offset, __pyx_n_s_kwargs, __pyx_n_s_its, __pyx_n_s_itc, __pyx_n_s_it); if (unlikely(!__pyx_tuple__431)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__431);
  __Pyx_GIVEREF(__pyx_tuple__431);
  __pyx_codeobj__432 = (PyObject*)__Pyx_PyCode_New(9, 0, 13, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__431, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_iter_binned, 3750, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__432)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3783
 * 
 * 
 * def _iter_binned_chrom(_StatBinned stat, AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                        chrom, start=None, end=None, one_based=False,
 *                        int window_size=300, int window_offset=150, **kwargs):
 */
  __pyx_tuple__433 = PyTuple_Pack(20, __pyx_n_s_stat, __pyx_n_s_alignmentfile, __pyx_n_s_fafile, __pyx_n_s_chrom, __pyx_n_s_start, __pyx_n_s_end, __pyx_n_s_one_based, __pyx_n_s_window_size, __pyx_n_s_window_offset, __pyx_n_s_kwargs, __pyx_n_s_rtid, __pyx_n_s_rstart, __pyx_n_s_rend, __pyx_n_s_has_coord, __pyx_n_s_bin_start, __pyx_n_s_bin_end, __pyx_n_s_it, __pyx_n_s_b, __pyx_n_s_rec, __pyx_n_s_pos); if (unlikely(!__pyx_tuple__433)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__433);
  __Pyx_GIVEREF(__pyx_tuple__433);
  __pyx_codeobj__434 = (PyObject*)__Pyx_PyCode_New(9, 0, 20, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__433, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_iter_binned_chrom, 3783, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__434)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3856
 * 
 * 
 * def _normalise_coords(AlignmentFile alignmentfile, chrom, start, end, one_based):             # <<<<<<<<<<<<<<
 *     """Convert to zero-based coordinates and deal with unspecified start
 *     and/or end.
 */
  __pyx_tuple__435 = PyTuple_Pack(6, __pyx_n_s_alignmentfile, __pyx_n_s_chrom, __pyx_n_s_start, __pyx_n_s_end, __pyx_n_s_one_based, __pyx_n_s_chrlen); if (unlikely(!__pyx_tuple__435)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__435);
  __Pyx_GIVEREF(__pyx_tuple__435);
  __pyx_codeobj__436 = (PyObject*)__Pyx_PyCode_New(5, 0, 6, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__435, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_normalise_coords, 3856, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__436)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3884
 * 
 * 
 * def write_csv(stats_type, outfile, alignmentfile, fields=None, dialect='excel-tab',             # <<<<<<<<<<<<<<
 *               write_header=True, progress=None, **kwargs):
 *     """Write statistics output to a CSV file.
 */
  __pyx_tuple__437 = PyTuple_Pack(23, __pyx_n_s_stats_type, __pyx_n_s_outfile, __pyx_n_s_alignmentfile, __pyx_n_s_fields, __pyx_n_s_dialect, __pyx_n_s_write_header, __pyx_n_s_progress, __pyx_n_s_kwargs, __pyx_n_s_counter, __pyx_n_s_modulus, __pyx_n_s_stats_function, __pyx_n_s_recs, __pyx_n_s_rows, __pyx_n_s_writer, __pyx_n_s_row, __pyx_n_s_before, __pyx_n_s_before_all, __pyx_n_s_after, __pyx_n_s_elapsed, __pyx_n_s_batch_elapsed, __pyx_n_s_msg, __pyx_n_s_after_all, __pyx_n_s_elapsed_all); if (unlikely(!__pyx_tuple__437)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__437);
  __Pyx_GIVEREF(__pyx_tuple__437);
  __pyx_codeobj__438 = (PyObject*)__Pyx_PyCode_New(7, 0, 23, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__437, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_write_csv, 3884, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__438)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":3962
 * 
 * 
 * def write_hdf5(stats_type, outfile, alignmentfile, fields=None, progress=None,             # <<<<<<<<<<<<<<
 *                hdf5_group='/', hdf5_dataset='data', hdf5_complevel=5,
 *                hdf5_complib='zlib', hdf5_shuffle=True,
 */
  __pyx_tuple__439 = PyTuple_Pack(39, __pyx_n_s_stats_type, __pyx_n_s_outfile, __pyx_n_s_alignmentfile, __pyx_n_s_fields, __pyx_n_s_progress, __pyx_n_s_hdf5_group, __pyx_n_s_hdf5_dataset, __pyx_n_s_hdf5_complevel, __pyx_n_s_hdf5_complib, __pyx_n_s_hdf5_shuffle, __pyx_n_s_hdf5_fletcher32, __pyx_n_s_hdf5_chunksize, __pyx_n_s_kwargs, __pyx_n_s_tables, __pyx_n_s_np, __pyx_n_s_h5file, __pyx_n_s_stats_function, __pyx_n_s_default_dtype, __pyx_n_s_dtype_2, __pyx_n_s_dtype_overrides, __pyx_n_s_recs, __pyx_n_s_rows, __pyx_n_s_hdf5_chunklen, __pyx_n_s_hdf5_chunkshape, __pyx_n_s_h5table, __pyx_n_s_counter, __pyx_n_s_counter_before, __pyx_n_s_before, __pyx_n_s_before_all, __pyx_n_s_chunk, __pyx_n_s_n, __pyx_n_s_after, __pyx_n_s_elapsed, __pyx_n_s_batch_elapsed, __pyx_n_s_batch_size, __pyx_n_s_msg, __pyx_n_s_after_all, __pyx_n_s_elapsed_all, __pyx_n_s_f); if (unlikely(!__pyx_tuple__439)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__439);
  __Pyx_GIVEREF(__pyx_tuple__439);
  __pyx_codeobj__440 = (PyObject*)__Pyx_PyCode_New(12, 0, 39, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__439, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_write_hdf5, 3962, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__440)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":4109
 * 
 * 
 * def flatten(recs, *fields):             # <<<<<<<<<<<<<<
 *     """Convert a record (dict) iterator to a row (tuple) iterator.
 * 
 */
  __pyx_tuple__441 = PyTuple_Pack(6, __pyx_n_s_recs, __pyx_n_s_fields, __pyx_n_s_getter, __pyx_n_s_it, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!__pyx_tuple__441)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__441);
  __Pyx_GIVEREF(__pyx_tuple__441);
  __pyx_codeobj__442 = (PyObject*)__Pyx_PyCode_New(1, 0, 6, 0, CO_VARARGS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__441, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_flatten, 4109, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__442)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":4133
 * 
 * 
 * def tabulate(stat, *args, **kwargs):             # <<<<<<<<<<<<<<
 *     """Tabulate statistics.
 * 
 */
  __pyx_tuple__443 = PyTuple_Pack(3, __pyx_n_s_stat, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__443)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__443);
  __Pyx_GIVEREF(__pyx_tuple__443);
  __pyx_codeobj__444 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__443, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_tabulate, 4133, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__444)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":4160
 * class _StatsTable(object):
 * 
 *     def __init__(self, stats_type, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         try:
 *             self.stats_function = globals()['stat_' + stats_type]
 */
  __pyx_tuple__445 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_stats_type, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__445)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__445);
  __Pyx_GIVEREF(__pyx_tuple__445);
  __pyx_codeobj__446 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__445, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_init, 4160, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__446)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":4171
 *             raise Exception('statistics type not found: %r' % stats_type)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         recs = self.stats_function(*self.args, **self.kwargs)
 *         fields = tuple(self.fields)
 */
  __pyx_tuple__447 = PyTuple_Pack(5, __pyx_n_s_self, __pyx_n_s_recs, __pyx_n_s_fields, __pyx_n_s_rows, __pyx_n_s_row); if (unlikely(!__pyx_tuple__447)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__447);
  __Pyx_GIVEREF(__pyx_tuple__447);
  __pyx_codeobj__448 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__447, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_iter, 4171, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__448)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":4180
 * 
 * 
 * def _load_stats(statfun, default_dtype, *args, **kwargs):             # <<<<<<<<<<<<<<
 * 
 *     import numpy as np
 */
  __pyx_tuple__449 = PyTuple_Pack(13, __pyx_n_s_statfun, __pyx_n_s_default_dtype, __pyx_n_s_args, __pyx_n_s_kwargs, __pyx_n_s_np, __pyx_n_s_fields, __pyx_n_s_dtype_2, __pyx_n_s_dtype_overrides, __pyx_n_s_recs, __pyx_n_s_it, __pyx_n_s_a, __pyx_n_s_t, __pyx_n_s_f); if (unlikely(!__pyx_tuple__449)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__449);
  __Pyx_GIVEREF(__pyx_tuple__449);
  __pyx_codeobj__450 = (PyObject*)__Pyx_PyCode_New(2, 0, 13, 0, CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__449, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_load_stats, 4180, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__450)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":4259
 * 
 * 
 * def count_reads(AlignmentFile alignmentfile, chrom=None, start=None, end=None):             # <<<<<<<<<<<<<<
 *     cdef IteratorRowRegion it
 *     cdef int n = 0
 */
  __pyx_tuple__451 = PyTuple_Pack(10, __pyx_n_s_alignmentfile, __pyx_n_s_chrom, __pyx_n_s_start, __pyx_n_s_end, __pyx_n_s_it, __pyx_n_s_n, __pyx_n_s_has_coord, __pyx_n_s_rtid, __pyx_n_s_rstart, __pyx_n_s_rend); if (unlikely(!__pyx_tuple__451)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__451);
  __Pyx_GIVEREF(__pyx_tuple__451);
  __pyx_codeobj__452 = (PyObject*)__Pyx_PyCode_New(4, 0, 10, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__451, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_aliman_src_github_alimanfo, __pyx_n_s_count_reads, 4259, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__452)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) {__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;}
  __pyx_int_8000 = PyInt_FromLong(8000); if (unlikely(!__pyx_int_8000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_131072 = PyInt_FromLong(131072L); if (unlikely(!__pyx_int_131072)) {__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;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #if CYTHON_REFNANNY
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  #endif
  __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_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("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;}
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  if (__pyx_module_is_main_pysamstats) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!PyDict_GetItemString(modules, "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
  /*--- 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 ---*/
  __pyx_vtabptr_10pysamstats__StatBinned = &__pyx_vtable_10pysamstats__StatBinned;
  __pyx_vtable_10pysamstats__StatBinned.rec = (PyObject *(*)(struct __pyx_obj_10pysamstats__StatBinned *, PyObject *, PyObject *, PyObject *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *))__pyx_f_10pysamstats_11_StatBinned_rec;
  __pyx_vtable_10pysamstats__StatBinned.recv = (PyObject *(*)(struct __pyx_obj_10pysamstats__StatBinned *, bam1_t *))__pyx_f_10pysamstats_11_StatBinned_recv;
  if (PyType_Ready(&__pyx_type_10pysamstats__StatBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats__StatBinned.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_10pysamstats__StatBinned.tp_dict, __pyx_vtabptr_10pysamstats__StatBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "_StatBinned", (PyObject *)&__pyx_type_10pysamstats__StatBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats__StatBinned = &__pyx_type_10pysamstats__StatBinned;
  __pyx_vtabptr_10pysamstats__CoverageBinned = &__pyx_vtable_10pysamstats__CoverageBinned;
  __pyx_vtable_10pysamstats__CoverageBinned.__pyx_base = *__pyx_vtabptr_10pysamstats__StatBinned;
  __pyx_vtable_10pysamstats__CoverageBinned.__pyx_base.rec = (PyObject *(*)(struct __pyx_obj_10pysamstats__StatBinned *, PyObject *, PyObject *, PyObject *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *))__pyx_f_10pysamstats_15_CoverageBinned_rec;
  __pyx_vtable_10pysamstats__CoverageBinned.__pyx_base.recv = (PyObject *(*)(struct __pyx_obj_10pysamstats__StatBinned *, bam1_t *))__pyx_f_10pysamstats_15_CoverageBinned_recv;
  __pyx_type_10pysamstats__CoverageBinned.tp_base = __pyx_ptype_10pysamstats__StatBinned;
  if (PyType_Ready(&__pyx_type_10pysamstats__CoverageBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats__CoverageBinned.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_10pysamstats__CoverageBinned.tp_dict, __pyx_vtabptr_10pysamstats__CoverageBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "_CoverageBinned", (PyObject *)&__pyx_type_10pysamstats__CoverageBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats__CoverageBinned = &__pyx_type_10pysamstats__CoverageBinned;
  __pyx_vtabptr_10pysamstats__CoverageExtBinned = &__pyx_vtable_10pysamstats__CoverageExtBinned;
  __pyx_vtable_10pysamstats__CoverageExtBinned.__pyx_base = *__pyx_vtabptr_10pysamstats__StatBinned;
  __pyx_vtable_10pysamstats__CoverageExtBinned.__pyx_base.rec = (PyObject *(*)(struct __pyx_obj_10pysamstats__StatBinned *, PyObject *, PyObject *, PyObject *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *))__pyx_f_10pysamstats_18_CoverageExtBinned_rec;
  __pyx_vtable_10pysamstats__CoverageExtBinned.__pyx_base.recv = (PyObject *(*)(struct __pyx_obj_10pysamstats__StatBinned *, bam1_t *))__pyx_f_10pysamstats_18_CoverageExtBinned_recv;
  __pyx_type_10pysamstats__CoverageExtBinned.tp_base = __pyx_ptype_10pysamstats__StatBinned;
  if (PyType_Ready(&__pyx_type_10pysamstats__CoverageExtBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats__CoverageExtBinned.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_10pysamstats__CoverageExtBinned.tp_dict, __pyx_vtabptr_10pysamstats__CoverageExtBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "_CoverageExtBinned", (PyObject *)&__pyx_type_10pysamstats__CoverageExtBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats__CoverageExtBinned = &__pyx_type_10pysamstats__CoverageExtBinned;
  __pyx_vtabptr_10pysamstats__MapqBinned = &__pyx_vtable_10pysamstats__MapqBinned;
  __pyx_vtable_10pysamstats__MapqBinned.__pyx_base = *__pyx_vtabptr_10pysamstats__StatBinned;
  __pyx_vtable_10pysamstats__MapqBinned.__pyx_base.rec = (PyObject *(*)(struct __pyx_obj_10pysamstats__StatBinned *, PyObject *, PyObject *, PyObject *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *))__pyx_f_10pysamstats_11_MapqBinned_rec;
  __pyx_vtable_10pysamstats__MapqBinned.__pyx_base.recv = (PyObject *(*)(struct __pyx_obj_10pysamstats__StatBinned *, bam1_t *))__pyx_f_10pysamstats_11_MapqBinned_recv;
  __pyx_type_10pysamstats__MapqBinned.tp_base = __pyx_ptype_10pysamstats__StatBinned;
  if (PyType_Ready(&__pyx_type_10pysamstats__MapqBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats__MapqBinned.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_10pysamstats__MapqBinned.tp_dict, __pyx_vtabptr_10pysamstats__MapqBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "_MapqBinned", (PyObject *)&__pyx_type_10pysamstats__MapqBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats__MapqBinned = &__pyx_type_10pysamstats__MapqBinned;
  __pyx_vtabptr_10pysamstats__AlignmentBinned = &__pyx_vtable_10pysamstats__AlignmentBinned;
  __pyx_vtable_10pysamstats__AlignmentBinned.__pyx_base = *__pyx_vtabptr_10pysamstats__StatBinned;
  __pyx_vtable_10pysamstats__AlignmentBinned.__pyx_base.rec = (PyObject *(*)(struct __pyx_obj_10pysamstats__StatBinned *, PyObject *, PyObject *, PyObject *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *))__pyx_f_10pysamstats_16_AlignmentBinned_rec;
  __pyx_vtable_10pysamstats__AlignmentBinned.__pyx_base.recv = (PyObject *(*)(struct __pyx_obj_10pysamstats__StatBinned *, bam1_t *))__pyx_f_10pysamstats_16_AlignmentBinned_recv;
  __pyx_type_10pysamstats__AlignmentBinned.tp_base = __pyx_ptype_10pysamstats__StatBinned;
  if (PyType_Ready(&__pyx_type_10pysamstats__AlignmentBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats__AlignmentBinned.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_10pysamstats__AlignmentBinned.tp_dict, __pyx_vtabptr_10pysamstats__AlignmentBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "_AlignmentBinned", (PyObject *)&__pyx_type_10pysamstats__AlignmentBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats__AlignmentBinned = &__pyx_type_10pysamstats__AlignmentBinned;
  __pyx_vtabptr_10pysamstats__TlenBinned = &__pyx_vtable_10pysamstats__TlenBinned;
  __pyx_vtable_10pysamstats__TlenBinned.__pyx_base = *__pyx_vtabptr_10pysamstats__StatBinned;
  __pyx_vtable_10pysamstats__TlenBinned.__pyx_base.rec = (PyObject *(*)(struct __pyx_obj_10pysamstats__StatBinned *, PyObject *, PyObject *, PyObject *, struct __pyx_obj_5pysam_6cfaidx_FastaFile *))__pyx_f_10pysamstats_11_TlenBinned_rec;
  __pyx_vtable_10pysamstats__TlenBinned.__pyx_base.recv = (PyObject *(*)(struct __pyx_obj_10pysamstats__StatBinned *, bam1_t *))__pyx_f_10pysamstats_11_TlenBinned_recv;
  __pyx_type_10pysamstats__TlenBinned.tp_base = __pyx_ptype_10pysamstats__StatBinned;
  if (PyType_Ready(&__pyx_type_10pysamstats__TlenBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats__TlenBinned.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_10pysamstats__TlenBinned.tp_dict, __pyx_vtabptr_10pysamstats__TlenBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "_TlenBinned", (PyObject *)&__pyx_type_10pysamstats__TlenBinned) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats__TlenBinned = &__pyx_type_10pysamstats__TlenBinned;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct__stat_coverage_gc) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats___pyx_scope_struct__stat_coverage_gc.tp_print = 0;
  __pyx_ptype_10pysamstats___pyx_scope_struct__stat_coverage_gc = &__pyx_type_10pysamstats___pyx_scope_struct__stat_coverage_gc;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_1__iter_pileup_default) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats___pyx_scope_struct_1__iter_pileup_default.tp_print = 0;
  __pyx_ptype_10pysamstats___pyx_scope_struct_1__iter_pileup_default = &__pyx_type_10pysamstats___pyx_scope_struct_1__iter_pileup_default;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom.tp_print = 0;
  __pyx_ptype_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom = &__pyx_type_10pysamstats___pyx_scope_struct_2__iter_pileup_padded_chrom;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_3__iter_binned_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats___pyx_scope_struct_3__iter_binned_chrom.tp_print = 0;
  __pyx_ptype_10pysamstats___pyx_scope_struct_3__iter_binned_chrom = &__pyx_type_10pysamstats___pyx_scope_struct_3__iter_binned_chrom;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_4_flatten) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats___pyx_scope_struct_4_flatten.tp_print = 0;
  __pyx_ptype_10pysamstats___pyx_scope_struct_4_flatten = &__pyx_type_10pysamstats___pyx_scope_struct_4_flatten;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_5_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats___pyx_scope_struct_5_genexpr.tp_print = 0;
  __pyx_ptype_10pysamstats___pyx_scope_struct_5_genexpr = &__pyx_type_10pysamstats___pyx_scope_struct_5_genexpr;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_6___iter__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_10pysamstats___pyx_scope_struct_6___iter__.tp_print = 0;
  __pyx_ptype_10pysamstats___pyx_scope_struct_6___iter__ = &__pyx_type_10pysamstats___pyx_scope_struct_6___iter__;
  /*--- Type import code ---*/
  __pyx_ptype_5pysam_6cfaidx_FastaFile = __Pyx_ImportType("pysam.cfaidx", "FastaFile", sizeof(struct __pyx_obj_5pysam_6cfaidx_FastaFile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_FastaFile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_FastaFile = (struct __pyx_vtabstruct_5pysam_6cfaidx_FastaFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_FastaFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_FastaFile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastqProxy = __Pyx_ImportType("pysam.cfaidx", "FastqProxy", sizeof(struct __pyx_obj_5pysam_6cfaidx_FastqProxy), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_FastqProxy)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastqFile = __Pyx_ImportType("pysam.cfaidx", "FastqFile", sizeof(struct __pyx_obj_5pysam_6cfaidx_FastqFile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_FastqFile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_FastqFile = (struct __pyx_vtabstruct_5pysam_6cfaidx_FastqFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_FastqFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_FastqFile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_Fastafile = __Pyx_ImportType("pysam.cfaidx", "Fastafile", sizeof(struct __pyx_obj_5pysam_6cfaidx_Fastafile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_Fastafile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_Fastafile = (struct __pyx_vtabstruct_5pysam_6cfaidx_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_Fastafile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_Fastafile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_Fastqfile = __Pyx_ImportType("pysam.cfaidx", "Fastqfile", sizeof(struct __pyx_obj_5pysam_6cfaidx_Fastqfile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_Fastqfile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_Fastqfile = (struct __pyx_vtabstruct_5pysam_6cfaidx_Fastqfile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_Fastqfile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_Fastqfile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_AlignedSegment = __Pyx_ImportType("pysam.calignmentfile", "AlignedSegment", sizeof(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_AlignedSegment)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_AlignedSegment = (struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignedSegment*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_AlignedSegment->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_AlignedSegment)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_AlignmentFile = __Pyx_ImportType("pysam.calignmentfile", "AlignmentFile", sizeof(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_AlignmentFile)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_AlignmentFile = (struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignmentFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_AlignmentFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_AlignmentFile)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_PileupColumn = __Pyx_ImportType("pysam.calignmentfile", "PileupColumn", sizeof(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_PileupColumn)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_PileupRead = __Pyx_ImportType("pysam.calignmentfile", "PileupRead", sizeof(struct __pyx_obj_5pysam_14calignmentfile_PileupRead), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_PileupRead)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRow = __Pyx_ImportType("pysam.calignmentfile", "IteratorRow", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRow), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorRow)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion = __Pyx_ImportType("pysam.calignmentfile", "IteratorRowRegion", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowRegion = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowRegion)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowHead = __Pyx_ImportType("pysam.calignmentfile", "IteratorRowHead", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorRowHead)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowHead = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowHead*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorRowHead->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowHead)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowAll = __Pyx_ImportType("pysam.calignmentfile", "IteratorRowAll", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorRowAll)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowAll = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowAll*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorRowAll->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowAll)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowAllRefs = __Pyx_ImportType("pysam.calignmentfile", "IteratorRowAllRefs", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorRowAllRefs)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowSelection = __Pyx_ImportType("pysam.calignmentfile", "IteratorRowSelection", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorRowSelection)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowSelection = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowSelection*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorRowSelection->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowSelection)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorColumn = __Pyx_ImportType("pysam.calignmentfile", "IteratorColumn", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorColumn)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumn = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorColumn->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumn)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorColumnRegion = __Pyx_ImportType("pysam.calignmentfile", "IteratorColumnRegion", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorColumnRegion)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnRegion = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorColumnRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnRegion)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorColumnAllRefs = __Pyx_ImportType("pysam.calignmentfile", "IteratorColumnAllRefs", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorColumnAllRefs)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnAllRefs = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnAllRefs*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorColumnAllRefs->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnAllRefs)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IndexedReads = __Pyx_ImportType("pysam.calignmentfile", "IndexedReads", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IndexedReads), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IndexedReads)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if CYTHON_COMPILING_IN_PYPY
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) {__pyx_filename = __pyx_f[4]; __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[5]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "pysamstats.pyx":6
 * 
 * 
 * __version__ = '0.20'             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_version, __pyx_kp_s_0_20) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":9
 * 
 * 
 * import sys as _sys             # <<<<<<<<<<<<<<
 * import itertools as _itertools
 * import time as _time
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys_2, 0, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":10
 * 
 * import sys as _sys
 * import itertools as _itertools             # <<<<<<<<<<<<<<
 * import time as _time
 * import csv as _csv
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_itertools_2, 0, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_itertools, __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
 * import sys as _sys
 * import itertools as _itertools
 * import time as _time             # <<<<<<<<<<<<<<
 * import csv as _csv
 * from libc.stdint cimport uint32_t, uint8_t, uint64_t, int64_t
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_time_2, 0, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __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":12
 * import itertools as _itertools
 * import time as _time
 * import csv as _csv             # <<<<<<<<<<<<<<
 * from libc.stdint cimport uint32_t, uint8_t, uint64_t, int64_t
 * from libc.math cimport sqrt
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_csv_2, 0, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_csv, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":24
 * 
 * # PY2/3 compatibility
 * PY2 = _sys.version_info[0] == 2             # <<<<<<<<<<<<<<
 * if PY2:
 *     _string_types = basestring,
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_version_info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_PY2, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":25
 * # PY2/3 compatibility
 * PY2 = _sys.version_info[0] == 2
 * if PY2:             # <<<<<<<<<<<<<<
 *     _string_types = basestring,
 * else:
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_PY2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "pysamstats.pyx":26
 * PY2 = _sys.version_info[0] == 2
 * if PY2:
 *     _string_types = basestring,             # <<<<<<<<<<<<<<
 * else:
 *     _string_types = str,
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)((PyObject*)(&PyBaseString_Type))));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)((PyObject*)(&PyBaseString_Type))));
    __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyBaseString_Type))));
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_string_types, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L2;
  }
  /*else*/ {

    /* "pysamstats.pyx":28
 *     _string_types = basestring,
 * else:
 *     _string_types = str,             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
    __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_string_types, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_L2:;

  /* "pysamstats.pyx":71
 * DEF BAM_CDIFF      = 8
 * 
 * cdef char* CODE2CIGAR= "MIDNSHP=X"             # <<<<<<<<<<<<<<
 * 
 * cdef char * bam_nt16_rev_table = "=ACMGRSVTWYHKDBN"
 */
  __pyx_v_10pysamstats_CODE2CIGAR = __pyx_k_MIDNSHP_X;

  /* "pysamstats.pyx":73
 * cdef char* CODE2CIGAR= "MIDNSHP=X"
 * 
 * cdef char * bam_nt16_rev_table = "=ACMGRSVTWYHKDBN"             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_v_10pysamstats_bam_nt16_rev_table = __pyx_k_ACMGRSVTWYHKDBN;

  /* "pysamstats.pyx":81
 * 
 * 
 * dtype_coverage = [('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *                   ('pos', 'i4'),
 *                   ('reads_all', 'i4'),
 */
  __pyx_t_2 = PyList_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__12);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);
  __Pyx_INCREF(__pyx_tuple__13);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);
  __Pyx_INCREF(__pyx_tuple__14);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__14);
  __Pyx_GIVEREF(__pyx_tuple__14);
  __Pyx_INCREF(__pyx_tuple__15);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_coverage, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":87
 * 
 * 
 * fields_coverage = [t[0] for t in dtype_coverage]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_coverage, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":137
 * 
 * 
 * def stat_coverage(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate coverage statistics per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_5stat_coverage, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_coverage, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":172
 * 
 * 
 * def load_coverage(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage, dtype_coverage, *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_7load_coverage, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_coverage, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":181
 * 
 * 
 * dtype_coverage_strand = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__20);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);
  __Pyx_INCREF(__pyx_tuple__21);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);
  __Pyx_INCREF(__pyx_tuple__22);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);
  __Pyx_INCREF(__pyx_tuple__23);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);
  __Pyx_INCREF(__pyx_tuple__24);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);
  __Pyx_INCREF(__pyx_tuple__25);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__25);
  __Pyx_GIVEREF(__pyx_tuple__25);
  __Pyx_INCREF(__pyx_tuple__26);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);
  __Pyx_INCREF(__pyx_tuple__27);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__27);
  __Pyx_GIVEREF(__pyx_tuple__27);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_coverage_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":193
 * 
 * 
 * fields_coverage_strand = [t[0] for t in dtype_coverage_strand]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage_strand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_7 = __pyx_t_4; __Pyx_INCREF(__pyx_t_7); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_7))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_6(__pyx_t_7);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_coverage_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":265
 * 
 * 
 * def stat_coverage_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate coverage statistics by strand per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_13stat_coverage_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_coverage_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":301
 * 
 * 
 * def load_coverage_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_strand, dtype_coverage_strand,
 *                       *args, **kwargs)
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_15load_coverage_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_coverage_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":311
 * 
 * 
 * dtype_coverage_ext = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__32);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);
  __Pyx_INCREF(__pyx_tuple__33);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);
  __Pyx_INCREF(__pyx_tuple__34);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);
  __Pyx_INCREF(__pyx_tuple__35);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);
  __Pyx_INCREF(__pyx_tuple__36);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);
  __Pyx_INCREF(__pyx_tuple__37);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);
  __Pyx_INCREF(__pyx_tuple__38);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);
  __Pyx_INCREF(__pyx_tuple__39);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);
  __Pyx_INCREF(__pyx_tuple__40);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);
  __Pyx_INCREF(__pyx_tuple__41);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_coverage_ext, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":325
 * 
 * 
 * fields_coverage_ext = [t[0] for t in dtype_coverage_ext]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage_ext); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
    __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); 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_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_coverage_ext, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":415
 * 
 * 
 * def stat_coverage_ext(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended coverage statistics per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_21stat_coverage_ext, NULL, __pyx_n_s_pysamstats); 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);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_coverage_ext, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":450
 * 
 * 
 * def load_coverage_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_ext, dtype_coverage_ext, *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_23load_coverage_ext, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_coverage_ext, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":459
 * 
 * 
 * dtype_coverage_ext_strand = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(26); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__46);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__46);
  __Pyx_GIVEREF(__pyx_tuple__46);
  __Pyx_INCREF(__pyx_tuple__47);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__47);
  __Pyx_GIVEREF(__pyx_tuple__47);
  __Pyx_INCREF(__pyx_tuple__48);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);
  __Pyx_INCREF(__pyx_tuple__49);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__49);
  __Pyx_GIVEREF(__pyx_tuple__49);
  __Pyx_INCREF(__pyx_tuple__50);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__50);
  __Pyx_GIVEREF(__pyx_tuple__50);
  __Pyx_INCREF(__pyx_tuple__51);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);
  __Pyx_INCREF(__pyx_tuple__52);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__52);
  __Pyx_GIVEREF(__pyx_tuple__52);
  __Pyx_INCREF(__pyx_tuple__53);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);
  __Pyx_INCREF(__pyx_tuple__54);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__54);
  __Pyx_GIVEREF(__pyx_tuple__54);
  __Pyx_INCREF(__pyx_tuple__55);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);
  __Pyx_INCREF(__pyx_tuple__56);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_tuple__56);
  __Pyx_GIVEREF(__pyx_tuple__56);
  __Pyx_INCREF(__pyx_tuple__57);
  PyList_SET_ITEM(__pyx_t_2, 11, __pyx_tuple__57);
  __Pyx_GIVEREF(__pyx_tuple__57);
  __Pyx_INCREF(__pyx_tuple__58);
  PyList_SET_ITEM(__pyx_t_2, 12, __pyx_tuple__58);
  __Pyx_GIVEREF(__pyx_tuple__58);
  __Pyx_INCREF(__pyx_tuple__59);
  PyList_SET_ITEM(__pyx_t_2, 13, __pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);
  __Pyx_INCREF(__pyx_tuple__60);
  PyList_SET_ITEM(__pyx_t_2, 14, __pyx_tuple__60);
  __Pyx_GIVEREF(__pyx_tuple__60);
  __Pyx_INCREF(__pyx_tuple__61);
  PyList_SET_ITEM(__pyx_t_2, 15, __pyx_tuple__61);
  __Pyx_GIVEREF(__pyx_tuple__61);
  __Pyx_INCREF(__pyx_tuple__62);
  PyList_SET_ITEM(__pyx_t_2, 16, __pyx_tuple__62);
  __Pyx_GIVEREF(__pyx_tuple__62);
  __Pyx_INCREF(__pyx_tuple__63);
  PyList_SET_ITEM(__pyx_t_2, 17, __pyx_tuple__63);
  __Pyx_GIVEREF(__pyx_tuple__63);
  __Pyx_INCREF(__pyx_tuple__64);
  PyList_SET_ITEM(__pyx_t_2, 18, __pyx_tuple__64);
  __Pyx_GIVEREF(__pyx_tuple__64);
  __Pyx_INCREF(__pyx_tuple__65);
  PyList_SET_ITEM(__pyx_t_2, 19, __pyx_tuple__65);
  __Pyx_GIVEREF(__pyx_tuple__65);
  __Pyx_INCREF(__pyx_tuple__66);
  PyList_SET_ITEM(__pyx_t_2, 20, __pyx_tuple__66);
  __Pyx_GIVEREF(__pyx_tuple__66);
  __Pyx_INCREF(__pyx_tuple__67);
  PyList_SET_ITEM(__pyx_t_2, 21, __pyx_tuple__67);
  __Pyx_GIVEREF(__pyx_tuple__67);
  __Pyx_INCREF(__pyx_tuple__68);
  PyList_SET_ITEM(__pyx_t_2, 22, __pyx_tuple__68);
  __Pyx_GIVEREF(__pyx_tuple__68);
  __Pyx_INCREF(__pyx_tuple__69);
  PyList_SET_ITEM(__pyx_t_2, 23, __pyx_tuple__69);
  __Pyx_GIVEREF(__pyx_tuple__69);
  __Pyx_INCREF(__pyx_tuple__70);
  PyList_SET_ITEM(__pyx_t_2, 24, __pyx_tuple__70);
  __Pyx_GIVEREF(__pyx_tuple__70);
  __Pyx_INCREF(__pyx_tuple__71);
  PyList_SET_ITEM(__pyx_t_2, 25, __pyx_tuple__71);
  __Pyx_GIVEREF(__pyx_tuple__71);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_coverage_ext_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":489
 * 
 * 
 * fields_coverage_ext_strand = [t[0] for t in dtype_coverage_ext_strand]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage_ext_strand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_coverage_ext_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":660
 * 
 * 
 * def stat_coverage_ext_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended coverage statistics by strand per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_29stat_coverage_ext_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_coverage_ext_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":695
 * 
 * 
 * def load_coverage_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_ext_strand, dtype_coverage_ext_strand,
 *                        *args, **kwargs)
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_31load_coverage_ext_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_coverage_ext_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":705
 * 
 * 
 * dtype_variation = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(23); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__76);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__76);
  __Pyx_GIVEREF(__pyx_tuple__76);
  __Pyx_INCREF(__pyx_tuple__77);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__77);
  __Pyx_GIVEREF(__pyx_tuple__77);
  __Pyx_INCREF(__pyx_tuple__78);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__78);
  __Pyx_GIVEREF(__pyx_tuple__78);
  __Pyx_INCREF(__pyx_tuple__79);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__79);
  __Pyx_GIVEREF(__pyx_tuple__79);
  __Pyx_INCREF(__pyx_tuple__80);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__80);
  __Pyx_GIVEREF(__pyx_tuple__80);
  __Pyx_INCREF(__pyx_tuple__81);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__81);
  __Pyx_GIVEREF(__pyx_tuple__81);
  __Pyx_INCREF(__pyx_tuple__82);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__82);
  __Pyx_GIVEREF(__pyx_tuple__82);
  __Pyx_INCREF(__pyx_tuple__83);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__83);
  __Pyx_GIVEREF(__pyx_tuple__83);
  __Pyx_INCREF(__pyx_tuple__84);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__84);
  __Pyx_GIVEREF(__pyx_tuple__84);
  __Pyx_INCREF(__pyx_tuple__85);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__85);
  __Pyx_GIVEREF(__pyx_tuple__85);
  __Pyx_INCREF(__pyx_tuple__86);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_tuple__86);
  __Pyx_GIVEREF(__pyx_tuple__86);
  __Pyx_INCREF(__pyx_tuple__87);
  PyList_SET_ITEM(__pyx_t_2, 11, __pyx_tuple__87);
  __Pyx_GIVEREF(__pyx_tuple__87);
  __Pyx_INCREF(__pyx_tuple__88);
  PyList_SET_ITEM(__pyx_t_2, 12, __pyx_tuple__88);
  __Pyx_GIVEREF(__pyx_tuple__88);
  __Pyx_INCREF(__pyx_tuple__89);
  PyList_SET_ITEM(__pyx_t_2, 13, __pyx_tuple__89);
  __Pyx_GIVEREF(__pyx_tuple__89);
  __Pyx_INCREF(__pyx_tuple__90);
  PyList_SET_ITEM(__pyx_t_2, 14, __pyx_tuple__90);
  __Pyx_GIVEREF(__pyx_tuple__90);
  __Pyx_INCREF(__pyx_tuple__91);
  PyList_SET_ITEM(__pyx_t_2, 15, __pyx_tuple__91);
  __Pyx_GIVEREF(__pyx_tuple__91);
  __Pyx_INCREF(__pyx_tuple__92);
  PyList_SET_ITEM(__pyx_t_2, 16, __pyx_tuple__92);
  __Pyx_GIVEREF(__pyx_tuple__92);
  __Pyx_INCREF(__pyx_tuple__93);
  PyList_SET_ITEM(__pyx_t_2, 17, __pyx_tuple__93);
  __Pyx_GIVEREF(__pyx_tuple__93);
  __Pyx_INCREF(__pyx_tuple__94);
  PyList_SET_ITEM(__pyx_t_2, 18, __pyx_tuple__94);
  __Pyx_GIVEREF(__pyx_tuple__94);
  __Pyx_INCREF(__pyx_tuple__95);
  PyList_SET_ITEM(__pyx_t_2, 19, __pyx_tuple__95);
  __Pyx_GIVEREF(__pyx_tuple__95);
  __Pyx_INCREF(__pyx_tuple__96);
  PyList_SET_ITEM(__pyx_t_2, 20, __pyx_tuple__96);
  __Pyx_GIVEREF(__pyx_tuple__96);
  __Pyx_INCREF(__pyx_tuple__97);
  PyList_SET_ITEM(__pyx_t_2, 21, __pyx_tuple__97);
  __Pyx_GIVEREF(__pyx_tuple__97);
  __Pyx_INCREF(__pyx_tuple__98);
  PyList_SET_ITEM(__pyx_t_2, 22, __pyx_tuple__98);
  __Pyx_GIVEREF(__pyx_tuple__98);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_variation, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":732
 * 
 * 
 * fields_variation = [t[0] for t in dtype_variation]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_variation); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_7 = __pyx_t_4; __Pyx_INCREF(__pyx_t_7); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_7))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_6(__pyx_t_7);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_variation, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":874
 * 
 * 
 * def stat_variation(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate variation statistics per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_37stat_variation, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_variation, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":911
 * 
 * 
 * def load_variation(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_variation, dtype_variation, *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_39load_variation, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_variation, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":920
 * 
 * 
 * dtype_variation_strand = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(63); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 920; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__103);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__103);
  __Pyx_GIVEREF(__pyx_tuple__103);
  __Pyx_INCREF(__pyx_tuple__104);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__104);
  __Pyx_GIVEREF(__pyx_tuple__104);
  __Pyx_INCREF(__pyx_tuple__105);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__105);
  __Pyx_GIVEREF(__pyx_tuple__105);
  __Pyx_INCREF(__pyx_tuple__106);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__106);
  __Pyx_GIVEREF(__pyx_tuple__106);
  __Pyx_INCREF(__pyx_tuple__107);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__107);
  __Pyx_GIVEREF(__pyx_tuple__107);
  __Pyx_INCREF(__pyx_tuple__108);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__108);
  __Pyx_GIVEREF(__pyx_tuple__108);
  __Pyx_INCREF(__pyx_tuple__109);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__109);
  __Pyx_GIVEREF(__pyx_tuple__109);
  __Pyx_INCREF(__pyx_tuple__110);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__110);
  __Pyx_GIVEREF(__pyx_tuple__110);
  __Pyx_INCREF(__pyx_tuple__111);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__111);
  __Pyx_GIVEREF(__pyx_tuple__111);
  __Pyx_INCREF(__pyx_tuple__112);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__112);
  __Pyx_GIVEREF(__pyx_tuple__112);
  __Pyx_INCREF(__pyx_tuple__113);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_tuple__113);
  __Pyx_GIVEREF(__pyx_tuple__113);
  __Pyx_INCREF(__pyx_tuple__114);
  PyList_SET_ITEM(__pyx_t_2, 11, __pyx_tuple__114);
  __Pyx_GIVEREF(__pyx_tuple__114);
  __Pyx_INCREF(__pyx_tuple__115);
  PyList_SET_ITEM(__pyx_t_2, 12, __pyx_tuple__115);
  __Pyx_GIVEREF(__pyx_tuple__115);
  __Pyx_INCREF(__pyx_tuple__116);
  PyList_SET_ITEM(__pyx_t_2, 13, __pyx_tuple__116);
  __Pyx_GIVEREF(__pyx_tuple__116);
  __Pyx_INCREF(__pyx_tuple__117);
  PyList_SET_ITEM(__pyx_t_2, 14, __pyx_tuple__117);
  __Pyx_GIVEREF(__pyx_tuple__117);
  __Pyx_INCREF(__pyx_tuple__118);
  PyList_SET_ITEM(__pyx_t_2, 15, __pyx_tuple__118);
  __Pyx_GIVEREF(__pyx_tuple__118);
  __Pyx_INCREF(__pyx_tuple__119);
  PyList_SET_ITEM(__pyx_t_2, 16, __pyx_tuple__119);
  __Pyx_GIVEREF(__pyx_tuple__119);
  __Pyx_INCREF(__pyx_tuple__120);
  PyList_SET_ITEM(__pyx_t_2, 17, __pyx_tuple__120);
  __Pyx_GIVEREF(__pyx_tuple__120);
  __Pyx_INCREF(__pyx_tuple__121);
  PyList_SET_ITEM(__pyx_t_2, 18, __pyx_tuple__121);
  __Pyx_GIVEREF(__pyx_tuple__121);
  __Pyx_INCREF(__pyx_tuple__122);
  PyList_SET_ITEM(__pyx_t_2, 19, __pyx_tuple__122);
  __Pyx_GIVEREF(__pyx_tuple__122);
  __Pyx_INCREF(__pyx_tuple__123);
  PyList_SET_ITEM(__pyx_t_2, 20, __pyx_tuple__123);
  __Pyx_GIVEREF(__pyx_tuple__123);
  __Pyx_INCREF(__pyx_tuple__124);
  PyList_SET_ITEM(__pyx_t_2, 21, __pyx_tuple__124);
  __Pyx_GIVEREF(__pyx_tuple__124);
  __Pyx_INCREF(__pyx_tuple__125);
  PyList_SET_ITEM(__pyx_t_2, 22, __pyx_tuple__125);
  __Pyx_GIVEREF(__pyx_tuple__125);
  __Pyx_INCREF(__pyx_tuple__126);
  PyList_SET_ITEM(__pyx_t_2, 23, __pyx_tuple__126);
  __Pyx_GIVEREF(__pyx_tuple__126);
  __Pyx_INCREF(__pyx_tuple__127);
  PyList_SET_ITEM(__pyx_t_2, 24, __pyx_tuple__127);
  __Pyx_GIVEREF(__pyx_tuple__127);
  __Pyx_INCREF(__pyx_tuple__128);
  PyList_SET_ITEM(__pyx_t_2, 25, __pyx_tuple__128);
  __Pyx_GIVEREF(__pyx_tuple__128);
  __Pyx_INCREF(__pyx_tuple__129);
  PyList_SET_ITEM(__pyx_t_2, 26, __pyx_tuple__129);
  __Pyx_GIVEREF(__pyx_tuple__129);
  __Pyx_INCREF(__pyx_tuple__130);
  PyList_SET_ITEM(__pyx_t_2, 27, __pyx_tuple__130);
  __Pyx_GIVEREF(__pyx_tuple__130);
  __Pyx_INCREF(__pyx_tuple__131);
  PyList_SET_ITEM(__pyx_t_2, 28, __pyx_tuple__131);
  __Pyx_GIVEREF(__pyx_tuple__131);
  __Pyx_INCREF(__pyx_tuple__132);
  PyList_SET_ITEM(__pyx_t_2, 29, __pyx_tuple__132);
  __Pyx_GIVEREF(__pyx_tuple__132);
  __Pyx_INCREF(__pyx_tuple__133);
  PyList_SET_ITEM(__pyx_t_2, 30, __pyx_tuple__133);
  __Pyx_GIVEREF(__pyx_tuple__133);
  __Pyx_INCREF(__pyx_tuple__134);
  PyList_SET_ITEM(__pyx_t_2, 31, __pyx_tuple__134);
  __Pyx_GIVEREF(__pyx_tuple__134);
  __Pyx_INCREF(__pyx_tuple__135);
  PyList_SET_ITEM(__pyx_t_2, 32, __pyx_tuple__135);
  __Pyx_GIVEREF(__pyx_tuple__135);
  __Pyx_INCREF(__pyx_tuple__136);
  PyList_SET_ITEM(__pyx_t_2, 33, __pyx_tuple__136);
  __Pyx_GIVEREF(__pyx_tuple__136);
  __Pyx_INCREF(__pyx_tuple__137);
  PyList_SET_ITEM(__pyx_t_2, 34, __pyx_tuple__137);
  __Pyx_GIVEREF(__pyx_tuple__137);
  __Pyx_INCREF(__pyx_tuple__138);
  PyList_SET_ITEM(__pyx_t_2, 35, __pyx_tuple__138);
  __Pyx_GIVEREF(__pyx_tuple__138);
  __Pyx_INCREF(__pyx_tuple__139);
  PyList_SET_ITEM(__pyx_t_2, 36, __pyx_tuple__139);
  __Pyx_GIVEREF(__pyx_tuple__139);
  __Pyx_INCREF(__pyx_tuple__140);
  PyList_SET_ITEM(__pyx_t_2, 37, __pyx_tuple__140);
  __Pyx_GIVEREF(__pyx_tuple__140);
  __Pyx_INCREF(__pyx_tuple__141);
  PyList_SET_ITEM(__pyx_t_2, 38, __pyx_tuple__141);
  __Pyx_GIVEREF(__pyx_tuple__141);
  __Pyx_INCREF(__pyx_tuple__142);
  PyList_SET_ITEM(__pyx_t_2, 39, __pyx_tuple__142);
  __Pyx_GIVEREF(__pyx_tuple__142);
  __Pyx_INCREF(__pyx_tuple__143);
  PyList_SET_ITEM(__pyx_t_2, 40, __pyx_tuple__143);
  __Pyx_GIVEREF(__pyx_tuple__143);
  __Pyx_INCREF(__pyx_tuple__144);
  PyList_SET_ITEM(__pyx_t_2, 41, __pyx_tuple__144);
  __Pyx_GIVEREF(__pyx_tuple__144);
  __Pyx_INCREF(__pyx_tuple__145);
  PyList_SET_ITEM(__pyx_t_2, 42, __pyx_tuple__145);
  __Pyx_GIVEREF(__pyx_tuple__145);
  __Pyx_INCREF(__pyx_tuple__146);
  PyList_SET_ITEM(__pyx_t_2, 43, __pyx_tuple__146);
  __Pyx_GIVEREF(__pyx_tuple__146);
  __Pyx_INCREF(__pyx_tuple__147);
  PyList_SET_ITEM(__pyx_t_2, 44, __pyx_tuple__147);
  __Pyx_GIVEREF(__pyx_tuple__147);
  __Pyx_INCREF(__pyx_tuple__148);
  PyList_SET_ITEM(__pyx_t_2, 45, __pyx_tuple__148);
  __Pyx_GIVEREF(__pyx_tuple__148);
  __Pyx_INCREF(__pyx_tuple__149);
  PyList_SET_ITEM(__pyx_t_2, 46, __pyx_tuple__149);
  __Pyx_GIVEREF(__pyx_tuple__149);
  __Pyx_INCREF(__pyx_tuple__150);
  PyList_SET_ITEM(__pyx_t_2, 47, __pyx_tuple__150);
  __Pyx_GIVEREF(__pyx_tuple__150);
  __Pyx_INCREF(__pyx_tuple__151);
  PyList_SET_ITEM(__pyx_t_2, 48, __pyx_tuple__151);
  __Pyx_GIVEREF(__pyx_tuple__151);
  __Pyx_INCREF(__pyx_tuple__152);
  PyList_SET_ITEM(__pyx_t_2, 49, __pyx_tuple__152);
  __Pyx_GIVEREF(__pyx_tuple__152);
  __Pyx_INCREF(__pyx_tuple__153);
  PyList_SET_ITEM(__pyx_t_2, 50, __pyx_tuple__153);
  __Pyx_GIVEREF(__pyx_tuple__153);
  __Pyx_INCREF(__pyx_tuple__154);
  PyList_SET_ITEM(__pyx_t_2, 51, __pyx_tuple__154);
  __Pyx_GIVEREF(__pyx_tuple__154);
  __Pyx_INCREF(__pyx_tuple__155);
  PyList_SET_ITEM(__pyx_t_2, 52, __pyx_tuple__155);
  __Pyx_GIVEREF(__pyx_tuple__155);
  __Pyx_INCREF(__pyx_tuple__156);
  PyList_SET_ITEM(__pyx_t_2, 53, __pyx_tuple__156);
  __Pyx_GIVEREF(__pyx_tuple__156);
  __Pyx_INCREF(__pyx_tuple__157);
  PyList_SET_ITEM(__pyx_t_2, 54, __pyx_tuple__157);
  __Pyx_GIVEREF(__pyx_tuple__157);
  __Pyx_INCREF(__pyx_tuple__158);
  PyList_SET_ITEM(__pyx_t_2, 55, __pyx_tuple__158);
  __Pyx_GIVEREF(__pyx_tuple__158);
  __Pyx_INCREF(__pyx_tuple__159);
  PyList_SET_ITEM(__pyx_t_2, 56, __pyx_tuple__159);
  __Pyx_GIVEREF(__pyx_tuple__159);
  __Pyx_INCREF(__pyx_tuple__160);
  PyList_SET_ITEM(__pyx_t_2, 57, __pyx_tuple__160);
  __Pyx_GIVEREF(__pyx_tuple__160);
  __Pyx_INCREF(__pyx_tuple__161);
  PyList_SET_ITEM(__pyx_t_2, 58, __pyx_tuple__161);
  __Pyx_GIVEREF(__pyx_tuple__161);
  __Pyx_INCREF(__pyx_tuple__162);
  PyList_SET_ITEM(__pyx_t_2, 59, __pyx_tuple__162);
  __Pyx_GIVEREF(__pyx_tuple__162);
  __Pyx_INCREF(__pyx_tuple__163);
  PyList_SET_ITEM(__pyx_t_2, 60, __pyx_tuple__163);
  __Pyx_GIVEREF(__pyx_tuple__163);
  __Pyx_INCREF(__pyx_tuple__164);
  PyList_SET_ITEM(__pyx_t_2, 61, __pyx_tuple__164);
  __Pyx_GIVEREF(__pyx_tuple__164);
  __Pyx_INCREF(__pyx_tuple__165);
  PyList_SET_ITEM(__pyx_t_2, 62, __pyx_tuple__165);
  __Pyx_GIVEREF(__pyx_tuple__165);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_variation_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 920; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":967
 * 
 * 
 * fields_variation_strand = [t[0] for t in dtype_variation_strand]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_variation_strand); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
    __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_variation_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1113
 * 
 * 
 * def stat_variation_strand(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate variation statistics by strand per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_45stat_variation_strand, NULL, __pyx_n_s_pysamstats); 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);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_variation_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1151
 * 
 * 
 * def load_variation_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_variation_strand, dtype_variation_strand,
 *                        *args, **kwargs)
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_47load_variation_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_variation_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1161
 * 
 * 
 * dtype_tlen = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(11); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__170);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__170);
  __Pyx_GIVEREF(__pyx_tuple__170);
  __Pyx_INCREF(__pyx_tuple__171);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__171);
  __Pyx_GIVEREF(__pyx_tuple__171);
  __Pyx_INCREF(__pyx_tuple__172);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__172);
  __Pyx_GIVEREF(__pyx_tuple__172);
  __Pyx_INCREF(__pyx_tuple__173);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__173);
  __Pyx_GIVEREF(__pyx_tuple__173);
  __Pyx_INCREF(__pyx_tuple__174);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__174);
  __Pyx_GIVEREF(__pyx_tuple__174);
  __Pyx_INCREF(__pyx_tuple__175);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__175);
  __Pyx_GIVEREF(__pyx_tuple__175);
  __Pyx_INCREF(__pyx_tuple__176);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__176);
  __Pyx_GIVEREF(__pyx_tuple__176);
  __Pyx_INCREF(__pyx_tuple__177);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__177);
  __Pyx_GIVEREF(__pyx_tuple__177);
  __Pyx_INCREF(__pyx_tuple__178);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__178);
  __Pyx_GIVEREF(__pyx_tuple__178);
  __Pyx_INCREF(__pyx_tuple__179);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__179);
  __Pyx_GIVEREF(__pyx_tuple__179);
  __Pyx_INCREF(__pyx_tuple__180);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_tuple__180);
  __Pyx_GIVEREF(__pyx_tuple__180);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_tlen, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1176
 * 
 * 
 * fields_tlen = [t[0] for t in dtype_tlen]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_tlen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_tlen, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1315
 * 
 * 
 * def stat_tlen(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate insert size statistics per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_53stat_tlen, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_tlen, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1349
 * 
 * 
 * def load_tlen(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_tlen, dtype_tlen, *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_55load_tlen, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_tlen, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1358
 * 
 * 
 * dtype_tlen_strand = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(29); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__185);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__185);
  __Pyx_GIVEREF(__pyx_tuple__185);
  __Pyx_INCREF(__pyx_tuple__186);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__186);
  __Pyx_GIVEREF(__pyx_tuple__186);
  __Pyx_INCREF(__pyx_tuple__187);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__187);
  __Pyx_GIVEREF(__pyx_tuple__187);
  __Pyx_INCREF(__pyx_tuple__188);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__188);
  __Pyx_GIVEREF(__pyx_tuple__188);
  __Pyx_INCREF(__pyx_tuple__189);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__189);
  __Pyx_GIVEREF(__pyx_tuple__189);
  __Pyx_INCREF(__pyx_tuple__190);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__190);
  __Pyx_GIVEREF(__pyx_tuple__190);
  __Pyx_INCREF(__pyx_tuple__191);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__191);
  __Pyx_GIVEREF(__pyx_tuple__191);
  __Pyx_INCREF(__pyx_tuple__192);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__192);
  __Pyx_GIVEREF(__pyx_tuple__192);
  __Pyx_INCREF(__pyx_tuple__193);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__193);
  __Pyx_GIVEREF(__pyx_tuple__193);
  __Pyx_INCREF(__pyx_tuple__194);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__194);
  __Pyx_GIVEREF(__pyx_tuple__194);
  __Pyx_INCREF(__pyx_tuple__195);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_tuple__195);
  __Pyx_GIVEREF(__pyx_tuple__195);
  __Pyx_INCREF(__pyx_tuple__196);
  PyList_SET_ITEM(__pyx_t_2, 11, __pyx_tuple__196);
  __Pyx_GIVEREF(__pyx_tuple__196);
  __Pyx_INCREF(__pyx_tuple__197);
  PyList_SET_ITEM(__pyx_t_2, 12, __pyx_tuple__197);
  __Pyx_GIVEREF(__pyx_tuple__197);
  __Pyx_INCREF(__pyx_tuple__198);
  PyList_SET_ITEM(__pyx_t_2, 13, __pyx_tuple__198);
  __Pyx_GIVEREF(__pyx_tuple__198);
  __Pyx_INCREF(__pyx_tuple__199);
  PyList_SET_ITEM(__pyx_t_2, 14, __pyx_tuple__199);
  __Pyx_GIVEREF(__pyx_tuple__199);
  __Pyx_INCREF(__pyx_tuple__200);
  PyList_SET_ITEM(__pyx_t_2, 15, __pyx_tuple__200);
  __Pyx_GIVEREF(__pyx_tuple__200);
  __Pyx_INCREF(__pyx_tuple__201);
  PyList_SET_ITEM(__pyx_t_2, 16, __pyx_tuple__201);
  __Pyx_GIVEREF(__pyx_tuple__201);
  __Pyx_INCREF(__pyx_tuple__202);
  PyList_SET_ITEM(__pyx_t_2, 17, __pyx_tuple__202);
  __Pyx_GIVEREF(__pyx_tuple__202);
  __Pyx_INCREF(__pyx_tuple__203);
  PyList_SET_ITEM(__pyx_t_2, 18, __pyx_tuple__203);
  __Pyx_GIVEREF(__pyx_tuple__203);
  __Pyx_INCREF(__pyx_tuple__204);
  PyList_SET_ITEM(__pyx_t_2, 19, __pyx_tuple__204);
  __Pyx_GIVEREF(__pyx_tuple__204);
  __Pyx_INCREF(__pyx_tuple__205);
  PyList_SET_ITEM(__pyx_t_2, 20, __pyx_tuple__205);
  __Pyx_GIVEREF(__pyx_tuple__205);
  __Pyx_INCREF(__pyx_tuple__206);
  PyList_SET_ITEM(__pyx_t_2, 21, __pyx_tuple__206);
  __Pyx_GIVEREF(__pyx_tuple__206);
  __Pyx_INCREF(__pyx_tuple__207);
  PyList_SET_ITEM(__pyx_t_2, 22, __pyx_tuple__207);
  __Pyx_GIVEREF(__pyx_tuple__207);
  __Pyx_INCREF(__pyx_tuple__208);
  PyList_SET_ITEM(__pyx_t_2, 23, __pyx_tuple__208);
  __Pyx_GIVEREF(__pyx_tuple__208);
  __Pyx_INCREF(__pyx_tuple__209);
  PyList_SET_ITEM(__pyx_t_2, 24, __pyx_tuple__209);
  __Pyx_GIVEREF(__pyx_tuple__209);
  __Pyx_INCREF(__pyx_tuple__210);
  PyList_SET_ITEM(__pyx_t_2, 25, __pyx_tuple__210);
  __Pyx_GIVEREF(__pyx_tuple__210);
  __Pyx_INCREF(__pyx_tuple__211);
  PyList_SET_ITEM(__pyx_t_2, 26, __pyx_tuple__211);
  __Pyx_GIVEREF(__pyx_tuple__211);
  __Pyx_INCREF(__pyx_tuple__212);
  PyList_SET_ITEM(__pyx_t_2, 27, __pyx_tuple__212);
  __Pyx_GIVEREF(__pyx_tuple__212);
  __Pyx_INCREF(__pyx_tuple__213);
  PyList_SET_ITEM(__pyx_t_2, 28, __pyx_tuple__213);
  __Pyx_GIVEREF(__pyx_tuple__213);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_tlen_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1391
 * 
 * 
 * fields_tlen_strand = [t[0] for t in dtype_tlen_strand]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_tlen_strand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_7 = __pyx_t_4; __Pyx_INCREF(__pyx_t_7); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_7))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_6(__pyx_t_7);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_tlen_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1673
 * 
 * 
 * def stat_tlen_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate insert size statistics by strand per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_61stat_tlen_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_tlen_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1708
 * 
 * 
 * def load_tlen_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_tlen_strand, dtype_tlen_strand, *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_63load_tlen_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_tlen_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1717
 * 
 * 
 * dtype_mapq = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__218);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__218);
  __Pyx_GIVEREF(__pyx_tuple__218);
  __Pyx_INCREF(__pyx_tuple__219);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__219);
  __Pyx_GIVEREF(__pyx_tuple__219);
  __Pyx_INCREF(__pyx_tuple__220);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__220);
  __Pyx_GIVEREF(__pyx_tuple__220);
  __Pyx_INCREF(__pyx_tuple__221);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__221);
  __Pyx_GIVEREF(__pyx_tuple__221);
  __Pyx_INCREF(__pyx_tuple__222);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__222);
  __Pyx_GIVEREF(__pyx_tuple__222);
  __Pyx_INCREF(__pyx_tuple__223);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__223);
  __Pyx_GIVEREF(__pyx_tuple__223);
  __Pyx_INCREF(__pyx_tuple__224);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__224);
  __Pyx_GIVEREF(__pyx_tuple__224);
  __Pyx_INCREF(__pyx_tuple__225);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__225);
  __Pyx_GIVEREF(__pyx_tuple__225);
  __Pyx_INCREF(__pyx_tuple__226);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__226);
  __Pyx_GIVEREF(__pyx_tuple__226);
  __Pyx_INCREF(__pyx_tuple__227);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__227);
  __Pyx_GIVEREF(__pyx_tuple__227);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_mapq, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1731
 * 
 * 
 * fields_mapq = [t[0] for t in dtype_mapq]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_mapq); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
    __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_mapq, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1822
 * 
 * 
 * def stat_mapq(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate mapping quality statistics per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_69stat_mapq, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_mapq, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1856
 * 
 * 
 * def load_mapq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_mapq, dtype_mapq, *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_71load_mapq, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_mapq, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1865
 * 
 * 
 * dtype_mapq_strand = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(26); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__232);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__232);
  __Pyx_GIVEREF(__pyx_tuple__232);
  __Pyx_INCREF(__pyx_tuple__233);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__233);
  __Pyx_GIVEREF(__pyx_tuple__233);
  __Pyx_INCREF(__pyx_tuple__234);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__234);
  __Pyx_GIVEREF(__pyx_tuple__234);
  __Pyx_INCREF(__pyx_tuple__235);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__235);
  __Pyx_GIVEREF(__pyx_tuple__235);
  __Pyx_INCREF(__pyx_tuple__236);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__236);
  __Pyx_GIVEREF(__pyx_tuple__236);
  __Pyx_INCREF(__pyx_tuple__237);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__237);
  __Pyx_GIVEREF(__pyx_tuple__237);
  __Pyx_INCREF(__pyx_tuple__238);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__238);
  __Pyx_GIVEREF(__pyx_tuple__238);
  __Pyx_INCREF(__pyx_tuple__239);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__239);
  __Pyx_GIVEREF(__pyx_tuple__239);
  __Pyx_INCREF(__pyx_tuple__240);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__240);
  __Pyx_GIVEREF(__pyx_tuple__240);
  __Pyx_INCREF(__pyx_tuple__241);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__241);
  __Pyx_GIVEREF(__pyx_tuple__241);
  __Pyx_INCREF(__pyx_tuple__242);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_tuple__242);
  __Pyx_GIVEREF(__pyx_tuple__242);
  __Pyx_INCREF(__pyx_tuple__243);
  PyList_SET_ITEM(__pyx_t_2, 11, __pyx_tuple__243);
  __Pyx_GIVEREF(__pyx_tuple__243);
  __Pyx_INCREF(__pyx_tuple__244);
  PyList_SET_ITEM(__pyx_t_2, 12, __pyx_tuple__244);
  __Pyx_GIVEREF(__pyx_tuple__244);
  __Pyx_INCREF(__pyx_tuple__245);
  PyList_SET_ITEM(__pyx_t_2, 13, __pyx_tuple__245);
  __Pyx_GIVEREF(__pyx_tuple__245);
  __Pyx_INCREF(__pyx_tuple__246);
  PyList_SET_ITEM(__pyx_t_2, 14, __pyx_tuple__246);
  __Pyx_GIVEREF(__pyx_tuple__246);
  __Pyx_INCREF(__pyx_tuple__247);
  PyList_SET_ITEM(__pyx_t_2, 15, __pyx_tuple__247);
  __Pyx_GIVEREF(__pyx_tuple__247);
  __Pyx_INCREF(__pyx_tuple__248);
  PyList_SET_ITEM(__pyx_t_2, 16, __pyx_tuple__248);
  __Pyx_GIVEREF(__pyx_tuple__248);
  __Pyx_INCREF(__pyx_tuple__249);
  PyList_SET_ITEM(__pyx_t_2, 17, __pyx_tuple__249);
  __Pyx_GIVEREF(__pyx_tuple__249);
  __Pyx_INCREF(__pyx_tuple__250);
  PyList_SET_ITEM(__pyx_t_2, 18, __pyx_tuple__250);
  __Pyx_GIVEREF(__pyx_tuple__250);
  __Pyx_INCREF(__pyx_tuple__251);
  PyList_SET_ITEM(__pyx_t_2, 19, __pyx_tuple__251);
  __Pyx_GIVEREF(__pyx_tuple__251);
  __Pyx_INCREF(__pyx_tuple__252);
  PyList_SET_ITEM(__pyx_t_2, 20, __pyx_tuple__252);
  __Pyx_GIVEREF(__pyx_tuple__252);
  __Pyx_INCREF(__pyx_tuple__253);
  PyList_SET_ITEM(__pyx_t_2, 21, __pyx_tuple__253);
  __Pyx_GIVEREF(__pyx_tuple__253);
  __Pyx_INCREF(__pyx_tuple__254);
  PyList_SET_ITEM(__pyx_t_2, 22, __pyx_tuple__254);
  __Pyx_GIVEREF(__pyx_tuple__254);
  __Pyx_INCREF(__pyx_tuple__255);
  PyList_SET_ITEM(__pyx_t_2, 23, __pyx_tuple__255);
  __Pyx_GIVEREF(__pyx_tuple__255);
  __Pyx_INCREF(__pyx_tuple__256);
  PyList_SET_ITEM(__pyx_t_2, 24, __pyx_tuple__256);
  __Pyx_GIVEREF(__pyx_tuple__256);
  __Pyx_INCREF(__pyx_tuple__257);
  PyList_SET_ITEM(__pyx_t_2, 25, __pyx_tuple__257);
  __Pyx_GIVEREF(__pyx_tuple__257);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_mapq_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1895
 * 
 * 
 * fields_mapq_strand = [t[0] for t in dtype_mapq_strand]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_mapq_strand); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_mapq_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2092
 * 
 * 
 * def stat_mapq_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate mapping quality statistics by strand per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_77stat_mapq_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_mapq_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2127
 * 
 * 
 * def load_mapq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_mapq_strand, dtype_mapq_strand, *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_79load_mapq_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_mapq_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2136
 * 
 * 
 * dtype_baseq = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__262);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__262);
  __Pyx_GIVEREF(__pyx_tuple__262);
  __Pyx_INCREF(__pyx_tuple__263);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__263);
  __Pyx_GIVEREF(__pyx_tuple__263);
  __Pyx_INCREF(__pyx_tuple__264);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__264);
  __Pyx_GIVEREF(__pyx_tuple__264);
  __Pyx_INCREF(__pyx_tuple__265);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__265);
  __Pyx_GIVEREF(__pyx_tuple__265);
  __Pyx_INCREF(__pyx_tuple__266);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__266);
  __Pyx_GIVEREF(__pyx_tuple__266);
  __Pyx_INCREF(__pyx_tuple__267);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__267);
  __Pyx_GIVEREF(__pyx_tuple__267);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_baseq, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2146
 * 
 * 
 * fields_baseq = [t[0] for t in dtype_baseq]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_baseq); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_7 = __pyx_t_4; __Pyx_INCREF(__pyx_t_7); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_7))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_6(__pyx_t_7);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_baseq, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2219
 * 
 * 
 * def stat_baseq(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate base quality statistics per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_85stat_baseq, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_baseq, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2253
 * 
 * 
 * def load_baseq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq, dtype_baseq, *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_87load_baseq, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_baseq, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2262
 * 
 * 
 * dtype_baseq_strand = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__272);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__272);
  __Pyx_GIVEREF(__pyx_tuple__272);
  __Pyx_INCREF(__pyx_tuple__273);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__273);
  __Pyx_GIVEREF(__pyx_tuple__273);
  __Pyx_INCREF(__pyx_tuple__274);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__274);
  __Pyx_GIVEREF(__pyx_tuple__274);
  __Pyx_INCREF(__pyx_tuple__275);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__275);
  __Pyx_GIVEREF(__pyx_tuple__275);
  __Pyx_INCREF(__pyx_tuple__276);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__276);
  __Pyx_GIVEREF(__pyx_tuple__276);
  __Pyx_INCREF(__pyx_tuple__277);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__277);
  __Pyx_GIVEREF(__pyx_tuple__277);
  __Pyx_INCREF(__pyx_tuple__278);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__278);
  __Pyx_GIVEREF(__pyx_tuple__278);
  __Pyx_INCREF(__pyx_tuple__279);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__279);
  __Pyx_GIVEREF(__pyx_tuple__279);
  __Pyx_INCREF(__pyx_tuple__280);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__280);
  __Pyx_GIVEREF(__pyx_tuple__280);
  __Pyx_INCREF(__pyx_tuple__281);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__281);
  __Pyx_GIVEREF(__pyx_tuple__281);
  __Pyx_INCREF(__pyx_tuple__282);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_tuple__282);
  __Pyx_GIVEREF(__pyx_tuple__282);
  __Pyx_INCREF(__pyx_tuple__283);
  PyList_SET_ITEM(__pyx_t_2, 11, __pyx_tuple__283);
  __Pyx_GIVEREF(__pyx_tuple__283);
  __Pyx_INCREF(__pyx_tuple__284);
  PyList_SET_ITEM(__pyx_t_2, 12, __pyx_tuple__284);
  __Pyx_GIVEREF(__pyx_tuple__284);
  __Pyx_INCREF(__pyx_tuple__285);
  PyList_SET_ITEM(__pyx_t_2, 13, __pyx_tuple__285);
  __Pyx_GIVEREF(__pyx_tuple__285);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_baseq_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2280
 * 
 * 
 * fields_baseq_strand = [t[0] for t in dtype_baseq_strand]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_baseq_strand); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
    __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_baseq_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2414
 * 
 * 
 * def stat_baseq_strand(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate base quality statistics by strand per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_93stat_baseq_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_baseq_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2449
 * 
 * 
 * def load_baseq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq_strand, dtype_baseq_strand,
 *                        *args, **kwargs)
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_95load_baseq_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_baseq_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2459
 * 
 * 
 * dtype_baseq_ext = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(15); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__290);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__290);
  __Pyx_GIVEREF(__pyx_tuple__290);
  __Pyx_INCREF(__pyx_tuple__291);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__291);
  __Pyx_GIVEREF(__pyx_tuple__291);
  __Pyx_INCREF(__pyx_tuple__292);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__292);
  __Pyx_GIVEREF(__pyx_tuple__292);
  __Pyx_INCREF(__pyx_tuple__293);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__293);
  __Pyx_GIVEREF(__pyx_tuple__293);
  __Pyx_INCREF(__pyx_tuple__294);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__294);
  __Pyx_GIVEREF(__pyx_tuple__294);
  __Pyx_INCREF(__pyx_tuple__295);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__295);
  __Pyx_GIVEREF(__pyx_tuple__295);
  __Pyx_INCREF(__pyx_tuple__296);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__296);
  __Pyx_GIVEREF(__pyx_tuple__296);
  __Pyx_INCREF(__pyx_tuple__297);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__297);
  __Pyx_GIVEREF(__pyx_tuple__297);
  __Pyx_INCREF(__pyx_tuple__298);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__298);
  __Pyx_GIVEREF(__pyx_tuple__298);
  __Pyx_INCREF(__pyx_tuple__299);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__299);
  __Pyx_GIVEREF(__pyx_tuple__299);
  __Pyx_INCREF(__pyx_tuple__300);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_tuple__300);
  __Pyx_GIVEREF(__pyx_tuple__300);
  __Pyx_INCREF(__pyx_tuple__301);
  PyList_SET_ITEM(__pyx_t_2, 11, __pyx_tuple__301);
  __Pyx_GIVEREF(__pyx_tuple__301);
  __Pyx_INCREF(__pyx_tuple__302);
  PyList_SET_ITEM(__pyx_t_2, 12, __pyx_tuple__302);
  __Pyx_GIVEREF(__pyx_tuple__302);
  __Pyx_INCREF(__pyx_tuple__303);
  PyList_SET_ITEM(__pyx_t_2, 13, __pyx_tuple__303);
  __Pyx_GIVEREF(__pyx_tuple__303);
  __Pyx_INCREF(__pyx_tuple__304);
  PyList_SET_ITEM(__pyx_t_2, 14, __pyx_tuple__304);
  __Pyx_GIVEREF(__pyx_tuple__304);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_baseq_ext, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2478
 * 
 * 
 * fields_baseq_ext = [t[0] for t in dtype_baseq_ext]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_baseq_ext); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_baseq_ext, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2601
 * 
 * 
 * def stat_baseq_ext(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended base quality statistics per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_101stat_baseq_ext, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_baseq_ext, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2638
 * 
 * 
 * def load_baseq_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq_ext, dtype_baseq_ext, *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_103load_baseq_ext, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_baseq_ext, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2647
 * 
 * 
 * dtype_baseq_ext_strand = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(39); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2647; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__309);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__309);
  __Pyx_GIVEREF(__pyx_tuple__309);
  __Pyx_INCREF(__pyx_tuple__310);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__310);
  __Pyx_GIVEREF(__pyx_tuple__310);
  __Pyx_INCREF(__pyx_tuple__311);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__311);
  __Pyx_GIVEREF(__pyx_tuple__311);
  __Pyx_INCREF(__pyx_tuple__312);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__312);
  __Pyx_GIVEREF(__pyx_tuple__312);
  __Pyx_INCREF(__pyx_tuple__313);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__313);
  __Pyx_GIVEREF(__pyx_tuple__313);
  __Pyx_INCREF(__pyx_tuple__314);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__314);
  __Pyx_GIVEREF(__pyx_tuple__314);
  __Pyx_INCREF(__pyx_tuple__315);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__315);
  __Pyx_GIVEREF(__pyx_tuple__315);
  __Pyx_INCREF(__pyx_tuple__316);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__316);
  __Pyx_GIVEREF(__pyx_tuple__316);
  __Pyx_INCREF(__pyx_tuple__317);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__317);
  __Pyx_GIVEREF(__pyx_tuple__317);
  __Pyx_INCREF(__pyx_tuple__318);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__318);
  __Pyx_GIVEREF(__pyx_tuple__318);
  __Pyx_INCREF(__pyx_tuple__319);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_tuple__319);
  __Pyx_GIVEREF(__pyx_tuple__319);
  __Pyx_INCREF(__pyx_tuple__320);
  PyList_SET_ITEM(__pyx_t_2, 11, __pyx_tuple__320);
  __Pyx_GIVEREF(__pyx_tuple__320);
  __Pyx_INCREF(__pyx_tuple__321);
  PyList_SET_ITEM(__pyx_t_2, 12, __pyx_tuple__321);
  __Pyx_GIVEREF(__pyx_tuple__321);
  __Pyx_INCREF(__pyx_tuple__322);
  PyList_SET_ITEM(__pyx_t_2, 13, __pyx_tuple__322);
  __Pyx_GIVEREF(__pyx_tuple__322);
  __Pyx_INCREF(__pyx_tuple__323);
  PyList_SET_ITEM(__pyx_t_2, 14, __pyx_tuple__323);
  __Pyx_GIVEREF(__pyx_tuple__323);
  __Pyx_INCREF(__pyx_tuple__324);
  PyList_SET_ITEM(__pyx_t_2, 15, __pyx_tuple__324);
  __Pyx_GIVEREF(__pyx_tuple__324);
  __Pyx_INCREF(__pyx_tuple__325);
  PyList_SET_ITEM(__pyx_t_2, 16, __pyx_tuple__325);
  __Pyx_GIVEREF(__pyx_tuple__325);
  __Pyx_INCREF(__pyx_tuple__326);
  PyList_SET_ITEM(__pyx_t_2, 17, __pyx_tuple__326);
  __Pyx_GIVEREF(__pyx_tuple__326);
  __Pyx_INCREF(__pyx_tuple__327);
  PyList_SET_ITEM(__pyx_t_2, 18, __pyx_tuple__327);
  __Pyx_GIVEREF(__pyx_tuple__327);
  __Pyx_INCREF(__pyx_tuple__328);
  PyList_SET_ITEM(__pyx_t_2, 19, __pyx_tuple__328);
  __Pyx_GIVEREF(__pyx_tuple__328);
  __Pyx_INCREF(__pyx_tuple__329);
  PyList_SET_ITEM(__pyx_t_2, 20, __pyx_tuple__329);
  __Pyx_GIVEREF(__pyx_tuple__329);
  __Pyx_INCREF(__pyx_tuple__330);
  PyList_SET_ITEM(__pyx_t_2, 21, __pyx_tuple__330);
  __Pyx_GIVEREF(__pyx_tuple__330);
  __Pyx_INCREF(__pyx_tuple__331);
  PyList_SET_ITEM(__pyx_t_2, 22, __pyx_tuple__331);
  __Pyx_GIVEREF(__pyx_tuple__331);
  __Pyx_INCREF(__pyx_tuple__332);
  PyList_SET_ITEM(__pyx_t_2, 23, __pyx_tuple__332);
  __Pyx_GIVEREF(__pyx_tuple__332);
  __Pyx_INCREF(__pyx_tuple__333);
  PyList_SET_ITEM(__pyx_t_2, 24, __pyx_tuple__333);
  __Pyx_GIVEREF(__pyx_tuple__333);
  __Pyx_INCREF(__pyx_tuple__334);
  PyList_SET_ITEM(__pyx_t_2, 25, __pyx_tuple__334);
  __Pyx_GIVEREF(__pyx_tuple__334);
  __Pyx_INCREF(__pyx_tuple__335);
  PyList_SET_ITEM(__pyx_t_2, 26, __pyx_tuple__335);
  __Pyx_GIVEREF(__pyx_tuple__335);
  __Pyx_INCREF(__pyx_tuple__336);
  PyList_SET_ITEM(__pyx_t_2, 27, __pyx_tuple__336);
  __Pyx_GIVEREF(__pyx_tuple__336);
  __Pyx_INCREF(__pyx_tuple__337);
  PyList_SET_ITEM(__pyx_t_2, 28, __pyx_tuple__337);
  __Pyx_GIVEREF(__pyx_tuple__337);
  __Pyx_INCREF(__pyx_tuple__338);
  PyList_SET_ITEM(__pyx_t_2, 29, __pyx_tuple__338);
  __Pyx_GIVEREF(__pyx_tuple__338);
  __Pyx_INCREF(__pyx_tuple__339);
  PyList_SET_ITEM(__pyx_t_2, 30, __pyx_tuple__339);
  __Pyx_GIVEREF(__pyx_tuple__339);
  __Pyx_INCREF(__pyx_tuple__340);
  PyList_SET_ITEM(__pyx_t_2, 31, __pyx_tuple__340);
  __Pyx_GIVEREF(__pyx_tuple__340);
  __Pyx_INCREF(__pyx_tuple__341);
  PyList_SET_ITEM(__pyx_t_2, 32, __pyx_tuple__341);
  __Pyx_GIVEREF(__pyx_tuple__341);
  __Pyx_INCREF(__pyx_tuple__342);
  PyList_SET_ITEM(__pyx_t_2, 33, __pyx_tuple__342);
  __Pyx_GIVEREF(__pyx_tuple__342);
  __Pyx_INCREF(__pyx_tuple__343);
  PyList_SET_ITEM(__pyx_t_2, 34, __pyx_tuple__343);
  __Pyx_GIVEREF(__pyx_tuple__343);
  __Pyx_INCREF(__pyx_tuple__344);
  PyList_SET_ITEM(__pyx_t_2, 35, __pyx_tuple__344);
  __Pyx_GIVEREF(__pyx_tuple__344);
  __Pyx_INCREF(__pyx_tuple__345);
  PyList_SET_ITEM(__pyx_t_2, 36, __pyx_tuple__345);
  __Pyx_GIVEREF(__pyx_tuple__345);
  __Pyx_INCREF(__pyx_tuple__346);
  PyList_SET_ITEM(__pyx_t_2, 37, __pyx_tuple__346);
  __Pyx_GIVEREF(__pyx_tuple__346);
  __Pyx_INCREF(__pyx_tuple__347);
  PyList_SET_ITEM(__pyx_t_2, 38, __pyx_tuple__347);
  __Pyx_GIVEREF(__pyx_tuple__347);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_baseq_ext_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2647; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2690
 * 
 * 
 * fields_baseq_ext_strand = [t[0] for t in dtype_baseq_ext_strand]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_baseq_ext_strand); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_7 = __pyx_t_4; __Pyx_INCREF(__pyx_t_7); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_7))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_6(__pyx_t_7);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_baseq_ext_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2913
 * 
 * 
 * def stat_baseq_ext_strand(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate extended base quality statistics by strand per genome position.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_109stat_baseq_ext_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2913; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_baseq_ext_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2913; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2950
 * 
 * 
 * def load_baseq_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_baseq_ext_strand, dtype_baseq_ext_strand,
 *                        *args, **kwargs)
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_111load_baseq_ext_strand, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_baseq_ext_strand, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2960
 * 
 * 
 * dtype_coverage_gc = [('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *                      ('pos', 'i4'),
 *                      ('gc', 'u1'),
 */
  __pyx_t_2 = PyList_New(5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__352);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__352);
  __Pyx_GIVEREF(__pyx_tuple__352);
  __Pyx_INCREF(__pyx_tuple__353);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__353);
  __Pyx_GIVEREF(__pyx_tuple__353);
  __Pyx_INCREF(__pyx_tuple__354);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__354);
  __Pyx_GIVEREF(__pyx_tuple__354);
  __Pyx_INCREF(__pyx_tuple__355);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__355);
  __Pyx_GIVEREF(__pyx_tuple__355);
  __Pyx_INCREF(__pyx_tuple__356);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__356);
  __Pyx_GIVEREF(__pyx_tuple__356);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_coverage_gc, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2967
 * 
 * 
 * fields_coverage_gc = [t[0] for t in dtype_coverage_gc]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage_gc); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
    __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_coverage_gc, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":2970
 * 
 * 
 * def stat_coverage_gc(alignmentfile, fafile, chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                      one_based=False, truncate=False, pad=False, max_depth=8000,
 *                      window_size=300, window_offset=None, **kwargs):
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_113stat_coverage_gc, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_coverage_gc, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3060
 * 
 * 
 * def load_coverage_gc(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_gc, dtype_coverage_gc, *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_115load_coverage_gc, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_coverage_gc, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3069
 * 
 * 
 * dtype_coverage_binned = [('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *                          ('pos', 'i4'),
 *                          ('gc', 'u1'),
 */
  __pyx_t_2 = PyList_New(5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__361);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__361);
  __Pyx_GIVEREF(__pyx_tuple__361);
  __Pyx_INCREF(__pyx_tuple__362);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__362);
  __Pyx_GIVEREF(__pyx_tuple__362);
  __Pyx_INCREF(__pyx_tuple__363);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__363);
  __Pyx_GIVEREF(__pyx_tuple__363);
  __Pyx_INCREF(__pyx_tuple__364);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__364);
  __Pyx_GIVEREF(__pyx_tuple__364);
  __Pyx_INCREF(__pyx_tuple__365);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__365);
  __Pyx_GIVEREF(__pyx_tuple__365);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_coverage_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3076
 * 
 * 
 * fields_coverage_binned = [t[0] for t in dtype_coverage_binned]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage_binned); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_coverage_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3079
 * 
 * 
 * def stat_coverage_binned(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned coverage statistics.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_117stat_coverage_binned, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_coverage_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3178
 * 
 * 
 * def load_coverage_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_binned, dtype_coverage_binned,
 *                        *args, **kwargs)
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_119load_coverage_binned, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_coverage_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3188
 * 
 * 
 * dtype_coverage_ext_binned = [('chrom', 'a12'),             # <<<<<<<<<<<<<<
 *                              ('pos', 'i4'),
 *                              ('gc', 'u1'),
 */
  __pyx_t_2 = PyList_New(11); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__370);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__370);
  __Pyx_GIVEREF(__pyx_tuple__370);
  __Pyx_INCREF(__pyx_tuple__371);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__371);
  __Pyx_GIVEREF(__pyx_tuple__371);
  __Pyx_INCREF(__pyx_tuple__372);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__372);
  __Pyx_GIVEREF(__pyx_tuple__372);
  __Pyx_INCREF(__pyx_tuple__373);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__373);
  __Pyx_GIVEREF(__pyx_tuple__373);
  __Pyx_INCREF(__pyx_tuple__374);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__374);
  __Pyx_GIVEREF(__pyx_tuple__374);
  __Pyx_INCREF(__pyx_tuple__375);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__375);
  __Pyx_GIVEREF(__pyx_tuple__375);
  __Pyx_INCREF(__pyx_tuple__376);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__376);
  __Pyx_GIVEREF(__pyx_tuple__376);
  __Pyx_INCREF(__pyx_tuple__377);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__377);
  __Pyx_GIVEREF(__pyx_tuple__377);
  __Pyx_INCREF(__pyx_tuple__378);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__378);
  __Pyx_GIVEREF(__pyx_tuple__378);
  __Pyx_INCREF(__pyx_tuple__379);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__379);
  __Pyx_GIVEREF(__pyx_tuple__379);
  __Pyx_INCREF(__pyx_tuple__380);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_tuple__380);
  __Pyx_GIVEREF(__pyx_tuple__380);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_coverage_ext_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3201
 * 
 * 
 * fields_coverage_ext_binned = [t[0] for t in dtype_coverage_ext_binned]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_coverage_ext_binned); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_7 = __pyx_t_4; __Pyx_INCREF(__pyx_t_7); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_7))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_6(__pyx_t_7);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_coverage_ext_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3204
 * 
 * 
 * def stat_coverage_ext_binned(alignmentfile, fafile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned extended coverage statistics.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_121stat_coverage_ext_binned, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_coverage_ext_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3319
 * 
 * 
 * def load_coverage_ext_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_coverage_ext_binned, dtype_coverage_ext_binned,
 *                        *args, **kwargs)
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_123load_coverage_ext_binned, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_coverage_ext_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3329
 * 
 * 
 * dtype_mapq_binned = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__385);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__385);
  __Pyx_GIVEREF(__pyx_tuple__385);
  __Pyx_INCREF(__pyx_tuple__386);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__386);
  __Pyx_GIVEREF(__pyx_tuple__386);
  __Pyx_INCREF(__pyx_tuple__387);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__387);
  __Pyx_GIVEREF(__pyx_tuple__387);
  __Pyx_INCREF(__pyx_tuple__388);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__388);
  __Pyx_GIVEREF(__pyx_tuple__388);
  __Pyx_INCREF(__pyx_tuple__389);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__389);
  __Pyx_GIVEREF(__pyx_tuple__389);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_mapq_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3338
 * 
 * 
 * fields_mapq_binned = [t[0] for t in dtype_mapq_binned]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_mapq_binned); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
    __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_mapq_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3341
 * 
 * 
 * def stat_mapq_binned(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned mapping quality statistics.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_125stat_mapq_binned, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_mapq_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3416
 * 
 * 
 * def load_mapq_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_mapq_binned, dtype_mapq_binned, *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_127load_mapq_binned, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_mapq_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3425
 * 
 * 
 * dtype_alignment_binned = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(13); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__394);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__394);
  __Pyx_GIVEREF(__pyx_tuple__394);
  __Pyx_INCREF(__pyx_tuple__395);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__395);
  __Pyx_GIVEREF(__pyx_tuple__395);
  __Pyx_INCREF(__pyx_tuple__396);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__396);
  __Pyx_GIVEREF(__pyx_tuple__396);
  __Pyx_INCREF(__pyx_tuple__397);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__397);
  __Pyx_GIVEREF(__pyx_tuple__397);
  __Pyx_INCREF(__pyx_tuple__398);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__398);
  __Pyx_GIVEREF(__pyx_tuple__398);
  __Pyx_INCREF(__pyx_tuple__399);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__399);
  __Pyx_GIVEREF(__pyx_tuple__399);
  __Pyx_INCREF(__pyx_tuple__400);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__400);
  __Pyx_GIVEREF(__pyx_tuple__400);
  __Pyx_INCREF(__pyx_tuple__401);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__401);
  __Pyx_GIVEREF(__pyx_tuple__401);
  __Pyx_INCREF(__pyx_tuple__402);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_tuple__402);
  __Pyx_GIVEREF(__pyx_tuple__402);
  __Pyx_INCREF(__pyx_tuple__403);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_tuple__403);
  __Pyx_GIVEREF(__pyx_tuple__403);
  __Pyx_INCREF(__pyx_tuple__404);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_tuple__404);
  __Pyx_GIVEREF(__pyx_tuple__404);
  __Pyx_INCREF(__pyx_tuple__405);
  PyList_SET_ITEM(__pyx_t_2, 11, __pyx_tuple__405);
  __Pyx_GIVEREF(__pyx_tuple__405);
  __Pyx_INCREF(__pyx_tuple__406);
  PyList_SET_ITEM(__pyx_t_2, 12, __pyx_tuple__406);
  __Pyx_GIVEREF(__pyx_tuple__406);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_alignment_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3442
 * 
 * 
 * fields_alignment_binned = [t[0] for t in dtype_alignment_binned]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_alignment_binned); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_alignment_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3445
 * 
 * 
 * def stat_alignment_binned(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned alignment statistics.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_129stat_alignment_binned, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_alignment_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3542
 * 
 * 
 * def load_alignment_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_alignment_binned, dtype_alignment_binned,
 *                        *args, **kwargs)
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_131load_alignment_binned, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_alignment_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3552
 * 
 * 
 * dtype_tlen_binned = [             # <<<<<<<<<<<<<<
 *     ('chrom', 'a12'),
 *     ('pos', 'i4'),
 */
  __pyx_t_2 = PyList_New(8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_tuple__411);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_tuple__411);
  __Pyx_GIVEREF(__pyx_tuple__411);
  __Pyx_INCREF(__pyx_tuple__412);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_tuple__412);
  __Pyx_GIVEREF(__pyx_tuple__412);
  __Pyx_INCREF(__pyx_tuple__413);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_tuple__413);
  __Pyx_GIVEREF(__pyx_tuple__413);
  __Pyx_INCREF(__pyx_tuple__414);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_tuple__414);
  __Pyx_GIVEREF(__pyx_tuple__414);
  __Pyx_INCREF(__pyx_tuple__415);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_tuple__415);
  __Pyx_GIVEREF(__pyx_tuple__415);
  __Pyx_INCREF(__pyx_tuple__416);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_tuple__416);
  __Pyx_GIVEREF(__pyx_tuple__416);
  __Pyx_INCREF(__pyx_tuple__417);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_tuple__417);
  __Pyx_GIVEREF(__pyx_tuple__417);
  __Pyx_INCREF(__pyx_tuple__418);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_tuple__418);
  __Pyx_GIVEREF(__pyx_tuple__418);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtype_tlen_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3564
 * 
 * 
 * fields_tlen_binned = [t[0] for t in dtype_tlen_binned]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_dtype_tlen_binned); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_7 = __pyx_t_4; __Pyx_INCREF(__pyx_t_7); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_7))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_6(__pyx_t_7);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_t, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fields_tlen_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3567
 * 
 * 
 * def stat_tlen_binned(alignmentfile, **kwargs):             # <<<<<<<<<<<<<<
 *     """Generate binned insert size statistics.
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_133stat_tlen_binned, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stat_tlen_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3656
 * 
 * 
 * def load_tlen_binned(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     return _load_stats(stat_tlen_binned, dtype_tlen_binned, *args, **kwargs)
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_135load_tlen_binned, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_tlen_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3665
 * 
 * 
 * def _iter_pileup(frec, fpad, alignmentfile, fafile=None, chrom=None, start=None,             # <<<<<<<<<<<<<<
 *                  end=None, one_based=False, truncate=False, pad=False,
 *                  max_depth=8000, **kwargs):
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_137_iter_pileup, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_iter_pileup, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3693
 * 
 * 
 * def _iter_pileup_default(frec, alignmentfile, fafile=None,             # <<<<<<<<<<<<<<
 *                          chrom=None, start=None, end=None,
 *                          one_based=False, truncate=False,
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_139_iter_pileup_default, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_iter_pileup_default, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3704
 * 
 * 
 * def _iter_pileup_padded(frec, fpad, alignmentfile, fafile=None, chrom=None,             # <<<<<<<<<<<<<<
 *                         start=None, end=None, one_based=False,
 *                         truncate=False, max_depth=8000, **kwargs):
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_142_iter_pileup_padded, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_iter_pileup_padded, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3729
 * 
 * 
 * def _iter_pileup_padded_chrom(frec, fpad, alignmentfile, fafile, chrom, start=None,             # <<<<<<<<<<<<<<
 *                               end=None, one_based=False, truncate=False,
 *                               max_depth=8000, **kwargs):
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_144_iter_pileup_padded_chrom, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_iter_pileup_padded_chrom, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3750
 * 
 * 
 * def _iter_binned(stat, alignmentfile, fafile=None, chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                  one_based=False, window_size=300, window_offset=None,
 *                  **kwargs):
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_147_iter_binned, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_iter_binned, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3783
 * 
 * 
 * def _iter_binned_chrom(_StatBinned stat, AlignmentFile alignmentfile, FastaFile fafile,             # <<<<<<<<<<<<<<
 *                        chrom, start=None, end=None, one_based=False,
 *                        int window_size=300, int window_offset=150, **kwargs):
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_149_iter_binned_chrom, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_iter_binned_chrom, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3856
 * 
 * 
 * def _normalise_coords(AlignmentFile alignmentfile, chrom, start, end, one_based):             # <<<<<<<<<<<<<<
 *     """Convert to zero-based coordinates and deal with unspecified start
 *     and/or end.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_152_normalise_coords, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_normalise_coords, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3884
 * 
 * 
 * def write_csv(stats_type, outfile, alignmentfile, fields=None, dialect='excel-tab',             # <<<<<<<<<<<<<<
 *               write_header=True, progress=None, **kwargs):
 *     """Write statistics output to a CSV file.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_154write_csv, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_write_csv, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":3962
 * 
 * 
 * def write_hdf5(stats_type, outfile, alignmentfile, fields=None, progress=None,             # <<<<<<<<<<<<<<
 *                hdf5_group='/', hdf5_dataset='data', hdf5_complevel=5,
 *                hdf5_complib='zlib', hdf5_shuffle=True,
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_156write_hdf5, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_write_hdf5, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":4106
 * 
 * 
 * from operator import itemgetter             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_itemgetter);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_itemgetter);
  __Pyx_GIVEREF(__pyx_n_s_itemgetter);
  __pyx_t_7 = __Pyx_Import(__pyx_n_s_operator, __pyx_t_2, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_itemgetter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_itemgetter, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysamstats.pyx":4109
 * 
 * 
 * def flatten(recs, *fields):             # <<<<<<<<<<<<<<
 *     """Convert a record (dict) iterator to a row (tuple) iterator.
 * 
 */
  __pyx_t_7 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_158flatten, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_flatten, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysamstats.pyx":4133
 * 
 * 
 * def tabulate(stat, *args, **kwargs):             # <<<<<<<<<<<<<<
 *     """Tabulate statistics.
 * 
 */
  __pyx_t_7 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_160tabulate, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_tabulate, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysamstats.pyx":4158
 * 
 * 
 * class _StatsTable(object):             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, stats_type, *args, **kwargs):
 */
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_builtin_object);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_builtin_object);
  __Pyx_GIVEREF(__pyx_builtin_object);
  __pyx_t_2 = __Pyx_CalculateMetaclass(NULL, __pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_Py3MetaclassPrepare(__pyx_t_2, __pyx_t_7, __pyx_n_s_StatsTable, __pyx_n_s_StatsTable, (PyObject *) NULL, __pyx_n_s_pysamstats, (PyObject *) NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysamstats.pyx":4160
 * class _StatsTable(object):
 * 
 *     def __init__(self, stats_type, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         try:
 *             self.stats_function = globals()['stat_' + stats_type]
 */
  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_10pysamstats_11_StatsTable_1__init__, 0, __pyx_n_s_StatsTable___init, NULL, __pyx_n_s_pysamstats, __pyx_d, ((PyObject *)__pyx_codeobj__446)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s_init, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":4171
 *             raise Exception('statistics type not found: %r' % stats_type)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         recs = self.stats_function(*self.args, **self.kwargs)
 *         fields = tuple(self.fields)
 */
  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_10pysamstats_11_StatsTable_3__iter__, 0, __pyx_n_s_StatsTable___iter, NULL, __pyx_n_s_pysamstats, __pyx_d, ((PyObject *)__pyx_codeobj__448)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s_iter, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":4158
 * 
 * 
 * class _StatsTable(object):             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, stats_type, *args, **kwargs):
 */
  __pyx_t_4 = __Pyx_Py3ClassCreate(__pyx_t_2, __pyx_n_s_StatsTable, __pyx_t_7, __pyx_t_1, NULL, 0, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_StatsTable, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysamstats.pyx":4180
 * 
 * 
 * def _load_stats(statfun, default_dtype, *args, **kwargs):             # <<<<<<<<<<<<<<
 * 
 *     import numpy as np
 */
  __pyx_t_7 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_162_load_stats, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_load_stats, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysamstats.pyx":4259
 * 
 * 
 * def count_reads(AlignmentFile alignmentfile, chrom=None, start=None, end=None):             # <<<<<<<<<<<<<<
 *     cdef IteratorRowRegion it
 *     cdef int n = 0
 */
  __pyx_t_7 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_164count_reads, NULL, __pyx_n_s_pysamstats); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_count_reads, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysamstats.pyx":1
 * # cython: profile=False             # <<<<<<<<<<<<<<
 * # cython: embedsignature=True
 * from __future__ import print_function, division, absolute_import
 */
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  if (__pyx_m) {
    if (__pyx_d) {
      __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

static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject* args = PyTuple_Pack(1, arg);
    return (likely(args)) ? __Pyx_PyObject_Call(func, args, NULL) : NULL;
}
#endif

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) {
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
}
static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (likely(Py_TYPE(obj) == type)) return 1;
        #if PY_MAJOR_VERSION == 2
        else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(PyObject_TypeCheck(obj, type))) return 1;
    }
    __Pyx_RaiseArgumentTypeInvalid(name, obj, type);
    return 0;
}

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON
    result = PyDict_GetItem(__pyx_d, name);
    if (likely(result)) {
        Py_INCREF(result);
    } else {
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
#if CYTHON_COMPILING_IN_PYPY
    if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
        goto invalid_keyword;
    return 1;
#else
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
        #endif
            if (unlikely(!PyUnicode_Check(key)))
                goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    return 0;
#endif
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) {
    PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname);
}

static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
    PyObject* fake_module;
    PyTypeObject* cached_type = NULL;
    fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
    if (!fake_module) return NULL;
    Py_INCREF(fake_module);
    cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
    if (cached_type) {
        if (!PyType_Check((PyObject*)cached_type)) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s is not a type object",
                type->tp_name);
            goto bad;
        }
        if (cached_type->tp_basicsize != type->tp_basicsize) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s has the wrong size, try recompiling",
                type->tp_name);
            goto bad;
        }
    } else {
        if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
        PyErr_Clear();
        if (PyType_Ready(type) < 0) goto bad;
        if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
            goto bad;
        Py_INCREF(type);
        cached_type = type;
    }
done:
    Py_DECREF(fake_module);
    return cached_type;
bad:
    Py_XDECREF(cached_type);
    cached_type = NULL;
    goto done;
}

static PyObject *
__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
{
    if (unlikely(op->func_doc == NULL)) {
        if (op->func.m_ml->ml_doc) {
#if PY_MAJOR_VERSION >= 3
            op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc);
#else
            op->func_doc = PyString_FromString(op->func.m_ml->ml_doc);
#endif
            if (unlikely(op->func_doc == NULL))
                return NULL;
        } else {
            Py_INCREF(Py_None);
            return Py_None;
        }
    }
    Py_INCREF(op->func_doc);
    return op->func_doc;
}
static int
__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp = op->func_doc;
    if (value == NULL) {
        value = Py_None;
    }
    Py_INCREF(value);
    op->func_doc = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op)
{
    if (unlikely(op->func_name == NULL)) {
#if PY_MAJOR_VERSION >= 3
        op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name);
#else
        op->func_name = PyString_InternFromString(op->func.m_ml->ml_name);
#endif
        if (unlikely(op->func_name == NULL))
            return NULL;
    }
    Py_INCREF(op->func_name);
    return op->func_name;
}
static int
__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
    if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
        PyErr_SetString(PyExc_TypeError,
                        "__name__ must be set to a string object");
        return -1;
    }
    tmp = op->func_name;
    Py_INCREF(value);
    op->func_name = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op)
{
    Py_INCREF(op->func_qualname);
    return op->func_qualname;
}
static int
__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
    if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
        PyErr_SetString(PyExc_TypeError,
                        "__qualname__ must be set to a string object");
        return -1;
    }
    tmp = op->func_qualname;
    Py_INCREF(value);
    op->func_qualname = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure)
{
    PyObject *self;
    self = m->func_closure;
    if (self == NULL)
        self = Py_None;
    Py_INCREF(self);
    return self;
}
static PyObject *
__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op)
{
    if (unlikely(op->func_dict == NULL)) {
        op->func_dict = PyDict_New();
        if (unlikely(op->func_dict == NULL))
            return NULL;
    }
    Py_INCREF(op->func_dict);
    return op->func_dict;
}
static int
__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp;
    if (unlikely(value == NULL)) {
        PyErr_SetString(PyExc_TypeError,
               "function's dictionary may not be deleted");
        return -1;
    }
    if (unlikely(!PyDict_Check(value))) {
        PyErr_SetString(PyExc_TypeError,
               "setting function's dictionary to a non-dict");
        return -1;
    }
    tmp = op->func_dict;
    Py_INCREF(value);
    op->func_dict = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op)
{
    Py_INCREF(op->func_globals);
    return op->func_globals;
}
static PyObject *
__Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op)
{
    Py_INCREF(Py_None);
    return Py_None;
}
static PyObject *
__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op)
{
    PyObject* result = (op->func_code) ? op->func_code : Py_None;
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
    PyObject *res = op->defaults_getter((PyObject *) op);
    if (unlikely(!res))
        return -1;
    op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
    Py_INCREF(op->defaults_tuple);
    op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
    Py_INCREF(op->defaults_kwdict);
    Py_DECREF(res);
    return 0;
}
static int
__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value) {
    PyObject* tmp;
    if (!value) {
        value = Py_None;
    } else if (value != Py_None && !PyTuple_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__defaults__ must be set to a tuple object");
        return -1;
    }
    Py_INCREF(value);
    tmp = op->defaults_tuple;
    op->defaults_tuple = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op) {
    PyObject* result = op->defaults_tuple;
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
            result = op->defaults_tuple;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value) {
    PyObject* tmp;
    if (!value) {
        value = Py_None;
    } else if (value != Py_None && !PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__kwdefaults__ must be set to a dict object");
        return -1;
    }
    Py_INCREF(value);
    tmp = op->defaults_kwdict;
    op->defaults_kwdict = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op) {
    PyObject* result = op->defaults_kwdict;
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
            result = op->defaults_kwdict;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value) {
    PyObject* tmp;
    if (!value || value == Py_None) {
        value = NULL;
    } else if (!PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__annotations__ must be set to a dict object");
        return -1;
    }
    Py_XINCREF(value);
    tmp = op->func_annotations;
    op->func_annotations = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op) {
    PyObject* result = op->func_annotations;
    if (unlikely(!result)) {
        result = PyDict_New();
        if (unlikely(!result)) return NULL;
        op->func_annotations = result;
    }
    Py_INCREF(result);
    return result;
}
static PyGetSetDef __pyx_CyFunction_getsets[] = {
    {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    {(char *) "__doc__",  (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0},
    {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0},
    {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
    {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
    {0, 0, 0, 0, 0}
};
#ifndef PY_WRITE_RESTRICTED
#define PY_WRITE_RESTRICTED WRITE_RESTRICTED
#endif
static PyMemberDef __pyx_CyFunction_members[] = {
    {(char *) "__module__", T_OBJECT, offsetof(__pyx_CyFunctionObject, func.m_module), PY_WRITE_RESTRICTED, 0},
    {0, 0, 0,  0, 0}
};
static PyObject *
__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args)
{
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_FromString(m->func.m_ml->ml_name);
#else
    return PyString_FromString(m->func.m_ml->ml_name);
#endif
}
static PyMethodDef __pyx_CyFunction_methods[] = {
    {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
    {0, 0, 0, 0}
};
#if PY_VERSION_HEX < 0x030500A0
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist)
#else
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func.m_weakreflist)
#endif
static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, PyObject* qualname,
                                      PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
    __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type);
    if (op == NULL)
        return NULL;
    op->flags = flags;
    __Pyx_CyFunction_weakreflist(op) = NULL;
    op->func.m_ml = ml;
    op->func.m_self = (PyObject *) op;
    Py_XINCREF(closure);
    op->func_closure = closure;
    Py_XINCREF(module);
    op->func.m_module = module;
    op->func_dict = NULL;
    op->func_name = NULL;
    Py_INCREF(qualname);
    op->func_qualname = qualname;
    op->func_doc = NULL;
    op->func_classobj = NULL;
    op->func_globals = globals;
    Py_INCREF(op->func_globals);
    Py_XINCREF(code);
    op->func_code = code;
    op->defaults_pyobjects = 0;
    op->defaults = NULL;
    op->defaults_tuple = NULL;
    op->defaults_kwdict = NULL;
    op->defaults_getter = NULL;
    op->func_annotations = NULL;
    PyObject_GC_Track(op);
    return (PyObject *) op;
}
static int
__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
{
    Py_CLEAR(m->func_closure);
    Py_CLEAR(m->func.m_module);
    Py_CLEAR(m->func_dict);
    Py_CLEAR(m->func_name);
    Py_CLEAR(m->func_qualname);
    Py_CLEAR(m->func_doc);
    Py_CLEAR(m->func_globals);
    Py_CLEAR(m->func_code);
    Py_CLEAR(m->func_classobj);
    Py_CLEAR(m->defaults_tuple);
    Py_CLEAR(m->defaults_kwdict);
    Py_CLEAR(m->func_annotations);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_XDECREF(pydefaults[i]);
        PyMem_Free(m->defaults);
        m->defaults = NULL;
    }
    return 0;
}
static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
{
    PyObject_GC_UnTrack(m);
    if (__Pyx_CyFunction_weakreflist(m) != NULL)
        PyObject_ClearWeakRefs((PyObject *) m);
    __Pyx_CyFunction_clear(m);
    PyObject_GC_Del(m);
}
static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
{
    Py_VISIT(m->func_closure);
    Py_VISIT(m->func.m_module);
    Py_VISIT(m->func_dict);
    Py_VISIT(m->func_name);
    Py_VISIT(m->func_qualname);
    Py_VISIT(m->func_doc);
    Py_VISIT(m->func_globals);
    Py_VISIT(m->func_code);
    Py_VISIT(m->func_classobj);
    Py_VISIT(m->defaults_tuple);
    Py_VISIT(m->defaults_kwdict);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_VISIT(pydefaults[i]);
    }
    return 0;
}
static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type)
{
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) {
        Py_INCREF(func);
        return func;
    }
    if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) {
        if (type == NULL)
            type = (PyObject *)(Py_TYPE(obj));
        return __Pyx_PyMethod_New(func, type, (PyObject *)(Py_TYPE(type)));
    }
    if (obj == Py_None)
        obj = NULL;
    return __Pyx_PyMethod_New(func, obj, type);
}
static PyObject*
__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
{
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_FromFormat("<cyfunction %U at %p>",
                                op->func_qualname, (void *)op);
#else
    return PyString_FromFormat("<cyfunction %s at %p>",
                               PyString_AsString(op->func_qualname), (void *)op);
#endif
}
#if CYTHON_COMPILING_IN_PYPY
static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyCFunctionObject* f = (PyCFunctionObject*)func;
    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    PyObject *self = PyCFunction_GET_SELF(func);
    Py_ssize_t size;
    switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)) {
    case METH_VARARGS:
        if (likely(kw == NULL) || PyDict_Size(kw) == 0)
            return (*meth)(self, arg);
        break;
    case METH_VARARGS | METH_KEYWORDS:
        return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
    case METH_NOARGS:
        if (likely(kw == NULL) || PyDict_Size(kw) == 0) {
            size = PyTuple_GET_SIZE(arg);
            if (size == 0)
                return (*meth)(self, NULL);
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes no arguments (%zd given)",
                f->m_ml->ml_name, size);
            return NULL;
        }
        break;
    case METH_O:
        if (likely(kw == NULL) || PyDict_Size(kw) == 0) {
            size = PyTuple_GET_SIZE(arg);
            if (size == 1)
                return (*meth)(self, PyTuple_GET_ITEM(arg, 0));
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes exactly one argument (%zd given)",
                f->m_ml->ml_name, size);
            return NULL;
        }
        break;
    default:
        PyErr_SetString(PyExc_SystemError, "Bad call flags in "
                        "__Pyx_CyFunction_Call. METH_OLDARGS is no "
                        "longer supported!");
        return NULL;
    }
    PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
                 f->m_ml->ml_name);
    return NULL;
}
#else
static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
	return PyCFunction_Call(func, arg, kw);
}
#endif
static PyTypeObject __pyx_CyFunctionType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    "cython_function_or_method",
    sizeof(__pyx_CyFunctionObject),
    0,
    (destructor) __Pyx_CyFunction_dealloc,
    0,
    0,
    0,
#if PY_MAJOR_VERSION < 3
    0,
#else
    0,
#endif
    (reprfunc) __Pyx_CyFunction_repr,
    0,
    0,
    0,
    0,
    __Pyx_CyFunction_Call,
    0,
    0,
    0,
    0,
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
    0,
    (traverseproc) __Pyx_CyFunction_traverse,
    (inquiry) __Pyx_CyFunction_clear,
    0,
#if PY_VERSION_HEX < 0x030500A0
    offsetof(__pyx_CyFunctionObject, func_weakreflist),
#else
    offsetof(PyCFunctionObject, m_weakreflist),
#endif
    0,
    0,
    __pyx_CyFunction_methods,
    __pyx_CyFunction_members,
    __pyx_CyFunction_getsets,
    0,
    0,
    __Pyx_CyFunction_descr_get,
    0,
    offsetof(__pyx_CyFunctionObject, func_dict),
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
#if PY_VERSION_HEX >= 0x030400a1
    0,
#endif
};
static int __Pyx_CyFunction_init(void) {
#if !CYTHON_COMPILING_IN_PYPY
    __pyx_CyFunctionType_type.tp_call = PyCFunction_Call;
#endif
    __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
    if (__pyx_CyFunctionType == NULL) {
        return -1;
    }
    return 0;
}
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults = PyMem_Malloc(size);
    if (!m->defaults)
        return PyErr_NoMemory();
    memset(m->defaults, 0, size);
    m->defaults_pyobjects = pyobjects;
    return m->defaults;
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_tuple = tuple;
    Py_INCREF(tuple);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_kwdict = dict;
    Py_INCREF(dict);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->func_annotations = dict;
    Py_INCREF(dict);
}

static 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
}

static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
}

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    } else {
        return __Pyx_IterFinish();
    }
    return 0;
}

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
#if CYTHON_COMPILING_IN_CPYTHON
#if PY_MAJOR_VERSION >= 3
    if (likely(PyUnicode_Check(n)))
#else
    if (likely(PyString_Check(n)))
#endif
        return __Pyx_PyObject_GetAttrStr(o, n);
#endif
    return PyObject_GetAttr(o, n);
}

static PyObject* __Pyx_Globals(void) {
    Py_ssize_t i;
    PyObject *names;
    PyObject *globals = __pyx_d;
    Py_INCREF(globals);
    names = PyObject_Dir(__pyx_m);
    if (!names)
        goto bad;
    for (i = PyList_GET_SIZE(names)-1; i >= 0; i--) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject* name = PySequence_GetItem(names, i);
        if (!name)
            goto bad;
#else
        PyObject* name = PyList_GET_ITEM(names, i);
#endif
        if (!PyDict_Contains(globals, name)) {
            PyObject* value = __Pyx_GetAttr(__pyx_m, name);
            if (!value) {
#if CYTHON_COMPILING_IN_PYPY
                Py_DECREF(name);
#endif
                goto bad;
            }
            if (PyDict_SetItem(globals, name, value) < 0) {
#if CYTHON_COMPILING_IN_PYPY
                Py_DECREF(name);
#endif
                Py_DECREF(value);
                goto bad;
            }
        }
#if CYTHON_COMPILING_IN_PYPY
        Py_DECREF(name);
#endif
    }
    Py_DECREF(names);
    return globals;
bad:
    Py_XDECREF(names);
    Py_XDECREF(globals);
    return NULL;
}

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 PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (PyErr_ExceptionMatches(PyExc_OverflowError))
                        PyErr_Clear();
                    else
                        return NULL;
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
#else
    PyErr_GetExcInfo(type, value, tb);
#endif
}
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(type, value, tb);
#endif
}

static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
    PyObject *method, *result = NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto bad;
#if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *args;
            PyObject *function = PyMethod_GET_FUNCTION(method);
            args = PyTuple_New(2);
            if (unlikely(!args)) goto bad;
            Py_INCREF(self);
            PyTuple_SET_ITEM(args, 0, self);
            Py_INCREF(arg);
            PyTuple_SET_ITEM(args, 1, arg);
            Py_INCREF(function);
            Py_DECREF(method); method = NULL;
            result = __Pyx_PyObject_Call(function, args, NULL);
            Py_DECREF(args);
            Py_DECREF(function);
            return result;
        }
    }
#endif
    result = __Pyx_PyObject_CallOneArg(method, arg);
bad:
    Py_XDECREF(method);
    return result;
}

static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
    } else {
        PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x);
        if (unlikely(!retval))
            return -1;
        Py_DECREF(retval);
    }
    return 0;
}

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_COMPILING_IN_CPYTHON
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

static CYTHON_INLINE 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;
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                if (PyObject_IsSubclass(instance_class, type)) {
                    type = instance_class;
                } else {
                    instance_class = NULL;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
#if PY_VERSION_HEX >= 0x03030000
    if (cause) {
#else
    if (cause && cause != Py_None) {
#endif
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(tmp_type, tmp_value, tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#else
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

static CYTHON_INLINE 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 int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

static void* __Pyx_GetVtable(PyObject *dict) {
    void* ptr;
    PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable);
    if (!ob)
        goto bad;
#if PY_VERSION_HEX >= 0x02070000
    ptr = PyCapsule_GetPointer(ob, 0);
#else
    ptr = PyCObject_AsVoidPtr(ob);
#endif
    if (!ptr && !PyErr_Occurred())
        PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
    Py_DECREF(ob);
    return ptr;
bad:
    Py_XDECREF(ob);
    return NULL;
}

static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) {
    Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases);
    for (i=0; i < nbases; i++) {
        PyTypeObject *tmptype;
        PyObject *tmp = PyTuple_GET_ITEM(bases, i);
        tmptype = Py_TYPE(tmp);
#if PY_MAJOR_VERSION < 3
        if (tmptype == &PyClass_Type)
            continue;
#endif
        if (!metaclass) {
            metaclass = tmptype;
            continue;
        }
        if (PyType_IsSubtype(metaclass, tmptype))
            continue;
        if (PyType_IsSubtype(tmptype, metaclass)) {
            metaclass = tmptype;
            continue;
        }
        PyErr_SetString(PyExc_TypeError,
                        "metaclass conflict: "
                        "the metaclass of a derived class "
                        "must be a (non-strict) subclass "
                        "of the metaclasses of all its bases");
        return NULL;
    }
    if (!metaclass) {
#if PY_MAJOR_VERSION < 3
        metaclass = &PyClass_Type;
#else
        metaclass = &PyType_Type;
#endif
    }
    Py_INCREF((PyObject*) metaclass);
    return (PyObject*) metaclass;
}

static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name,
                                           PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) {
    PyObject *ns;
    if (metaclass) {
        PyObject *prep = __Pyx_PyObject_GetAttrStr(metaclass, __pyx_n_s_prepare);
        if (prep) {
            PyObject *pargs = PyTuple_Pack(2, name, bases);
            if (unlikely(!pargs)) {
                Py_DECREF(prep);
                return NULL;
            }
            ns = PyObject_Call(prep, pargs, mkw);
            Py_DECREF(prep);
            Py_DECREF(pargs);
        } else {
            if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError)))
                return NULL;
            PyErr_Clear();
            ns = PyDict_New();
        }
    } else {
        ns = PyDict_New();
    }
    if (unlikely(!ns))
        return NULL;
    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_module, modname) < 0)) goto bad;
    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_qualname, qualname) < 0)) goto bad;
    if (unlikely(doc && PyObject_SetItem(ns, __pyx_n_s_doc, doc) < 0)) goto bad;
    return ns;
bad:
    Py_DECREF(ns);
    return NULL;
}
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases,
                                      PyObject *dict, PyObject *mkw,
                                      int calculate_metaclass, int allow_py2_metaclass) {
    PyObject *result, *margs;
    PyObject *owned_metaclass = NULL;
    if (allow_py2_metaclass) {
        owned_metaclass = PyObject_GetItem(dict, __pyx_n_s_metaclass);
        if (owned_metaclass) {
            metaclass = owned_metaclass;
        } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
            PyErr_Clear();
        } else {
            return NULL;
        }
    }
    if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) {
        metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
        Py_XDECREF(owned_metaclass);
        if (unlikely(!metaclass))
            return NULL;
        owned_metaclass = metaclass;
    }
    margs = PyTuple_Pack(3, name, bases, dict);
    if (unlikely(!margs)) {
        result = NULL;
    } else {
        result = PyObject_Call(metaclass, margs, mkw);
        Py_DECREF(margs);
    }
    Py_XDECREF(owned_metaclass);
    return result;
}

static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = (start + end) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    py_code = __pyx_find_code_object(c_line ? c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        __pyx_d,      /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = py_line;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_VERSION_HEX < 0x03030000
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                #if PY_VERSION_HEX < 0x03030000
                PyObject *py_level = PyInt_FromLong(1);
                if (!py_level)
                    goto bad;
                module = PyObject_CallFunctionObjArgs(py_import,
                    name, global_dict, empty_dict, list, py_level, NULL);
                Py_DECREF(py_level);
                #else
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                #endif
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_VERSION_HEX < 0x03030000
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_VERSION_HEX < 0x03030000
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(long) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)       \
    {                                                                     \
        func_type value = func_value;                                     \
        if (sizeof(target_type) < sizeof(func_type)) {                    \
            if (unlikely(value != (func_type) (target_type) value)) {     \
                func_type zero = 0;                                       \
                if (is_unsigned && unlikely(value < zero))                \
                    goto raise_neg_overflow;                              \
                else                                                      \
                    goto raise_overflow;                                  \
            }                                                             \
        }                                                                 \
        return (target_type) value;                                       \
    }

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif

static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(int, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(int) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(int, unsigned long long, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +(((PyLongObject*)x)->ob_digit[0]));
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(int, long, PyLong_AsLong(x))
            } else if (sizeof(int) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(int, long long, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE 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 1
    if (unlikely(e<0)) return 0;
    #endif
    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 0
    if (unlikely(e<0)) return 0;
    #endif
    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_From_uint64_t(uint64_t value) {
    const uint64_t neg_one = (uint64_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint64_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint64_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(uint64_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(uint64_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint64_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint64_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value) {
    const uint16_t neg_one = (uint16_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint16_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint16_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(uint16_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(uint16_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint16_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint16_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(long, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(long) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(long, unsigned long long, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +(((PyLongObject*)x)->ob_digit[0]));
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(long, long, PyLong_AsLong(x))
            } else if (sizeof(long) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(long, long long, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

static PyObject *__Pyx_Generator_Next(PyObject *self);
static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value);
static PyObject *__Pyx_Generator_Close(PyObject *self);
static PyObject *__Pyx_Generator_Throw(PyObject *gen, PyObject *args);
static PyTypeObject *__pyx_GeneratorType = 0;
#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType)
#define __Pyx_Generator_Undelegate(gen) Py_CLEAR((gen)->yieldfrom)
#if 1 || PY_VERSION_HEX < 0x030300B0
static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
    PyObject *et, *ev, *tb;
    PyObject *value = NULL;
    __Pyx_ErrFetch(&et, &ev, &tb);
    if (!et) {
        Py_XDECREF(tb);
        Py_XDECREF(ev);
        Py_INCREF(Py_None);
        *pvalue = Py_None;
        return 0;
    }
    if (unlikely(et != PyExc_StopIteration) &&
            unlikely(!PyErr_GivenExceptionMatches(et, PyExc_StopIteration))) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    if (likely(et == PyExc_StopIteration)) {
        if (likely(!ev) || !PyObject_IsInstance(ev, PyExc_StopIteration)) {
            if (!ev) {
                Py_INCREF(Py_None);
                ev = Py_None;
            }
            Py_XDECREF(tb);
            Py_DECREF(et);
            *pvalue = ev;
            return 0;
        }
    }
    PyErr_NormalizeException(&et, &ev, &tb);
    if (unlikely(!PyObject_IsInstance(ev, PyExc_StopIteration))) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    Py_XDECREF(tb);
    Py_DECREF(et);
#if PY_VERSION_HEX >= 0x030300A0
    value = ((PyStopIterationObject *)ev)->value;
    Py_INCREF(value);
    Py_DECREF(ev);
#else
    {
        PyObject* args = PyObject_GetAttr(ev, __pyx_n_s_args);
        Py_DECREF(ev);
        if (likely(args)) {
            value = PyObject_GetItem(args, 0);
            Py_DECREF(args);
        }
        if (unlikely(!value)) {
            __Pyx_ErrRestore(NULL, NULL, NULL);
            Py_INCREF(Py_None);
            value = Py_None;
        }
    }
#endif
    *pvalue = value;
    return 0;
}
#endif
static CYTHON_INLINE
void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self) {
    PyObject *exc_type = self->exc_type;
    PyObject *exc_value = self->exc_value;
    PyObject *exc_traceback = self->exc_traceback;
    self->exc_type = NULL;
    self->exc_value = NULL;
    self->exc_traceback = NULL;
    Py_XDECREF(exc_type);
    Py_XDECREF(exc_value);
    Py_XDECREF(exc_traceback);
}
static CYTHON_INLINE
int __Pyx_Generator_CheckRunning(__pyx_GeneratorObject *gen) {
    if (unlikely(gen->is_running)) {
        PyErr_SetString(PyExc_ValueError,
                        "generator already executing");
        return 1;
    }
    return 0;
}
static CYTHON_INLINE
PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) {
    PyObject *retval;
    assert(!self->is_running);
    if (unlikely(self->resume_label == 0)) {
        if (unlikely(value && value != Py_None)) {
            PyErr_SetString(PyExc_TypeError,
                            "can't send non-None value to a "
                            "just-started generator");
            return NULL;
        }
    }
    if (unlikely(self->resume_label == -1)) {
        PyErr_SetNone(PyExc_StopIteration);
        return NULL;
    }
    if (value) {
#if CYTHON_COMPILING_IN_PYPY
#else
        if (self->exc_traceback) {
            PyThreadState *tstate = PyThreadState_GET();
            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            Py_XINCREF(tstate->frame);
            assert(f->f_back == NULL);
            f->f_back = tstate->frame;
        }
#endif
        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                            &self->exc_traceback);
    } else {
        __Pyx_Generator_ExceptionClear(self);
    }
    self->is_running = 1;
    retval = self->body((PyObject *) self, value);
    self->is_running = 0;
    if (retval) {
        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                            &self->exc_traceback);
#if CYTHON_COMPILING_IN_PYPY
#else
        if (self->exc_traceback) {
            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            Py_CLEAR(f->f_back);
        }
#endif
    } else {
        __Pyx_Generator_ExceptionClear(self);
    }
    return retval;
}
static CYTHON_INLINE
PyObject *__Pyx_Generator_FinishDelegation(__pyx_GeneratorObject *gen) {
    PyObject *ret;
    PyObject *val = NULL;
    __Pyx_Generator_Undelegate(gen);
    __Pyx_PyGen_FetchStopIterationValue(&val);
    ret = __Pyx_Generator_SendEx(gen, val);
    Py_XDECREF(val);
    return ret;
}
static PyObject *__Pyx_Generator_Next(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        ret = Py_TYPE(yf)->tp_iternext(yf);
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        return __Pyx_Generator_FinishDelegation(gen);
    }
    return __Pyx_Generator_SendEx(gen, Py_None);
}
static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Generator_Send(yf, value);
        } else {
            if (value == Py_None)
                ret = PyIter_Next(yf);
            else
                ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value);
        }
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        return __Pyx_Generator_FinishDelegation(gen);
    }
    return __Pyx_Generator_SendEx(gen, value);
}
static int __Pyx_Generator_CloseIter(__pyx_GeneratorObject *gen, PyObject *yf) {
    PyObject *retval = NULL;
    int err = 0;
    if (__Pyx_Generator_CheckExact(yf)) {
        retval = __Pyx_Generator_Close(yf);
        if (!retval)
            return -1;
    } else {
        PyObject *meth;
        gen->is_running = 1;
        meth = PyObject_GetAttr(yf, __pyx_n_s_close);
        if (unlikely(!meth)) {
            if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                PyErr_WriteUnraisable(yf);
            }
            PyErr_Clear();
        } else {
            retval = PyObject_CallFunction(meth, NULL);
            Py_DECREF(meth);
            if (!retval)
                err = -1;
        }
        gen->is_running = 0;
    }
    Py_XDECREF(retval);
    return err;
}
static PyObject *__Pyx_Generator_Close(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    PyObject *retval, *raised_exception;
    PyObject *yf = gen->yieldfrom;
    int err = 0;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        Py_INCREF(yf);
        err = __Pyx_Generator_CloseIter(gen, yf);
        __Pyx_Generator_Undelegate(gen);
        Py_DECREF(yf);
    }
    if (err == 0)
        PyErr_SetNone(PyExc_GeneratorExit);
    retval = __Pyx_Generator_SendEx(gen, NULL);
    if (retval) {
        Py_DECREF(retval);
        PyErr_SetString(PyExc_RuntimeError,
                        "generator ignored GeneratorExit");
        return NULL;
    }
    raised_exception = PyErr_Occurred();
    if (!raised_exception
        || raised_exception == PyExc_StopIteration
        || raised_exception == PyExc_GeneratorExit
        || PyErr_GivenExceptionMatches(raised_exception, PyExc_GeneratorExit)
        || PyErr_GivenExceptionMatches(raised_exception, PyExc_StopIteration))
    {
        if (raised_exception) PyErr_Clear();
        Py_INCREF(Py_None);
        return Py_None;
    }
    return NULL;
}
static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    PyObject *typ;
    PyObject *tb = NULL;
    PyObject *val = NULL;
    PyObject *yf = gen->yieldfrom;
    if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
        return NULL;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        Py_INCREF(yf);
        if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) {
            int err = __Pyx_Generator_CloseIter(gen, yf);
            Py_DECREF(yf);
            __Pyx_Generator_Undelegate(gen);
            if (err < 0)
                return __Pyx_Generator_SendEx(gen, NULL);
            goto throw_here;
        }
        gen->is_running = 1;
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Generator_Throw(yf, args);
        } else {
            PyObject *meth = PyObject_GetAttr(yf, __pyx_n_s_throw);
            if (unlikely(!meth)) {
                Py_DECREF(yf);
                if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                    gen->is_running = 0;
                    return NULL;
                }
                PyErr_Clear();
                __Pyx_Generator_Undelegate(gen);
                gen->is_running = 0;
                goto throw_here;
            }
            ret = PyObject_CallObject(meth, args);
            Py_DECREF(meth);
        }
        gen->is_running = 0;
        Py_DECREF(yf);
        if (!ret) {
            ret = __Pyx_Generator_FinishDelegation(gen);
        }
        return ret;
    }
throw_here:
    __Pyx_Raise(typ, val, tb, NULL);
    return __Pyx_Generator_SendEx(gen, NULL);
}
static int __Pyx_Generator_traverse(PyObject *self, visitproc visit, void *arg) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    Py_VISIT(gen->closure);
    Py_VISIT(gen->classobj);
    Py_VISIT(gen->yieldfrom);
    Py_VISIT(gen->exc_type);
    Py_VISIT(gen->exc_value);
    Py_VISIT(gen->exc_traceback);
    return 0;
}
static int __Pyx_Generator_clear(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    Py_CLEAR(gen->closure);
    Py_CLEAR(gen->classobj);
    Py_CLEAR(gen->yieldfrom);
    Py_CLEAR(gen->exc_type);
    Py_CLEAR(gen->exc_value);
    Py_CLEAR(gen->exc_traceback);
    Py_CLEAR(gen->gi_name);
    Py_CLEAR(gen->gi_qualname);
    return 0;
}
static void __Pyx_Generator_dealloc(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    PyObject_GC_UnTrack(gen);
    if (gen->gi_weakreflist != NULL)
        PyObject_ClearWeakRefs(self);
    if (gen->resume_label > 0) {
        PyObject_GC_Track(self);
#if PY_VERSION_HEX >= 0x030400a1
        if (PyObject_CallFinalizerFromDealloc(self))
#else
        Py_TYPE(gen)->tp_del(self);
        if (self->ob_refcnt > 0)
#endif
        {
            return;
        }
        PyObject_GC_UnTrack(self);
    }
    __Pyx_Generator_clear(self);
    PyObject_GC_Del(gen);
}
static void __Pyx_Generator_del(PyObject *self) {
    PyObject *res;
    PyObject *error_type, *error_value, *error_traceback;
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    if (gen->resume_label <= 0)
        return ;
#if PY_VERSION_HEX < 0x030400a1
    assert(self->ob_refcnt == 0);
    self->ob_refcnt = 1;
#endif
    __Pyx_ErrFetch(&error_type, &error_value, &error_traceback);
    res = __Pyx_Generator_Close(self);
    if (res == NULL)
        PyErr_WriteUnraisable(self);
    else
        Py_DECREF(res);
    __Pyx_ErrRestore(error_type, error_value, error_traceback);
#if PY_VERSION_HEX < 0x030400a1
    assert(self->ob_refcnt > 0);
    if (--self->ob_refcnt == 0) {
        return;
    }
    {
        Py_ssize_t refcnt = self->ob_refcnt;
        _Py_NewReference(self);
        self->ob_refcnt = refcnt;
    }
#if CYTHON_COMPILING_IN_CPYTHON
    assert(PyType_IS_GC(self->ob_type) &&
           _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
    _Py_DEC_REFTOTAL;
#endif
#ifdef COUNT_ALLOCS
    --Py_TYPE(self)->tp_frees;
    --Py_TYPE(self)->tp_allocs;
#endif
#endif
}
static PyObject *
__Pyx_Generator_get_name(__pyx_GeneratorObject *self)
{
    Py_INCREF(self->gi_name);
    return self->gi_name;
}
static int
__Pyx_Generator_set_name(__pyx_GeneratorObject *self, PyObject *value)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
    if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
        PyErr_SetString(PyExc_TypeError,
                        "__name__ must be set to a string object");
        return -1;
    }
    tmp = self->gi_name;
    Py_INCREF(value);
    self->gi_name = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_Generator_get_qualname(__pyx_GeneratorObject *self)
{
    Py_INCREF(self->gi_qualname);
    return self->gi_qualname;
}
static int
__Pyx_Generator_set_qualname(__pyx_GeneratorObject *self, PyObject *value)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
    if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
        PyErr_SetString(PyExc_TypeError,
                        "__qualname__ must be set to a string object");
        return -1;
    }
    tmp = self->gi_qualname;
    Py_INCREF(value);
    self->gi_qualname = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyGetSetDef __pyx_Generator_getsets[] = {
    {(char *) "__name__", (getter)__Pyx_Generator_get_name, (setter)__Pyx_Generator_set_name,
     (char*) PyDoc_STR("name of the generator"), 0},
    {(char *) "__qualname__", (getter)__Pyx_Generator_get_qualname, (setter)__Pyx_Generator_set_qualname,
     (char*) PyDoc_STR("qualified name of the generator"), 0},
    {0, 0, 0, 0, 0}
};
static PyMemberDef __pyx_Generator_memberlist[] = {
    {(char *) "gi_running", T_BOOL, offsetof(__pyx_GeneratorObject, is_running), READONLY, NULL},
    {0, 0, 0, 0, 0}
};
static PyMethodDef __pyx_Generator_methods[] = {
    {"send", (PyCFunction) __Pyx_Generator_Send, METH_O, 0},
    {"throw", (PyCFunction) __Pyx_Generator_Throw, METH_VARARGS, 0},
    {"close", (PyCFunction) __Pyx_Generator_Close, METH_NOARGS, 0},
    {0, 0, 0, 0}
};
static PyTypeObject __pyx_GeneratorType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    "generator",
    sizeof(__pyx_GeneratorObject),
    0,
    (destructor) __Pyx_Generator_dealloc,
    0,
    0,
    0,
#if PY_MAJOR_VERSION < 3
    0,
#else
    0,
#endif
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE,
    0,
    (traverseproc) __Pyx_Generator_traverse,
    0,
    0,
    offsetof(__pyx_GeneratorObject, gi_weakreflist),
    0,
    (iternextfunc) __Pyx_Generator_Next,
    __pyx_Generator_methods,
    __pyx_Generator_memberlist,
    __pyx_Generator_getsets,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
#if PY_VERSION_HEX >= 0x030400a1
    0,
#else
    __Pyx_Generator_del,
#endif
    0,
#if PY_VERSION_HEX >= 0x030400a1
    __Pyx_Generator_del,
#endif
};
static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body,
                                                  PyObject *closure, PyObject *name, PyObject *qualname) {
    __pyx_GeneratorObject *gen =
        PyObject_GC_New(__pyx_GeneratorObject, &__pyx_GeneratorType_type);
    if (gen == NULL)
        return NULL;
    gen->body = body;
    gen->closure = closure;
    Py_XINCREF(closure);
    gen->is_running = 0;
    gen->resume_label = 0;
    gen->classobj = NULL;
    gen->yieldfrom = NULL;
    gen->exc_type = NULL;
    gen->exc_value = NULL;
    gen->exc_traceback = NULL;
    gen->gi_weakreflist = NULL;
    Py_XINCREF(qualname);
    gen->gi_qualname = qualname;
    Py_XINCREF(name);
    gen->gi_name = name;
    PyObject_GC_Track(gen);
    return gen;
}
static int __pyx_Generator_init(void) {
    __pyx_GeneratorType_type.tp_getattro = PyObject_GenericGetAttr;
    __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter;
    __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type);
    if (__pyx_GeneratorType == NULL) {
        return -1;
    }
    return 0;
}

static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

#ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
    PyObject *py_name = 0;
    PyObject *py_module = 0;
    py_name = __Pyx_PyIdentifier_FromString(name);
    if (!py_name)
        goto bad;
    py_module = PyImport_Import(py_name);
    Py_DECREF(py_name);
    return py_module;
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
    size_t size, int strict)
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    PyObject *py_name = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    py_module = __Pyx_ImportModule(module_name);
    if (!py_module)
        goto bad;
    py_name = __Pyx_PyIdentifier_FromString(class_name);
    if (!py_name)
        goto bad;
    result = PyObject_GetAttr(py_module, py_name);
    Py_DECREF(py_name);
    py_name = 0;
    Py_DECREF(py_module);
    py_module = 0;
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if (!strict && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility",
            module_name, class_name);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    else if ((size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s has the wrong size, try recompiling",
            module_name, class_name);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#endif

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
#if PY_VERSION_HEX < 0x03030000
        char* defenc_c;
        PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
        if (!defenc) return NULL;
        defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        {
            char* end = defenc_c + PyBytes_GET_SIZE(defenc);
            char* c;
            for (c = defenc_c; c < end; c++) {
                if ((unsigned char) (*c) >= 128) {
                    PyUnicode_AsASCIIString(o);
                    return NULL;
                }
            }
        }
#endif
        *length = PyBytes_GET_SIZE(defenc);
        return defenc_c;
#else
        if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        if (PyUnicode_IS_ASCII(o)) {
            *length = PyUnicode_GET_LENGTH(o);
            return PyUnicode_AsUTF8(o);
        } else {
            PyUnicode_AsASCIIString(o);
            return NULL;
        }
#else
        return PyUnicode_AsUTF8AndSize(o, length);
#endif
#endif
    } else
#endif
#if !CYTHON_COMPILING_IN_PYPY
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_MAJOR_VERSION < 3
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%.4s__ returned non-%.4s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b)))
      return PyInt_AS_LONG(b);
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
     #if CYTHON_USE_PYLONG_INTERNALS
       switch (Py_SIZE(b)) {
       case -1: return -(sdigit)((PyLongObject*)b)->ob_digit[0];
       case  0: return 0;
       case  1: return ((PyLongObject*)b)->ob_digit[0];
       }
     #endif
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
