/* Generated by Cython 0.22 */

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


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

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

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

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif

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

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


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

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


static const char *__pyx_f[] = {
  "pysam/cfaidx.pyx",
  "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_FastxFile;
struct __pyx_obj_5pysam_6cfaidx_FastqFile;
struct __pyx_obj_5pysam_6cfaidx_Fastafile;
struct __pyx_obj_5pysam_6cfaidx_Fastqfile;
struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open;
struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr;
struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr;

/* "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 FastxFile:             # <<<<<<<<<<<<<<
 *     cdef object _filename
 *     cdef gzFile fastqfile
 */
struct __pyx_obj_5pysam_6cfaidx_FastxFile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile *__pyx_vtab;
  PyObject *_filename;
  gzFile fastqfile;
  kseq_t *entry;
};


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


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


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


/* "pysam/cfaidx.pyx":93
 *         return faidx_nseq(self.fastafile)
 * 
 *     def _open(self, filename):             # <<<<<<<<<<<<<<
 *         '''open an indexed fasta file.
 * 
 */
struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open {
  PyObject_HEAD
  PyObject *__pyx_v_data;
};


/* "pysam/cfaidx.pyx":113
 *         with open( self._filename + b".fai" ) as inf:
 *             data = [ x.split("\t") for x in inf ]
 *             self._references = tuple(x[0] for x in data)             # <<<<<<<<<<<<<<
 *             self._lengths = tuple(int(x[1]) for x in data)
 *             self.reference2length = dict(zip(self._references, self._lengths))
 */
struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr {
  PyObject_HEAD
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *__pyx_outer_scope;
  PyObject *__pyx_v_x;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
};


/* "pysam/cfaidx.pyx":114
 *             data = [ x.split("\t") for x in inf ]
 *             self._references = tuple(x[0] for x in data)
 *             self._lengths = tuple(int(x[1]) for x in data)             # <<<<<<<<<<<<<<
 *             self.reference2length = dict(zip(self._references, self._lengths))
 * 
 */
struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr {
  PyObject_HEAD
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *__pyx_outer_scope;
  PyObject *__pyx_v_x;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
};



/* "pysam/cfaidx.pyx":66
 * ##        add automatic indexing.
 * ##        add function to get sequence names.
 * cdef class FastaFile:             # <<<<<<<<<<<<<<
 *     '''*(filename)*
 * 
 */

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.pyx":265
 * 
 * 
 * cdef class FastxFile:             # <<<<<<<<<<<<<<
 *     '''*(filename)*
 * 
 */

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


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

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


/* "pysam/cfaidx.pyx":347
 * 
 * # 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.pyx":350
 *     pass
 * 
 * cdef class Fastqfile(FastxFile):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */

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

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

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

static PyObject *__Pyx_GetBuiltinName(PyObject *name);

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

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

#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 CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb);

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

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

static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname);

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

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

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);

#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name) {
    PyObject *res;
    PyTypeObject *tp = Py_TYPE(obj);
#if PY_MAJOR_VERSION < 3
    if (unlikely(PyInstance_Check(obj)))
        return __Pyx_PyObject_GetAttrStr(obj, attr_name);
#endif
    res = _PyType_Lookup(tp, attr_name);
    if (likely(res)) {
        descrgetfunc f = Py_TYPE(res)->tp_descr_get;
        if (!f) {
            Py_INCREF(res);
        } else {
            res = f(res, obj, (PyObject *)tp);
        }
    } else {
        PyErr_SetObject(PyExc_AttributeError, attr_name);
    }
    return res;
}
#else
#define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n)
#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 int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);

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

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

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

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

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

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

#include <string.h>

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

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 PyObject* __Pyx_PyInt_From_int(int value);

static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);

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

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

static int __Pyx_check_binary_version(void);

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

static PyObject *__Pyx_ImportModule(const char *name);

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

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);

static char *__pyx_f_5pysam_6cfaidx_9FastaFile__fetch(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, char *__pyx_v_reference, int __pyx_v_start, int __pyx_v_end, int *__pyx_v_length); /* proto*/
static kseq_t *__pyx_f_5pysam_6cfaidx_9FastxFile_getCurrent(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_6cfaidx_9FastxFile_cnext(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self); /* proto*/

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* Module declarations from 'cpython' */

/* Module declarations from 'pysam.cfaidx' */
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_FastaFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_FastqProxy = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_FastxFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_FastqFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_Fastafile = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_Fastqfile = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx___pyx_scope_struct___open = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx___pyx_scope_struct_1_genexpr = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx___pyx_scope_struct_2_genexpr = 0;
static PyObject *__pyx_v_5pysam_6cfaidx__FILENAME_ENCODING = 0;
static int __pyx_v_5pysam_6cfaidx_max_pos;
static PyObject *__pyx_f_5pysam_6cfaidx_makeFastqProxy(kseq_t *); /*proto*/
static PyObject *__pyx_f_5pysam_6cfaidx__encodeFilename(PyObject *); /*proto*/
#define __Pyx_MODULE_NAME "pysam.cfaidx"
int __pyx_module_is_main_pysam__cfaidx = 0;

/* Implementation of 'pysam.cfaidx' */
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_IOError;
static PyObject *__pyx_builtin_open;
static PyObject *__pyx_builtin_zip;
static PyObject *__pyx_builtin_IndexError;
static PyObject *__pyx_builtin_StopIteration;
static int __pyx_pf_5pysam_6cfaidx_9FastaFile___cinit__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_2_isOpen(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self); /* proto */
static Py_ssize_t __pyx_pf_5pysam_6cfaidx_9FastaFile_4__len__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_5_open_genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_5_open_3genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_6_open(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_filename); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_8close(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_6cfaidx_9FastaFile_10__dealloc__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_8filename___get__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_10references___get__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_11nreferences___get__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_7lengths___get__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_12fetch(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_14get_reference_length(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_16__getitem__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static int __pyx_pf_5pysam_6cfaidx_9FastaFile_18__contains__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static int __pyx_pf_5pysam_6cfaidx_10FastqProxy___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastqProxy *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_10FastqProxy_4name___get__(struct __pyx_obj_5pysam_6cfaidx_FastqProxy *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_10FastqProxy_8sequence___get__(struct __pyx_obj_5pysam_6cfaidx_FastqProxy *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_10FastqProxy_7comment___get__(struct __pyx_obj_5pysam_6cfaidx_FastqProxy *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_10FastqProxy_7quality___get__(struct __pyx_obj_5pysam_6cfaidx_FastqProxy *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_6cfaidx_9FastxFile___cinit__(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastxFile_2_isOpen(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastxFile_4_open(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self, PyObject *__pyx_v_filename); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastxFile_6close(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_6cfaidx_9FastxFile_8__dealloc__(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastxFile_8filename___get__(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastxFile_10__iter__(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_6cfaidx_9FastxFile_12__next__(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self); /* proto */
static PyObject *__pyx_tp_new_5pysam_6cfaidx_FastaFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_6cfaidx_FastqProxy(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_6cfaidx_FastxFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_6cfaidx_FastqFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_6cfaidx_Fastafile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_6cfaidx_Fastqfile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_6cfaidx___pyx_scope_struct___open(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_6cfaidx___pyx_scope_struct_1_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_6cfaidx___pyx_scope_struct_2_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static char __pyx_k_r[] = "r";
static char __pyx_k__3[] = "\t";
static char __pyx_k__8[] = "";
static char __pyx_k_os[] = "os";
static char __pyx_k_all[] = "__all__";
static char __pyx_k_end[] = "end";
static char __pyx_k_fai[] = ".fai";
static char __pyx_k_sys[] = "sys";
static char __pyx_k_zip[] = "zip";
static char __pyx_k_args[] = "args";
static char __pyx_k_exit[] = "__exit__";
static char __pyx_k_main[] = "__main__";
static char __pyx_k_open[] = "open";
static char __pyx_k_path[] = "path";
static char __pyx_k_send[] = "send";
static char __pyx_k_test[] = "__test__";
static char __pyx_k_ascii[] = "ascii";
static char __pyx_k_close[] = "close";
static char __pyx_k_enter[] = "__enter__";
static char __pyx_k_fetch[] = "fetch";
static char __pyx_k_s_i_i[] = "%s:%i-%i";
static char __pyx_k_split[] = "split";
static char __pyx_k_start[] = "start";
static char __pyx_k_throw[] = "throw";
static char __pyx_k_encode[] = "encode";
static char __pyx_k_exists[] = "exists";
static char __pyx_k_import[] = "__import__";
static char __pyx_k_isOpen[] = "_isOpen";
static char __pyx_k_open_2[] = "_open";
static char __pyx_k_region[] = "region";
static char __pyx_k_IOError[] = "IOError";
static char __pyx_k_genexpr[] = "genexpr";
static char __pyx_k_FastaFile[] = "FastaFile";
static char __pyx_k_Fastafile[] = "Fastafile";
static char __pyx_k_FastqFile[] = "FastqFile";
static char __pyx_k_Fastqfile[] = "Fastqfile";
static char __pyx_k_TypeError[] = "TypeError";
static char __pyx_k_reference[] = "reference";
static char __pyx_k_IS_PYTHON3[] = "IS_PYTHON3";
static char __pyx_k_IndexError[] = "IndexError";
static char __pyx_k_ValueError[] = "ValueError";
static char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static char __pyx_k_references[] = "references";
static char __pyx_k_StopIteration[] = "StopIteration";
static char __pyx_k_end_out_of_range_i[] = "end out of range (%i)";
static char __pyx_k_getdefaultencoding[] = "getdefaultencoding";
static char __pyx_k_open_locals_genexpr[] = "_open.<locals>.genexpr";
static char __pyx_k_start_out_of_range_i[] = "start out of range (%i)";
static char __pyx_k_could_not_open_file_s[] = "could not open file `%s`";
static char __pyx_k_getfilesystemencoding[] = "getfilesystemencoding";
static char __pyx_k_calling_len_on_closed_file[] = "calling len() on closed file";
static char __pyx_k_could_not_locate_index_file[] = "could not locate index file";
static char __pyx_k_no_sequence_region_supplied[] = "no sequence/region supplied.";
static char __pyx_k_no_such_file_or_directory_s[] = "no such file or directory: %s";
static char __pyx_k_I_O_operation_on_closed_file[] = "I/O operation on closed file";
static char __pyx_k_invalid_region_start_i_end_i[] = "invalid region: start (%i) > end (%i)";
static char __pyx_k_Argument_must_be_string_or_unico[] = "Argument must be string or unicode.";
static char __pyx_k_filename_associated_with_this_ob[] = "filename associated with this object.";
static char __pyx_k_number_of_term_reference_sequenc[] = "number of :term:`reference` sequences in the file.";
static char __pyx_k_tuple_with_the_lengths_of_term_r[] = "tuple with the lengths of :term:`reference` sequences.";
static char __pyx_k_tuple_with_the_names_of_term_ref[] = "tuple with the names of :term:`reference` sequences.";
static PyObject *__pyx_kp_u_Argument_must_be_string_or_unico;
static PyObject *__pyx_n_s_FastaFile;
static PyObject *__pyx_n_s_Fastafile;
static PyObject *__pyx_n_s_FastqFile;
static PyObject *__pyx_n_s_Fastqfile;
static PyObject *__pyx_n_s_IOError;
static PyObject *__pyx_n_s_IS_PYTHON3;
static PyObject *__pyx_kp_s_I_O_operation_on_closed_file;
static PyObject *__pyx_n_s_IndexError;
static PyObject *__pyx_n_s_StopIteration;
static PyObject *__pyx_n_s_TypeError;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_kp_s__3;
static PyObject *__pyx_kp_b__8;
static PyObject *__pyx_n_s_all;
static PyObject *__pyx_n_s_args;
static PyObject *__pyx_n_s_ascii;
static PyObject *__pyx_kp_s_calling_len_on_closed_file;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_kp_s_could_not_locate_index_file;
static PyObject *__pyx_kp_s_could_not_open_file_s;
static PyObject *__pyx_n_s_encode;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_kp_s_end_out_of_range_i;
static PyObject *__pyx_n_s_enter;
static PyObject *__pyx_n_s_exists;
static PyObject *__pyx_n_s_exit;
static PyObject *__pyx_kp_b_fai;
static PyObject *__pyx_n_s_fetch;
static PyObject *__pyx_n_s_genexpr;
static PyObject *__pyx_n_s_getdefaultencoding;
static PyObject *__pyx_n_s_getfilesystemencoding;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_kp_s_invalid_region_start_i_end_i;
static PyObject *__pyx_n_s_isOpen;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_kp_s_no_sequence_region_supplied;
static PyObject *__pyx_kp_s_no_such_file_or_directory_s;
static PyObject *__pyx_n_s_open;
static PyObject *__pyx_n_s_open_2;
static PyObject *__pyx_n_s_open_locals_genexpr;
static PyObject *__pyx_n_s_os;
static PyObject *__pyx_n_s_path;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_s_reference;
static PyObject *__pyx_n_s_references;
static PyObject *__pyx_n_s_region;
static PyObject *__pyx_kp_s_s_i_i;
static PyObject *__pyx_n_s_send;
static PyObject *__pyx_n_s_split;
static PyObject *__pyx_n_s_start;
static PyObject *__pyx_kp_s_start_out_of_range_i;
static PyObject *__pyx_n_s_sys;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_throw;
static PyObject *__pyx_n_s_zip;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__4;
static PyObject *__pyx_tuple__5;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_tuple__7;
static PyObject *__pyx_tuple__9;
static PyObject *__pyx_tuple__10;

/* "pysam/cfaidx.pyx":8
 * 
 * cdef class FastqProxy
 * cdef makeFastqProxy(kseq_t * src):             # <<<<<<<<<<<<<<
 *     '''enter src into AlignedRead.'''
 *     cdef FastqProxy dest = FastqProxy.__new__(FastqProxy)
 */

static PyObject *__pyx_f_5pysam_6cfaidx_makeFastqProxy(kseq_t *__pyx_v_src) {
  struct __pyx_obj_5pysam_6cfaidx_FastqProxy *__pyx_v_dest = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("makeFastqProxy", 0);
  __Pyx_TraceCall("makeFastqProxy", __pyx_f[0], 8);

  /* "pysam/cfaidx.pyx":10
 * cdef makeFastqProxy(kseq_t * src):
 *     '''enter src into AlignedRead.'''
 *     cdef FastqProxy dest = FastqProxy.__new__(FastqProxy)             # <<<<<<<<<<<<<<
 *     dest._delegate = src
 *     return dest
 */
  __pyx_t_1 = __pyx_tp_new_5pysam_6cfaidx_FastqProxy(((PyTypeObject *)((PyObject*)__pyx_ptype_5pysam_6cfaidx_FastqProxy)), __pyx_empty_tuple, NULL); 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 (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_6cfaidx_FastqProxy)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest = ((struct __pyx_obj_5pysam_6cfaidx_FastqProxy *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/cfaidx.pyx":11
 *     '''enter src into AlignedRead.'''
 *     cdef FastqProxy dest = FastqProxy.__new__(FastqProxy)
 *     dest._delegate = src             # <<<<<<<<<<<<<<
 *     return dest
 * 
 */
  __pyx_v_dest->_delegate = __pyx_v_src;

  /* "pysam/cfaidx.pyx":12
 *     cdef FastqProxy dest = FastqProxy.__new__(FastqProxy)
 *     dest._delegate = src
 *     return dest             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_dest));
  __pyx_r = ((PyObject *)__pyx_v_dest);
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":8
 * 
 * cdef class FastqProxy
 * cdef makeFastqProxy(kseq_t * src):             # <<<<<<<<<<<<<<
 *     '''enter src into AlignedRead.'''
 *     cdef FastqProxy dest = FastqProxy.__new__(FastqProxy)
 */

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

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

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

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

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

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

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

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

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

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

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

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

/* "pysam/cfaidx.pyx":75
 *     '''
 * 
 *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
 *         self.fastafile = NULL
 *         self._filename = None
 */

/* Python wrapper */
static int __pyx_pw_5pysam_6cfaidx_9FastaFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_6cfaidx_9FastaFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return -1;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile___cinit__(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

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

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

  /* "pysam/cfaidx.pyx":76
 * 
 *     def __cinit__(self, *args, **kwargs ):
 *         self.fastafile = NULL             # <<<<<<<<<<<<<<
 *         self._filename = None
 *         self._references = None
 */
  __pyx_v_self->fastafile = NULL;

  /* "pysam/cfaidx.pyx":77
 *     def __cinit__(self, *args, **kwargs ):
 *         self.fastafile = NULL
 *         self._filename = None             # <<<<<<<<<<<<<<
 *         self._references = None
 *         self._lengths = None
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_filename);
  __Pyx_DECREF(__pyx_v_self->_filename);
  __pyx_v_self->_filename = Py_None;

  /* "pysam/cfaidx.pyx":78
 *         self.fastafile = NULL
 *         self._filename = None
 *         self._references = None             # <<<<<<<<<<<<<<
 *         self._lengths = None
 *         self.reference2length = None
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_references);
  __Pyx_DECREF(__pyx_v_self->_references);
  __pyx_v_self->_references = Py_None;

  /* "pysam/cfaidx.pyx":79
 *         self._filename = None
 *         self._references = None
 *         self._lengths = None             # <<<<<<<<<<<<<<
 *         self.reference2length = None
 *         self._open( *args, **kwargs )
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_lengths);
  __Pyx_DECREF(__pyx_v_self->_lengths);
  __pyx_v_self->_lengths = Py_None;

  /* "pysam/cfaidx.pyx":80
 *         self._references = None
 *         self._lengths = None
 *         self.reference2length = None             # <<<<<<<<<<<<<<
 *         self._open( *args, **kwargs )
 * 
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->reference2length);
  __Pyx_DECREF(__pyx_v_self->reference2length);
  __pyx_v_self->reference2length = Py_None;

  /* "pysam/cfaidx.pyx":81
 *         self._lengths = None
 *         self.reference2length = None
 *         self._open( *args, **kwargs )             # <<<<<<<<<<<<<<
 * 
 *     def _isOpen( self ):
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/cfaidx.pyx":75
 *     '''
 * 
 *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
 *         self.fastafile = NULL
 *         self._filename = None
 */

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

/* "pysam/cfaidx.pyx":83
 *         self._open( *args, **kwargs )
 * 
 *     def _isOpen( self ):             # <<<<<<<<<<<<<<
 *         '''return true if samfile has been opened.'''
 *         return self.fastafile != NULL
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_3_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_6cfaidx_9FastaFile_2_isOpen[] = "FastaFile._isOpen(self)\nreturn true if samfile has been opened.";
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_3_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_isOpen (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile_2_isOpen(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self));

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

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

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

  /* "pysam/cfaidx.pyx":83
 *         self._open( *args, **kwargs )
 * 
 *     def _isOpen( self ):             # <<<<<<<<<<<<<<
 *         '''return true if samfile has been opened.'''
 *         return self.fastafile != NULL
 */

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

/* "pysam/cfaidx.pyx":87
 *         return self.fastafile != NULL
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         if self.fastafile == NULL:
 *             raise ValueError("calling len() on closed file")
 */

/* Python wrapper */
static Py_ssize_t __pyx_pw_5pysam_6cfaidx_9FastaFile_5__len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_pw_5pysam_6cfaidx_9FastaFile_5__len__(PyObject *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile_4__len__(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self));

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

static Py_ssize_t __pyx_pf_5pysam_6cfaidx_9FastaFile_4__len__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__len__", 0);
  __Pyx_TraceCall("__len__", __pyx_f[0], 87);

  /* "pysam/cfaidx.pyx":88
 * 
 *     def __len__(self):
 *         if self.fastafile == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError("calling len() on closed file")
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->fastafile == NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/cfaidx.pyx":89
 *     def __len__(self):
 *         if self.fastafile == NULL:
 *             raise ValueError("calling len() on closed file")             # <<<<<<<<<<<<<<
 * 
 *         return faidx_nseq(self.fastafile)
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/cfaidx.pyx":91
 *             raise ValueError("calling len() on closed file")
 * 
 *         return faidx_nseq(self.fastafile)             # <<<<<<<<<<<<<<
 * 
 *     def _open(self, filename):
 */
  __pyx_r = faidx_nseq(__pyx_v_self->fastafile);
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":87
 *         return self.fastafile != NULL
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         if self.fastafile == NULL:
 *             raise ValueError("calling len() on closed file")
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.cfaidx.FastaFile.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/cfaidx.pyx":93
 *         return faidx_nseq(self.fastafile)
 * 
 *     def _open(self, filename):             # <<<<<<<<<<<<<<
 *         '''open an indexed fasta file.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_v_filename); /*proto*/
static char __pyx_doc_5pysam_6cfaidx_9FastaFile_6_open[] = "FastaFile._open(self, filename)\nopen an indexed fasta file.\n\n        This method expects an indexed fasta file.\n        ";
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_v_filename) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_open (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile_6_open(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self), ((PyObject *)__pyx_v_filename));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5pysam_6cfaidx_9FastaFile_5_open_2generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysam/cfaidx.pyx":113
 *         with open( self._filename + b".fai" ) as inf:
 *             data = [ x.split("\t") for x in inf ]
 *             self._references = tuple(x[0] for x in data)             # <<<<<<<<<<<<<<
 *             self._lengths = tuple(int(x[1]) for x in data)
 *             self.reference2length = dict(zip(self._references, self._lengths))
 */

static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_5_open_genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr *)__pyx_tp_new_5pysam_6cfaidx___pyx_scope_struct_1_genexpr(__pyx_ptype_5pysam_6cfaidx___pyx_scope_struct_1_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_5pysam_6cfaidx___pyx_scope_struct___open *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  __Pyx_TraceCall("genexpr", __pyx_f[0], 113);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5pysam_6cfaidx_9FastaFile_5_open_2generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_open_locals_genexpr); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

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

static PyObject *__pyx_gb_5pysam_6cfaidx_9FastaFile_5_open_2generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = 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 = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data)) { __Pyx_RaiseClosureNameError("data"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
  if (unlikely(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_data; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_x, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
    __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;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __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_3);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r);
  __pyx_generator->resume_label = -1;
  __Pyx_Generator_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return NULL;
}
static PyObject *__pyx_gb_5pysam_6cfaidx_9FastaFile_5_open_5generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysam/cfaidx.pyx":114
 *             data = [ x.split("\t") for x in inf ]
 *             self._references = tuple(x[0] for x in data)
 *             self._lengths = tuple(int(x[1]) for x in data)             # <<<<<<<<<<<<<<
 *             self.reference2length = dict(zip(self._references, self._lengths))
 * 
 */

static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_5_open_3genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr *)__pyx_tp_new_5pysam_6cfaidx___pyx_scope_struct_2_genexpr(__pyx_ptype_5pysam_6cfaidx___pyx_scope_struct_2_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_5pysam_6cfaidx___pyx_scope_struct___open *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  __Pyx_TraceCall("genexpr", __pyx_f[0], 114);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5pysam_6cfaidx_9FastaFile_5_open_5generator1, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_open_locals_genexpr); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

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

static PyObject *__pyx_gb_5pysam_6cfaidx_9FastaFile_5_open_5generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L6_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data)) { __Pyx_RaiseClosureNameError("data"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
  if (unlikely(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_data; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_x, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
    __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;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __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_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r);
  __pyx_generator->resume_label = -1;
  __Pyx_Generator_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return NULL;
}

/* "pysam/cfaidx.pyx":93
 *         return faidx_nseq(self.fastafile)
 * 
 *     def _open(self, filename):             # <<<<<<<<<<<<<<
 *         '''open an indexed fasta file.
 * 
 */

static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_6_open(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_filename) {
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *__pyx_cur_scope;
  PyObject *__pyx_v_inf = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  char *__pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  Py_ssize_t __pyx_t_13;
  PyObject *(*__pyx_t_14)(PyObject *);
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_open", 0);
  __pyx_cur_scope = (struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *)__pyx_tp_new_5pysam_6cfaidx___pyx_scope_struct___open(__pyx_ptype_5pysam_6cfaidx___pyx_scope_struct___open, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __Pyx_TraceCall("_open", __pyx_f[0], 93);

  /* "pysam/cfaidx.pyx":100
 * 
 *         # close a previously opened file
 *         if self.fastafile != NULL: self.close()             # <<<<<<<<<<<<<<
 *         self._filename = _encodeFilename(filename)
 *         self.fastafile = fai_load(self._filename)
 */
  __pyx_t_1 = ((__pyx_v_self->fastafile != NULL) != 0);
  if (__pyx_t_1) {
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __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_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    if (__pyx_t_4) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/cfaidx.pyx":101
 *         # close a previously opened file
 *         if self.fastafile != NULL: self.close()
 *         self._filename = _encodeFilename(filename)             # <<<<<<<<<<<<<<
 *         self.fastafile = fai_load(self._filename)
 * 
 */
  __pyx_t_2 = __pyx_f_5pysam_6cfaidx__encodeFilename(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF(__pyx_v_self->_filename);
  __Pyx_DECREF(__pyx_v_self->_filename);
  __pyx_v_self->_filename = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysam/cfaidx.pyx":102
 *         if self.fastafile != NULL: self.close()
 *         self._filename = _encodeFilename(filename)
 *         self.fastafile = fai_load(self._filename)             # <<<<<<<<<<<<<<
 * 
 *         if self.fastafile == NULL:
 */
  __pyx_t_5 = __Pyx_PyObject_AsString(__pyx_v_self->_filename); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->fastafile = fai_load(__pyx_t_5);

  /* "pysam/cfaidx.pyx":104
 *         self.fastafile = fai_load(self._filename)
 * 
 *         if self.fastafile == NULL:             # <<<<<<<<<<<<<<
 *             raise IOError("could not open file `%s`" % filename)
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->fastafile == NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/cfaidx.pyx":105
 * 
 *         if self.fastafile == NULL:
 *             raise IOError("could not open file `%s`" % filename)             # <<<<<<<<<<<<<<
 * 
 *         # read index
 */
    __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_file_s, __pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    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_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/cfaidx.pyx":108
 * 
 *         # read index
 *         if not os.path.exists( self._filename + b".fai" ):             # <<<<<<<<<<<<<<
 *             raise ValueError("could not locate index file")
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); 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_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); 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_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exists); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Add(__pyx_v_self->_filename, __pyx_kp_b_fai); 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_6 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_6) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__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_2);
  } else {
    __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __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_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_8 = ((!__pyx_t_1) != 0);
  if (__pyx_t_8) {

    /* "pysam/cfaidx.pyx":109
 *         # read index
 *         if not os.path.exists( self._filename + b".fai" ):
 *             raise ValueError("could not locate index file")             # <<<<<<<<<<<<<<
 * 
 *         with open( self._filename + b".fai" ) as inf:
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/cfaidx.pyx":111
 *             raise ValueError("could not locate index file")
 * 
 *         with open( self._filename + b".fai" ) as inf:             # <<<<<<<<<<<<<<
 *             data = [ x.split("\t") for x in inf ]
 *             self._references = tuple(x[0] for x in data)
 */
  /*with:*/ {
    __pyx_t_2 = PyNumber_Add(__pyx_v_self->_filename, __pyx_kp_b_fai); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __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 = 111; __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_open, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_9 = __Pyx_PyObject_LookupSpecial(__pyx_t_2, __pyx_n_s_exit); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_t_2, __pyx_n_s_enter); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L6_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (__pyx_t_4) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L6_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L6_error;}
    }
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    /*try:*/ {
      {
        __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
        __Pyx_XGOTREF(__pyx_t_10);
        __Pyx_XGOTREF(__pyx_t_11);
        __Pyx_XGOTREF(__pyx_t_12);
        /*try:*/ {
          __pyx_v_inf = __pyx_t_7;
          __pyx_t_7 = 0;

          /* "pysam/cfaidx.pyx":112
 * 
 *         with open( self._filename + b".fai" ) as inf:
 *             data = [ x.split("\t") for x in inf ]             # <<<<<<<<<<<<<<
 *             self._references = tuple(x[0] for x in data)
 *             self._lengths = tuple(int(x[1]) for x in data)
 */
          __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_7);
          if (likely(PyList_CheckExact(__pyx_v_inf)) || PyTuple_CheckExact(__pyx_v_inf)) {
            __pyx_t_2 = __pyx_v_inf; __Pyx_INCREF(__pyx_t_2); __pyx_t_13 = 0;
            __pyx_t_14 = NULL;
          } else {
            __pyx_t_13 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_inf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_14 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          }
          for (;;) {
            if (likely(!__pyx_t_14)) {
              if (likely(PyList_CheckExact(__pyx_t_2))) {
                if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_2)) break;
                #if CYTHON_COMPILING_IN_CPYTHON
                __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
                #else
                __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
                #endif
              } else {
                if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
                #if CYTHON_COMPILING_IN_CPYTHON
                __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
                #else
                __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
                #endif
              }
            } else {
              __pyx_t_3 = __pyx_t_14(__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 = 112; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
                }
                break;
              }
              __Pyx_GOTREF(__pyx_t_3);
            }
            __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_3);
            __pyx_t_3 = 0;
            __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            if (unlikely(__Pyx_ListComp_Append(__pyx_t_7, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          }
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GIVEREF(__pyx_t_7);
          __pyx_cur_scope->__pyx_v_data = ((PyObject*)__pyx_t_7);
          __pyx_t_7 = 0;

          /* "pysam/cfaidx.pyx":113
 *         with open( self._filename + b".fai" ) as inf:
 *             data = [ x.split("\t") for x in inf ]
 *             self._references = tuple(x[0] for x in data)             # <<<<<<<<<<<<<<
 *             self._lengths = tuple(int(x[1]) for x in data)
 *             self.reference2length = dict(zip(self._references, self._lengths))
 */
          __pyx_t_7 = __pyx_pf_5pysam_6cfaidx_9FastaFile_5_open_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_2 = PySequence_Tuple(__pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_GIVEREF(__pyx_t_2);
          __Pyx_GOTREF(__pyx_v_self->_references);
          __Pyx_DECREF(__pyx_v_self->_references);
          __pyx_v_self->_references = __pyx_t_2;
          __pyx_t_2 = 0;

          /* "pysam/cfaidx.pyx":114
 *             data = [ x.split("\t") for x in inf ]
 *             self._references = tuple(x[0] for x in data)
 *             self._lengths = tuple(int(x[1]) for x in data)             # <<<<<<<<<<<<<<
 *             self.reference2length = dict(zip(self._references, self._lengths))
 * 
 */
          __pyx_t_2 = __pyx_pf_5pysam_6cfaidx_9FastaFile_5_open_3genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_7 = PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GIVEREF(__pyx_t_7);
          __Pyx_GOTREF(__pyx_v_self->_lengths);
          __Pyx_DECREF(__pyx_v_self->_lengths);
          __pyx_v_self->_lengths = __pyx_t_7;
          __pyx_t_7 = 0;

          /* "pysam/cfaidx.pyx":115
 *             self._references = tuple(x[0] for x in data)
 *             self._lengths = tuple(int(x[1]) for x in data)
 *             self.reference2length = dict(zip(self._references, self._lengths))             # <<<<<<<<<<<<<<
 * 
 *     def close( self ):
 */
          __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_INCREF(__pyx_v_self->_references);
          PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_self->_references);
          __Pyx_GIVEREF(__pyx_v_self->_references);
          __Pyx_INCREF(__pyx_v_self->_lengths);
          PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_self->_lengths);
          __Pyx_GIVEREF(__pyx_v_self->_lengths);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_2);
          __pyx_t_2 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_GIVEREF(__pyx_t_2);
          __Pyx_GOTREF(__pyx_v_self->reference2length);
          __Pyx_DECREF(__pyx_v_self->reference2length);
          __pyx_v_self->reference2length = __pyx_t_2;
          __pyx_t_2 = 0;
        }
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        goto __pyx_L17_try_end;
        __pyx_L10_error:;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "pysam/cfaidx.pyx":111
 *             raise ValueError("could not locate index file")
 * 
 *         with open( self._filename + b".fai" ) as inf:             # <<<<<<<<<<<<<<
 *             data = [ x.split("\t") for x in inf ]
 *             self._references = tuple(x[0] for x in data)
 */
        /*except:*/ {
          __Pyx_AddTraceback("pysam.cfaidx.FastaFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_7, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_3 = PyTuple_Pack(3, __pyx_t_2, __pyx_t_7, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_3, NULL);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
          __Pyx_GOTREF(__pyx_t_15);
          __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_15);
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          if (__pyx_t_8 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
          __pyx_t_1 = ((!(__pyx_t_8 != 0)) != 0);
          if (__pyx_t_1) {
            __Pyx_GIVEREF(__pyx_t_2);
            __Pyx_GIVEREF(__pyx_t_7);
            __Pyx_XGIVEREF(__pyx_t_4);
            __Pyx_ErrRestore(__pyx_t_2, __pyx_t_7, __pyx_t_4);
            __pyx_t_2 = 0; __pyx_t_7 = 0; __pyx_t_4 = 0; 
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
          }
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          goto __pyx_L11_exception_handled;
        }
        __pyx_L12_except_error:;
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_XGIVEREF(__pyx_t_12);
        __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
        goto __pyx_L1_error;
        __pyx_L11_exception_handled:;
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_XGIVEREF(__pyx_t_12);
        __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
        __pyx_L17_try_end:;
      }
    }
    /*finally:*/ {
      /*normal exit:*/{
        if (__pyx_t_9) {
          __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__5, NULL);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        }
        goto __pyx_L9;
      }
      __pyx_L9:;
    }
    goto __pyx_L23;
    __pyx_L6_error:;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    goto __pyx_L1_error;
    __pyx_L23:;
  }

  /* "pysam/cfaidx.pyx":93
 *         return faidx_nseq(self.fastafile)
 * 
 *     def _open(self, filename):             # <<<<<<<<<<<<<<
 *         '''open an indexed fasta file.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysam.cfaidx.FastaFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_inf);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/cfaidx.pyx":117
 *             self.reference2length = dict(zip(self._references, self._lengths))
 * 
 *     def close( self ):             # <<<<<<<<<<<<<<
 *         if self.fastafile != NULL:
 *             fai_destroy( self.fastafile )
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_9close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_6cfaidx_9FastaFile_8close[] = "FastaFile.close(self)";
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_9close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile_8close(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self));

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

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

  /* "pysam/cfaidx.pyx":118
 * 
 *     def close( self ):
 *         if self.fastafile != NULL:             # <<<<<<<<<<<<<<
 *             fai_destroy( self.fastafile )
 *             self.fastafile = NULL
 */
  __pyx_t_1 = ((__pyx_v_self->fastafile != NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/cfaidx.pyx":119
 *     def close( self ):
 *         if self.fastafile != NULL:
 *             fai_destroy( self.fastafile )             # <<<<<<<<<<<<<<
 *             self.fastafile = NULL
 * 
 */
    fai_destroy(__pyx_v_self->fastafile);

    /* "pysam/cfaidx.pyx":120
 *         if self.fastafile != NULL:
 *             fai_destroy( self.fastafile )
 *             self.fastafile = NULL             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    __pyx_v_self->fastafile = NULL;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/cfaidx.pyx":117
 *             self.reference2length = dict(zip(self._references, self._lengths))
 * 
 *     def close( self ):             # <<<<<<<<<<<<<<
 *         if self.fastafile != NULL:
 *             fai_destroy( self.fastafile )
 */

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

/* "pysam/cfaidx.pyx":122
 *             self.fastafile = NULL
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

/* Python wrapper */
static void __pyx_pw_5pysam_6cfaidx_9FastaFile_11__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_6cfaidx_9FastaFile_11__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_6cfaidx_9FastaFile_10__dealloc__(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self));

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

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

  /* "pysam/cfaidx.pyx":123
 * 
 *     def __dealloc__(self):
 *         self.close()             # <<<<<<<<<<<<<<
 * 
 *     property filename:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/cfaidx.pyx":122
 *             self.fastafile = NULL
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

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

/* "pysam/cfaidx.pyx":127
 *     property filename:
 *         '''filename associated with this object.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._filename
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_8filename_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_8filename_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile_8filename___get__(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_8filename___get__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 127);

  /* "pysam/cfaidx.pyx":128
 *         '''filename associated with this object.'''
 *         def __get__(self):
 *             return self._filename             # <<<<<<<<<<<<<<
 * 
 *     property references:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_filename);
  __pyx_r = __pyx_v_self->_filename;
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":127
 *     property filename:
 *         '''filename associated with this object.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._filename
 * 
 */

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

/* "pysam/cfaidx.pyx":132
 *     property references:
 *         '''tuple with the names of :term:`reference` sequences.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._references
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_10references_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_10references_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile_10references___get__(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_10references___get__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 132);

  /* "pysam/cfaidx.pyx":133
 *         '''tuple with the names of :term:`reference` sequences.'''
 *         def __get__(self):
 *             return self._references             # <<<<<<<<<<<<<<
 * 
 *     property nreferences:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_references);
  __pyx_r = __pyx_v_self->_references;
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":132
 *     property references:
 *         '''tuple with the names of :term:`reference` sequences.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._references
 * 
 */

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

/* "pysam/cfaidx.pyx":137
 *     property nreferences:
 *         '''number of :term:`reference` sequences in the file.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return len(self._references) if self.references else None
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_11nreferences_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_11nreferences_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile_11nreferences___get__(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self));

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

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

  /* "pysam/cfaidx.pyx":138
 *         '''number of :term:`reference` sequences in the file.'''
 *         def __get__(self):
 *             return len(self._references) if self.references else None             # <<<<<<<<<<<<<<
 * 
 *     property lengths:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_references); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __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 = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
    __pyx_t_2 = __pyx_v_self->_references;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_4 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __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(Py_None);
    __pyx_t_1 = Py_None;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":137
 *     property nreferences:
 *         '''number of :term:`reference` sequences in the file.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return len(self._references) if self.references else None
 * 
 */

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

/* "pysam/cfaidx.pyx":142
 *     property lengths:
 *         '''tuple with the lengths of :term:`reference` sequences.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._lengths
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_7lengths_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_7lengths_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile_7lengths___get__(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_7lengths___get__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 142);

  /* "pysam/cfaidx.pyx":143
 *         '''tuple with the lengths of :term:`reference` sequences.'''
 *         def __get__(self):
 *             return self._lengths             # <<<<<<<<<<<<<<
 * 
 *     def fetch(self,
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_lengths);
  __pyx_r = __pyx_v_self->_lengths;
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":142
 *     property lengths:
 *         '''tuple with the lengths of :term:`reference` sequences.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._lengths
 * 
 */

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

/* "pysam/cfaidx.pyx":145
 *             return self._lengths
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               start=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_13fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_6cfaidx_9FastaFile_12fetch[] = "FastaFile.fetch(self, reference=None, start=None, end=None, region=None)\n*(reference = None, start = None, end = None, region = None)*\n\n        fetch sequences in a :term:`region` using 0-based indexing.\n\n        The region is specified by :term:`reference`, *start* and *end*.\n\n        fetch returns an empty string if the region is out of range or\n        addresses an unknown *reference*.\n\n        If *reference* is given and *start* is None, the sequence from the\n        first base is returned. Similarly, if *end* is None, the sequence\n        until the last base is returned.\n\n        Alternatively, a samtools :term:`region` string can be supplied.\n        ";
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_13fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_region = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("fetch (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,0};
    PyObject* values[4] = {0,0,0,0};

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

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

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

    /* "pysam/cfaidx.pyx":149
 *               start=None,
 *               end=None,
 *               region=None):             # <<<<<<<<<<<<<<
 * 
 *         '''*(reference = None, start = None, end = None, region = 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 (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reference);
          if (value) { values[0] = value; kw_args--; }
        }
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_region);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.cfaidx.FastaFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile_12fetch(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region);

  /* "pysam/cfaidx.pyx":145
 *             return self._lengths
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               start=None,
 */

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

static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_12fetch(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region) {
  int __pyx_v_length;
  char *__pyx_v_seq;
  PyObject *__pyx_v_py_seq = 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;
  char *__pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  char const *__pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("fetch", 0);
  __Pyx_TraceCall("fetch", __pyx_f[0], 145);
  __Pyx_INCREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  __Pyx_INCREF(__pyx_v_region);

  /* "pysam/cfaidx.pyx":167
 *         '''
 * 
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {

    /* "pysam/cfaidx.pyx":168
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         cdef int length
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__6, NULL); 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_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/cfaidx.pyx":173
 *         cdef char * seq
 * 
 *         if not region:             # <<<<<<<<<<<<<<
 *             if reference is None:
 *                 raise ValueError('no sequence/region supplied.')
 */
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = ((!__pyx_t_5) != 0);
  if (__pyx_t_4) {

    /* "pysam/cfaidx.pyx":174
 * 
 *         if not region:
 *             if reference is None:             # <<<<<<<<<<<<<<
 *                 raise ValueError('no sequence/region supplied.')
 *             if start is None:
 */
    __pyx_t_4 = (__pyx_v_reference == Py_None);
    __pyx_t_5 = (__pyx_t_4 != 0);
    if (__pyx_t_5) {

      /* "pysam/cfaidx.pyx":175
 *         if not region:
 *             if reference is None:
 *                 raise ValueError('no sequence/region supplied.')             # <<<<<<<<<<<<<<
 *             if start is None:
 *                 start = 0
 */
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/cfaidx.pyx":176
 *             if reference is None:
 *                 raise ValueError('no sequence/region supplied.')
 *             if start is None:             # <<<<<<<<<<<<<<
 *                 start = 0
 *             if end is None:
 */
    __pyx_t_5 = (__pyx_v_start == Py_None);
    __pyx_t_4 = (__pyx_t_5 != 0);
    if (__pyx_t_4) {

      /* "pysam/cfaidx.pyx":177
 *                 raise ValueError('no sequence/region supplied.')
 *             if start is None:
 *                 start = 0             # <<<<<<<<<<<<<<
 *             if end is None:
 *                 end = max_pos - 1
 */
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_DECREF_SET(__pyx_v_start, __pyx_int_0);
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysam/cfaidx.pyx":178
 *             if start is None:
 *                 start = 0
 *             if end is None:             # <<<<<<<<<<<<<<
 *                 end = max_pos - 1
 * 
 */
    __pyx_t_4 = (__pyx_v_end == Py_None);
    __pyx_t_5 = (__pyx_t_4 != 0);
    if (__pyx_t_5) {

      /* "pysam/cfaidx.pyx":179
 *                 start = 0
 *             if end is None:
 *                 end = max_pos - 1             # <<<<<<<<<<<<<<
 * 
 *             if start > end:
 */
      __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_5pysam_6cfaidx_max_pos - 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF_SET(__pyx_v_end, __pyx_t_1);
      __pyx_t_1 = 0;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "pysam/cfaidx.pyx":181
 *                 end = max_pos - 1
 * 
 *             if start > end:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     'invalid region: start (%i) > end (%i)' % (start, end))
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_5) {

      /* "pysam/cfaidx.pyx":183
 *             if start > end:
 *                 raise ValueError(
 *                     'invalid region: start (%i) > end (%i)' % (start, end))             # <<<<<<<<<<<<<<
 *             if start == end:
 *                 return b""
 */
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_start);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_start);
      __Pyx_GIVEREF(__pyx_v_start);
      __Pyx_INCREF(__pyx_v_end);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_end);
      __Pyx_GIVEREF(__pyx_v_end);
      __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_invalid_region_start_i_end_i, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/cfaidx.pyx":182
 * 
 *             if start > end:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     'invalid region: start (%i) > end (%i)' % (start, end))
 *             if start == end:
 */
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/cfaidx.pyx":184
 *                 raise ValueError(
 *                     'invalid region: start (%i) > end (%i)' % (start, end))
 *             if start == end:             # <<<<<<<<<<<<<<
 *                 return b""
 *             # valid ranges are from 0 to 2^29-1
 */
    __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_5) {

      /* "pysam/cfaidx.pyx":185
 *                     'invalid region: start (%i) > end (%i)' % (start, end))
 *             if start == end:
 *                 return b""             # <<<<<<<<<<<<<<
 *             # valid ranges are from 0 to 2^29-1
 *             if not 0 <= start < max_pos:
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_kp_b__8);
      __pyx_r = __pyx_kp_b__8;
      goto __pyx_L0;
    }

    /* "pysam/cfaidx.pyx":187
 *                 return b""
 *             # valid ranges are from 0 to 2^29-1
 *             if not 0 <= start < max_pos:             # <<<<<<<<<<<<<<
 *                 raise IndexError('start out of range (%i)' % start)
 *             if not 0 <= end < max_pos:
 */
    __pyx_t_2 = PyObject_RichCompare(__pyx_int_0, __pyx_v_start, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__Pyx_PyObject_IsTrue(__pyx_t_2)) {
      __Pyx_DECREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_5pysam_6cfaidx_max_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = ((!__pyx_t_5) != 0);
    if (__pyx_t_4) {

      /* "pysam/cfaidx.pyx":188
 *             # valid ranges are from 0 to 2^29-1
 *             if not 0 <= start < max_pos:
 *                 raise IndexError('start out of range (%i)' % start)             # <<<<<<<<<<<<<<
 *             if not 0 <= end < max_pos:
 *                 raise IndexError('end out of range (%i)' % end)
 */
      __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/cfaidx.pyx":189
 *             if not 0 <= start < max_pos:
 *                 raise IndexError('start out of range (%i)' % start)
 *             if not 0 <= end < max_pos:             # <<<<<<<<<<<<<<
 *                 raise IndexError('end out of range (%i)' % end)
 *             # note: faidx_fetch_seq has a bug such that out-of-range access
 */
    __pyx_t_2 = PyObject_RichCompare(__pyx_int_0, __pyx_v_end, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__Pyx_PyObject_IsTrue(__pyx_t_2)) {
      __Pyx_DECREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_5pysam_6cfaidx_max_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyObject_RichCompare(__pyx_v_end, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = ((!__pyx_t_4) != 0);
    if (__pyx_t_5) {

      /* "pysam/cfaidx.pyx":190
 *                 raise IndexError('start out of range (%i)' % start)
 *             if not 0 <= end < max_pos:
 *                 raise IndexError('end out of range (%i)' % end)             # <<<<<<<<<<<<<<
 *             # note: faidx_fetch_seq has a bug such that out-of-range access
 *             # always returns the last residue. Hence do not use faidx_fetch_seq,
 */
      __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_end_out_of_range_i, __pyx_v_end); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/cfaidx.pyx":199
 *             #                       end-1,
 *             #                       &length)
 *             region = "%s:%i-%i" % (reference, start+1, end)             # <<<<<<<<<<<<<<
 *             if PY_MAJOR_VERSION >= 3:
 *                 region = region.encode('ascii')
 */
    __pyx_t_2 = PyNumber_Add(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_reference);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
    __Pyx_GIVEREF(__pyx_v_reference);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_end);
    PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_end);
    __Pyx_GIVEREF(__pyx_v_end);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_i_i, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_region, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "pysam/cfaidx.pyx":200
 *             #                       &length)
 *             region = "%s:%i-%i" % (reference, start+1, end)
 *             if PY_MAJOR_VERSION >= 3:             # <<<<<<<<<<<<<<
 *                 region = region.encode('ascii')
 *             seq = fai_fetch( self.fastafile,
 */
    __pyx_t_5 = ((PY_MAJOR_VERSION >= 3) != 0);
    if (__pyx_t_5) {

      /* "pysam/cfaidx.pyx":201
 *             region = "%s:%i-%i" % (reference, start+1, end)
 *             if PY_MAJOR_VERSION >= 3:
 *                 region = region.encode('ascii')             # <<<<<<<<<<<<<<
 *             seq = fai_fetch( self.fastafile,
 *                              region,
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_region, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __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_region, __pyx_t_1);
      __pyx_t_1 = 0;
      goto __pyx_L12;
    }
    __pyx_L12:;

    /* "pysam/cfaidx.pyx":203
 *                 region = region.encode('ascii')
 *             seq = fai_fetch( self.fastafile,
 *                              region,             # <<<<<<<<<<<<<<
 *                              &length )
 *         else:
 */
    __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_region); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/cfaidx.pyx":202
 *             if PY_MAJOR_VERSION >= 3:
 *                 region = region.encode('ascii')
 *             seq = fai_fetch( self.fastafile,             # <<<<<<<<<<<<<<
 *                              region,
 *                              &length )
 */
    __pyx_v_seq = fai_fetch(__pyx_v_self->fastafile, __pyx_t_6, (&__pyx_v_length));
    goto __pyx_L4;
  }
  /*else*/ {

    /* "pysam/cfaidx.pyx":207
 *         else:
 *             # samtools adds a '\0' at the end
 *             seq = fai_fetch( self.fastafile, region, &length )             # <<<<<<<<<<<<<<
 * 
 *         # copy to python
 */
    __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_region); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_seq = fai_fetch(__pyx_v_self->fastafile, __pyx_t_6, (&__pyx_v_length));
  }
  __pyx_L4:;

  /* "pysam/cfaidx.pyx":210
 * 
 *         # copy to python
 *         if seq == NULL:             # <<<<<<<<<<<<<<
 *             return b""
 *         else:
 */
  __pyx_t_5 = ((__pyx_v_seq == NULL) != 0);
  if (__pyx_t_5) {

    /* "pysam/cfaidx.pyx":211
 *         # copy to python
 *         if seq == NULL:
 *             return b""             # <<<<<<<<<<<<<<
 *         else:
 *             try:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_kp_b__8);
    __pyx_r = __pyx_kp_b__8;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/cfaidx.pyx":213
 *             return b""
 *         else:
 *             try:             # <<<<<<<<<<<<<<
 *                 py_seq = seq[:length]
 *             finally:
 */
    /*try:*/ {

      /* "pysam/cfaidx.pyx":214
 *         else:
 *             try:
 *                 py_seq = seq[:length]             # <<<<<<<<<<<<<<
 *             finally:
 *                 free(seq)
 */
      __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_seq + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L15_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_py_seq = ((PyObject*)__pyx_t_1);
      __pyx_t_1 = 0;
    }

    /* "pysam/cfaidx.pyx":216
 *                 py_seq = seq[:length]
 *             finally:
 *                 free(seq)             # <<<<<<<<<<<<<<
 * 
 *         return py_seq
 */
    /*finally:*/ {
      /*normal exit:*/{
        free(__pyx_v_seq);
        goto __pyx_L16;
      }
      /*exception exit:*/{
        __pyx_L15_error:;
        __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
        if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12) < 0)) __Pyx_ErrFetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
        __Pyx_XGOTREF(__pyx_t_10);
        __Pyx_XGOTREF(__pyx_t_11);
        __Pyx_XGOTREF(__pyx_t_12);
        __Pyx_XGOTREF(__pyx_t_13);
        __Pyx_XGOTREF(__pyx_t_14);
        __Pyx_XGOTREF(__pyx_t_15);
        __pyx_t_7 = __pyx_lineno; __pyx_t_8 = __pyx_clineno; __pyx_t_9 = __pyx_filename;
        {
          free(__pyx_v_seq);
        }
        if (PY_MAJOR_VERSION >= 3) {
          __Pyx_XGIVEREF(__pyx_t_13);
          __Pyx_XGIVEREF(__pyx_t_14);
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
        }
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_XGIVEREF(__pyx_t_12);
        __Pyx_ErrRestore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
        __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
        __pyx_lineno = __pyx_t_7; __pyx_clineno = __pyx_t_8; __pyx_filename = __pyx_t_9;
        goto __pyx_L1_error;
      }
      __pyx_L16:;
    }
  }

  /* "pysam/cfaidx.pyx":218
 *                 free(seq)
 * 
 *         return py_seq             # <<<<<<<<<<<<<<
 * 
 *     cdef char * _fetch( self, char * reference, int start, int end, int * length ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_py_seq);
  __pyx_r = __pyx_v_py_seq;
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":145
 *             return self._lengths
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               start=None,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.cfaidx.FastaFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_py_seq);
  __Pyx_XDECREF(__pyx_v_start);
  __Pyx_XDECREF(__pyx_v_end);
  __Pyx_XDECREF(__pyx_v_region);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/cfaidx.pyx":220
 *         return py_seq
 * 
 *     cdef char * _fetch( self, char * reference, int start, int end, int * length ):             # <<<<<<<<<<<<<<
 *         '''fetch sequence for reference, start and end'''
 * 
 */

static char *__pyx_f_5pysam_6cfaidx_9FastaFile__fetch(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, char *__pyx_v_reference, int __pyx_v_start, int __pyx_v_end, int *__pyx_v_length) {
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_fetch", 0);
  __Pyx_TraceCall("_fetch", __pyx_f[0], 220);

  /* "pysam/cfaidx.pyx":223
 *         '''fetch sequence for reference, start and end'''
 * 
 *         return faidx_fetch_seq(self.fastafile,             # <<<<<<<<<<<<<<
 *                                reference,
 *                                start,
 */
  __pyx_r = faidx_fetch_seq(__pyx_v_self->fastafile, __pyx_v_reference, __pyx_v_start, (__pyx_v_end - 1), __pyx_v_length);
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":220
 *         return py_seq
 * 
 *     cdef char * _fetch( self, char * reference, int start, int end, int * length ):             # <<<<<<<<<<<<<<
 *         '''fetch sequence for reference, start and end'''
 * 
 */

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

/* "pysam/cfaidx.pyx":229
 *                                length )
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         '''return the length of reference.'''
 *         return self.reference2length[reference]
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_15get_reference_length(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
static char __pyx_doc_5pysam_6cfaidx_9FastaFile_14get_reference_length[] = "FastaFile.get_reference_length(self, reference)\nreturn the length of reference.";
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_15get_reference_length(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_reference_length (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile_14get_reference_length(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self), ((PyObject *)__pyx_v_reference));

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

static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_14get_reference_length(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("get_reference_length", 0);
  __Pyx_TraceCall("get_reference_length", __pyx_f[0], 229);

  /* "pysam/cfaidx.pyx":231
 *     def get_reference_length(self, reference):
 *         '''return the length of reference.'''
 *         return self.reference2length[reference]             # <<<<<<<<<<<<<<
 * 
 *     def __getitem__(self, reference):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetItem(__pyx_v_self->reference2length, __pyx_v_reference); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":229
 *                                length )
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         '''return the length of reference.'''
 *         return self.reference2length[reference]
 */

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

/* "pysam/cfaidx.pyx":233
 *         return self.reference2length[reference]
 * 
 *     def __getitem__(self, reference):             # <<<<<<<<<<<<<<
 *         return self.fetch(reference)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_17__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastaFile_17__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile_16__getitem__(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self), ((PyObject *)__pyx_v_reference));

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

static PyObject *__pyx_pf_5pysam_6cfaidx_9FastaFile_16__getitem__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__getitem__", 0);
  __Pyx_TraceCall("__getitem__", __pyx_f[0], 233);

  /* "pysam/cfaidx.pyx":234
 * 
 *     def __getitem__(self, reference):
 *         return self.fetch(reference)             # <<<<<<<<<<<<<<
 * 
 *     def __contains__(self, reference):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_reference); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
    __Pyx_INCREF(__pyx_v_reference);
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_reference);
    __Pyx_GIVEREF(__pyx_v_reference);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":233
 *         return self.reference2length[reference]
 * 
 *     def __getitem__(self, reference):             # <<<<<<<<<<<<<<
 *         return self.fetch(reference)
 * 
 */

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

/* "pysam/cfaidx.pyx":236
 *         return self.fetch(reference)
 * 
 *     def __contains__(self, reference):             # <<<<<<<<<<<<<<
 *         '''return true if reference in fasta file.'''
 *         return reference in self.reference2length
 */

/* Python wrapper */
static int __pyx_pw_5pysam_6cfaidx_9FastaFile_19__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
static char __pyx_doc_5pysam_6cfaidx_9FastaFile_18__contains__[] = "return true if reference in fasta file.";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_6cfaidx_9FastaFile_18__contains__;
#endif
static int __pyx_pw_5pysam_6cfaidx_9FastaFile_19__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastaFile_18__contains__(((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)__pyx_v_self), ((PyObject *)__pyx_v_reference));

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

static int __pyx_pf_5pysam_6cfaidx_9FastaFile_18__contains__(struct __pyx_obj_5pysam_6cfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_reference) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__contains__", 0);
  __Pyx_TraceCall("__contains__", __pyx_f[0], 236);

  /* "pysam/cfaidx.pyx":238
 *     def __contains__(self, reference):
 *         '''return true if reference in fasta file.'''
 *         return reference in self.reference2length             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = (__Pyx_PySequence_Contains(__pyx_v_reference, __pyx_v_self->reference2length, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":236
 *         return self.fetch(reference)
 * 
 *     def __contains__(self, reference):             # <<<<<<<<<<<<<<
 *         '''return true if reference in fasta file.'''
 *         return reference in self.reference2length
 */

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

/* "pysam/cfaidx.pyx":242
 * 
 * cdef class FastqProxy:
 *     def __init__(self): pass             # <<<<<<<<<<<<<<
 * 
 *     property name:
 */

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

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

static int __pyx_pf_5pysam_6cfaidx_10FastqProxy___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_6cfaidx_FastqProxy *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 242);

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

/* "pysam/cfaidx.pyx":245
 * 
 *     property name:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.name.s
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_10FastqProxy_4name_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_6cfaidx_10FastqProxy_4name_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_10FastqProxy_4name___get__(((struct __pyx_obj_5pysam_6cfaidx_FastqProxy *)__pyx_v_self));

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

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

  /* "pysam/cfaidx.pyx":246
 *     property name:
 *         def __get__(self):
 *             return self._delegate.name.s             # <<<<<<<<<<<<<<
 * 
 *     property sequence:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->_delegate->name.s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":245
 * 
 *     property name:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.name.s
 * 
 */

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

/* "pysam/cfaidx.pyx":249
 * 
 *     property sequence:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.seq.s
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_10FastqProxy_8sequence_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_6cfaidx_10FastqProxy_8sequence_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_10FastqProxy_8sequence___get__(((struct __pyx_obj_5pysam_6cfaidx_FastqProxy *)__pyx_v_self));

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

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

  /* "pysam/cfaidx.pyx":250
 *     property sequence:
 *         def __get__(self):
 *             return self._delegate.seq.s             # <<<<<<<<<<<<<<
 * 
 *     property comment:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->_delegate->seq.s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":249
 * 
 *     property sequence:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.seq.s
 * 
 */

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

/* "pysam/cfaidx.pyx":253
 * 
 *     property comment:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self._delegate.comment.l:
 *                 return self._delegate.comment.s
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_10FastqProxy_7comment_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_6cfaidx_10FastqProxy_7comment_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_10FastqProxy_7comment___get__(((struct __pyx_obj_5pysam_6cfaidx_FastqProxy *)__pyx_v_self));

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

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

  /* "pysam/cfaidx.pyx":254
 *     property comment:
 *         def __get__(self):
 *             if self._delegate.comment.l:             # <<<<<<<<<<<<<<
 *                 return self._delegate.comment.s
 *             else: return None
 */
  __pyx_t_1 = (__pyx_v_self->_delegate->comment.l != 0);
  if (__pyx_t_1) {

    /* "pysam/cfaidx.pyx":255
 *         def __get__(self):
 *             if self._delegate.comment.l:
 *                 return self._delegate.comment.s             # <<<<<<<<<<<<<<
 *             else: return None
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_self->_delegate->comment.s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/cfaidx.pyx":256
 *             if self._delegate.comment.l:
 *                 return self._delegate.comment.s
 *             else: return None             # <<<<<<<<<<<<<<
 * 
 *     property quality:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/cfaidx.pyx":253
 * 
 *     property comment:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self._delegate.comment.l:
 *                 return self._delegate.comment.s
 */

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

/* "pysam/cfaidx.pyx":259
 * 
 *     property quality:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self._delegate.qual.l:
 *                 return self._delegate.qual.s
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_10FastqProxy_7quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_6cfaidx_10FastqProxy_7quality_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_10FastqProxy_7quality___get__(((struct __pyx_obj_5pysam_6cfaidx_FastqProxy *)__pyx_v_self));

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

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

  /* "pysam/cfaidx.pyx":260
 *     property quality:
 *         def __get__(self):
 *             if self._delegate.qual.l:             # <<<<<<<<<<<<<<
 *                 return self._delegate.qual.s
 *             else: return None
 */
  __pyx_t_1 = (__pyx_v_self->_delegate->qual.l != 0);
  if (__pyx_t_1) {

    /* "pysam/cfaidx.pyx":261
 *         def __get__(self):
 *             if self._delegate.qual.l:
 *                 return self._delegate.qual.s             # <<<<<<<<<<<<<<
 *             else: return None
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_self->_delegate->qual.s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/cfaidx.pyx":262
 *             if self._delegate.qual.l:
 *                 return self._delegate.qual.s
 *             else: return None             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/cfaidx.pyx":259
 * 
 *     property quality:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self._delegate.qual.l:
 *                 return self._delegate.qual.s
 */

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

/* "pysam/cfaidx.pyx":279
 * 
 *     '''
 *     def __cinit__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         # self.fastqfile = <gzFile*>NULL
 *         self._filename = None
 */

/* Python wrapper */
static int __pyx_pw_5pysam_6cfaidx_9FastxFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_6cfaidx_9FastxFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return -1;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastxFile___cinit__(((struct __pyx_obj_5pysam_6cfaidx_FastxFile *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

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

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

  /* "pysam/cfaidx.pyx":281
 *     def __cinit__(self, *args, **kwargs):
 *         # self.fastqfile = <gzFile*>NULL
 *         self._filename = None             # <<<<<<<<<<<<<<
 *         self.entry = NULL
 *         self._open(*args, **kwargs)
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_filename);
  __Pyx_DECREF(__pyx_v_self->_filename);
  __pyx_v_self->_filename = Py_None;

  /* "pysam/cfaidx.pyx":282
 *         # self.fastqfile = <gzFile*>NULL
 *         self._filename = None
 *         self.entry = NULL             # <<<<<<<<<<<<<<
 *         self._open(*args, **kwargs)
 * 
 */
  __pyx_v_self->entry = NULL;

  /* "pysam/cfaidx.pyx":283
 *         self._filename = None
 *         self.entry = NULL
 *         self._open(*args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 *     def _isOpen( self ):
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/cfaidx.pyx":279
 * 
 *     '''
 *     def __cinit__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         # self.fastqfile = <gzFile*>NULL
 *         self._filename = None
 */

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

/* "pysam/cfaidx.pyx":285
 *         self._open(*args, **kwargs)
 * 
 *     def _isOpen( self ):             # <<<<<<<<<<<<<<
 *         '''return true if samfile has been opened.'''
 *         return self.entry != NULL
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastxFile_3_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_6cfaidx_9FastxFile_2_isOpen[] = "FastxFile._isOpen(self)\nreturn true if samfile has been opened.";
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastxFile_3_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_isOpen (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastxFile_2_isOpen(((struct __pyx_obj_5pysam_6cfaidx_FastxFile *)__pyx_v_self));

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

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

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

  /* "pysam/cfaidx.pyx":285
 *         self._open(*args, **kwargs)
 * 
 *     def _isOpen( self ):             # <<<<<<<<<<<<<<
 *         '''return true if samfile has been opened.'''
 *         return self.entry != NULL
 */

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

/* "pysam/cfaidx.pyx":289
 *         return self.entry != NULL
 * 
 *     def _open(self, filename):             # <<<<<<<<<<<<<<
 *         '''open a fastq/fasta file.
 *         '''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastxFile_5_open(PyObject *__pyx_v_self, PyObject *__pyx_v_filename); /*proto*/
static char __pyx_doc_5pysam_6cfaidx_9FastxFile_4_open[] = "FastxFile._open(self, filename)\nopen a fastq/fasta file.\n        ";
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastxFile_5_open(PyObject *__pyx_v_self, PyObject *__pyx_v_filename) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_open (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastxFile_4_open(((struct __pyx_obj_5pysam_6cfaidx_FastxFile *)__pyx_v_self), ((PyObject *)__pyx_v_filename));

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

static PyObject *__pyx_pf_5pysam_6cfaidx_9FastxFile_4_open(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self, PyObject *__pyx_v_filename) {
  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;
  char *__pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_open", 0);
  __Pyx_TraceCall("_open", __pyx_f[0], 289);
  __Pyx_INCREF(__pyx_v_filename);

  /* "pysam/cfaidx.pyx":292
 *         '''open a fastq/fasta file.
 *         '''
 *         self.close()             # <<<<<<<<<<<<<<
 * 
 *         if not os.path.exists(filename):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/cfaidx.pyx":294
 *         self.close()
 * 
 *         if not os.path.exists(filename):             # <<<<<<<<<<<<<<
 *             raise IOError("no such file or directory: %s" % filename)
 * 
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_exists); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
    __Pyx_INCREF(__pyx_v_filename);
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_filename);
    __Pyx_GIVEREF(__pyx_v_filename);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __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) {

    /* "pysam/cfaidx.pyx":295
 * 
 *         if not os.path.exists(filename):
 *             raise IOError("no such file or directory: %s" % filename)             # <<<<<<<<<<<<<<
 * 
 *         filename = _encodeFilename(filename)
 */
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_no_such_file_or_directory_s, __pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __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 = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/cfaidx.pyx":297
 *             raise IOError("no such file or directory: %s" % filename)
 * 
 *         filename = _encodeFilename(filename)             # <<<<<<<<<<<<<<
 *         self.fastqfile = gzopen(filename, "r")
 *         self.entry = kseq_init(self.fastqfile)
 */
  __pyx_t_1 = __pyx_f_5pysam_6cfaidx__encodeFilename(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF_SET(__pyx_v_filename, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/cfaidx.pyx":298
 * 
 *         filename = _encodeFilename(filename)
 *         self.fastqfile = gzopen(filename, "r")             # <<<<<<<<<<<<<<
 *         self.entry = kseq_init(self.fastqfile)
 *         self._filename = filename
 */
  __pyx_t_7 = __Pyx_PyObject_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->fastqfile = gzopen(__pyx_t_7, __pyx_k_r);

  /* "pysam/cfaidx.pyx":299
 *         filename = _encodeFilename(filename)
 *         self.fastqfile = gzopen(filename, "r")
 *         self.entry = kseq_init(self.fastqfile)             # <<<<<<<<<<<<<<
 *         self._filename = filename
 * 
 */
  __pyx_v_self->entry = kseq_init(__pyx_v_self->fastqfile);

  /* "pysam/cfaidx.pyx":300
 *         self.fastqfile = gzopen(filename, "r")
 *         self.entry = kseq_init(self.fastqfile)
 *         self._filename = filename             # <<<<<<<<<<<<<<
 * 
 *     def close( self ):
 */
  __Pyx_INCREF(__pyx_v_filename);
  __Pyx_GIVEREF(__pyx_v_filename);
  __Pyx_GOTREF(__pyx_v_self->_filename);
  __Pyx_DECREF(__pyx_v_self->_filename);
  __pyx_v_self->_filename = __pyx_v_filename;

  /* "pysam/cfaidx.pyx":289
 *         return self.entry != NULL
 * 
 *     def _open(self, filename):             # <<<<<<<<<<<<<<
 *         '''open a fastq/fasta 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_4);
  __Pyx_AddTraceback("pysam.cfaidx.FastxFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_filename);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/cfaidx.pyx":302
 *         self._filename = filename
 * 
 *     def close( self ):             # <<<<<<<<<<<<<<
 *         '''close file.'''
 *         if self.entry != NULL:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastxFile_7close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_6cfaidx_9FastxFile_6close[] = "FastxFile.close(self)\nclose file.";
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastxFile_7close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastxFile_6close(((struct __pyx_obj_5pysam_6cfaidx_FastxFile *)__pyx_v_self));

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

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

  /* "pysam/cfaidx.pyx":304
 *     def close( self ):
 *         '''close file.'''
 *         if self.entry != NULL:             # <<<<<<<<<<<<<<
 *             gzclose(self.fastqfile)
 *             if self.entry:
 */
  __pyx_t_1 = ((__pyx_v_self->entry != NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/cfaidx.pyx":305
 *         '''close file.'''
 *         if self.entry != NULL:
 *             gzclose(self.fastqfile)             # <<<<<<<<<<<<<<
 *             if self.entry:
 *                 kseq_destroy(self.entry)
 */
    gzclose(__pyx_v_self->fastqfile);

    /* "pysam/cfaidx.pyx":306
 *         if self.entry != NULL:
 *             gzclose(self.fastqfile)
 *             if self.entry:             # <<<<<<<<<<<<<<
 *                 kseq_destroy(self.entry)
 *                 self.entry = NULL
 */
    __pyx_t_1 = (__pyx_v_self->entry != 0);
    if (__pyx_t_1) {

      /* "pysam/cfaidx.pyx":307
 *             gzclose(self.fastqfile)
 *             if self.entry:
 *                 kseq_destroy(self.entry)             # <<<<<<<<<<<<<<
 *                 self.entry = NULL
 * 
 */
      kseq_destroy(__pyx_v_self->entry);

      /* "pysam/cfaidx.pyx":308
 *             if self.entry:
 *                 kseq_destroy(self.entry)
 *                 self.entry = NULL             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
      __pyx_v_self->entry = NULL;
      goto __pyx_L4;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/cfaidx.pyx":302
 *         self._filename = filename
 * 
 *     def close( self ):             # <<<<<<<<<<<<<<
 *         '''close file.'''
 *         if self.entry != NULL:
 */

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

/* "pysam/cfaidx.pyx":310
 *                 self.entry = NULL
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

/* Python wrapper */
static void __pyx_pw_5pysam_6cfaidx_9FastxFile_9__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_6cfaidx_9FastxFile_9__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_6cfaidx_9FastxFile_8__dealloc__(((struct __pyx_obj_5pysam_6cfaidx_FastxFile *)__pyx_v_self));

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

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

  /* "pysam/cfaidx.pyx":311
 * 
 *     def __dealloc__(self):
 *         self.close()             # <<<<<<<<<<<<<<
 * 
 *     property filename:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/cfaidx.pyx":310
 *                 self.entry = NULL
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

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

/* "pysam/cfaidx.pyx":315
 *     property filename:
 *         '''filename associated with this object.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._filename
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastxFile_8filename_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastxFile_8filename_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastxFile_8filename___get__(((struct __pyx_obj_5pysam_6cfaidx_FastxFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_6cfaidx_9FastxFile_8filename___get__(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 315);

  /* "pysam/cfaidx.pyx":316
 *         '''filename associated with this object.'''
 *         def __get__(self):
 *             return self._filename             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_filename);
  __pyx_r = __pyx_v_self->_filename;
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":315
 *     property filename:
 *         '''filename associated with this object.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._filename
 * 
 */

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

/* "pysam/cfaidx.pyx":318
 *             return self._filename
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastxFile_11__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastxFile_11__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastxFile_10__iter__(((struct __pyx_obj_5pysam_6cfaidx_FastxFile *)__pyx_v_self));

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

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

  /* "pysam/cfaidx.pyx":319
 * 
 *     def __iter__(self):
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 *         return self
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {

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

  /* "pysam/cfaidx.pyx":321
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef kseq_t * getCurrent(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":318
 *             return self._filename
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")
 */

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

/* "pysam/cfaidx.pyx":323
 *         return self
 * 
 *     cdef kseq_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.entry
 * 
 */

static kseq_t *__pyx_f_5pysam_6cfaidx_9FastxFile_getCurrent(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self) {
  kseq_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 323);

  /* "pysam/cfaidx.pyx":324
 * 
 *     cdef kseq_t * getCurrent(self):
 *         return self.entry             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->entry;
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":323
 *         return self
 * 
 *     cdef kseq_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.entry
 * 
 */

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

/* "pysam/cfaidx.pyx":326
 *         return self.entry
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''C version of iterator
 *         '''
 */

static int __pyx_f_5pysam_6cfaidx_9FastxFile_cnext(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 326);

  /* "pysam/cfaidx.pyx":329
 *         '''C version of iterator
 *         '''
 *         return kseq_read(self.entry)             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_r = kseq_read(__pyx_v_self->entry);
  goto __pyx_L0;

  /* "pysam/cfaidx.pyx":326
 *         return self.entry
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''C version of iterator
 *         '''
 */

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

/* "pysam/cfaidx.pyx":331
 *         return kseq_read(self.entry)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """
 *         python version of next().
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastxFile_13__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_6cfaidx_9FastxFile_12__next__[] = "\n        python version of next().\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_6cfaidx_9FastxFile_12__next__;
#endif
static PyObject *__pyx_pw_5pysam_6cfaidx_9FastxFile_13__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_6cfaidx_9FastxFile_12__next__(((struct __pyx_obj_5pysam_6cfaidx_FastxFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_6cfaidx_9FastxFile_12__next__(struct __pyx_obj_5pysam_6cfaidx_FastxFile *__pyx_v_self) {
  int __pyx_v_l;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 331);

  /* "pysam/cfaidx.pyx":336
 *         """
 *         cdef int l
 *         l = kseq_read(self.entry)             # <<<<<<<<<<<<<<
 *         if (l > 0):
 *             return makeFastqProxy(self.entry)
 */
  __pyx_v_l = kseq_read(__pyx_v_self->entry);

  /* "pysam/cfaidx.pyx":337
 *         cdef int l
 *         l = kseq_read(self.entry)
 *         if (l > 0):             # <<<<<<<<<<<<<<
 *             return makeFastqProxy(self.entry)
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_l > 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/cfaidx.pyx":338
 *         l = kseq_read(self.entry)
 *         if (l > 0):
 *             return makeFastqProxy(self.entry)             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_5pysam_6cfaidx_makeFastqProxy(__pyx_v_self->entry); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/cfaidx.pyx":340
 *             return makeFastqProxy(self.entry)
 *         else:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * # Compatibility Layer for pysam 0.8.1
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/cfaidx.pyx":331
 *         return kseq_read(self.entry)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """
 *         python version of next().
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.cfaidx.FastxFile.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_5pysam_6cfaidx_FastaFile __pyx_vtable_5pysam_6cfaidx_FastaFile;

static PyObject *__pyx_tp_new_5pysam_6cfaidx_FastaFile(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_6cfaidx_FastaFile *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_6cfaidx_FastaFile;
  p->_filename = Py_None; Py_INCREF(Py_None);
  p->_references = Py_None; Py_INCREF(Py_None);
  p->_lengths = Py_None; Py_INCREF(Py_None);
  p->reference2length = Py_None; Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_5pysam_6cfaidx_9FastaFile_1__cinit__(o, a, k) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_6cfaidx_FastaFile(PyObject *o) {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *p = (struct __pyx_obj_5pysam_6cfaidx_FastaFile *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_6cfaidx_9FastaFile_11__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->_filename);
  Py_CLEAR(p->_references);
  Py_CLEAR(p->_lengths);
  Py_CLEAR(p->reference2length);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_6cfaidx_FastaFile(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *p = (struct __pyx_obj_5pysam_6cfaidx_FastaFile *)o;
  if (p->_filename) {
    e = (*v)(p->_filename, a); if (e) return e;
  }
  if (p->_references) {
    e = (*v)(p->_references, a); if (e) return e;
  }
  if (p->_lengths) {
    e = (*v)(p->_lengths, a); if (e) return e;
  }
  if (p->reference2length) {
    e = (*v)(p->reference2length, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_6cfaidx_FastaFile(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_6cfaidx_FastaFile *p = (struct __pyx_obj_5pysam_6cfaidx_FastaFile *)o;
  tmp = ((PyObject*)p->_filename);
  p->_filename = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_references);
  p->_references = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_lengths);
  p->_lengths = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->reference2length);
  p->reference2length = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}
static PyObject *__pyx_sq_item_5pysam_6cfaidx_FastaFile(PyObject *o, Py_ssize_t i) {
  PyObject *r;
  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
  r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);
  Py_DECREF(x);
  return r;
}

static PyObject *__pyx_getprop_5pysam_6cfaidx_9FastaFile_filename(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_6cfaidx_9FastaFile_8filename_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_6cfaidx_9FastaFile_references(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_6cfaidx_9FastaFile_10references_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_6cfaidx_9FastaFile_nreferences(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_6cfaidx_9FastaFile_11nreferences_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_6cfaidx_9FastaFile_lengths(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_6cfaidx_9FastaFile_7lengths_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_6cfaidx_FastaFile[] = {
  {"_isOpen", (PyCFunction)__pyx_pw_5pysam_6cfaidx_9FastaFile_3_isOpen, METH_NOARGS, __pyx_doc_5pysam_6cfaidx_9FastaFile_2_isOpen},
  {"_open", (PyCFunction)__pyx_pw_5pysam_6cfaidx_9FastaFile_7_open, METH_O, __pyx_doc_5pysam_6cfaidx_9FastaFile_6_open},
  {"close", (PyCFunction)__pyx_pw_5pysam_6cfaidx_9FastaFile_9close, METH_NOARGS, __pyx_doc_5pysam_6cfaidx_9FastaFile_8close},
  {"fetch", (PyCFunction)__pyx_pw_5pysam_6cfaidx_9FastaFile_13fetch, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_6cfaidx_9FastaFile_12fetch},
  {"get_reference_length", (PyCFunction)__pyx_pw_5pysam_6cfaidx_9FastaFile_15get_reference_length, METH_O, __pyx_doc_5pysam_6cfaidx_9FastaFile_14get_reference_length},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_6cfaidx_FastaFile[] = {
  {(char *)"filename", __pyx_getprop_5pysam_6cfaidx_9FastaFile_filename, 0, __pyx_k_filename_associated_with_this_ob, 0},
  {(char *)"references", __pyx_getprop_5pysam_6cfaidx_9FastaFile_references, 0, __pyx_k_tuple_with_the_names_of_term_ref, 0},
  {(char *)"nreferences", __pyx_getprop_5pysam_6cfaidx_9FastaFile_nreferences, 0, __pyx_k_number_of_term_reference_sequenc, 0},
  {(char *)"lengths", __pyx_getprop_5pysam_6cfaidx_9FastaFile_lengths, 0, __pyx_k_tuple_with_the_lengths_of_term_r, 0},
  {0, 0, 0, 0, 0}
};

static PySequenceMethods __pyx_tp_as_sequence_FastaFile = {
  __pyx_pw_5pysam_6cfaidx_9FastaFile_5__len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  __pyx_sq_item_5pysam_6cfaidx_FastaFile, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  __pyx_pw_5pysam_6cfaidx_9FastaFile_19__contains__, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_FastaFile = {
  __pyx_pw_5pysam_6cfaidx_9FastaFile_5__len__, /*mp_length*/
  __pyx_pw_5pysam_6cfaidx_9FastaFile_17__getitem__, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyTypeObject __pyx_type_5pysam_6cfaidx_FastaFile = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.cfaidx.FastaFile", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_6cfaidx_FastaFile), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_6cfaidx_FastaFile, /*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*/
  &__pyx_tp_as_sequence_FastaFile, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_FastaFile, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "*(filename)*\n\n    A *FASTA* file. The file is automatically opened.\n\n    This class expects an indexed fasta file and permits\n    random access to fasta sequences.\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_6cfaidx_FastaFile, /*tp_traverse*/
  __pyx_tp_clear_5pysam_6cfaidx_FastaFile, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_6cfaidx_FastaFile, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_6cfaidx_FastaFile, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_6cfaidx_FastaFile, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_6cfaidx_FastqProxy(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  return o;
}

static void __pyx_tp_dealloc_5pysam_6cfaidx_FastqProxy(PyObject *o) {
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_5pysam_6cfaidx_10FastqProxy_name(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_6cfaidx_10FastqProxy_4name_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_6cfaidx_10FastqProxy_sequence(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_6cfaidx_10FastqProxy_8sequence_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_6cfaidx_10FastqProxy_comment(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_6cfaidx_10FastqProxy_7comment_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_6cfaidx_10FastqProxy_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_6cfaidx_10FastqProxy_7quality_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_6cfaidx_FastqProxy[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_6cfaidx_FastqProxy[] = {
  {(char *)"name", __pyx_getprop_5pysam_6cfaidx_10FastqProxy_name, 0, 0, 0},
  {(char *)"sequence", __pyx_getprop_5pysam_6cfaidx_10FastqProxy_sequence, 0, 0, 0},
  {(char *)"comment", __pyx_getprop_5pysam_6cfaidx_10FastqProxy_comment, 0, 0, 0},
  {(char *)"quality", __pyx_getprop_5pysam_6cfaidx_10FastqProxy_quality, 0, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_6cfaidx_FastqProxy = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.cfaidx.FastqProxy", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_6cfaidx_FastqProxy), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_6cfaidx_FastqProxy, /*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*/
  "FastqProxy()", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_6cfaidx_FastqProxy, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_6cfaidx_FastqProxy, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5pysam_6cfaidx_10FastqProxy_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_6cfaidx_FastqProxy, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile __pyx_vtable_5pysam_6cfaidx_FastxFile;

static PyObject *__pyx_tp_new_5pysam_6cfaidx_FastxFile(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_6cfaidx_FastxFile *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_6cfaidx_FastxFile *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_6cfaidx_FastxFile;
  p->_filename = Py_None; Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_5pysam_6cfaidx_9FastxFile_1__cinit__(o, a, k) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_6cfaidx_FastxFile(PyObject *o) {
  struct __pyx_obj_5pysam_6cfaidx_FastxFile *p = (struct __pyx_obj_5pysam_6cfaidx_FastxFile *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_6cfaidx_9FastxFile_9__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->_filename);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_6cfaidx_FastxFile(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_6cfaidx_FastxFile *p = (struct __pyx_obj_5pysam_6cfaidx_FastxFile *)o;
  if (p->_filename) {
    e = (*v)(p->_filename, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_6cfaidx_FastxFile(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_6cfaidx_FastxFile *p = (struct __pyx_obj_5pysam_6cfaidx_FastxFile *)o;
  tmp = ((PyObject*)p->_filename);
  p->_filename = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_6cfaidx_9FastxFile_filename(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_6cfaidx_9FastxFile_8filename_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_6cfaidx_FastxFile[] = {
  {"_isOpen", (PyCFunction)__pyx_pw_5pysam_6cfaidx_9FastxFile_3_isOpen, METH_NOARGS, __pyx_doc_5pysam_6cfaidx_9FastxFile_2_isOpen},
  {"_open", (PyCFunction)__pyx_pw_5pysam_6cfaidx_9FastxFile_5_open, METH_O, __pyx_doc_5pysam_6cfaidx_9FastxFile_4_open},
  {"close", (PyCFunction)__pyx_pw_5pysam_6cfaidx_9FastxFile_7close, METH_NOARGS, __pyx_doc_5pysam_6cfaidx_9FastxFile_6close},
  {"__next__", (PyCFunction)__pyx_pw_5pysam_6cfaidx_9FastxFile_13__next__, METH_NOARGS|METH_COEXIST, __pyx_doc_5pysam_6cfaidx_9FastxFile_12__next__},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_6cfaidx_FastxFile[] = {
  {(char *)"filename", __pyx_getprop_5pysam_6cfaidx_9FastxFile_filename, 0, __pyx_k_filename_associated_with_this_ob, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_6cfaidx_FastxFile = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.cfaidx.FastxFile", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_6cfaidx_FastxFile), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_6cfaidx_FastxFile, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "*(filename)*\n\n    A :term:`fastq` or :term:`fasta` formatted file. The file\n    is automatically opened.\n\n    Entries in the file can be both fastq or fasta formatted\n    or even a mixture of the two.\n\n    This file object permits iterating over all entries in\n    the file. Random access is not implemented. The iteration\n    returns objects of type :class:`FastqProxy`\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_6cfaidx_FastxFile, /*tp_traverse*/
  __pyx_tp_clear_5pysam_6cfaidx_FastxFile, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_6cfaidx_9FastxFile_11__iter__, /*tp_iter*/
  __pyx_pw_5pysam_6cfaidx_9FastxFile_13__next__, /*tp_iternext*/
  __pyx_methods_5pysam_6cfaidx_FastxFile, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_6cfaidx_FastxFile, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_6cfaidx_FastxFile, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_FastqFile __pyx_vtable_5pysam_6cfaidx_FastqFile;

static PyObject *__pyx_tp_new_5pysam_6cfaidx_FastqFile(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_6cfaidx_FastqFile *p;
  PyObject *o = __pyx_tp_new_5pysam_6cfaidx_FastxFile(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_6cfaidx_FastqFile *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile*)__pyx_vtabptr_5pysam_6cfaidx_FastqFile;
  return o;
}

static PyTypeObject __pyx_type_5pysam_6cfaidx_FastqFile = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.cfaidx.FastqFile", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_6cfaidx_FastqFile), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_6cfaidx_FastxFile, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5pysam_6cfaidx_FastxFile, /*tp_traverse*/
  __pyx_tp_clear_5pysam_6cfaidx_FastxFile, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_5pysam_6cfaidx_9FastxFile_11__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_5pysam_6cfaidx_9FastxFile_13__next__, /*tp_iternext*/
  #else
  0, /*tp_iternext*/
  #endif
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_6cfaidx_FastqFile, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_Fastafile __pyx_vtable_5pysam_6cfaidx_Fastafile;

static PyObject *__pyx_tp_new_5pysam_6cfaidx_Fastafile(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_6cfaidx_Fastafile *p;
  PyObject *o = __pyx_tp_new_5pysam_6cfaidx_FastaFile(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_6cfaidx_Fastafile *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_6cfaidx_FastaFile*)__pyx_vtabptr_5pysam_6cfaidx_Fastafile;
  return o;
}

static PyTypeObject __pyx_type_5pysam_6cfaidx_Fastafile = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.cfaidx.Fastafile", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_6cfaidx_Fastafile), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_6cfaidx_FastaFile, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5pysam_6cfaidx_FastaFile, /*tp_traverse*/
  __pyx_tp_clear_5pysam_6cfaidx_FastaFile, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_6cfaidx_Fastafile, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_Fastqfile __pyx_vtable_5pysam_6cfaidx_Fastqfile;

static PyObject *__pyx_tp_new_5pysam_6cfaidx_Fastqfile(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_6cfaidx_Fastqfile *p;
  PyObject *o = __pyx_tp_new_5pysam_6cfaidx_FastxFile(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_6cfaidx_Fastqfile *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile*)__pyx_vtabptr_5pysam_6cfaidx_Fastqfile;
  return o;
}

static PyTypeObject __pyx_type_5pysam_6cfaidx_Fastqfile = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.cfaidx.Fastqfile", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_6cfaidx_Fastqfile), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_6cfaidx_FastxFile, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5pysam_6cfaidx_FastxFile, /*tp_traverse*/
  __pyx_tp_clear_5pysam_6cfaidx_FastxFile, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_5pysam_6cfaidx_9FastxFile_11__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_5pysam_6cfaidx_9FastxFile_13__next__, /*tp_iternext*/
  #else
  0, /*tp_iternext*/
  #endif
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_6cfaidx_Fastqfile, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *__pyx_freelist_5pysam_6cfaidx___pyx_scope_struct___open[8];
static int __pyx_freecount_5pysam_6cfaidx___pyx_scope_struct___open = 0;

static PyObject *__pyx_tp_new_5pysam_6cfaidx___pyx_scope_struct___open(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_6cfaidx___pyx_scope_struct___open > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open)))) {
    o = (PyObject*)__pyx_freelist_5pysam_6cfaidx___pyx_scope_struct___open[--__pyx_freecount_5pysam_6cfaidx___pyx_scope_struct___open];
    memset(o, 0, sizeof(struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_6cfaidx___pyx_scope_struct___open(PyObject *o) {
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *p = (struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_data);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_6cfaidx___pyx_scope_struct___open < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open)))) {
    __pyx_freelist_5pysam_6cfaidx___pyx_scope_struct___open[__pyx_freecount_5pysam_6cfaidx___pyx_scope_struct___open++] = ((struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5pysam_6cfaidx___pyx_scope_struct___open(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *p = (struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *)o;
  if (p->__pyx_v_data) {
    e = (*v)(p->__pyx_v_data, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_6cfaidx___pyx_scope_struct___open(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *p = (struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *)o;
  tmp = ((PyObject*)p->__pyx_v_data);
  p->__pyx_v_data = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_5pysam_6cfaidx___pyx_scope_struct___open = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.cfaidx.__pyx_scope_struct___open", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_6cfaidx___pyx_scope_struct___open, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5pysam_6cfaidx___pyx_scope_struct___open, /*tp_traverse*/
  __pyx_tp_clear_5pysam_6cfaidx___pyx_scope_struct___open, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_6cfaidx___pyx_scope_struct___open, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr *__pyx_freelist_5pysam_6cfaidx___pyx_scope_struct_1_genexpr[8];
static int __pyx_freecount_5pysam_6cfaidx___pyx_scope_struct_1_genexpr = 0;

static PyObject *__pyx_tp_new_5pysam_6cfaidx___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_6cfaidx___pyx_scope_struct_1_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr)))) {
    o = (PyObject*)__pyx_freelist_5pysam_6cfaidx___pyx_scope_struct_1_genexpr[--__pyx_freecount_5pysam_6cfaidx___pyx_scope_struct_1_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_6cfaidx___pyx_scope_struct_1_genexpr(PyObject *o) {
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_x);
  Py_CLEAR(p->__pyx_t_0);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_6cfaidx___pyx_scope_struct_1_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr)))) {
    __pyx_freelist_5pysam_6cfaidx___pyx_scope_struct_1_genexpr[__pyx_freecount_5pysam_6cfaidx___pyx_scope_struct_1_genexpr++] = ((struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5pysam_6cfaidx___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr *)o;
  if (p->__pyx_outer_scope) {
    e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e;
  }
  if (p->__pyx_v_x) {
    e = (*v)(p->__pyx_v_x, 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_5pysam_6cfaidx___pyx_scope_struct_1_genexpr(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr *)o;
  tmp = ((PyObject*)p->__pyx_outer_scope);
  p->__pyx_outer_scope = ((struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_x);
  p->__pyx_v_x = 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_5pysam_6cfaidx___pyx_scope_struct_1_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.cfaidx.__pyx_scope_struct_1_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_1_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_6cfaidx___pyx_scope_struct_1_genexpr, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5pysam_6cfaidx___pyx_scope_struct_1_genexpr, /*tp_traverse*/
  __pyx_tp_clear_5pysam_6cfaidx___pyx_scope_struct_1_genexpr, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_6cfaidx___pyx_scope_struct_1_genexpr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr *__pyx_freelist_5pysam_6cfaidx___pyx_scope_struct_2_genexpr[8];
static int __pyx_freecount_5pysam_6cfaidx___pyx_scope_struct_2_genexpr = 0;

static PyObject *__pyx_tp_new_5pysam_6cfaidx___pyx_scope_struct_2_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_6cfaidx___pyx_scope_struct_2_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr)))) {
    o = (PyObject*)__pyx_freelist_5pysam_6cfaidx___pyx_scope_struct_2_genexpr[--__pyx_freecount_5pysam_6cfaidx___pyx_scope_struct_2_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_6cfaidx___pyx_scope_struct_2_genexpr(PyObject *o) {
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_x);
  Py_CLEAR(p->__pyx_t_0);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_6cfaidx___pyx_scope_struct_2_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr)))) {
    __pyx_freelist_5pysam_6cfaidx___pyx_scope_struct_2_genexpr[__pyx_freecount_5pysam_6cfaidx___pyx_scope_struct_2_genexpr++] = ((struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5pysam_6cfaidx___pyx_scope_struct_2_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr *)o;
  if (p->__pyx_outer_scope) {
    e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e;
  }
  if (p->__pyx_v_x) {
    e = (*v)(p->__pyx_v_x, 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_5pysam_6cfaidx___pyx_scope_struct_2_genexpr(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr *)o;
  tmp = ((PyObject*)p->__pyx_outer_scope);
  p->__pyx_outer_scope = ((struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct___open *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_x);
  p->__pyx_v_x = 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_5pysam_6cfaidx___pyx_scope_struct_2_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.cfaidx.__pyx_scope_struct_2_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_6cfaidx___pyx_scope_struct_2_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_6cfaidx___pyx_scope_struct_2_genexpr, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5pysam_6cfaidx___pyx_scope_struct_2_genexpr, /*tp_traverse*/
  __pyx_tp_clear_5pysam_6cfaidx___pyx_scope_struct_2_genexpr, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_6cfaidx___pyx_scope_struct_2_genexpr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {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
    "cfaidx",
    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_u_Argument_must_be_string_or_unico, __pyx_k_Argument_must_be_string_or_unico, sizeof(__pyx_k_Argument_must_be_string_or_unico), 0, 1, 0, 0},
  {&__pyx_n_s_FastaFile, __pyx_k_FastaFile, sizeof(__pyx_k_FastaFile), 0, 0, 1, 1},
  {&__pyx_n_s_Fastafile, __pyx_k_Fastafile, sizeof(__pyx_k_Fastafile), 0, 0, 1, 1},
  {&__pyx_n_s_FastqFile, __pyx_k_FastqFile, sizeof(__pyx_k_FastqFile), 0, 0, 1, 1},
  {&__pyx_n_s_Fastqfile, __pyx_k_Fastqfile, sizeof(__pyx_k_Fastqfile), 0, 0, 1, 1},
  {&__pyx_n_s_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 0, 0, 1, 1},
  {&__pyx_n_s_IS_PYTHON3, __pyx_k_IS_PYTHON3, sizeof(__pyx_k_IS_PYTHON3), 0, 0, 1, 1},
  {&__pyx_kp_s_I_O_operation_on_closed_file, __pyx_k_I_O_operation_on_closed_file, sizeof(__pyx_k_I_O_operation_on_closed_file), 0, 0, 1, 0},
  {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1},
  {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1},
  {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_kp_s__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 1, 0},
  {&__pyx_kp_b__8, __pyx_k__8, sizeof(__pyx_k__8), 0, 0, 0, 0},
  {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 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_kp_s_calling_len_on_closed_file, __pyx_k_calling_len_on_closed_file, sizeof(__pyx_k_calling_len_on_closed_file), 0, 0, 1, 0},
  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_kp_s_could_not_locate_index_file, __pyx_k_could_not_locate_index_file, sizeof(__pyx_k_could_not_locate_index_file), 0, 0, 1, 0},
  {&__pyx_kp_s_could_not_open_file_s, __pyx_k_could_not_open_file_s, sizeof(__pyx_k_could_not_open_file_s), 0, 0, 1, 0},
  {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
  {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1},
  {&__pyx_kp_s_end_out_of_range_i, __pyx_k_end_out_of_range_i, sizeof(__pyx_k_end_out_of_range_i), 0, 0, 1, 0},
  {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1},
  {&__pyx_n_s_exists, __pyx_k_exists, sizeof(__pyx_k_exists), 0, 0, 1, 1},
  {&__pyx_n_s_exit, __pyx_k_exit, sizeof(__pyx_k_exit), 0, 0, 1, 1},
  {&__pyx_kp_b_fai, __pyx_k_fai, sizeof(__pyx_k_fai), 0, 0, 0, 0},
  {&__pyx_n_s_fetch, __pyx_k_fetch, sizeof(__pyx_k_fetch), 0, 0, 1, 1},
  {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1},
  {&__pyx_n_s_getdefaultencoding, __pyx_k_getdefaultencoding, sizeof(__pyx_k_getdefaultencoding), 0, 0, 1, 1},
  {&__pyx_n_s_getfilesystemencoding, __pyx_k_getfilesystemencoding, sizeof(__pyx_k_getfilesystemencoding), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_kp_s_invalid_region_start_i_end_i, __pyx_k_invalid_region_start_i_end_i, sizeof(__pyx_k_invalid_region_start_i_end_i), 0, 0, 1, 0},
  {&__pyx_n_s_isOpen, __pyx_k_isOpen, sizeof(__pyx_k_isOpen), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_kp_s_no_sequence_region_supplied, __pyx_k_no_sequence_region_supplied, sizeof(__pyx_k_no_sequence_region_supplied), 0, 0, 1, 0},
  {&__pyx_kp_s_no_such_file_or_directory_s, __pyx_k_no_such_file_or_directory_s, sizeof(__pyx_k_no_such_file_or_directory_s), 0, 0, 1, 0},
  {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1},
  {&__pyx_n_s_open_2, __pyx_k_open_2, sizeof(__pyx_k_open_2), 0, 0, 1, 1},
  {&__pyx_n_s_open_locals_genexpr, __pyx_k_open_locals_genexpr, sizeof(__pyx_k_open_locals_genexpr), 0, 0, 1, 1},
  {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1},
  {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  {&__pyx_n_s_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_region, __pyx_k_region, sizeof(__pyx_k_region), 0, 0, 1, 1},
  {&__pyx_kp_s_s_i_i, __pyx_k_s_i_i, sizeof(__pyx_k_s_i_i), 0, 0, 1, 0},
  {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1},
  {&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1},
  {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
  {&__pyx_kp_s_start_out_of_range_i, __pyx_k_start_out_of_range_i, sizeof(__pyx_k_start_out_of_range_i), 0, 0, 1, 0},
  {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 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_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_open = __Pyx_GetBuiltinName(__pyx_n_s_open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "pysam/cfaidx.pyx":89
 *     def __len__(self):
 *         if self.fastafile == NULL:
 *             raise ValueError("calling len() on closed file")             # <<<<<<<<<<<<<<
 * 
 *         return faidx_nseq(self.fastafile)
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_calling_len_on_closed_file); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "pysam/cfaidx.pyx":109
 *         # read index
 *         if not os.path.exists( self._filename + b".fai" ):
 *             raise ValueError("could not locate index file")             # <<<<<<<<<<<<<<
 * 
 *         with open( self._filename + b".fai" ) as inf:
 */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_could_not_locate_index_file); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "pysam/cfaidx.pyx":112
 * 
 *         with open( self._filename + b".fai" ) as inf:
 *             data = [ x.split("\t") for x in inf ]             # <<<<<<<<<<<<<<
 *             self._references = tuple(x[0] for x in data)
 *             self._lengths = tuple(int(x[1]) for x in data)
 */
  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s__3); if (unlikely(!__pyx_tuple__4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);

  /* "pysam/cfaidx.pyx":111
 *             raise ValueError("could not locate index file")
 * 
 *         with open( self._filename + b".fai" ) as inf:             # <<<<<<<<<<<<<<
 *             data = [ x.split("\t") for x in inf ]
 *             self._references = tuple(x[0] for x in data)
 */
  __pyx_tuple__5 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);

  /* "pysam/cfaidx.pyx":168
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         cdef int length
 */
  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);

  /* "pysam/cfaidx.pyx":175
 *         if not region:
 *             if reference is None:
 *                 raise ValueError('no sequence/region supplied.')             # <<<<<<<<<<<<<<
 *             if start is None:
 *                 start = 0
 */
  __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_no_sequence_region_supplied); if (unlikely(!__pyx_tuple__7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__7);
  __Pyx_GIVEREF(__pyx_tuple__7);

  /* "pysam/cfaidx.pyx":201
 *             region = "%s:%i-%i" % (reference, start+1, end)
 *             if PY_MAJOR_VERSION >= 3:
 *                 region = region.encode('ascii')             # <<<<<<<<<<<<<<
 *             seq = fai_fetch( self.fastafile,
 *                              region,
 */
  __pyx_tuple__9 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__9);
  __Pyx_GIVEREF(__pyx_tuple__9);

  /* "pysam/cfaidx.pyx":320
 *     def __iter__(self):
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         return self
 * 
 */
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);
  __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;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initcfaidx(void); /*proto*/
PyMODINIT_FUNC initcfaidx(void)
#else
PyMODINIT_FUNC PyInit_cfaidx(void); /*proto*/
PyMODINIT_FUNC PyInit_cfaidx(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #if CYTHON_REFNANNY
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  #endif
  __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_cfaidx(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("cfaidx", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  if (__pyx_module_is_main_pysam__cfaidx) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!PyDict_GetItemString(modules, "pysam.cfaidx")) {
      if (unlikely(PyDict_SetItemString(modules, "pysam.cfaidx", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Constants init code ---*/
  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  __pyx_v_5pysam_6cfaidx__FILENAME_ENCODING = ((PyObject*)Py_None); Py_INCREF(Py_None);
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  __pyx_vtabptr_5pysam_6cfaidx_FastaFile = &__pyx_vtable_5pysam_6cfaidx_FastaFile;
  __pyx_vtable_5pysam_6cfaidx_FastaFile._fetch = (char *(*)(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, char *, int, int, int *))__pyx_f_5pysam_6cfaidx_9FastaFile__fetch;
  if (PyType_Ready(&__pyx_type_5pysam_6cfaidx_FastaFile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_6cfaidx_FastaFile.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_6cfaidx_FastaFile, "__contains__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_6cfaidx_9FastaFile_18__contains__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_6cfaidx_9FastaFile_18__contains__.doc = __pyx_doc_5pysam_6cfaidx_9FastaFile_18__contains__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_6cfaidx_9FastaFile_18__contains__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_6cfaidx_FastaFile.tp_dict, __pyx_vtabptr_5pysam_6cfaidx_FastaFile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "FastaFile", (PyObject *)&__pyx_type_5pysam_6cfaidx_FastaFile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastaFile = &__pyx_type_5pysam_6cfaidx_FastaFile;
  if (PyType_Ready(&__pyx_type_5pysam_6cfaidx_FastqProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_6cfaidx_FastqProxy.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "FastqProxy", (PyObject *)&__pyx_type_5pysam_6cfaidx_FastqProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastqProxy = &__pyx_type_5pysam_6cfaidx_FastqProxy;
  __pyx_vtabptr_5pysam_6cfaidx_FastxFile = &__pyx_vtable_5pysam_6cfaidx_FastxFile;
  __pyx_vtable_5pysam_6cfaidx_FastxFile.getCurrent = (kseq_t *(*)(struct __pyx_obj_5pysam_6cfaidx_FastxFile *))__pyx_f_5pysam_6cfaidx_9FastxFile_getCurrent;
  __pyx_vtable_5pysam_6cfaidx_FastxFile.cnext = (int (*)(struct __pyx_obj_5pysam_6cfaidx_FastxFile *))__pyx_f_5pysam_6cfaidx_9FastxFile_cnext;
  if (PyType_Ready(&__pyx_type_5pysam_6cfaidx_FastxFile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_6cfaidx_FastxFile.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_6cfaidx_FastxFile, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_6cfaidx_9FastxFile_12__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_6cfaidx_9FastxFile_12__next__.doc = __pyx_doc_5pysam_6cfaidx_9FastxFile_12__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_6cfaidx_9FastxFile_12__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_6cfaidx_FastxFile.tp_dict, __pyx_vtabptr_5pysam_6cfaidx_FastxFile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "FastxFile", (PyObject *)&__pyx_type_5pysam_6cfaidx_FastxFile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastxFile = &__pyx_type_5pysam_6cfaidx_FastxFile;
  __pyx_vtabptr_5pysam_6cfaidx_FastqFile = &__pyx_vtable_5pysam_6cfaidx_FastqFile;
  __pyx_vtable_5pysam_6cfaidx_FastqFile.__pyx_base = *__pyx_vtabptr_5pysam_6cfaidx_FastxFile;
  __pyx_type_5pysam_6cfaidx_FastqFile.tp_base = __pyx_ptype_5pysam_6cfaidx_FastxFile;
  if (PyType_Ready(&__pyx_type_5pysam_6cfaidx_FastqFile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_6cfaidx_FastqFile.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_5pysam_6cfaidx_FastqFile.tp_dict, __pyx_vtabptr_5pysam_6cfaidx_FastqFile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "FastqFile", (PyObject *)&__pyx_type_5pysam_6cfaidx_FastqFile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastqFile = &__pyx_type_5pysam_6cfaidx_FastqFile;
  __pyx_vtabptr_5pysam_6cfaidx_Fastafile = &__pyx_vtable_5pysam_6cfaidx_Fastafile;
  __pyx_vtable_5pysam_6cfaidx_Fastafile.__pyx_base = *__pyx_vtabptr_5pysam_6cfaidx_FastaFile;
  __pyx_type_5pysam_6cfaidx_Fastafile.tp_base = __pyx_ptype_5pysam_6cfaidx_FastaFile;
  if (PyType_Ready(&__pyx_type_5pysam_6cfaidx_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_6cfaidx_Fastafile.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_5pysam_6cfaidx_Fastafile.tp_dict, __pyx_vtabptr_5pysam_6cfaidx_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "Fastafile", (PyObject *)&__pyx_type_5pysam_6cfaidx_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_Fastafile = &__pyx_type_5pysam_6cfaidx_Fastafile;
  __pyx_vtabptr_5pysam_6cfaidx_Fastqfile = &__pyx_vtable_5pysam_6cfaidx_Fastqfile;
  __pyx_vtable_5pysam_6cfaidx_Fastqfile.__pyx_base = *__pyx_vtabptr_5pysam_6cfaidx_FastxFile;
  __pyx_type_5pysam_6cfaidx_Fastqfile.tp_base = __pyx_ptype_5pysam_6cfaidx_FastxFile;
  if (PyType_Ready(&__pyx_type_5pysam_6cfaidx_Fastqfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_6cfaidx_Fastqfile.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_5pysam_6cfaidx_Fastqfile.tp_dict, __pyx_vtabptr_5pysam_6cfaidx_Fastqfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "Fastqfile", (PyObject *)&__pyx_type_5pysam_6cfaidx_Fastqfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_Fastqfile = &__pyx_type_5pysam_6cfaidx_Fastqfile;
  if (PyType_Ready(&__pyx_type_5pysam_6cfaidx___pyx_scope_struct___open) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_6cfaidx___pyx_scope_struct___open.tp_print = 0;
  __pyx_ptype_5pysam_6cfaidx___pyx_scope_struct___open = &__pyx_type_5pysam_6cfaidx___pyx_scope_struct___open;
  if (PyType_Ready(&__pyx_type_5pysam_6cfaidx___pyx_scope_struct_1_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_6cfaidx___pyx_scope_struct_1_genexpr.tp_print = 0;
  __pyx_ptype_5pysam_6cfaidx___pyx_scope_struct_1_genexpr = &__pyx_type_5pysam_6cfaidx___pyx_scope_struct_1_genexpr;
  if (PyType_Ready(&__pyx_type_5pysam_6cfaidx___pyx_scope_struct_2_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_6cfaidx___pyx_scope_struct_2_genexpr.tp_print = 0;
  __pyx_ptype_5pysam_6cfaidx___pyx_scope_struct_2_genexpr = &__pyx_type_5pysam_6cfaidx___pyx_scope_struct_2_genexpr;
  /*--- Type import code ---*/
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if CYTHON_COMPILING_IN_PYPY
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) {__pyx_filename = __pyx_f[1]; __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[2]; __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[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "pysam/cfaidx.pyx":4
 * # cython: profile=True
 * # adds doc-strings for sphinx
 * import sys             # <<<<<<<<<<<<<<
 * import os
 * 
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/cfaidx.pyx":5
 * # adds doc-strings for sphinx
 * import sys
 * import os             # <<<<<<<<<<<<<<
 * 
 * cdef class FastqProxy
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/cfaidx.pyx":33
 * ## Python 3 compatibility functions
 * ########################################################################
 * IS_PYTHON3 = PY_MAJOR_VERSION >= 3             # <<<<<<<<<<<<<<
 * 
 * # filename encoding (copied from lxml.etree.pyx)
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong((PY_MAJOR_VERSION >= 3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_IS_PYTHON3, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/cfaidx.pyx":37
 * # filename encoding (copied from lxml.etree.pyx)
 * cdef str _FILENAME_ENCODING
 * _FILENAME_ENCODING = sys.getfilesystemencoding()             # <<<<<<<<<<<<<<
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = sys.getdefaultencoding()
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_getfilesystemencoding); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __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 = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_XGOTREF(__pyx_v_5pysam_6cfaidx__FILENAME_ENCODING);
  __Pyx_DECREF_SET(__pyx_v_5pysam_6cfaidx__FILENAME_ENCODING, ((PyObject*)__pyx_t_1));
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/cfaidx.pyx":38
 * cdef str _FILENAME_ENCODING
 * _FILENAME_ENCODING = sys.getfilesystemencoding()
 * if _FILENAME_ENCODING is None:             # <<<<<<<<<<<<<<
 *     _FILENAME_ENCODING = sys.getdefaultencoding()
 * if _FILENAME_ENCODING is None:
 */
  __pyx_t_4 = (__pyx_v_5pysam_6cfaidx__FILENAME_ENCODING == ((PyObject*)Py_None));
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "pysam/cfaidx.pyx":39
 * _FILENAME_ENCODING = sys.getfilesystemencoding()
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = sys.getdefaultencoding()             # <<<<<<<<<<<<<<
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = 'ascii'
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_getdefaultencoding); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    if (__pyx_t_3) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XGOTREF(__pyx_v_5pysam_6cfaidx__FILENAME_ENCODING);
    __Pyx_DECREF_SET(__pyx_v_5pysam_6cfaidx__FILENAME_ENCODING, ((PyObject*)__pyx_t_1));
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "pysam/cfaidx.pyx":40
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = sys.getdefaultencoding()
 * if _FILENAME_ENCODING is None:             # <<<<<<<<<<<<<<
 *     _FILENAME_ENCODING = 'ascii'
 * 
 */
  __pyx_t_5 = (__pyx_v_5pysam_6cfaidx__FILENAME_ENCODING == ((PyObject*)Py_None));
  __pyx_t_4 = (__pyx_t_5 != 0);
  if (__pyx_t_4) {

    /* "pysam/cfaidx.pyx":41
 *     _FILENAME_ENCODING = sys.getdefaultencoding()
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = 'ascii'             # <<<<<<<<<<<<<<
 * 
 * #cdef char* _C_FILENAME_ENCODING
 */
    __Pyx_INCREF(__pyx_n_s_ascii);
    __Pyx_XGOTREF(__pyx_v_5pysam_6cfaidx__FILENAME_ENCODING);
    __Pyx_DECREF_SET(__pyx_v_5pysam_6cfaidx__FILENAME_ENCODING, __pyx_n_s_ascii);
    __Pyx_GIVEREF(__pyx_n_s_ascii);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/cfaidx.pyx":61
 * #####################################################################
 * # hard-coded constants
 * cdef int max_pos = 2 << 29             # <<<<<<<<<<<<<<
 * 
 * ## TODO:
 */
  __pyx_v_5pysam_6cfaidx_max_pos = 1073741824;

  /* "pysam/cfaidx.pyx":353
 *     pass
 * 
 * __all__ = ["FastaFile",             # <<<<<<<<<<<<<<
 *            "FastqFile",
 *            "Fastafile",
 */
  __pyx_t_1 = PyList_New(4); 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_INCREF(__pyx_n_s_FastaFile);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_FastaFile);
  __Pyx_GIVEREF(__pyx_n_s_FastaFile);
  __Pyx_INCREF(__pyx_n_s_FastqFile);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_FastqFile);
  __Pyx_GIVEREF(__pyx_n_s_FastqFile);
  __Pyx_INCREF(__pyx_n_s_Fastafile);
  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_Fastafile);
  __Pyx_GIVEREF(__pyx_n_s_Fastafile);
  __Pyx_INCREF(__pyx_n_s_Fastqfile);
  PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_Fastqfile);
  __Pyx_GIVEREF(__pyx_n_s_Fastqfile);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/cfaidx.pyx":1
 * # cython: embedsignature=True             # <<<<<<<<<<<<<<
 * # cython: profile=True
 * # adds doc-strings for sphinx
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init pysam.cfaidx", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init pysam.cfaidx");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* --- Runtime support code --- */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

#if CYTHON_PROFILE
static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
                                   PyFrameObject** frame,
                                   const char *funcname,
                                   const char *srcfile,
                                   int firstlineno) {
    int retval;
    PyThreadState* tstate = PyThreadState_GET();
    if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) {
        if (*code == NULL) {
            *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno);
            if (*code == NULL) return 0;
        }
        *frame = PyFrame_New(
            tstate,                          /*PyThreadState *tstate*/
            *code,                           /*PyCodeObject *code*/
            __pyx_d,                  /*PyObject *globals*/
            0                                /*PyObject *locals*/
        );
        if (*frame == NULL) return 0;
        if (CYTHON_TRACE && (*frame)->f_trace == NULL) {
            Py_INCREF(Py_None);
            (*frame)->f_trace = Py_None;
        }
#if PY_VERSION_HEX < 0x030400B1
    } else {
        (*frame)->f_tstate = tstate;
#endif
    }
    (*frame)->f_lineno = firstlineno;
    retval = 1;
    tstate->tracing++;
    tstate->use_tracing = 0;
    #if CYTHON_TRACE
    if (tstate->c_tracefunc)
        retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0;
    if (retval && tstate->c_profilefunc)
    #endif
        retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0;
    tstate->use_tracing = (tstate->c_profilefunc ||
                           (CYTHON_TRACE && tstate->c_tracefunc));
    tstate->tracing--;
    return tstate->use_tracing && retval;
}
static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyCodeObject *py_code = 0;
    #if PY_MAJOR_VERSION < 3
    py_funcname = PyString_FromString(funcname);
    py_srcfile = PyString_FromString(srcfile);
    #else
    py_funcname = PyUnicode_FromString(funcname);
    py_srcfile = PyUnicode_FromString(srcfile);
    #endif
    if (!py_funcname | !py_srcfile) goto bad;
    py_code = PyCode_New(
        0,
        #if PY_MAJOR_VERSION >= 3
        0,
        #endif
        0,
        0,
        0,
        __pyx_empty_bytes,     /*PyObject *code,*/
        __pyx_empty_tuple,     /*PyObject *consts,*/
        __pyx_empty_tuple,     /*PyObject *names,*/
        __pyx_empty_tuple,     /*PyObject *varnames,*/
        __pyx_empty_tuple,     /*PyObject *freevars,*/
        __pyx_empty_tuple,     /*PyObject *cellvars,*/
        py_srcfile,       /*PyObject *filename,*/
        py_funcname,      /*PyObject *name,*/
        firstlineno,
        __pyx_empty_bytes      /*PyObject *lnotab*/
    );
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return py_code;
}
#endif

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_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 CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_Restore(type, value, tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(type, value, tb);
#endif
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                if (PyObject_IsSubclass(instance_class, type)) {
                    type = instance_class;
                } else {
                    instance_class = NULL;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
#if PY_VERSION_HEX >= 0x03030000
    if (cause) {
#else
    if (cause && cause != Py_None) {
#endif
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(tmp_type, tmp_value, tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#else
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
#if CYTHON_COMPILING_IN_PYPY
    if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
        goto invalid_keyword;
    return 1;
#else
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
        #endif
            if (unlikely(!PyUnicode_Check(key)))
                goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    return 0;
#endif
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) {
    PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname);
}

static CYTHON_INLINE 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));
}

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

static CYTHON_INLINE PyObject *__Pyx_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 void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
#else
    PyErr_GetExcInfo(type, value, tb);
#endif
}
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(type, value, tb);
#endif
}

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_COMPILING_IN_CPYTHON
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

static 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 void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = *type;
    tstate->exc_value = *value;
    tstate->exc_traceback = *tb;
#else
    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
    PyErr_SetExcInfo(*type, *value, *tb);
#endif
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}

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

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

#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 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 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 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_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 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 */
