/* Generated by Cython 0.29.28 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [
            "/opt/conda/conda-bld/plastid_1651772276994/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h",
            "/opt/conda/conda-bld/plastid_1651772276994/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/core/include/numpy/arrayscalars.h",
            "/opt/conda/conda-bld/plastid_1651772276994/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h",
            "/opt/conda/conda-bld/plastid_1651772276994/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h",
            "/opt/conda/conda-bld/plastid_1651772276994/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/core/include/numpy/ufuncobject.h"
        ],
        "include_dirs": [
            "/opt/conda/conda-bld/plastid_1651772276994/work/kent/src/htslib",
            "/opt/conda/conda-bld/plastid_1651772276994/work/kent/src/inc",
            "/opt/conda/conda-bld/plastid_1651772276994/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/core/include",
            "/opt/conda/conda-bld/plastid_1651772276994/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/pysam",
            "/opt/conda/conda-bld/plastid_1651772276994/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/pysam/include/htslib",
            "/opt/conda/conda-bld/plastid_1651772276994/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/pysam/include/samtools"
        ],
        "language": "c",
        "libraries": [
            "ssl",
            "crypto",
            "z"
        ],
        "name": "plastid.genomics.roitools",
        "sources": [
            "/opt/conda/conda-bld/plastid_1651772276994/work/plastid/genomics/roitools.pyx"
        ]
    },
    "module_name": "plastid.genomics.roitools"
}
END: Cython Metadata */

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

#ifndef CYTHON_INLINE
  #if defined(__clang__)
    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  #elif defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif

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

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

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

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

#define __PYX_HAVE__plastid__genomics__roitools
#define __PYX_HAVE_API__plastid__genomics__roitools
/* Early includes */
#include <string.h>
#include <stdio.h>
#include "pythread.h"
#include "numpy/arrayobject.h"
#include "numpy/ndarrayobject.h"
#include "numpy/ndarraytypes.h"
#include "numpy/arrayscalars.h"
#include "numpy/ufuncobject.h"

    /* NumPy API declarations from "numpy/__init__.pxd" */
    
#include <stdlib.h>
#include "pystate.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

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

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

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
    (sizeof(type) < sizeof(Py_ssize_t))  ||\
    (sizeof(type) > sizeof(Py_ssize_t) &&\
          likely(v < (type)PY_SSIZE_T_MAX ||\
                 v == (type)PY_SSIZE_T_MAX)  &&\
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
                                v == (type)PY_SSIZE_T_MIN)))  ||\
    (sizeof(type) == sizeof(Py_ssize_t) &&\
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                               v == (type)PY_SSIZE_T_MAX)))  )
static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
    return (size_t) i < (size_t) limit;
}
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (_MSC_VER)
    #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyBytes_AsWritableString(s)     ((char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyObject_AsWritableString(s)    ((char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((const unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
#define __Pyx_PySequence_Tuple(obj)\
    (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*);
#if CYTHON_ASSUME_SAFE_MACROS
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


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

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

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


static const char *__pyx_f[] = {
  "plastid/genomics/roitools.pyx",
  "plastid/genomics/roitools.pxd",
  "array.pxd",
  "__init__.pxd",
  "stringsource",
  "plastid/genomics/c_common.pxd",
  "type.pxd",
  "bool.pxd",
  "complex.pxd",
};
/* MemviewSliceStruct.proto */
struct __pyx_memoryview_obj;
typedef struct {
  struct __pyx_memoryview_obj *memview;
  char *data;
  Py_ssize_t shape[8];
  Py_ssize_t strides[8];
  Py_ssize_t suboffsets[8];
} __Pyx_memviewslice;
#define __Pyx_MemoryView_Len(m)  (m.shape[0])

/* Atomics.proto */
#include <pythread.h>
#ifndef CYTHON_ATOMICS
    #define CYTHON_ATOMICS 1
#endif
#define __pyx_atomic_int_type int
#if CYTHON_ATOMICS && __GNUC__ >= 4 && (__GNUC_MINOR__ > 1 ||\
                    (__GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL >= 2)) &&\
                    !defined(__i386__)
    #define __pyx_atomic_incr_aligned(value, lock) __sync_fetch_and_add(value, 1)
    #define __pyx_atomic_decr_aligned(value, lock) __sync_fetch_and_sub(value, 1)
    #ifdef __PYX_DEBUG_ATOMICS
        #warning "Using GNU atomics"
    #endif
#elif CYTHON_ATOMICS && defined(_MSC_VER) && 0
    #include <Windows.h>
    #undef __pyx_atomic_int_type
    #define __pyx_atomic_int_type LONG
    #define __pyx_atomic_incr_aligned(value, lock) InterlockedIncrement(value)
    #define __pyx_atomic_decr_aligned(value, lock) InterlockedDecrement(value)
    #ifdef __PYX_DEBUG_ATOMICS
        #pragma message ("Using MSVC atomics")
    #endif
#elif CYTHON_ATOMICS && (defined(__ICC) || defined(__INTEL_COMPILER)) && 0
    #define __pyx_atomic_incr_aligned(value, lock) _InterlockedIncrement(value)
    #define __pyx_atomic_decr_aligned(value, lock) _InterlockedDecrement(value)
    #ifdef __PYX_DEBUG_ATOMICS
        #warning "Using Intel atomics"
    #endif
#else
    #undef CYTHON_ATOMICS
    #define CYTHON_ATOMICS 0
    #ifdef __PYX_DEBUG_ATOMICS
        #warning "Not using atomics"
    #endif
#endif
typedef volatile __pyx_atomic_int_type __pyx_atomic_int;
#if CYTHON_ATOMICS
    #define __pyx_add_acquisition_count(memview)\
             __pyx_atomic_incr_aligned(__pyx_get_slice_count_pointer(memview), memview->lock)
    #define __pyx_sub_acquisition_count(memview)\
            __pyx_atomic_decr_aligned(__pyx_get_slice_count_pointer(memview), memview->lock)
#else
    #define __pyx_add_acquisition_count(memview)\
            __pyx_add_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
    #define __pyx_sub_acquisition_count(memview)\
            __pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
#endif

/* BufferFormatStructs.proto */
#define IS_UNSIGNED(type) (((type) -1) > 0)
struct __Pyx_StructField_;
#define __PYX_BUF_FLAGS_PACKED_STRUCT (1 << 0)
typedef struct {
  const char* name;
  struct __Pyx_StructField_* fields;
  size_t size;
  size_t arraysize[8];
  int ndim;
  char typegroup;
  char is_unsigned;
  int flags;
} __Pyx_TypeInfo;
typedef struct __Pyx_StructField_ {
  __Pyx_TypeInfo* type;
  const char* name;
  size_t offset;
} __Pyx_StructField;
typedef struct {
  __Pyx_StructField* field;
  size_t parent_offset;
} __Pyx_BufFmt_StackElem;
typedef struct {
  __Pyx_StructField root;
  __Pyx_BufFmt_StackElem* head;
  size_t fmt_offset;
  size_t new_count, enc_count;
  size_t struct_alignment;
  int is_complex;
  char enc_type;
  char new_packmode;
  char enc_packmode;
  char is_valid_array;
} __Pyx_BufFmt_Context;

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

/* NoFastGil.proto */
#define __Pyx_PyGILState_Ensure PyGILState_Ensure
#define __Pyx_PyGILState_Release PyGILState_Release
#define __Pyx_FastGIL_Remember()
#define __Pyx_FastGIL_Forget()
#define __Pyx_FastGilFuncInit()


/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":690
 * # in Cython to enable them only on the right systems.
 * 
 * ctypedef npy_int8       int8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 */
typedef npy_int8 __pyx_t_5numpy_int8_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":691
 * 
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t
 */
typedef npy_int16 __pyx_t_5numpy_int16_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":692
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int64      int64_t
 * #ctypedef npy_int96      int96_t
 */
typedef npy_int32 __pyx_t_5numpy_int32_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":693
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_int96      int96_t
 * #ctypedef npy_int128     int128_t
 */
typedef npy_int64 __pyx_t_5numpy_int64_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":697
 * #ctypedef npy_int128     int128_t
 * 
 * ctypedef npy_uint8      uint8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 */
typedef npy_uint8 __pyx_t_5numpy_uint8_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":698
 * 
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t
 */
typedef npy_uint16 __pyx_t_5numpy_uint16_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":699
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint64     uint64_t
 * #ctypedef npy_uint96     uint96_t
 */
typedef npy_uint32 __pyx_t_5numpy_uint32_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":700
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_uint96     uint96_t
 * #ctypedef npy_uint128    uint128_t
 */
typedef npy_uint64 __pyx_t_5numpy_uint64_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":704
 * #ctypedef npy_uint128    uint128_t
 * 
 * ctypedef npy_float32    float32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_float64    float64_t
 * #ctypedef npy_float80    float80_t
 */
typedef npy_float32 __pyx_t_5numpy_float32_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":705
 * 
 * ctypedef npy_float32    float32_t
 * ctypedef npy_float64    float64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_float80    float80_t
 * #ctypedef npy_float128   float128_t
 */
typedef npy_float64 __pyx_t_5numpy_float64_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":714
 * # The int types are mapped a bit surprising --
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t
 */
typedef npy_long __pyx_t_5numpy_int_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":715
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   longlong_t
 * 
 */
typedef npy_longlong __pyx_t_5numpy_long_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":716
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_ulong      uint_t
 */
typedef npy_longlong __pyx_t_5numpy_longlong_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":718
 * ctypedef npy_longlong   longlong_t
 * 
 * ctypedef npy_ulong      uint_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t
 */
typedef npy_ulong __pyx_t_5numpy_uint_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":719
 * 
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 */
typedef npy_ulonglong __pyx_t_5numpy_ulong_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":720
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_intp       intp_t
 */
typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":722
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 * ctypedef npy_intp       intp_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uintp      uintp_t
 * 
 */
typedef npy_intp __pyx_t_5numpy_intp_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":723
 * 
 * ctypedef npy_intp       intp_t
 * ctypedef npy_uintp      uintp_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_double     float_t
 */
typedef npy_uintp __pyx_t_5numpy_uintp_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":725
 * ctypedef npy_uintp      uintp_t
 * 
 * ctypedef npy_double     float_t             # <<<<<<<<<<<<<<
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t
 */
typedef npy_double __pyx_t_5numpy_float_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":726
 * 
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longdouble longdouble_t
 * 
 */
typedef npy_double __pyx_t_5numpy_double_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":727
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cfloat      cfloat_t
 */
typedef npy_longdouble __pyx_t_5numpy_longdouble_t;

/* "plastid/genomics/roitools.pyx":182
 * LONG   = numpy.long
 * 
 * ctypedef numpy.int_t    INT_t             # <<<<<<<<<<<<<<
 * ctypedef numpy.float_t  FLOAT_t
 * ctypedef numpy.double_t DOUBLE_t
 */
typedef __pyx_t_5numpy_int_t __pyx_t_7plastid_8genomics_8roitools_INT_t;

/* "plastid/genomics/roitools.pyx":183
 * 
 * ctypedef numpy.int_t    INT_t
 * ctypedef numpy.float_t  FLOAT_t             # <<<<<<<<<<<<<<
 * ctypedef numpy.double_t DOUBLE_t
 * ctypedef numpy.long_t   LONG_t
 */
typedef __pyx_t_5numpy_float_t __pyx_t_7plastid_8genomics_8roitools_FLOAT_t;

/* "plastid/genomics/roitools.pyx":184
 * ctypedef numpy.int_t    INT_t
 * ctypedef numpy.float_t  FLOAT_t
 * ctypedef numpy.double_t DOUBLE_t             # <<<<<<<<<<<<<<
 * ctypedef numpy.long_t   LONG_t
 * 
 */
typedef __pyx_t_5numpy_double_t __pyx_t_7plastid_8genomics_8roitools_DOUBLE_t;

/* "plastid/genomics/roitools.pyx":185
 * ctypedef numpy.float_t  FLOAT_t
 * ctypedef numpy.double_t DOUBLE_t
 * ctypedef numpy.long_t   LONG_t             # <<<<<<<<<<<<<<
 * 
 * # cdef class SegmentChain
 */
typedef __pyx_t_5numpy_long_t __pyx_t_7plastid_8genomics_8roitools_LONG_t;
/* Declarations.proto */
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< float > __pyx_t_float_complex;
  #else
    typedef float _Complex __pyx_t_float_complex;
  #endif
#else
    typedef struct { float real, imag; } __pyx_t_float_complex;
#endif
static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float);

/* Declarations.proto */
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< double > __pyx_t_double_complex;
  #else
    typedef double _Complex __pyx_t_double_complex;
  #endif
#else
    typedef struct { double real, imag; } __pyx_t_double_complex;
#endif
static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double);


/*--- Type declarations ---*/
#ifndef _ARRAYARRAY_H
struct arrayobject;
typedef struct arrayobject arrayobject;
#endif
struct __pyx_obj_7plastid_8genomics_8c_common__GeneratorWrapper;
struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment;
struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain;
struct __pyx_obj_7plastid_8genomics_8roitools_Transcript;
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed;
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr;
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr;
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr;
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr;
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl;
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr;
struct __pyx_array_obj;
struct __pyx_MemviewEnum_obj;
struct __pyx_memoryview_obj;
struct __pyx_memoryviewslice_obj;

/* "plastid/genomics/c_common.pxd":1
 * cdef enum Strand:             # <<<<<<<<<<<<<<
 *     error_strand   = 666
 *     undef_strand   = 0
 */
enum __pyx_t_7plastid_8genomics_8c_common_Strand {
  __pyx_e_7plastid_8genomics_8c_common_error_strand = 0x29A,
  __pyx_e_7plastid_8genomics_8c_common_undef_strand = 0,
  __pyx_e_7plastid_8genomics_8c_common_forward_strand = 1,
  __pyx_e_7plastid_8genomics_8c_common_reverse_strand = 2,
  __pyx_e_7plastid_8genomics_8c_common_unstranded = 3
};

/* "plastid/genomics/c_common.pxd":8
 *     unstranded     = 3
 * 
 * cdef enum ExBool:             # <<<<<<<<<<<<<<
 *     bool_exception = -1
 *     false     = 0
 */
enum __pyx_t_7plastid_8genomics_8c_common_ExBool {
  __pyx_e_7plastid_8genomics_8c_common_bool_exception = -1L,
  __pyx_e_7plastid_8genomics_8c_common_false = 0,
  __pyx_e_7plastid_8genomics_8c_common_true = 1
};

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":729
 * ctypedef npy_longdouble longdouble_t
 * 
 * ctypedef npy_cfloat      cfloat_t             # <<<<<<<<<<<<<<
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t
 */
typedef npy_cfloat __pyx_t_5numpy_cfloat_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":730
 * 
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t             # <<<<<<<<<<<<<<
 * ctypedef npy_clongdouble clongdouble_t
 * 
 */
typedef npy_cdouble __pyx_t_5numpy_cdouble_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":731
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cdouble     complex_t
 */
typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t;

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":733
 * ctypedef npy_clongdouble clongdouble_t
 * 
 * ctypedef npy_cdouble     complex_t             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 */
typedef npy_cdouble __pyx_t_5numpy_complex_t;
struct __pyx_opt_args_7plastid_8genomics_8roitools_get_attr_from_bed;

/* "plastid/genomics/roitools.pxd":58
 * cdef dict get_attr_from_bed_column_number(list, int, int)
 * cdef dict get_standard_bed_attr(list, int)
 * cdef dict get_attr_from_bed(str line, object extra_columns=*)             # <<<<<<<<<<<<<<
 * cdef list get_segments_from_bed(dict attr)
 * 
 */
struct __pyx_opt_args_7plastid_8genomics_8roitools_get_attr_from_bed {
  int __pyx_n;
  PyObject *extra_columns;
};

/* "plastid/genomics/c_common.pxd":16
 * cdef Strand str_to_strand(str) except error_strand
 * 
 * cdef class _GeneratorWrapper(object):             # <<<<<<<<<<<<<<
 *     cdef:
 *         object generator
 */
struct __pyx_obj_7plastid_8genomics_8c_common__GeneratorWrapper {
  PyObject_HEAD
  PyObject *generator;
  PyObject *desc;
};


/* "plastid/genomics/roitools.pxd":32
 * #===============================================================================
 * 
 * cdef class GenomicSegment(object)             # <<<<<<<<<<<<<<
 * cdef class SegmentChain(object)
 * cdef class Transcript(SegmentChain)
 */
struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment {
  PyObject_HEAD
  struct __pyx_vtabstruct_7plastid_8genomics_8roitools_GenomicSegment *__pyx_vtab;
  PyObject *chrom;
  long start;
  long end;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand c_strand;
};


/* "plastid/genomics/roitools.pxd":33
 * 
 * cdef class GenomicSegment(object)
 * cdef class SegmentChain(object)             # <<<<<<<<<<<<<<
 * cdef class Transcript(SegmentChain)
 * 
 */
struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain {
  PyObject_HEAD
  struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *__pyx_vtab;
  PyObject *_segments;
  PyObject *_mask_segments;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *spanning_segment;
  long length;
  long masked_length;
  arrayobject *_position_hash;
  arrayobject *_position_mask;
  arrayobject *_endmap;
  PyObject *attr;
};


/* "plastid/genomics/roitools.pxd":34
 * cdef class GenomicSegment(object)
 * cdef class SegmentChain(object)
 * cdef class Transcript(SegmentChain)             # <<<<<<<<<<<<<<
 * 
 * 
 */
struct __pyx_obj_7plastid_8genomics_8roitools_Transcript {
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain __pyx_base;
  PyObject *cds_genome_start;
  PyObject *cds_genome_end;
  PyObject *cds_start;
  PyObject *cds_end;
};


/* "plastid/genomics/roitools.pyx":2669
 * 
 *     # TODO: optimize
 *     def as_bed(             # <<<<<<<<<<<<<<
 *         self,
 *         thickstart    = None,
 */
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed {
  PyObject_HEAD
  PyObject *__pyx_v_color;
};


/* "plastid/genomics/roitools.pyx":2770
 *                 else:
 *                     # is a tuple or sequence
 *                     if all(isinstance(X, float) for X in color) and \             # <<<<<<<<<<<<<<
 *                        all(X < 1 for X in color) and \
 *                        all(X > 0 for X in color):
 */
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr {
  PyObject_HEAD
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *__pyx_outer_scope;
  PyObject *__pyx_v_X;
};


/* "plastid/genomics/roitools.pyx":2771
 *                     # is a tuple or sequence
 *                     if all(isinstance(X, float) for X in color) and \
 *                        all(X < 1 for X in color) and \             # <<<<<<<<<<<<<<
 *                        all(X > 0 for X in color):
 *                         color = "%s,%s,%s" % (int(round(255*X)) for X in color)
 */
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr {
  PyObject_HEAD
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *__pyx_outer_scope;
  PyObject *__pyx_v_X;
};


/* "plastid/genomics/roitools.pyx":2772
 *                     if all(isinstance(X, float) for X in color) and \
 *                        all(X < 1 for X in color) and \
 *                        all(X > 0 for X in color):             # <<<<<<<<<<<<<<
 *                         color = "%s,%s,%s" % (int(round(255*X)) for X in color)
 *                     else:
 */
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr {
  PyObject_HEAD
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *__pyx_outer_scope;
  PyObject *__pyx_v_X;
};


/* "plastid/genomics/roitools.pyx":2773
 *                        all(X < 1 for X in color) and \
 *                        all(X > 0 for X in color):
 *                         color = "%s,%s,%s" % (int(round(255*X)) for X in color)             # <<<<<<<<<<<<<<
 *                     else:
 *                         color = "%s,%s,%s" % tuple(color)
 */
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr {
  PyObject_HEAD
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *__pyx_outer_scope;
  PyObject *__pyx_v_X;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "plastid/genomics/roitools.pyx":2809
 *             return ""
 * 
 *     def as_psl(self):             # <<<<<<<<<<<<<<
 *         """Formats |SegmentChain| as `PSL`_ (blat) output.
 * 
 */
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl {
  PyObject_HEAD
  PyObject *__pyx_v_ltmp;
};


/* "plastid/genomics/roitools.pyx":2893
 *             ltmp.append(q_starts)
 *             ltmp.append(t_starts)
 *             return "\t".join(str(X) for X in ltmp) + "\n"             # <<<<<<<<<<<<<<
 *         except KeyError:
 *             raise AttributeError(
 */
struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr {
  PyObject_HEAD
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl *__pyx_outer_scope;
  PyObject *__pyx_v_X;
};


/* "View.MemoryView":105
 * 
 * @cname("__pyx_array")
 * cdef class array:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */
struct __pyx_array_obj {
  PyObject_HEAD
  struct __pyx_vtabstruct_array *__pyx_vtab;
  char *data;
  Py_ssize_t len;
  char *format;
  int ndim;
  Py_ssize_t *_shape;
  Py_ssize_t *_strides;
  Py_ssize_t itemsize;
  PyObject *mode;
  PyObject *_format;
  void (*callback_free_data)(void *);
  int free_data;
  int dtype_is_object;
};


/* "View.MemoryView":279
 * 
 * @cname('__pyx_MemviewEnum')
 * cdef class Enum(object):             # <<<<<<<<<<<<<<
 *     cdef object name
 *     def __init__(self, name):
 */
struct __pyx_MemviewEnum_obj {
  PyObject_HEAD
  PyObject *name;
};


/* "View.MemoryView":330
 * 
 * @cname('__pyx_memoryview')
 * cdef class memoryview(object):             # <<<<<<<<<<<<<<
 * 
 *     cdef object obj
 */
struct __pyx_memoryview_obj {
  PyObject_HEAD
  struct __pyx_vtabstruct_memoryview *__pyx_vtab;
  PyObject *obj;
  PyObject *_size;
  PyObject *_array_interface;
  PyThread_type_lock lock;
  __pyx_atomic_int acquisition_count[2];
  __pyx_atomic_int *acquisition_count_aligned_p;
  Py_buffer view;
  int flags;
  int dtype_is_object;
  __Pyx_TypeInfo *typeinfo;
};


/* "View.MemoryView":965
 * 
 * @cname('__pyx_memoryviewslice')
 * cdef class _memoryviewslice(memoryview):             # <<<<<<<<<<<<<<
 *     "Internal class for passing memoryview slices to Python"
 * 
 */
struct __pyx_memoryviewslice_obj {
  struct __pyx_memoryview_obj __pyx_base;
  __Pyx_memviewslice from_slice;
  PyObject *from_object;
  PyObject *(*to_object_func)(char *);
  int (*to_dtype_func)(char *, PyObject *);
};



/* "plastid/genomics/roitools.pyx":941
 * #==============================================================================
 * 
 * cdef class GenomicSegment:             # <<<<<<<<<<<<<<
 *     """
 *     GenomicSegment(chrom, start, end, strand)
 */

struct __pyx_vtabstruct_7plastid_8genomics_8roitools_GenomicSegment {
  int (*contains)(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, int __pyx_skip_dispatch);
  int (*overlaps)(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, int __pyx_skip_dispatch);
  int (*_cmp_helper)(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, int, int __pyx_skip_dispatch);
  PyObject *(*as_igv_str)(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_7plastid_8genomics_8roitools_GenomicSegment *__pyx_vtabptr_7plastid_8genomics_8roitools_GenomicSegment;


/* "plastid/genomics/roitools.pyx":1251
 *             return self.c_strand
 * 
 * cdef class SegmentChain(object):             # <<<<<<<<<<<<<<
 *     """
 *     SegmentChain(*segments, **attributes)
 */

struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain {
  int (*c_add_segments)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, PyObject *);
  int (*_set_segments)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, PyObject *);
  arrayobject *(*_get_position_hash)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *);
  int (*_set_masks)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, PyObject *);
  void (*c_reset_masks)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *);
  PyObject *(*c_shares_segments_with)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *);
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool (*c_covers)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *);
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool (*c_antisense_overlaps)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *);
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool (*c_unstranded_overlaps)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *);
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool (*c_overlaps)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *);
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool (*c_contains)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *);
  PyObject *(*c_get_position_list)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *);
  PyObject *(*c_get_position_set)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *);
  PyArrayObject *(*c_get_position_array)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, int);
  PyObject *(*get_masked_position_set)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, int __pyx_skip_dispatch);
  long (*c_get_genomic_coordinate)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, long, int);
  long (*c_get_segmentchain_coordinate)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, long, int);
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *(*c_get_subchain)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, long, long, int);
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *(*_restrand)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, enum __pyx_t_7plastid_8genomics_8c_common_Strand);
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *(*get_unstranded)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, int __pyx_skip_dispatch);
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *(*get_antisense)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *__pyx_vtabptr_7plastid_8genomics_8roitools_SegmentChain;


/* "plastid/genomics/roitools.pyx":3555
 * 
 * 
 * cdef class Transcript(SegmentChain):             # <<<<<<<<<<<<<<
 *     """
 *     Transcript(*segments, **attributes)
 */

struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript {
  struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain __pyx_base;
  int (*_update_cds)(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *);
  int (*_update_from_cds_start)(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *);
  int (*_update_from_cds_end)(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *);
  int (*_update_from_cds_genome_start)(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *);
  int (*_update_from_cds_genome_end)(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *);
};
static struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *__pyx_vtabptr_7plastid_8genomics_8roitools_Transcript;


/* "View.MemoryView":105
 * 
 * @cname("__pyx_array")
 * cdef class array:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */

struct __pyx_vtabstruct_array {
  PyObject *(*get_memview)(struct __pyx_array_obj *);
};
static struct __pyx_vtabstruct_array *__pyx_vtabptr_array;


/* "View.MemoryView":330
 * 
 * @cname('__pyx_memoryview')
 * cdef class memoryview(object):             # <<<<<<<<<<<<<<
 * 
 *     cdef object obj
 */

struct __pyx_vtabstruct_memoryview {
  char *(*get_item_pointer)(struct __pyx_memoryview_obj *, PyObject *);
  PyObject *(*is_slice)(struct __pyx_memoryview_obj *, PyObject *);
  PyObject *(*setitem_slice_assignment)(struct __pyx_memoryview_obj *, PyObject *, PyObject *);
  PyObject *(*setitem_slice_assign_scalar)(struct __pyx_memoryview_obj *, struct __pyx_memoryview_obj *, PyObject *);
  PyObject *(*setitem_indexed)(struct __pyx_memoryview_obj *, PyObject *, PyObject *);
  PyObject *(*convert_item_to_object)(struct __pyx_memoryview_obj *, char *);
  PyObject *(*assign_item_from_object)(struct __pyx_memoryview_obj *, char *, PyObject *);
};
static struct __pyx_vtabstruct_memoryview *__pyx_vtabptr_memoryview;


/* "View.MemoryView":965
 * 
 * @cname('__pyx_memoryviewslice')
 * cdef class _memoryviewslice(memoryview):             # <<<<<<<<<<<<<<
 *     "Internal class for passing memoryview slices to Python"
 * 
 */

struct __pyx_vtabstruct__memoryviewslice {
  struct __pyx_vtabstruct_memoryview __pyx_base;
};
static struct __pyx_vtabstruct__memoryviewslice *__pyx_vtabptr__memoryviewslice;

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

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

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

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

/* py_dict_items.proto */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d);

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

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

/* CallUnboundCMethod0.proto */
static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CallUnboundCMethod0(cfunc, self)\
    (likely((cfunc)->func) ?\
        (likely((cfunc)->flag == METH_NOARGS) ?  (*((cfunc)->func))(self, NULL) :\
         (PY_VERSION_HEX >= 0x030600B1 && likely((cfunc)->flag == METH_FASTCALL) ?\
            (PY_VERSION_HEX >= 0x030700A0 ?\
                (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0) :\
                (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL)) :\
          (PY_VERSION_HEX >= 0x030700A0 && (cfunc)->flag == (METH_FASTCALL | METH_KEYWORDS) ?\
            (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL) :\
            (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ?  ((*(PyCFunctionWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\
               ((cfunc)->flag == METH_VARARGS ?  (*((cfunc)->func))(self, __pyx_empty_tuple) :\
               __Pyx__CallUnboundCMethod0(cfunc, self)))))) :\
        __Pyx__CallUnboundCMethod0(cfunc, self))
#else
#define __Pyx_CallUnboundCMethod0(cfunc, self)  __Pyx__CallUnboundCMethod0(cfunc, self)
#endif

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

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

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

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

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

/* PyObjectFormatAndDecref.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f);
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f);

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

/* JoinPyUnicode.proto */
static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
                                      Py_UCS4 max_char);

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

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

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

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

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

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

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

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

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

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

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

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

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

/* SetItemInt.proto */
#define __Pyx_SetItemInt(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_SetItemInt_Fast(o, (Py_ssize_t)i, v, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) :\
               __Pyx_SetItemInt_Generic(o, to_py_func(i), v)))
static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v);
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v,
                                               int is_list, int wraparound, int boundscheck);

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

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

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

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

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

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

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

/* BuildPyUnicode.proto */
static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength,
                                                int prepend_sign, char padding_char);

/* CIntToPyUnicode.proto */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_int(int value, Py_ssize_t width, char padding_char, char format_char);

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

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

/* PyUnicode_Unicode.proto */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Unicode(PyObject *obj);

/* CIntToPyUnicode.proto */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_long(long value, Py_ssize_t width, char padding_char, char format_char);

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

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

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

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

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

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

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

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

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

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

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

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

/* py_dict_pop.proto */
static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value);

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

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

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

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

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

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

/* BufferIndexError.proto */
static void __Pyx_RaiseBufferIndexError(int axis);

/* MemviewSliceInit.proto */
#define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d
#define __Pyx_MEMVIEW_DIRECT   1
#define __Pyx_MEMVIEW_PTR      2
#define __Pyx_MEMVIEW_FULL     4
#define __Pyx_MEMVIEW_CONTIG   8
#define __Pyx_MEMVIEW_STRIDED  16
#define __Pyx_MEMVIEW_FOLLOW   32
#define __Pyx_IS_C_CONTIG 1
#define __Pyx_IS_F_CONTIG 2
static int __Pyx_init_memviewslice(
                struct __pyx_memoryview_obj *memview,
                int ndim,
                __Pyx_memviewslice *memviewslice,
                int memview_is_new_reference);
static CYTHON_INLINE int __pyx_add_acquisition_count_locked(
    __pyx_atomic_int *acquisition_count, PyThread_type_lock lock);
static CYTHON_INLINE int __pyx_sub_acquisition_count_locked(
    __pyx_atomic_int *acquisition_count, PyThread_type_lock lock);
#define __pyx_get_slice_count_pointer(memview) (memview->acquisition_count_aligned_p)
#define __pyx_get_slice_count(memview) (*__pyx_get_slice_count_pointer(memview))
#define __PYX_INC_MEMVIEW(slice, have_gil) __Pyx_INC_MEMVIEW(slice, have_gil, __LINE__)
#define __PYX_XDEC_MEMVIEW(slice, have_gil) __Pyx_XDEC_MEMVIEW(slice, have_gil, __LINE__)
static CYTHON_INLINE void __Pyx_INC_MEMVIEW(__Pyx_memviewslice *, int, int);
static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *, int, int);

/* CIntToPyUnicode.proto */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_Py_ssize_t(Py_ssize_t value, Py_ssize_t width, char padding_char, char format_char);

/* IterNext.proto */
#define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL)
static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject *, PyObject *);

/* SliceTupleAndList.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
#else
#define __Pyx_PyList_GetSlice(seq, start, stop)   PySequence_GetSlice(seq, start, stop)
#define __Pyx_PyTuple_GetSlice(seq, start, stop)  PySequence_GetSlice(seq, start, stop)
#endif

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

/* IsLittleEndian.proto */
static CYTHON_INLINE int __Pyx_Is_Little_Endian(void);

/* BufferFormatCheck.proto */
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts);
static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
                              __Pyx_BufFmt_StackElem* stack,
                              __Pyx_TypeInfo* type);

/* BufferGetAndValidate.proto */
#define __Pyx_GetBufferAndValidate(buf, obj, dtype, flags, nd, cast, stack)\
    ((obj == Py_None || obj == NULL) ?\
    (__Pyx_ZeroBuffer(buf), 0) :\
    __Pyx__GetBufferAndValidate(buf, obj, dtype, flags, nd, cast, stack))
static int  __Pyx__GetBufferAndValidate(Py_buffer* buf, PyObject* obj,
    __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack);
static void __Pyx_ZeroBuffer(Py_buffer* buf);
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info);
static Py_ssize_t __Pyx_minusones[] = { -1, -1, -1, -1, -1, -1, -1, -1 };
static Py_ssize_t __Pyx_zeros[] = { 0, 0, 0, 0, 0, 0, 0, 0 };

/* BufferFallbackError.proto */
static void __Pyx_RaiseBufferFallbackError(void);

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

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

/* ModInt[long].proto */
static CYTHON_INLINE long __Pyx_mod_long(long, long);

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

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

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

/* GetItemIntUnicode.proto */
#define __Pyx_GetItemInt_Unicode(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Unicode_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "string index out of range"), (Py_UCS4)-1))
static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Fast(PyObject* ustring, Py_ssize_t i,
                                                           int wraparound, int boundscheck);

/* PyUnicode_Substring.proto */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Substring(
            PyObject* text, Py_ssize_t start, Py_ssize_t stop);

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

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

/* DivInt[Py_ssize_t].proto */
static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t, Py_ssize_t);

/* UnaryNegOverflows.proto */
#define UNARY_NEG_WOULD_OVERFLOW(x)\
        (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x)))

static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *); /*proto*/
/* GetAttr.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);

/* decode_c_string_utf16.proto */
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors) {
    int byteorder = 0;
    return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
}
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16LE(const char *s, Py_ssize_t size, const char *errors) {
    int byteorder = -1;
    return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
}
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16BE(const char *s, Py_ssize_t size, const char *errors) {
    int byteorder = 1;
    return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
}

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

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

/* SwapException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSwap(type, value, tb)  __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);
#endif

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

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

static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
/* DivInt[long].proto */
static CYTHON_INLINE long __Pyx_div_long(long, long);

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

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

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

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

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

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

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

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

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

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

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

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

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

#if PY_MAJOR_VERSION < 3
    static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags);
    static void __Pyx_ReleaseBuffer(Py_buffer *view);
#else
    #define __Pyx_GetBuffer PyObject_GetBuffer
    #define __Pyx_ReleaseBuffer PyBuffer_Release
#endif


/* BufferStructDeclare.proto */
typedef struct {
  Py_ssize_t shape, strides, suboffsets;
} __Pyx_Buf_DimInfo;
typedef struct {
  size_t refcount;
  Py_buffer pybuffer;
} __Pyx_Buffer;
typedef struct {
  __Pyx_Buffer *rcbuffer;
  char *data;
  __Pyx_Buf_DimInfo diminfo[8];
} __Pyx_LocalBuf_ND;

/* MemviewSliceIsContig.proto */
static int __pyx_memviewslice_is_contig(const __Pyx_memviewslice mvs, char order, int ndim);

/* OverlappingSlices.proto */
static int __pyx_slices_overlap(__Pyx_memviewslice *slice1,
                                __Pyx_memviewslice *slice2,
                                int ndim, size_t itemsize);

/* Capsule.proto */
static CYTHON_INLINE PyObject *__pyx_capsule_create(void *p, const char *sig);

/* TypeInfoCompare.proto */
static int __pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b);

/* MemviewSliceValidateAndInit.proto */
static int __Pyx_ValidateAndInit_memviewslice(
                int *axes_specs,
                int c_or_f_flag,
                int buf_flags,
                int ndim,
                __Pyx_TypeInfo *dtype,
                __Pyx_BufFmt_StackElem stack[],
                __Pyx_memviewslice *memviewslice,
                PyObject *original_obj);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_long(PyObject *, int writable_flag);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_int(PyObject *, int writable_flag);

/* RealImag.proto */
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    #define __Pyx_CREAL(z) ((z).real())
    #define __Pyx_CIMAG(z) ((z).imag())
  #else
    #define __Pyx_CREAL(z) (__real__(z))
    #define __Pyx_CIMAG(z) (__imag__(z))
  #endif
#else
    #define __Pyx_CREAL(z) ((z).real)
    #define __Pyx_CIMAG(z) ((z).imag)
#endif
#if defined(__cplusplus) && CYTHON_CCOMPLEX\
        && (defined(_WIN32) || defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 5 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4 )) || __cplusplus >= 201103)
    #define __Pyx_SET_CREAL(z,x) ((z).real(x))
    #define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
#else
    #define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
    #define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
#endif

/* Arithmetic.proto */
#if CYTHON_CCOMPLEX
    #define __Pyx_c_eq_float(a, b)   ((a)==(b))
    #define __Pyx_c_sum_float(a, b)  ((a)+(b))
    #define __Pyx_c_diff_float(a, b) ((a)-(b))
    #define __Pyx_c_prod_float(a, b) ((a)*(b))
    #define __Pyx_c_quot_float(a, b) ((a)/(b))
    #define __Pyx_c_neg_float(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zero_float(z) ((z)==(float)0)
    #define __Pyx_c_conj_float(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_abs_float(z)     (::std::abs(z))
        #define __Pyx_c_pow_float(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zero_float(z) ((z)==0)
    #define __Pyx_c_conj_float(z)    (conjf(z))
    #if 1
        #define __Pyx_c_abs_float(z)     (cabsf(z))
        #define __Pyx_c_pow_float(a, b)  (cpowf(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eq_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sum_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_diff_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prod_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quot_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_neg_float(__pyx_t_float_complex);
    static CYTHON_INLINE int __Pyx_c_is_zero_float(__pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conj_float(__pyx_t_float_complex);
    #if 1
        static CYTHON_INLINE float __Pyx_c_abs_float(__pyx_t_float_complex);
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_pow_float(__pyx_t_float_complex, __pyx_t_float_complex);
    #endif
#endif

/* Arithmetic.proto */
#if CYTHON_CCOMPLEX
    #define __Pyx_c_eq_double(a, b)   ((a)==(b))
    #define __Pyx_c_sum_double(a, b)  ((a)+(b))
    #define __Pyx_c_diff_double(a, b) ((a)-(b))
    #define __Pyx_c_prod_double(a, b) ((a)*(b))
    #define __Pyx_c_quot_double(a, b) ((a)/(b))
    #define __Pyx_c_neg_double(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zero_double(z) ((z)==(double)0)
    #define __Pyx_c_conj_double(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_abs_double(z)     (::std::abs(z))
        #define __Pyx_c_pow_double(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zero_double(z) ((z)==0)
    #define __Pyx_c_conj_double(z)    (conj(z))
    #if 1
        #define __Pyx_c_abs_double(z)     (cabs(z))
        #define __Pyx_c_pow_double(a, b)  (cpow(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eq_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg_double(__pyx_t_double_complex);
    static CYTHON_INLINE int __Pyx_c_is_zero_double(__pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj_double(__pyx_t_double_complex);
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs_double(__pyx_t_double_complex);
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow_double(__pyx_t_double_complex, __pyx_t_double_complex);
    #endif
#endif

/* MemviewSliceCopyTemplate.proto */
static __Pyx_memviewslice
__pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs,
                                 const char *mode, int ndim,
                                 size_t sizeof_dtype, int contig_flag,
                                 int dtype_is_object);

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

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

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

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

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7plastid_8genomics_8c_common_Strand(enum __pyx_t_7plastid_8genomics_8c_common_Strand value);

/* CIntFromPy.proto */
static CYTHON_INLINE enum __pyx_t_7plastid_8genomics_8c_common_Strand __Pyx_PyInt_As_enum____pyx_t_7plastid_8genomics_8c_common_Strand(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7plastid_8genomics_8c_common_ExBool(enum __pyx_t_7plastid_8genomics_8c_common_ExBool value);

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

/* FetchCommonType.proto */
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);

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

/* CoroutineBase.proto */
typedef PyObject *(*__pyx_coroutine_body_t)(PyObject *, PyThreadState *, PyObject *);
#if CYTHON_USE_EXC_INFO_STACK
#define __Pyx_ExcInfoStruct  _PyErr_StackItem
#else
typedef struct {
    PyObject *exc_type;
    PyObject *exc_value;
    PyObject *exc_traceback;
} __Pyx_ExcInfoStruct;
#endif
typedef struct {
    PyObject_HEAD
    __pyx_coroutine_body_t body;
    PyObject *closure;
    __Pyx_ExcInfoStruct gi_exc_state;
    PyObject *gi_weakreflist;
    PyObject *classobj;
    PyObject *yieldfrom;
    PyObject *gi_name;
    PyObject *gi_qualname;
    PyObject *gi_modulename;
    PyObject *gi_code;
    PyObject *gi_frame;
    int resume_label;
    char is_running;
} __pyx_CoroutineObject;
static __pyx_CoroutineObject *__Pyx__Coroutine_New(
    PyTypeObject *type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
    PyObject *name, PyObject *qualname, PyObject *module_name);
static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit(
            __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
            PyObject *name, PyObject *qualname, PyObject *module_name);
static CYTHON_INLINE void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *self);
static int __Pyx_Coroutine_clear(PyObject *self);
static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value);
static PyObject *__Pyx_Coroutine_Close(PyObject *self);
static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args);
#if CYTHON_USE_EXC_INFO_STACK
#define __Pyx_Coroutine_SwapException(self)
#define __Pyx_Coroutine_ResetAndClearException(self)  __Pyx_Coroutine_ExceptionClear(&(self)->gi_exc_state)
#else
#define __Pyx_Coroutine_SwapException(self) {\
    __Pyx_ExceptionSwap(&(self)->gi_exc_state.exc_type, &(self)->gi_exc_state.exc_value, &(self)->gi_exc_state.exc_traceback);\
    __Pyx_Coroutine_ResetFrameBackpointer(&(self)->gi_exc_state);\
    }
#define __Pyx_Coroutine_ResetAndClearException(self) {\
    __Pyx_ExceptionReset((self)->gi_exc_state.exc_type, (self)->gi_exc_state.exc_value, (self)->gi_exc_state.exc_traceback);\
    (self)->gi_exc_state.exc_type = (self)->gi_exc_state.exc_value = (self)->gi_exc_state.exc_traceback = NULL;\
    }
#endif
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\
    __Pyx_PyGen__FetchStopIterationValue(__pyx_tstate, pvalue)
#else
#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\
    __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, pvalue)
#endif
static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *tstate, PyObject **pvalue);
static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state);

/* PatchModuleWithCoroutine.proto */
static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code);

/* PatchGeneratorABC.proto */
static int __Pyx_patch_abc(void);

/* Generator.proto */
#define __Pyx_Generator_USED
static PyTypeObject *__pyx_GeneratorType = 0;
#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType)
#define __Pyx_Generator_New(body, code, closure, name, qualname, module_name)\
    __Pyx__Coroutine_New(__pyx_GeneratorType, body, code, closure, name, qualname, module_name)
static PyObject *__Pyx_Generator_Next(PyObject *self);
static int __pyx_Generator_init(void);

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

/* PyObjectSetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL)
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value);
#else
#define __Pyx_PyObject_DelAttrStr(o,n)   PyObject_DelAttr(o,n)
#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
#endif

/* VoidPtrExport.proto */
static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig);

/* FunctionExport.proto */
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig);

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

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

static int __pyx_f_7plastid_8genomics_8roitools_14GenomicSegment__cmp_helper(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other, int __pyx_v_cmptype, int __pyx_skip_dispatch); /* proto*/
static int __pyx_f_7plastid_8genomics_8roitools_14GenomicSegment_contains(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other, int __pyx_skip_dispatch); /* proto*/
static int __pyx_f_7plastid_8genomics_8roitools_14GenomicSegment_overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other, int __pyx_skip_dispatch); /* proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_14GenomicSegment_as_igv_str(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
static int __pyx_f_7plastid_8genomics_8roitools_12SegmentChain__set_segments(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_segments); /* proto*/
static arrayobject *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain__get_position_hash(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto*/
static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_contains(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_other); /* proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_shares_segments_with(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_other); /* proto*/
static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_unstranded_overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_other); /* proto*/
static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_other); /* proto*/
static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_antisense_overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_other); /* proto*/
static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_covers(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_other); /* proto*/
static struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain__restrand(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_v_strand); /* proto*/
static struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_get_unstranded(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
static struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_get_antisense(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_position_list(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto*/
static PyArrayObject *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_position_array(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, int __pyx_v_copy); /* proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_position_set(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_get_masked_position_set(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
static int __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_add_segments(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_segments); /* proto*/
static int __pyx_f_7plastid_8genomics_8roitools_12SegmentChain__set_masks(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_segments); /* proto*/
static void __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_reset_masks(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto*/
static long __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_segmentchain_coordinate(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, long __pyx_v_genomic_x, int __pyx_v_stranded); /* proto*/
static long __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_genomic_coordinate(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, long __pyx_v_x, int __pyx_v_stranded); /* proto*/
static struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_subchain(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, long __pyx_v_start, long __pyx_v_end, int __pyx_v_stranded); /* proto*/
static int __pyx_f_7plastid_8genomics_8roitools_10Transcript__update_cds(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto*/
static int __pyx_f_7plastid_8genomics_8roitools_10Transcript__update_from_cds_start(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto*/
static int __pyx_f_7plastid_8genomics_8roitools_10Transcript__update_from_cds_end(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto*/
static int __pyx_f_7plastid_8genomics_8roitools_10Transcript__update_from_cds_genome_start(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto*/
static int __pyx_f_7plastid_8genomics_8roitools_10Transcript__update_from_cds_genome_end(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto*/
static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self); /* proto*/
static char *__pyx_memoryview_get_item_pointer(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index); /* proto*/
static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj); /* proto*/
static PyObject *__pyx_memoryview_setitem_slice_assignment(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_dst, PyObject *__pyx_v_src); /* proto*/
static PyObject *__pyx_memoryview_setitem_slice_assign_scalar(struct __pyx_memoryview_obj *__pyx_v_self, struct __pyx_memoryview_obj *__pyx_v_dst, PyObject *__pyx_v_value); /* proto*/
static PyObject *__pyx_memoryview_setitem_indexed(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /* proto*/
static PyObject *__pyx_memoryview_convert_item_to_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp); /* proto*/
static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value); /* proto*/
static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp); /* proto*/
static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value); /* proto*/

/* Module declarations from 'plastid.genomics.c_common' */
static PyTypeObject *__pyx_ptype_7plastid_8genomics_8c_common__GeneratorWrapper = 0;
static PyObject *(*__pyx_f_7plastid_8genomics_8c_common_strand_to_str)(enum __pyx_t_7plastid_8genomics_8c_common_Strand); /*proto*/
static enum __pyx_t_7plastid_8genomics_8c_common_Strand (*__pyx_f_7plastid_8genomics_8c_common_str_to_strand)(PyObject *); /*proto*/

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

/* Module declarations from '__builtin__' */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* Module declarations from 'cpython' */

/* Module declarations from 'array' */

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

/* Module declarations from 'numpy' */

/* Module declarations from 'numpy' */
static PyTypeObject *__pyx_ptype_5numpy_dtype = 0;
static PyTypeObject *__pyx_ptype_5numpy_flatiter = 0;
static PyTypeObject *__pyx_ptype_5numpy_broadcast = 0;
static PyTypeObject *__pyx_ptype_5numpy_ndarray = 0;
static PyTypeObject *__pyx_ptype_5numpy_generic = 0;
static PyTypeObject *__pyx_ptype_5numpy_number = 0;
static PyTypeObject *__pyx_ptype_5numpy_integer = 0;
static PyTypeObject *__pyx_ptype_5numpy_signedinteger = 0;
static PyTypeObject *__pyx_ptype_5numpy_unsignedinteger = 0;
static PyTypeObject *__pyx_ptype_5numpy_inexact = 0;
static PyTypeObject *__pyx_ptype_5numpy_floating = 0;
static PyTypeObject *__pyx_ptype_5numpy_complexfloating = 0;
static PyTypeObject *__pyx_ptype_5numpy_flexible = 0;
static PyTypeObject *__pyx_ptype_5numpy_character = 0;
static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0;

/* Module declarations from 'plastid.genomics.roitools' */
static PyTypeObject *__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment = 0;
static PyTypeObject *__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain = 0;
static PyTypeObject *__pyx_ptype_7plastid_8genomics_8roitools_Transcript = 0;
static PyTypeObject *__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed = 0;
static PyTypeObject *__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr = 0;
static PyTypeObject *__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr = 0;
static PyTypeObject *__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr = 0;
static PyTypeObject *__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr = 0;
static PyTypeObject *__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl = 0;
static PyTypeObject *__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr = 0;
static PyTypeObject *__pyx_array_type = 0;
static PyTypeObject *__pyx_MemviewEnum_type = 0;
static PyTypeObject *__pyx_memoryview_type = 0;
static PyTypeObject *__pyx_memoryviewslice_type = 0;
static struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_7plastid_8genomics_8roitools_NullSegment = 0;
static PyObject *__pyx_v_7plastid_8genomics_8roitools_hash_template = 0;
static PyObject *__pyx_v_7plastid_8genomics_8roitools_mask_template = 0;
static PyObject *generic = 0;
static PyObject *strided = 0;
static PyObject *indirect = 0;
static PyObject *contiguous = 0;
static PyObject *indirect_contiguous = 0;
static int __pyx_memoryview_thread_locks_used;
static PyThread_type_lock __pyx_memoryview_thread_locks[8];
static PyObject *__pyx_f_7plastid_8genomics_8roitools_positions_to_segments(PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_positionlist_to_segments(PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch); /*proto*/
static struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_f_7plastid_8genomics_8roitools_add_three_for_stop_codon(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *, int __pyx_skip_dispatch); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_merge_segments(PyObject *, int __pyx_skip_dispatch); /*proto*/
static void __pyx_f_7plastid_8genomics_8roitools_nonecheck(PyObject *, PyObject *, PyObject *); /*proto*/
static int __pyx_f_7plastid_8genomics_8roitools_check_segments(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, PyObject *); /*proto*/
static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, int); /*proto*/
static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_transcript_richcmp(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *, struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *, int); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed_column_tuples(PyObject *, int, int, PyObject *); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed_column_names(PyObject *, int, PyObject *); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed_column_number(PyObject *, int, int); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_get_standard_bed_attr(PyObject *, int); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed(PyObject *, struct __pyx_opt_args_7plastid_8genomics_8roitools_get_attr_from_bed *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_get_segments_from_bed(PyObject *); /*proto*/
static struct __pyx_array_obj *__pyx_array_new(PyObject *, Py_ssize_t, char *, char *, char *); /*proto*/
static void *__pyx_align_pointer(void *, size_t); /*proto*/
static PyObject *__pyx_memoryview_new(PyObject *, int, int, __Pyx_TypeInfo *); /*proto*/
static CYTHON_INLINE int __pyx_memoryview_check(PyObject *); /*proto*/
static PyObject *_unellipsify(PyObject *, int); /*proto*/
static PyObject *assert_direct_dimensions(Py_ssize_t *, int); /*proto*/
static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *, PyObject *); /*proto*/
static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *, Py_ssize_t, Py_ssize_t, Py_ssize_t, int, int, int *, Py_ssize_t, Py_ssize_t, Py_ssize_t, int, int, int, int); /*proto*/
static char *__pyx_pybuffer_index(Py_buffer *, char *, Py_ssize_t, Py_ssize_t); /*proto*/
static int __pyx_memslice_transpose(__Pyx_memviewslice *); /*proto*/
static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice, int, PyObject *(*)(char *), int (*)(char *, PyObject *), int); /*proto*/
static __Pyx_memviewslice *__pyx_memoryview_get_slice_from_memoryview(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/
static void __pyx_memoryview_slice_copy(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/
static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *); /*proto*/
static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/
static Py_ssize_t abs_py_ssize_t(Py_ssize_t); /*proto*/
static char __pyx_get_best_slice_order(__Pyx_memviewslice *, int); /*proto*/
static void _copy_strided_to_strided(char *, Py_ssize_t *, char *, Py_ssize_t *, Py_ssize_t *, Py_ssize_t *, int, size_t); /*proto*/
static void copy_strided_to_strided(__Pyx_memviewslice *, __Pyx_memviewslice *, int, size_t); /*proto*/
static Py_ssize_t __pyx_memoryview_slice_get_size(__Pyx_memviewslice *, int); /*proto*/
static Py_ssize_t __pyx_fill_contig_strides_array(Py_ssize_t *, Py_ssize_t *, Py_ssize_t, int, char); /*proto*/
static void *__pyx_memoryview_copy_data_to_temp(__Pyx_memviewslice *, __Pyx_memviewslice *, char, int); /*proto*/
static int __pyx_memoryview_err_extents(int, Py_ssize_t, Py_ssize_t); /*proto*/
static int __pyx_memoryview_err_dim(PyObject *, char *, int); /*proto*/
static int __pyx_memoryview_err(PyObject *, char *); /*proto*/
static int __pyx_memoryview_copy_contents(__Pyx_memviewslice, __Pyx_memviewslice, int, int, int); /*proto*/
static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *, int, int); /*proto*/
static void __pyx_memoryview_refcount_copying(__Pyx_memviewslice *, int, int, int); /*proto*/
static void __pyx_memoryview_refcount_objects_in_slice_with_gil(char *, Py_ssize_t *, Py_ssize_t *, int, int); /*proto*/
static void __pyx_memoryview_refcount_objects_in_slice(char *, Py_ssize_t *, Py_ssize_t *, int, int); /*proto*/
static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *, int, size_t, void *, int); /*proto*/
static void __pyx_memoryview__slice_assign_scalar(char *, Py_ssize_t *, Py_ssize_t *, int, size_t, void *); /*proto*/
static PyObject *__pyx_unpickle_Enum__set_state(struct __pyx_MemviewEnum_obj *, PyObject *); /*proto*/
static __Pyx_TypeInfo __Pyx_TypeInfo_int = { "int", NULL, sizeof(int), { 0 }, 0, IS_UNSIGNED(int) ? 'U' : 'I', IS_UNSIGNED(int), 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_7plastid_8genomics_8roitools_LONG_t = { "LONG_t", NULL, sizeof(__pyx_t_7plastid_8genomics_8roitools_LONG_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_7plastid_8genomics_8roitools_LONG_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_7plastid_8genomics_8roitools_LONG_t), 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_long = { "long", NULL, sizeof(long), { 0 }, 0, IS_UNSIGNED(long) ? 'U' : 'I', IS_UNSIGNED(long), 0 };
#define __Pyx_MODULE_NAME "plastid.genomics.roitools"
extern int __pyx_module_is_main_plastid__genomics__roitools;
int __pyx_module_is_main_plastid__genomics__roitools = 0;

/* Implementation of 'plastid.genomics.roitools' */
static PyObject *__pyx_builtin_staticmethod;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_IndexError;
static PyObject *__pyx_builtin_all;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_AttributeError;
static PyObject *__pyx_builtin_sum;
static PyObject *__pyx_builtin_RuntimeError;
static PyObject *__pyx_builtin_UserWarning;
static PyObject *__pyx_builtin_round;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_zip;
static PyObject *__pyx_builtin_MemoryError;
static PyObject *__pyx_builtin_ImportError;
static PyObject *__pyx_builtin_Ellipsis;
static PyObject *__pyx_builtin_id;
static const char __pyx_k_[] = "='";
static const char __pyx_k_0[] = "0";
static const char __pyx_k_1[] = "1";
static const char __pyx_k_N[] = "N";
static const char __pyx_k_O[] = "O";
static const char __pyx_k_c[] = "c";
static const char __pyx_k_i[] = "i";
static const char __pyx_k_k[] = "k";
static const char __pyx_k_l[] = "l";
static const char __pyx_k_v[] = "v";
static const char __pyx_k_x[] = "x";
static const char __pyx_k_ID[] = ", ID='";
static const char __pyx_k__2[] = "'";
static const char __pyx_k__3[] = ",";
static const char __pyx_k__4[] = "', ";
static const char __pyx_k__5[] = ", ";
static const char __pyx_k__6[] = ", '";
static const char __pyx_k__7[] = "')";
static const char __pyx_k__8[] = " ,";
static const char __pyx_k__9[] = ")\n";
static const char __pyx_k_as[] = "' as '";
static const char __pyx_k_ga[] = "ga";
static const char __pyx_k_id[] = "id";
static const char __pyx_k_iv[] = "iv";
static const char __pyx_k_na[] = "na";
static const char __pyx_k_re[] = "re";
static const char __pyx_k_sb[] = "sb";
static const char __pyx_k_sq[] = "sq";
static const char __pyx_k_st[] = "st";
static const char __pyx_k_tx[] = "tx";
static const char __pyx_k_CDS[] = "CDS";
static const char __pyx_k_INT[] = "INT";
static const char __pyx_k_Seq[] = "Seq";
static const char __pyx_k__10[] = ".\n\t    ";
static const char __pyx_k__11[] = ".";
static const char __pyx_k__12[] = ":";
static const char __pyx_k__13[] = "-";
static const char __pyx_k__14[] = "(";
static const char __pyx_k__15[] = ")";
static const char __pyx_k__17[] = "'.";
static const char __pyx_k__18[] = "\n";
static const char __pyx_k__19[] = "\t";
static const char __pyx_k__25[] = ").";
static const char __pyx_k__26[] = "'>";
static const char __pyx_k__29[] = "<";
static const char __pyx_k__30[] = ">";
static const char __pyx_k__31[] = "^";
static const char __pyx_k__33[] = "";
static const char __pyx_k__35[] = "'.\n";
static const char __pyx_k__42[] = "+";
static const char __pyx_k__66[] = "([^:]*):([^(]+)\\(([+-.])\\)";
static const char __pyx_k__68[] = "\000";
static const char __pyx_k_all[] = "all";
static const char __pyx_k_end[] = "end";
static const char __pyx_k_get[] = "get";
static const char __pyx_k_inp[] = "inp";
static const char __pyx_k_int[] = "int";
static const char __pyx_k_nan[] = "nan";
static const char __pyx_k_new[] = "__new__";
static const char __pyx_k_obj[] = "obj";
static const char __pyx_k_pop[] = "pop";
static const char __pyx_k_seg[] = "seg";
static const char __pyx_k_seq[] = "seq";
static const char __pyx_k_sum[] = "sum";
static const char __pyx_k_zip[] = "zip";
static const char __pyx_k_3UTR[] = "3UTR";
static const char __pyx_k_5UTR[] = "5UTR";
static const char __pyx_k_ID_2[] = "ID";
static const char __pyx_k_LONG[] = "LONG";
static const char __pyx_k_Name[] = "Name";
static const char __pyx_k_None[] = "None";
static const char __pyx_k_args[] = "args";
static const char __pyx_k_attr[] = "attr";
static const char __pyx_k_base[] = "base";
static const char __pyx_k_copy[] = "copy";
static const char __pyx_k_dict[] = "__dict__";
static const char __pyx_k_dtmp[] = "dtmp";
static const char __pyx_k_exon[] = "exon";
static const char __pyx_k_intc[] = "intc";
static const char __pyx_k_line[] = "line";
static const char __pyx_k_long[] = "long";
static const char __pyx_k_ltmp[] = "ltmp";
static const char __pyx_k_mRNA[] = "mRNA";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_mask[] = "mask";
static const char __pyx_k_mode[] = "mode";
static const char __pyx_k_name[] = "__name__";
static const char __pyx_k_ndim[] = "ndim";
static const char __pyx_k_next[] = "__next__";
static const char __pyx_k_none[] = "none";
static const char __pyx_k_pack[] = "pack";
static const char __pyx_k_segs[] = "segs";
static const char __pyx_k_send[] = "send";
static const char __pyx_k_size[] = "size";
static const char __pyx_k_step[] = "step";
static const char __pyx_k_stmp[] = "stmp";
static const char __pyx_k_stop[] = "stop";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_type[] = "type";
static const char __pyx_k_warn[] = "warn";
static const char __pyx_k_with[] = " with '";
static const char __pyx_k_0_0_0[] = "0,0,0";
static const char __pyx_k_ASCII[] = "ASCII";
static const char __pyx_k_FLOAT[] = "FLOAT";
static const char __pyx_k_array[] = "array";
static const char __pyx_k_chain[] = "chain";
static const char __pyx_k_chrom[] = "chrom";
static const char __pyx_k_class[] = "__class__";
static const char __pyx_k_close[] = "close";
static const char __pyx_k_color[] = "color";
static const char __pyx_k_dtype[] = "dtype";
static const char __pyx_k_empty[] = "empty";
static const char __pyx_k_error[] = "error";
static const char __pyx_k_flags[] = "flags";
static const char __pyx_k_float[] = "float";
static const char __pyx_k_frame[] = "frame";
static const char __pyx_k_isnan[] = "isnan";
static const char __pyx_k_items[] = "items";
static const char __pyx_k_numpy[] = "numpy";
static const char __pyx_k_other[] = "other";
static const char __pyx_k_phase[] = "phase";
static const char __pyx_k_piece[] = "piece";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_round[] = "round";
static const char __pyx_k_s_CDS[] = "%s_CDS";
static const char __pyx_k_s_end[] = "s_end";
static const char __pyx_k_s_s_s[] = "%s,%s,%s";
static const char __pyx_k_score[] = "score";
static const char __pyx_k_shape[] = "shape";
static const char __pyx_k_split[] = "split";
static const char __pyx_k_start[] = "start";
static const char __pyx_k_strip[] = "strip";
static const char __pyx_k_throw[] = "throw";
static const char __pyx_k_000000[] = "#000000";
static const char __pyx_k_DOUBLE[] = "DOUBLE";
static const char __pyx_k_Parent[] = "Parent";
static const char __pyx_k_as_bed[] = "as_bed";
static const char __pyx_k_as_gtf[] = "as_gtf";
static const char __pyx_k_as_int[] = "as_int";
static const char __pyx_k_astype[] = "astype";
static const char __pyx_k_blocks[] = "blocks";
static const char __pyx_k_bounds[] = " bounds=";
static const char __pyx_k_copy_2[] = "__copy__";
static const char __pyx_k_double[] = "double";
static const char __pyx_k_encode[] = "encode";
static const char __pyx_k_escape[] = "escape";
static const char __pyx_k_exon_2[] = ":exon:";
static const char __pyx_k_format[] = "format";
static const char __pyx_k_genome[] = "genome";
static const char __pyx_k_groups[] = "groups";
static const char __pyx_k_igvpat[] = "igvpat";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_ivcpat[] = "ivcpat";
static const char __pyx_k_length[] = " (length ";
static const char __pyx_k_middle[] = "middle";
static const char __pyx_k_name_2[] = "name";
static const char __pyx_k_name_s[] = " name=%s";
static const char __pyx_k_pickle[] = "pickle";
static const char __pyx_k_reduce[] = "__reduce__";
static const char __pyx_k_s_3UTR[] = "%s_3UTR";
static const char __pyx_k_s_5UTR[] = "%s_5UTR";
static const char __pyx_k_search[] = "search";
static const char __pyx_k_segpat[] = "segpat";
static const char __pyx_k_source[] = "source";
static const char __pyx_k_sstart[] = "sstart";
static const char __pyx_k_strand[] = "strand";
static const char __pyx_k_struct[] = "struct";
static const char __pyx_k_tolist[] = "tolist";
static const char __pyx_k_unpack[] = "unpack";
static const char __pyx_k_update[] = "update";
static const char __pyx_k_values[] = "values";
static const char __pyx_k_0_9_0_9[] = "([^:]*):([0-9]+)-([0-9]+)";
static const char __pyx_k_Bio_Seq[] = "Bio.Seq";
static const char __pyx_k_as_gff3[] = "as_gff3";
static const char __pyx_k_asarray[] = "asarray";
static const char __pyx_k_cds_end[] = "': cds_end (";
static const char __pyx_k_cmptype[] = "cmptype";
static const char __pyx_k_compile[] = "compile";
static const char __pyx_k_fortran[] = "fortran";
static const char __pyx_k_gene__s[] = "gene_%s";
static const char __pyx_k_gene_id[] = "gene_id";
static const char __pyx_k_genexpr[] = "genexpr";
static const char __pyx_k_get_cds[] = "get_cds";
static const char __pyx_k_iv_ltmp[] = "iv_ltmp";
static const char __pyx_k_loc_str[] = "loc_str";
static const char __pyx_k_memview[] = "memview";
static const char __pyx_k_s_start[] = "s_start";
static const char __pyx_k_segment[] = "segment";
static const char __pyx_k_t_start[] = "t_start";
static const char __pyx_k_Ellipsis[] = "Ellipsis";
static const char __pyx_k_KeyError[] = "KeyError";
static const char __pyx_k_Position[] = "Position ";
static const char __pyx_k_c_strand[] = "c_strand";
static const char __pyx_k_contains[] = "contains";
static const char __pyx_k_custom_s[] = "custom%s";
static const char __pyx_k_deepcopy[] = "deepcopy";
static const char __pyx_k_excludes[] = "excludes";
static const char __pyx_k_from_bed[] = "from_bed";
static const char __pyx_k_from_psl[] = "from_psl";
static const char __pyx_k_from_str[] = "from_str";
static const char __pyx_k_get_attr[] = "_get_attr";
static const char __pyx_k_get_gene[] = "get_gene";
static const char __pyx_k_get_name[] = "get_name";
static const char __pyx_k_get_utr3[] = "get_utr3";
static const char __pyx_k_get_utr5[] = "get_utr5";
static const char __pyx_k_getstate[] = "__getstate__";
static const char __pyx_k_itemsize[] = "itemsize";
static const char __pyx_k_numpy_ma[] = "numpy.ma";
static const char __pyx_k_of_types[] = "' of types '";
static const char __pyx_k_overlaps[] = "overlaps";
static const char __pyx_k_psl_line[] = "psl_line";
static const char __pyx_k_pyx_capi[] = "__pyx_capi__";
static const char __pyx_k_pyx_type[] = "__pyx_type";
static const char __pyx_k_q_starts[] = "q_starts";
static const char __pyx_k_rna_type[] = "rna_type";
static const char __pyx_k_segchain[] = "segchain";
static const char __pyx_k_segments[] = " segments=";
static const char __pyx_k_setstate[] = "__setstate__";
static const char __pyx_k_strand_2[] = " strand='";
static const char __pyx_k_stranded[] = "stranded";
static const char __pyx_k_t_starts[] = "t_starts";
static const char __pyx_k_thickend[] = "thickend";
static const char __pyx_k_value_of[] = ": value of ";
static const char __pyx_k_0_9_0_9_2[] = "([^:]*):([0-9]+)-([0-9]+)\\(([+-.])\\)";
static const char __pyx_k_None_None[] = "None:(None)";
static const char __pyx_k_SeqRecord[] = "SeqRecord";
static const char __pyx_k_TypeError[] = "TypeError";
static const char __pyx_k_alignment[] = "alignment";
static const char __pyx_k_cds_start[] = "': cds_start (";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_genomic_x[] = "genomic_x";
static const char __pyx_k_must_be_0[] = ") must be >= 0";
static const char __pyx_k_positions[] = "positions";
static const char __pyx_k_pyx_state[] = "__pyx_state";
static const char __pyx_k_query_end[] = "query_end";
static const char __pyx_k_reduce_ex[] = "__reduce_ex__";
static const char __pyx_k_roi_order[] = "roi_order";
static const char __pyx_k_sq_starts[] = "sq_starts";
static const char __pyx_k_st_starts[] = "st_starts";
static const char __pyx_k_IndexError[] = "IndexError";
static const char __pyx_k_Transcript[] = "Transcript(";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_and_object[] = "' and object '";
static const char __pyx_k_as_igv_str[] = "as_igv_str";
static const char __pyx_k_block_size[] = "block_size";
static const char __pyx_k_blocksizes[] = "blocksizes";
static const char __pyx_k_cmp_helper[] = "_cmp_helper";
static const char __pyx_k_contains_2[] = "__contains__";
static const char __pyx_k_empty_like[] = "empty_like";
static const char __pyx_k_frombuffer[] = "frombuffer";
static const char __pyx_k_get_counts[] = "get_counts";
static const char __pyx_k_get_rgb255[] = "get_rgb255";
static const char __pyx_k_mismatches[] = "mismatches";
static const char __pyx_k_pyx_result[] = "__pyx_result";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static const char __pyx_k_query_name[] = "query_name";
static const char __pyx_k_s_subchain[] = "%s_subchain";
static const char __pyx_k_segments_2[] = "segments";
static const char __pyx_k_stop_codon[] = "stop_codon";
static const char __pyx_k_target_end[] = "target_end";
static const char __pyx_k_thickstart[] = "thickstart";
static const char __pyx_k_transcript[] = "transcript";
static const char __pyx_k_zeros_like[] = "zeros_like";
static const char __pyx_k_DataWarning[] = "DataWarning";
static const char __pyx_k_ImportError[] = "ImportError";
static const char __pyx_k_MaskedArray[] = "MaskedArray";
static const char __pyx_k_MemoryError[] = "MemoryError";
static const char __pyx_k_NullSegment[] = "NullSegment";
static const char __pyx_k_PickleError[] = "PickleError";
static const char __pyx_k_UserWarning[] = "UserWarning";
static const char __pyx_k_block_sizes[] = "block_sizes";
static const char __pyx_k_blockstarts[] = "blockstarts";
static const char __pyx_k_chrom_start[] = "chrom_start";
static const char __pyx_k_empty_value[] = "empty_value";
static const char __pyx_k_must_be_end[] = ") must be >= end (";
static const char __pyx_k_query_start[] = "query_start";
static const char __pyx_k_rep_matches[] = "rep_matches";
static const char __pyx_k_start_codon[] = "start_codon";
static const char __pyx_k_target_name[] = "target_name";
static const char __pyx_k_RuntimeError[] = "RuntimeError";
static const char __pyx_k_SegmentChain[] = "SegmentChain(";
static const char __pyx_k_Transcript_2[] = "Transcript '";
static const char __pyx_k_Transcript_3[] = "Transcript";
static const char __pyx_k_feature_type[] = "feature_type";
static const char __pyx_k_from_igv_str[] = "from_igv_str";
static const char __pyx_k_get_sequence[] = "get_sequence";
static const char __pyx_k_get_subchain[] = "get_subchain";
static const char __pyx_k_match_length[] = "match_length";
static const char __pyx_k_pyx_checksum[] = "__pyx_checksum";
static const char __pyx_k_query_length[] = "query_length";
static const char __pyx_k_staticmethod[] = "staticmethod";
static const char __pyx_k_stringsource[] = "stringsource";
static const char __pyx_k_target_start[] = "target_start";
static const char __pyx_k_Bio_SeqRecord[] = "Bio.SeqRecord";
static const char __pyx_k_extra_columns[] = "extra_columns";
static const char __pyx_k_get_antisense[] = "get_antisense";
static const char __pyx_k_get_junctions[] = "get_junctions";
static const char __pyx_k_pyx_getbuffer[] = "__pyx_getbuffer";
static const char __pyx_k_reduce_cython[] = "__reduce_cython__";
static const char __pyx_k_target_length[] = "target_length";
static const char __pyx_k_transcript_id[] = "transcript_id";
static const char __pyx_k_AttributeError[] = "AttributeError";
static const char __pyx_k_GenomicSegment[] = "GenomicSegment('";
static const char __pyx_k_NullChromosome[] = "NullChromosome";
static const char __pyx_k_SegmentChain_2[] = "SegmentChain";
static const char __pyx_k_cannot_be_None[] = " cannot be None";
static const char __pyx_k_cds_genome_end[] = ", cds_genome_end=";
static const char __pyx_k_five_prime_UTR[] = "five_prime_UTR";
static const char __pyx_k_get_unstranded[] = "get_unstranded";
static const char __pyx_k_View_MemoryView[] = "View.MemoryView";
static const char __pyx_k_allocate_buffer[] = "allocate_buffer";
static const char __pyx_k_dtype_is_object[] = "dtype_is_object";
static const char __pyx_k_is_not_in_chain[] = "' is not in chain '";
static const char __pyx_k_must_be_cds_end[] = ") must be <= cds_end (";
static const char __pyx_k_of_SegmentChain[] = ") of SegmentChain '";
static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError";
static const char __pyx_k_query_gap_bases[] = "query_gap_bases";
static const char __pyx_k_query_gap_count[] = "query_gap_count";
static const char __pyx_k_setstate_cython[] = "__setstate_cython__";
static const char __pyx_k_three_prime_UTR[] = "three_prime_UTR";
static const char __pyx_k_GenomicSegment_2[] = "<GenomicSegment ";
static const char __pyx_k_GenomicSegment_3[] = "GenomicSegment";
static const char __pyx_k_cds_genome_end_2[] = "cds_genome_end";
static const char __pyx_k_cds_genome_end_3[] = "': cds_genome_end (";
static const char __pyx_k_cds_genome_start[] = "', cds_genome_start=";
static const char __pyx_k_get_str_from_rgb[] = "get_str_from_rgb";
static const char __pyx_k_make_GFF3_tokens[] = "make_GFF3_tokens";
static const char __pyx_k_make_GTF2_tokens[] = "make_GTF2_tokens";
static const char __pyx_k_target_gap_bases[] = "target_gap_bases";
static const char __pyx_k_target_gap_count[] = "target_gap_count";
static const char __pyx_k_bedx_column_order[] = "_bedx_column_order";
static const char __pyx_k_format_transcript[] = "_format_transcript";
static const char __pyx_k_from_SegmentChain[] = " from SegmentChain ";
static const char __pyx_k_get_8_gff_columns[] = "_get_8_gff_columns";
static const char __pyx_k_get_position_list[] = "get_position_list";
static const char __pyx_k_must_be_cds_start[] = ") must be >= cds_start (";
static const char __pyx_k_pyx_unpickle_Enum[] = "__pyx_unpickle_Enum";
static const char __pyx_k_cds_genome_start_2[] = "cds_genome_start";
static const char __pyx_k_cds_genome_start_3[] = "': cds_genome_start (";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_reverse_complement[] = "reverse_complement";
static const char __pyx_k_strided_and_direct[] = "<strided and direct>";
static const char __pyx_k_GenomicSegment___eq[] = "GenomicSegment.__eq__";
static const char __pyx_k_format_segmentchain[] = "_format_segmentchain";
static const char __pyx_k_get_str_from_rgb255[] = "get_str_from_rgb255";
static const char __pyx_k_is_outside_bounds_0[] = " is outside bounds [0,";
static const char __pyx_k_must_be_self_length[] = ") must be <= self.length (";
static const char __pyx_k_not_in_SegmentChain[] = " not in SegmentChain ";
static const char __pyx_k_does_not_match_chain[] = "' does not match chain '";
static const char __pyx_k_strided_and_indirect[] = "<strided and indirect>";
static const char __pyx_k_GenomicSegment_eq_neq[] = "GenomicSegment eq/neq";
static const char __pyx_k_as_bed_locals_genexpr[] = "as_bed.<locals>.genexpr";
static const char __pyx_k_as_psl_locals_genexpr[] = "as_psl.<locals>.genexpr";
static const char __pyx_k_contiguous_and_direct[] = "<contiguous and direct>";
static const char __pyx_k_Defaulting_to_type_str[] = "'. Defaulting to type 'str'.";
static const char __pyx_k_MemoryView_of_r_object[] = "<MemoryView of %r object>";
static const char __pyx_k_must_be_cds_genome_end[] = ") must be <= cds_genome_end (";
static const char __pyx_k_Cannot_fetch_coordinate[] = "Cannot fetch coordinate ";
static const char __pyx_k_GenomicSegment_contains[] = "GenomicSegment.contains";
static const char __pyx_k_GenomicSegment_overlaps[] = "GenomicSegment.overlaps";
static const char __pyx_k_MemoryView_of_r_at_0x_x[] = "<MemoryView of %r at 0x%x>";
static const char __pyx_k_contiguous_and_indirect[] = "<contiguous and indirect>";
static const char __pyx_k_get_masked_position_set[] = "get_masked_position_set";
static const char __pyx_k_plastid_plotting_colors[] = "plastid.plotting.colors";
static const char __pyx_k_Cannot_index_with_type_s[] = "Cannot index with type '%s'";
static const char __pyx_k_must_be_cds_genome_start[] = ") must be >= cds_genome_start (";
static const char __pyx_k_Invalid_shape_in_axis_d_d[] = "Invalid shape in axis %d: %d.";
static const char __pyx_k_plastid_genomics_roitools[] = "plastid.genomics.roitools";
static const char __pyx_k_Could_not_parse_BED_line_s[] = "Could not parse BED line:\n\t    '%s'";
static const char __pyx_k_plastid_readers_gff_tokens[] = "plastid.readers.gff_tokens";
static const char __pyx_k_get_segmentchain_coordinate[] = "get_segmentchain_coordinate";
static const char __pyx_k_itemsize_0_for_cython_array[] = "itemsize <= 0 for cython.array";
static const char __pyx_k_Falling_back_to_default_value[] = "'. Falling back to default value '";
static const char __pyx_k_plastid_genomics_roitools_pyx[] = "plastid/genomics/roitools.pyx";
static const char __pyx_k_unable_to_allocate_array_data[] = "unable to allocate array data.";
static const char __pyx_k_wrong_and_or_multiple_strands[] = "; wrong and/or multiple strands";
static const char __pyx_k_strided_and_direct_or_indirect[] = "<strided and direct or indirect>";
static const char __pyx_k_GenomicSegment_start_coordinate[] = "GenomicSegment: start coordinate (";
static const char __pyx_k_SegmentChain_antisense_overlaps[] = "SegmentChain.antisense_overlaps() errored on chain '";
static const char __pyx_k_SegmentChain_from_bed_Could_not[] = "SegmentChain.from_bed(): Could not format '";
static const char __pyx_k_Segmentchain_adding_segments_to[] = "Segmentchain: adding segments to %s will reset its masks!";
static const char __pyx_k_end_coordinate_supplied_is_None[] = "end coordinate supplied is None. Expected int";
static const char __pyx_k_get_attr_from_bed_List_of_extra[] = "get_attr_from_bed: List of `extra_columns` contains mixed types. All items need to be the same type, either str or tuple.";
static const char __pyx_k_get_standard_bed_attr_Could_not[] = "get_standard_bed_attr: Could not format column ";
static const char __pyx_k_numpy_core_multiarray_failed_to[] = "numpy.core.multiarray failed to import";
static const char __pyx_k_s_is_a_zero_length_SegmentChain[] = "%s is a zero-length SegmentChain. Returning 0-length count vector.";
static const char __pyx_k_wrong_and_or_multiple_chromosom[] = "; wrong and/or multiple chromosomes";
static const char __pyx_k_Attempted_export_of_multi_interv[] = "Attempted export of multi-interval %s";
static const char __pyx_k_BED_format_requires_at_least_3_c[] = "BED format requires at least 3 columns. Found only ";
static const char __pyx_k_Buffer_view_does_not_expose_stri[] = "Buffer view does not expose strides";
static const char __pyx_k_Can_only_create_a_buffer_that_is[] = "Can only create a buffer that is contiguous in memory.";
static const char __pyx_k_Cannot_assign_to_read_only_memor[] = "Cannot assign to read-only memoryview";
static const char __pyx_k_Cannot_create_writable_memory_vi[] = "Cannot create writable memory view from read-only memoryview";
static const char __pyx_k_Comparison_operation_not_defined[] = "Comparison operation not defined";
static const char __pyx_k_Empty_shape_tuple_for_cython_arr[] = "Empty shape tuple for cython.array";
static const char __pyx_k_Incompatible_checksums_s_vs_0xb0[] = "Incompatible checksums (%s vs 0xb068931 = (name))";
static const char __pyx_k_Indirect_dimensions_not_supporte[] = "Indirect dimensions not supported";
static const char __pyx_k_Invalid_mode_expected_c_or_fortr[] = "Invalid mode, expected 'c' or 'fortran', got %s";
static const char __pyx_k_Out_of_bounds_on_buffer_access_a[] = "Out of bounds on buffer access (axis %d)";
static const char __pyx_k_SegmentChain_add_segments_incomi[] = "SegmentChain.add_segments: incoming segments (%s) mismatch chain '%s'";
static const char __pyx_k_SegmentChain_covers_is_only_defi[] = "SegmentChain.covers() is only defined for GenomicSegments and SegmentChains. Found %s.";
static const char __pyx_k_SegmentChain_eq_ineq_et_c_is_onl[] = "SegmentChain eq/ineq/et c is only defined for other SegmentChains or GenomicSegments.";
static const char __pyx_k_SegmentChain_get_masks_is_deprec[] = "SegmentChain.get_masks() is deprecated and will soon be removed from `plastid`. Use SegmentChain.mask_segments instead";
static const char __pyx_k_SegmentChain_get_segmentchain_co[] = "SegmentChain.get_segmentchain_coordinate: Genomic position ";
static const char __pyx_k_SegmentChain_overlaps_is_defined[] = "SegmentChain.overlaps() is defined only for GenomicSegments and SegmentChains. Found %s.";
static const char __pyx_k_SegmentChain_shares_segments_wit[] = "SegmentChain.shares_segments_with() is defined only for GenomicSegments and SegmentChains. Found %s.";
static const char __pyx_k_SegmentChain_unstranded_overlaps[] = "SegmentChain.unstranded_overlaps() errored on chain '";
static const char __pyx_k_SegmentChains_only_support_PSL_o[] = "SegmentChains only support PSL output if all PSL attributes are defined in self.attr: match_length, mismatches, rep_matches, N, query_gap_count, query_gap_bases, strand, query_length, query_start, query_end, target_name, target_length, target_start, target_end";
static const char __pyx_k_Strand_for_SegmentChain_s_is_und[] = "Strand for SegmentChain '%s' is undefined and has no anti-sense.";
static const char __pyx_k_The_in_containment_operator_is_o[] = "The 'in'/containment operator is only defined for GenomicSegments and SegmentChains";
static const char __pyx_k_This_module_contains_classes_for[] = "This module contains classes for representing and manipulating genomic\nfeatures.\n\n.. contents::\n   :local:\n\n\nSummary\n-------\n\nGenomic features are represented as |SegmentChains|, which can contain zero or\nmore continuous spans of the genome (|GenomicSegments|), as well as rich\nannotation data. For the specific case of RNA transcripts, a subclass of\n|SegmentChain|, called |Transcript| is provided.\n\n\nModule contents\n...............\n\n.. autosummary::\n\n   GenomicSegment\n   SegmentChain\n   Transcript\n   positions_to_segments\n   add_three_for_stop_codon\n\n\nExamples\n--------\n\n|SegmentChains| may be read directly from annotation files using the readers\nin :mod:`plastid.readers`::\n\n    >>> from plastid import *\n    >>> chains = list(BED_Reader(open(\"some_file.bed\")))\n\nor constructed from |GenomicSegments|::\n\n    >>> seg1 = GenomicSegment(\"chrA\", 5, 200, \"-\")\n    >>> seg2 = GenomicSegment(\"chrA\", 250, 300, \"-\")\n    >>> my_chain = SegmentChain(seg1, seg2, ID=\"some_chain\", ... , some_attribute=\"some_value\")\n\n|SegmentChains| contain convenience methods for a number of comman tasks, for\nexample:\n\n  - converting coordinates between the spliced space of the chain, and the genome::\n\n        >>> # get coordinate of 50th position from 5' end\n        >>> my_chain.get_genomic_coordinate(50)\n        ('chrA', 199, '-')\n\n        # get coordinate of 49th position. splicing is taken care of!\n        >>> my_chain.get_genomic_coordinate(49)\n        ('chrA', 250, '-')\n\n        # get coordinate in chain corresponding to genomic coordinate 118\n        >>> my_chain.get_segmentchain_coordinate(\"chrA\", 118, \"-\")\n        131\n\n        # get a subchain containing positions 45-70\n        >>> subchain = my_chain.get_subchain(45, 70)\n        >>> subchain\n        <SegmentChain segments=2 bounds=chrA:180-255(-) name=some_chain_subchain>\n\n        # the subchain preserves the discontinuity found in `my_chain`\n        >>> subcha""in.segments\n        [<GenomicSegment chrA:180-200 strand='-'>,\n         <GenomicSegment chrA:250-255 strand='-'>]\n\n  - fetching :class:`numpy arrays <numpy.ndarray>` of data at each position\n    in the chain. The data is assumed to be kept in a\n    :mod:`GenomeArray <plastid.genomics.genome_array>`::\n\n        >>> ga = BAMGenomeArray([\"some_file.bam\"], mapping=ThreePrimeMapFactory(offset=15))\n        >>> my_chain.get_counts(ga)\n        array([843, 854, 153,  86, 462, 359, 290,  38,  38, 758, 342, 299, 430,\n               628, 324, 437, 231, 417, 536, 673, 243, 981, 661, 415, 207, 446,\n               197, 520, 653, 468, 863,   3, 272, 754, 352, 960, 966, 913, 367,\n               ...\n               ])\n\n  - similarly, fetching spliced sequence, reverse-complemented if necessary\n    for minus-strand features. As input, the |SegmentChain| expects a\n    dictionary-like object mapping chromosome names to string-like sequences\n    (e.g. as in `BioPython`_ or `twobitreader`_)::\n\n        >>> seqdict = { \"chrA\" : \"TCTACATA ...\" } # some string of chrA sequence\n        >>> my_chain.get_sequence(seqdict)\n        \"ACTGTGTACTGTACGATCGATCGTACGTACGATCGATCGTACGTAGCTAGTCAGCTAGCTAGCTAGCTGA...\"\n\n  - testing for overlap, containment, equality with other |SegmentChains|::\n\n        >>> other_chain = SegmentChain(GenomicSegment(\"chrA\", 200, 300, \"-\"),\n        >>>                            GenomicSegment(\"chrA\", 800, 900, \"-\"))\n\n        >>>  my_chain.overlaps(other_chain)\n        True\n\n        >>> other_chain in my_chain\n        False\n\n        >>> my_chain in my_chain\n        True\n\n        >>> my_chain.covers(other_chain)\n        False\n\n        >>> my_chain == other_chain\n        False\n\n        >>> my_chain == my_chain\n        True\n\n  - export to `BED`_, `GTF2`_, or `GFF3`_::\n\n        >>> my_chain.as_bed()\n        chrA    5    300    some_chain    0    -    5    5    0,0,0    2    195,50,    0,245,\n\n        >>> my_chain.as_""gtf()\n        chrA    .    exon    6    200    .    -    .    gene_id \"gene_some_chain\"; transcript_id \"some_chain\"; some_attribute \"some_value\"; ID \"some_chain\";\n        chrA    .    exon    251  300    .    -    .    gene_id \"gene_some_chain\"; transcript_id \"some_chain\"; some_attribute \"some_value\"; ID \"some_chain\";\n";
static const char __pyx_k_This_operation_is_not_defined_fo[] = "This operation is not defined for SegmentChains.";
static const char __pyx_k_Unable_to_convert_item_to_object[] = "Unable to convert item to object";
static const char __pyx_k_get_attr_from_bed_Cannot_make_Se[] = "get_attr_from_bed: Cannot make SegmentChain from BED input: if a list, extra_columns must be a list of tuples of (column_name,formatter_func)";
static const char __pyx_k_get_attr_from_bed_Couldn_t_figur[] = "get_attr_from_bed: Couldn't figure out types from input '";
static const char __pyx_k_get_segmentchain_coordinate_quer[] = "get_segmentchain_coordinate: query chromosome '";
static const char __pyx_k_got_differing_extents_in_dimensi[] = "got differing extents in dimension %d (got %d and %d)";
static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__";
static const char __pyx_k_numpy_core_umath_failed_to_impor[] = "numpy.core.umath failed to import";
static const char __pyx_k_plastid_util_services_exceptions[] = "plastid.util.services.exceptions";
static const char __pyx_k_start_coordinate_supplied_is_Non[] = "start coordinate supplied is None. Expected int";
static const char __pyx_k_unable_to_allocate_shape_and_str[] = "unable to allocate shape and strides.";
static const char __pyx_k_SegmentChain_antisense_overlaps_2[] = "SegmentChain.antisense_overlaps() is only defined for GenomicSegments and SegmentChains. Found %s.";
static const char __pyx_k_s_is_a_zero_length_SegmentChain_2[] = "%s is a zero-length SegmentChain. Returning empty sequence.";
static const char __pyx_k_SegmentChain_get_segmentchain_co_2[] = "SegmentChain.get_segmentchain_coordinate: genomic position '";
static const char __pyx_k_SegmentChain_unstranded_overlaps_2[] = "SegmentChain.unstranded_overlaps() is only defined for GenomicSegments and SegmentChains. Found %s.";
static const char __pyx_k_This_operation_is_not_defined_fo_2[] = "This operation is not defined for Transcripts.";
static const char __pyx_k_get_attr_from_bed_Cannot_make_Se_2[] = "get_attr_from_bed: Cannot make SegmentChain from BED input: extra_columns must be an int or list. Got a %s";
static const char __pyx_k_get_segmentchain_coordinate_quer_2[] = "get_segmentchain_coordinate: query strand '";
static PyObject *__pyx_kp_u_;
static PyObject *__pyx_kp_u_0;
static PyObject *__pyx_kp_u_000000;
static PyObject *__pyx_kp_u_0_0_0;
static PyObject *__pyx_kp_u_0_9_0_9;
static PyObject *__pyx_kp_u_0_9_0_9_2;
static PyObject *__pyx_kp_u_1;
static PyObject *__pyx_kp_u_3UTR;
static PyObject *__pyx_kp_u_5UTR;
static PyObject *__pyx_n_s_ASCII;
static PyObject *__pyx_kp_u_Attempted_export_of_multi_interv;
static PyObject *__pyx_n_s_AttributeError;
static PyObject *__pyx_kp_u_BED_format_requires_at_least_3_c;
static PyObject *__pyx_n_s_Bio_Seq;
static PyObject *__pyx_n_s_Bio_SeqRecord;
static PyObject *__pyx_kp_s_Buffer_view_does_not_expose_stri;
static PyObject *__pyx_n_u_CDS;
static PyObject *__pyx_kp_s_Can_only_create_a_buffer_that_is;
static PyObject *__pyx_kp_s_Cannot_assign_to_read_only_memor;
static PyObject *__pyx_kp_s_Cannot_create_writable_memory_vi;
static PyObject *__pyx_kp_u_Cannot_fetch_coordinate;
static PyObject *__pyx_kp_s_Cannot_index_with_type_s;
static PyObject *__pyx_kp_u_Comparison_operation_not_defined;
static PyObject *__pyx_kp_u_Could_not_parse_BED_line_s;
static PyObject *__pyx_n_s_DOUBLE;
static PyObject *__pyx_n_s_DataWarning;
static PyObject *__pyx_kp_u_Defaulting_to_type_str;
static PyObject *__pyx_n_s_Ellipsis;
static PyObject *__pyx_kp_s_Empty_shape_tuple_for_cython_arr;
static PyObject *__pyx_n_s_FLOAT;
static PyObject *__pyx_kp_u_Falling_back_to_default_value;
static PyObject *__pyx_kp_u_GenomicSegment;
static PyObject *__pyx_kp_u_GenomicSegment_2;
static PyObject *__pyx_n_s_GenomicSegment_3;
static PyObject *__pyx_kp_u_GenomicSegment___eq;
static PyObject *__pyx_kp_u_GenomicSegment_contains;
static PyObject *__pyx_kp_u_GenomicSegment_eq_neq;
static PyObject *__pyx_kp_u_GenomicSegment_overlaps;
static PyObject *__pyx_kp_u_GenomicSegment_start_coordinate;
static PyObject *__pyx_kp_u_ID;
static PyObject *__pyx_n_s_ID_2;
static PyObject *__pyx_n_u_ID_2;
static PyObject *__pyx_n_s_INT;
static PyObject *__pyx_n_s_ImportError;
static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xb0;
static PyObject *__pyx_n_s_IndexError;
static PyObject *__pyx_kp_s_Indirect_dimensions_not_supporte;
static PyObject *__pyx_kp_s_Invalid_mode_expected_c_or_fortr;
static PyObject *__pyx_kp_s_Invalid_shape_in_axis_d_d;
static PyObject *__pyx_n_s_KeyError;
static PyObject *__pyx_n_s_LONG;
static PyObject *__pyx_n_s_MaskedArray;
static PyObject *__pyx_n_s_MemoryError;
static PyObject *__pyx_kp_s_MemoryView_of_r_at_0x_x;
static PyObject *__pyx_kp_s_MemoryView_of_r_object;
static PyObject *__pyx_n_u_N;
static PyObject *__pyx_n_u_Name;
static PyObject *__pyx_kp_u_None;
static PyObject *__pyx_kp_u_None_None;
static PyObject *__pyx_n_u_NullChromosome;
static PyObject *__pyx_n_s_NullSegment;
static PyObject *__pyx_n_b_O;
static PyObject *__pyx_kp_s_Out_of_bounds_on_buffer_access_a;
static PyObject *__pyx_n_s_Parent;
static PyObject *__pyx_n_u_Parent;
static PyObject *__pyx_n_s_PickleError;
static PyObject *__pyx_kp_u_Position;
static PyObject *__pyx_n_s_RuntimeError;
static PyObject *__pyx_kp_u_SegmentChain;
static PyObject *__pyx_n_s_SegmentChain_2;
static PyObject *__pyx_kp_u_SegmentChain_add_segments_incomi;
static PyObject *__pyx_kp_u_SegmentChain_antisense_overlaps;
static PyObject *__pyx_kp_u_SegmentChain_antisense_overlaps_2;
static PyObject *__pyx_kp_u_SegmentChain_covers_is_only_defi;
static PyObject *__pyx_kp_u_SegmentChain_eq_ineq_et_c_is_onl;
static PyObject *__pyx_kp_u_SegmentChain_from_bed_Could_not;
static PyObject *__pyx_kp_u_SegmentChain_get_masks_is_deprec;
static PyObject *__pyx_kp_u_SegmentChain_get_segmentchain_co;
static PyObject *__pyx_kp_u_SegmentChain_get_segmentchain_co_2;
static PyObject *__pyx_kp_u_SegmentChain_overlaps_is_defined;
static PyObject *__pyx_kp_u_SegmentChain_shares_segments_wit;
static PyObject *__pyx_kp_u_SegmentChain_unstranded_overlaps;
static PyObject *__pyx_kp_u_SegmentChain_unstranded_overlaps_2;
static PyObject *__pyx_kp_u_SegmentChains_only_support_PSL_o;
static PyObject *__pyx_kp_u_Segmentchain_adding_segments_to;
static PyObject *__pyx_n_s_Seq;
static PyObject *__pyx_n_s_SeqRecord;
static PyObject *__pyx_kp_u_Strand_for_SegmentChain_s_is_und;
static PyObject *__pyx_kp_u_The_in_containment_operator_is_o;
static PyObject *__pyx_kp_u_This_operation_is_not_defined_fo;
static PyObject *__pyx_kp_u_This_operation_is_not_defined_fo_2;
static PyObject *__pyx_kp_u_Transcript;
static PyObject *__pyx_kp_u_Transcript_2;
static PyObject *__pyx_n_s_Transcript_3;
static PyObject *__pyx_n_s_TypeError;
static PyObject *__pyx_kp_s_Unable_to_convert_item_to_object;
static PyObject *__pyx_n_s_UserWarning;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_n_s_View_MemoryView;
static PyObject *__pyx_kp_u__10;
static PyObject *__pyx_kp_u__11;
static PyObject *__pyx_kp_u__12;
static PyObject *__pyx_kp_u__13;
static PyObject *__pyx_kp_u__14;
static PyObject *__pyx_kp_u__15;
static PyObject *__pyx_kp_u__17;
static PyObject *__pyx_kp_u__18;
static PyObject *__pyx_kp_u__19;
static PyObject *__pyx_kp_u__2;
static PyObject *__pyx_kp_u__25;
static PyObject *__pyx_kp_u__26;
static PyObject *__pyx_kp_u__29;
static PyObject *__pyx_kp_u__3;
static PyObject *__pyx_kp_u__30;
static PyObject *__pyx_kp_u__31;
static PyObject *__pyx_kp_u__33;
static PyObject *__pyx_kp_u__35;
static PyObject *__pyx_kp_u__4;
static PyObject *__pyx_kp_u__42;
static PyObject *__pyx_kp_u__5;
static PyObject *__pyx_kp_u__6;
static PyObject *__pyx_kp_u__66;
static PyObject *__pyx_kp_u__68;
static PyObject *__pyx_kp_u__7;
static PyObject *__pyx_kp_u__8;
static PyObject *__pyx_kp_u__9;
static PyObject *__pyx_n_u_alignment;
static PyObject *__pyx_n_s_all;
static PyObject *__pyx_n_s_allocate_buffer;
static PyObject *__pyx_kp_u_and_object;
static PyObject *__pyx_n_s_args;
static PyObject *__pyx_n_s_array;
static PyObject *__pyx_kp_u_as;
static PyObject *__pyx_n_s_as_bed;
static PyObject *__pyx_n_s_as_bed_locals_genexpr;
static PyObject *__pyx_n_s_as_gff3;
static PyObject *__pyx_n_s_as_gtf;
static PyObject *__pyx_n_s_as_igv_str;
static PyObject *__pyx_n_s_as_int;
static PyObject *__pyx_n_s_as_psl_locals_genexpr;
static PyObject *__pyx_n_s_asarray;
static PyObject *__pyx_n_s_astype;
static PyObject *__pyx_n_s_attr;
static PyObject *__pyx_n_s_base;
static PyObject *__pyx_n_u_bedx_column_order;
static PyObject *__pyx_n_s_block_size;
static PyObject *__pyx_n_s_block_sizes;
static PyObject *__pyx_n_u_blocks;
static PyObject *__pyx_n_u_blocksizes;
static PyObject *__pyx_n_u_blockstarts;
static PyObject *__pyx_kp_u_bounds;
static PyObject *__pyx_n_s_c;
static PyObject *__pyx_n_u_c;
static PyObject *__pyx_n_s_c_strand;
static PyObject *__pyx_kp_u_cannot_be_None;
static PyObject *__pyx_kp_u_cds_end;
static PyObject *__pyx_kp_u_cds_genome_end;
static PyObject *__pyx_n_s_cds_genome_end_2;
static PyObject *__pyx_n_u_cds_genome_end_2;
static PyObject *__pyx_kp_u_cds_genome_end_3;
static PyObject *__pyx_kp_u_cds_genome_start;
static PyObject *__pyx_n_s_cds_genome_start_2;
static PyObject *__pyx_n_u_cds_genome_start_2;
static PyObject *__pyx_kp_u_cds_genome_start_3;
static PyObject *__pyx_kp_u_cds_start;
static PyObject *__pyx_n_s_chain;
static PyObject *__pyx_n_s_chrom;
static PyObject *__pyx_n_u_chrom;
static PyObject *__pyx_n_u_chrom_start;
static PyObject *__pyx_n_s_class;
static PyObject *__pyx_n_s_cline_in_traceback;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_cmp_helper;
static PyObject *__pyx_n_s_cmptype;
static PyObject *__pyx_n_s_color;
static PyObject *__pyx_n_u_color;
static PyObject *__pyx_n_s_compile;
static PyObject *__pyx_n_s_contains;
static PyObject *__pyx_n_s_contains_2;
static PyObject *__pyx_kp_s_contiguous_and_direct;
static PyObject *__pyx_kp_s_contiguous_and_indirect;
static PyObject *__pyx_n_s_copy;
static PyObject *__pyx_n_s_copy_2;
static PyObject *__pyx_kp_u_custom_s;
static PyObject *__pyx_n_s_deepcopy;
static PyObject *__pyx_n_s_dict;
static PyObject *__pyx_kp_u_does_not_match_chain;
static PyObject *__pyx_n_s_double;
static PyObject *__pyx_n_s_dtmp;
static PyObject *__pyx_n_s_dtype;
static PyObject *__pyx_n_s_dtype_is_object;
static PyObject *__pyx_n_s_empty;
static PyObject *__pyx_n_s_empty_like;
static PyObject *__pyx_n_s_empty_value;
static PyObject *__pyx_n_s_encode;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_kp_u_end_coordinate_supplied_is_None;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_n_s_error;
static PyObject *__pyx_n_s_escape;
static PyObject *__pyx_n_s_excludes;
static PyObject *__pyx_n_u_exon;
static PyObject *__pyx_kp_u_exon_2;
static PyObject *__pyx_n_s_extra_columns;
static PyObject *__pyx_n_s_feature_type;
static PyObject *__pyx_n_u_five_prime_UTR;
static PyObject *__pyx_n_s_flags;
static PyObject *__pyx_n_s_float;
static PyObject *__pyx_n_s_format;
static PyObject *__pyx_n_s_format_segmentchain;
static PyObject *__pyx_n_s_format_transcript;
static PyObject *__pyx_n_s_fortran;
static PyObject *__pyx_n_u_fortran;
static PyObject *__pyx_n_u_frame;
static PyObject *__pyx_kp_u_from_SegmentChain;
static PyObject *__pyx_n_s_from_bed;
static PyObject *__pyx_n_s_from_igv_str;
static PyObject *__pyx_n_s_from_psl;
static PyObject *__pyx_n_s_from_str;
static PyObject *__pyx_n_s_frombuffer;
static PyObject *__pyx_n_s_ga;
static PyObject *__pyx_kp_u_gene__s;
static PyObject *__pyx_n_u_gene_id;
static PyObject *__pyx_n_s_genexpr;
static PyObject *__pyx_n_s_genome;
static PyObject *__pyx_n_s_genomic_x;
static PyObject *__pyx_n_s_get;
static PyObject *__pyx_n_s_get_8_gff_columns;
static PyObject *__pyx_n_s_get_antisense;
static PyObject *__pyx_n_s_get_attr;
static PyObject *__pyx_kp_u_get_attr_from_bed_Cannot_make_Se;
static PyObject *__pyx_kp_u_get_attr_from_bed_Cannot_make_Se_2;
static PyObject *__pyx_kp_u_get_attr_from_bed_Couldn_t_figur;
static PyObject *__pyx_kp_u_get_attr_from_bed_List_of_extra;
static PyObject *__pyx_n_s_get_cds;
static PyObject *__pyx_n_s_get_counts;
static PyObject *__pyx_n_s_get_gene;
static PyObject *__pyx_n_s_get_junctions;
static PyObject *__pyx_n_s_get_masked_position_set;
static PyObject *__pyx_n_s_get_name;
static PyObject *__pyx_n_s_get_position_list;
static PyObject *__pyx_n_s_get_rgb255;
static PyObject *__pyx_n_s_get_segmentchain_coordinate;
static PyObject *__pyx_kp_u_get_segmentchain_coordinate_quer;
static PyObject *__pyx_kp_u_get_segmentchain_coordinate_quer_2;
static PyObject *__pyx_n_s_get_sequence;
static PyObject *__pyx_kp_u_get_standard_bed_attr_Could_not;
static PyObject *__pyx_n_s_get_str_from_rgb;
static PyObject *__pyx_n_s_get_str_from_rgb255;
static PyObject *__pyx_n_s_get_subchain;
static PyObject *__pyx_n_s_get_unstranded;
static PyObject *__pyx_n_s_get_utr3;
static PyObject *__pyx_n_s_get_utr5;
static PyObject *__pyx_n_s_getstate;
static PyObject *__pyx_kp_s_got_differing_extents_in_dimensi;
static PyObject *__pyx_n_s_groups;
static PyObject *__pyx_n_u_i;
static PyObject *__pyx_n_s_id;
static PyObject *__pyx_n_s_igvpat;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_inp;
static PyObject *__pyx_n_s_int;
static PyObject *__pyx_n_s_intc;
static PyObject *__pyx_kp_u_is_not_in_chain;
static PyObject *__pyx_kp_u_is_outside_bounds_0;
static PyObject *__pyx_n_s_isnan;
static PyObject *__pyx_n_s_items;
static PyObject *__pyx_n_s_itemsize;
static PyObject *__pyx_kp_s_itemsize_0_for_cython_array;
static PyObject *__pyx_n_s_iv;
static PyObject *__pyx_n_s_iv_ltmp;
static PyObject *__pyx_n_s_ivcpat;
static PyObject *__pyx_n_s_k;
static PyObject *__pyx_n_u_l;
static PyObject *__pyx_kp_u_length;
static PyObject *__pyx_n_s_line;
static PyObject *__pyx_n_s_loc_str;
static PyObject *__pyx_n_s_long;
static PyObject *__pyx_n_s_ltmp;
static PyObject *__pyx_n_u_mRNA;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_make_GFF3_tokens;
static PyObject *__pyx_n_s_make_GTF2_tokens;
static PyObject *__pyx_n_s_mask;
static PyObject *__pyx_n_u_match_length;
static PyObject *__pyx_n_s_memview;
static PyObject *__pyx_n_s_middle;
static PyObject *__pyx_n_u_mismatches;
static PyObject *__pyx_n_s_mode;
static PyObject *__pyx_kp_u_must_be_0;
static PyObject *__pyx_kp_u_must_be_cds_end;
static PyObject *__pyx_kp_u_must_be_cds_genome_end;
static PyObject *__pyx_kp_u_must_be_cds_genome_start;
static PyObject *__pyx_kp_u_must_be_cds_start;
static PyObject *__pyx_kp_u_must_be_end;
static PyObject *__pyx_kp_u_must_be_self_length;
static PyObject *__pyx_n_u_na;
static PyObject *__pyx_n_s_name;
static PyObject *__pyx_n_s_name_2;
static PyObject *__pyx_n_u_name_2;
static PyObject *__pyx_kp_u_name_s;
static PyObject *__pyx_n_s_nan;
static PyObject *__pyx_n_u_nan;
static PyObject *__pyx_n_s_ndim;
static PyObject *__pyx_n_s_new;
static PyObject *__pyx_n_s_next;
static PyObject *__pyx_kp_s_no_default___reduce___due_to_non;
static PyObject *__pyx_n_u_none;
static PyObject *__pyx_kp_u_not_in_SegmentChain;
static PyObject *__pyx_n_s_numpy;
static PyObject *__pyx_kp_u_numpy_core_multiarray_failed_to;
static PyObject *__pyx_kp_u_numpy_core_umath_failed_to_impor;
static PyObject *__pyx_n_s_numpy_ma;
static PyObject *__pyx_n_s_obj;
static PyObject *__pyx_kp_u_of_SegmentChain;
static PyObject *__pyx_kp_u_of_types;
static PyObject *__pyx_n_s_other;
static PyObject *__pyx_n_u_other;
static PyObject *__pyx_n_s_overlaps;
static PyObject *__pyx_n_s_pack;
static PyObject *__pyx_n_u_phase;
static PyObject *__pyx_n_s_pickle;
static PyObject *__pyx_n_s_piece;
static PyObject *__pyx_n_s_plastid_genomics_roitools;
static PyObject *__pyx_kp_s_plastid_genomics_roitools_pyx;
static PyObject *__pyx_n_s_plastid_plotting_colors;
static PyObject *__pyx_n_s_plastid_readers_gff_tokens;
static PyObject *__pyx_n_s_plastid_util_services_exceptions;
static PyObject *__pyx_n_s_pop;
static PyObject *__pyx_n_s_positions;
static PyObject *__pyx_n_s_psl_line;
static PyObject *__pyx_n_s_pyx_PickleError;
static PyObject *__pyx_n_s_pyx_capi;
static PyObject *__pyx_n_s_pyx_checksum;
static PyObject *__pyx_n_s_pyx_getbuffer;
static PyObject *__pyx_n_s_pyx_result;
static PyObject *__pyx_n_s_pyx_state;
static PyObject *__pyx_n_s_pyx_type;
static PyObject *__pyx_n_s_pyx_unpickle_Enum;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_s_q_starts;
static PyObject *__pyx_n_u_q_starts;
static PyObject *__pyx_n_u_query_end;
static PyObject *__pyx_n_u_query_gap_bases;
static PyObject *__pyx_n_u_query_gap_count;
static PyObject *__pyx_n_u_query_length;
static PyObject *__pyx_n_u_query_name;
static PyObject *__pyx_n_u_query_start;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_re;
static PyObject *__pyx_n_s_reduce;
static PyObject *__pyx_n_s_reduce_cython;
static PyObject *__pyx_n_s_reduce_ex;
static PyObject *__pyx_n_u_rep_matches;
static PyObject *__pyx_n_s_reverse_complement;
static PyObject *__pyx_n_s_rna_type;
static PyObject *__pyx_n_s_roi_order;
static PyObject *__pyx_n_s_round;
static PyObject *__pyx_kp_u_s_3UTR;
static PyObject *__pyx_kp_u_s_5UTR;
static PyObject *__pyx_kp_u_s_CDS;
static PyObject *__pyx_n_s_s_end;
static PyObject *__pyx_kp_u_s_is_a_zero_length_SegmentChain;
static PyObject *__pyx_kp_u_s_is_a_zero_length_SegmentChain_2;
static PyObject *__pyx_kp_u_s_s_s;
static PyObject *__pyx_n_s_s_start;
static PyObject *__pyx_kp_u_s_subchain;
static PyObject *__pyx_n_s_sb;
static PyObject *__pyx_n_u_score;
static PyObject *__pyx_n_s_search;
static PyObject *__pyx_n_s_seg;
static PyObject *__pyx_n_s_segchain;
static PyObject *__pyx_n_s_segment;
static PyObject *__pyx_kp_u_segments;
static PyObject *__pyx_n_s_segments_2;
static PyObject *__pyx_n_s_segpat;
static PyObject *__pyx_n_s_segs;
static PyObject *__pyx_n_s_send;
static PyObject *__pyx_n_s_seq;
static PyObject *__pyx_n_s_setstate;
static PyObject *__pyx_n_s_setstate_cython;
static PyObject *__pyx_n_s_shape;
static PyObject *__pyx_n_s_size;
static PyObject *__pyx_n_u_source;
static PyObject *__pyx_n_s_split;
static PyObject *__pyx_n_s_sq;
static PyObject *__pyx_n_s_sq_starts;
static PyObject *__pyx_n_s_sstart;
static PyObject *__pyx_n_s_st;
static PyObject *__pyx_n_s_st_starts;
static PyObject *__pyx_n_s_start;
static PyObject *__pyx_n_u_start_codon;
static PyObject *__pyx_kp_u_start_coordinate_supplied_is_Non;
static PyObject *__pyx_n_s_staticmethod;
static PyObject *__pyx_n_s_step;
static PyObject *__pyx_n_s_stmp;
static PyObject *__pyx_n_s_stop;
static PyObject *__pyx_n_u_stop_codon;
static PyObject *__pyx_n_s_strand;
static PyObject *__pyx_n_u_strand;
static PyObject *__pyx_kp_u_strand_2;
static PyObject *__pyx_n_s_stranded;
static PyObject *__pyx_kp_s_strided_and_direct;
static PyObject *__pyx_kp_s_strided_and_direct_or_indirect;
static PyObject *__pyx_kp_s_strided_and_indirect;
static PyObject *__pyx_kp_s_stringsource;
static PyObject *__pyx_n_s_strip;
static PyObject *__pyx_n_s_struct;
static PyObject *__pyx_n_s_sum;
static PyObject *__pyx_n_s_t_start;
static PyObject *__pyx_n_s_t_starts;
static PyObject *__pyx_n_u_t_starts;
static PyObject *__pyx_n_u_target_end;
static PyObject *__pyx_n_u_target_gap_bases;
static PyObject *__pyx_n_u_target_gap_count;
static PyObject *__pyx_n_u_target_length;
static PyObject *__pyx_n_u_target_name;
static PyObject *__pyx_n_u_target_start;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_thickend;
static PyObject *__pyx_n_u_thickend;
static PyObject *__pyx_n_s_thickstart;
static PyObject *__pyx_n_u_thickstart;
static PyObject *__pyx_n_u_three_prime_UTR;
static PyObject *__pyx_n_s_throw;
static PyObject *__pyx_n_s_tolist;
static PyObject *__pyx_n_s_transcript;
static PyObject *__pyx_n_u_transcript_id;
static PyObject *__pyx_n_s_tx;
static PyObject *__pyx_n_s_type;
static PyObject *__pyx_n_u_type;
static PyObject *__pyx_kp_s_unable_to_allocate_array_data;
static PyObject *__pyx_kp_s_unable_to_allocate_shape_and_str;
static PyObject *__pyx_n_s_unpack;
static PyObject *__pyx_n_s_update;
static PyObject *__pyx_n_s_v;
static PyObject *__pyx_kp_u_value_of;
static PyObject *__pyx_n_s_values;
static PyObject *__pyx_n_s_warn;
static PyObject *__pyx_kp_u_with;
static PyObject *__pyx_kp_u_wrong_and_or_multiple_chromosom;
static PyObject *__pyx_kp_u_wrong_and_or_multiple_strands;
static PyObject *__pyx_n_s_x;
static PyObject *__pyx_n_s_zeros_like;
static PyObject *__pyx_n_s_zip;
static PyObject *__pyx_pf_7plastid_8genomics_8roitools__get_attr(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dtmp); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_2_format_segmentchain(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_segchain); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_4_format_transcript(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_tx); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_6merge_segments(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_segments); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_8positions_to_segments(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_chrom, PyObject *__pyx_v_strand, PyObject *__pyx_v_positions); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10positionlist_to_segments(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_chrom, PyObject *__pyx_v_strand, PyObject *__pyx_v_positions); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12add_three_for_stop_codon(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_tx); /* proto */
static int __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment___cinit__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, PyObject *__pyx_v_chrom, long __pyx_v_start, long __pyx_v_end, PyObject *__pyx_v_strand); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_2__reduce__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_4__repr__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_6__str__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self); /* proto */
static Py_hash_t __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_8__hash__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_10from_str(PyObject *__pyx_v_inp); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_12__copy__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_14__deepcopy__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo); /* proto */
static Py_ssize_t __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_16__len__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_18__richcmp__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other, int __pyx_v_cmptype); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_20_cmp_helper(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other, int __pyx_v_cmptype); /* proto */
static int __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_22__contains__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_24contains(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_26overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_28as_igv_str(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_30from_igv_str(PyObject *__pyx_v_loc_str, PyObject *__pyx_v_strand); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_5start___get__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_3end___get__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_5chrom___get__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_6strand___get__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_8c_strand___get__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self); /* proto */
static int __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain___cinit__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_segments, PyObject *__pyx_v_attr); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_2sort(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_5chrom___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6strand___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_8c_strand___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_8segments___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_13mask_segments___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_4__reduce__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6__getstate__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_8__setstate__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_state); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_10__copy__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_12__deepcopy__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_14__richcmp__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_cmpval); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_16__repr__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_18__str__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_20__getitem__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, int __pyx_v_index); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_22__iter__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_24__next__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_26next(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static Py_ssize_t __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_28__len__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static int __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_30__contains__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_32shares_segments_with(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_34unstranded_overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_36overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_38antisense_overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_40covers(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_42get_unstranded(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_44get_antisense(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_46get_position_list(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_48get_position_set(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_50get_masked_position_set(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_52get_name(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_54get_gene(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_56add_segments(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_segments); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_58add_masks(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_mask_segments); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_60get_masks(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_62get_masks_as_segmentchain(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_64reset_masks(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_66get_junctions(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_68as_gff3(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_feature_type, CYTHON_UNUSED int __pyx_v_escape, PyObject *__pyx_v_excludes); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_70as_gtf(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_feature_type, int __pyx_v_escape, PyObject *__pyx_v_excludes); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_72_get_8_gff_columns(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_segment, PyObject *__pyx_v_feature_type); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_3genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_6genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_9genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_74as_bed(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_thickstart, PyObject *__pyx_v_thickend, PyObject *__pyx_v_as_int, PyObject *__pyx_v_color, PyObject *__pyx_v_extra_columns, PyObject *__pyx_v_empty_value); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_psl_genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_76as_psl(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_78get_segmentchain_coordinate(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_chrom, long __pyx_v_genomic_x, PyObject *__pyx_v_strand, int __pyx_v_stranded); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_80get_genomic_coordinate(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_x, PyObject *__pyx_v_stranded); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_82get_subchain(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, long __pyx_v_start, long __pyx_v_end, int __pyx_v_stranded, PyObject *__pyx_v_extra_attr); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_84get_counts(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_ga, PyObject *__pyx_v_stranded); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_86get_masked_counts(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_ga, CYTHON_UNUSED PyObject *__pyx_v_stranded, PyObject *__pyx_v_copy); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_88get_sequence(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_genome, PyObject *__pyx_v_stranded); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_90get_fasta(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_genome, PyObject *__pyx_v_stranded); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_92from_str(PyObject *__pyx_v_inp); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_94from_bed(PyObject *__pyx_v_line, PyObject *__pyx_v_extra_columns); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_96from_psl(PyObject *__pyx_v_psl_line); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_16spanning_segment___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6length___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_13masked_length___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_4attr___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static int __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_4attr_2__set__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
static int __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_4attr_4__del__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self); /* proto */
static int __pyx_pf_7plastid_8genomics_8roitools_10Transcript___cinit__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_type, CYTHON_UNUSED PyObject *__pyx_v_segments, PyObject *__pyx_v_attr); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_2__copy__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_4__deepcopy__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_6__reduce__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_8__getstate__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_10__setstate__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_state); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_12__richcmp__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_cmpval); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_9cds_start___get__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto */
static int __pyx_pf_7plastid_8genomics_8roitools_10Transcript_9cds_start_2__set__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_7cds_end___get__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto */
static int __pyx_pf_7plastid_8genomics_8roitools_10Transcript_7cds_end_2__set__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_16cds_genome_start___get__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto */
static int __pyx_pf_7plastid_8genomics_8roitools_10Transcript_16cds_genome_start_2__set__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_14cds_genome_end___get__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto */
static int __pyx_pf_7plastid_8genomics_8roitools_10Transcript_14cds_genome_end_2__set__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_14get_name(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_16get_cds(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_extra_attr); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_18get_utr5(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_extra_attr); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_20get_utr3(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_extra_attr); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_22as_gtf(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_feature_type, int __pyx_v_escape, PyObject *__pyx_v_excludes); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_24as_gff3(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, int __pyx_v_escape, PyObject *__pyx_v_excludes, PyObject *__pyx_v_rna_type); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_26as_bed(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_as_int, PyObject *__pyx_v_color, PyObject *__pyx_v_extra_columns, PyObject *__pyx_v_empty_value); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_28from_bed(PyObject *__pyx_v_line, PyObject *__pyx_v_extra_columns); /* proto */
static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_30from_psl(PyObject *__pyx_v_psl_line); /* proto */
static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags); /* proto */
static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */
static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer); /* proto */
static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self); /* proto */
static Py_ssize_t __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(struct __pyx_array_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr); /* proto */
static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item); /* proto */
static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name); /* proto */
static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_MemviewEnum___reduce_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object); /* proto */
static void __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index); /* proto */
static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /* proto */
static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static Py_ssize_t __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static void __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_memoryviewslice___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_memoryviewslice_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools_GenomicSegment(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools_SegmentChain(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools_Transcript(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_memoryview(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new__memoryviewslice(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_get = {0, &__pyx_n_s_get, 0, 0, 0};
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_items = {0, &__pyx_n_s_items, 0, 0, 0};
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_pop = {0, &__pyx_n_s_pop, 0, 0, 0};
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_update = {0, &__pyx_n_s_update, 0, 0, 0};
static __Pyx_CachedCFunction __pyx_umethod_PyUnicode_Type_strip = {0, &__pyx_n_s_strip, 0, 0, 0};
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_3;
static PyObject *__pyx_int_4;
static PyObject *__pyx_int_6;
static PyObject *__pyx_int_7;
static PyObject *__pyx_int_8;
static PyObject *__pyx_int_9;
static PyObject *__pyx_int_10;
static PyObject *__pyx_int_11;
static PyObject *__pyx_int_255;
static PyObject *__pyx_int_184977713;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_slice__38;
static PyObject *__pyx_slice__40;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__21;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__23;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__27;
static PyObject *__pyx_tuple__28;
static PyObject *__pyx_tuple__32;
static PyObject *__pyx_tuple__34;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__37;
static PyObject *__pyx_tuple__39;
static PyObject *__pyx_tuple__41;
static PyObject *__pyx_tuple__43;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__45;
static PyObject *__pyx_tuple__46;
static PyObject *__pyx_tuple__47;
static PyObject *__pyx_tuple__48;
static PyObject *__pyx_tuple__49;
static PyObject *__pyx_tuple__50;
static PyObject *__pyx_tuple__51;
static PyObject *__pyx_tuple__52;
static PyObject *__pyx_tuple__53;
static PyObject *__pyx_tuple__54;
static PyObject *__pyx_tuple__55;
static PyObject *__pyx_tuple__56;
static PyObject *__pyx_tuple__57;
static PyObject *__pyx_tuple__58;
static PyObject *__pyx_tuple__59;
static PyObject *__pyx_tuple__60;
static PyObject *__pyx_tuple__61;
static PyObject *__pyx_tuple__62;
static PyObject *__pyx_tuple__63;
static PyObject *__pyx_tuple__64;
static PyObject *__pyx_tuple__65;
static PyObject *__pyx_tuple__67;
static PyObject *__pyx_tuple__69;
static PyObject *__pyx_tuple__70;
static PyObject *__pyx_tuple__72;
static PyObject *__pyx_tuple__74;
static PyObject *__pyx_tuple__76;
static PyObject *__pyx_tuple__78;
static PyObject *__pyx_tuple__80;
static PyObject *__pyx_tuple__82;
static PyObject *__pyx_tuple__84;
static PyObject *__pyx_tuple__86;
static PyObject *__pyx_tuple__88;
static PyObject *__pyx_tuple__90;
static PyObject *__pyx_tuple__91;
static PyObject *__pyx_tuple__92;
static PyObject *__pyx_tuple__93;
static PyObject *__pyx_tuple__94;
static PyObject *__pyx_tuple__95;
static PyObject *__pyx_codeobj__71;
static PyObject *__pyx_codeobj__73;
static PyObject *__pyx_codeobj__75;
static PyObject *__pyx_codeobj__77;
static PyObject *__pyx_codeobj__79;
static PyObject *__pyx_codeobj__81;
static PyObject *__pyx_codeobj__83;
static PyObject *__pyx_codeobj__85;
static PyObject *__pyx_codeobj__87;
static PyObject *__pyx_codeobj__89;
static PyObject *__pyx_codeobj__96;
/* Late includes */

/* "plastid/genomics/roitools.pyx":201
 * #===============================================================================
 * 
 * def _get_attr(dict dtmp):             # <<<<<<<<<<<<<<
 *     ltmp=[]
 *     for k, v in sorted(dtmp.items()):
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_1_get_attr(PyObject *__pyx_self, PyObject *__pyx_v_dtmp); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools__get_attr[] = "_get_attr(dict dtmp)";
static PyMethodDef __pyx_mdef_7plastid_8genomics_8roitools_1_get_attr = {"_get_attr", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_1_get_attr, METH_O, __pyx_doc_7plastid_8genomics_8roitools__get_attr};
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_1_get_attr(PyObject *__pyx_self, PyObject *__pyx_v_dtmp) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_attr (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dtmp), (&PyDict_Type), 1, "dtmp", 1))) __PYX_ERR(0, 201, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools__get_attr(__pyx_self, ((PyObject*)__pyx_v_dtmp));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools__get_attr(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dtmp) {
  PyObject *__pyx_v_ltmp = NULL;
  PyObject *__pyx_v_k = NULL;
  PyObject *__pyx_v_v = 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;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *(*__pyx_t_8)(PyObject *);
  Py_ssize_t __pyx_t_9;
  Py_UCS4 __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_get_attr", 0);

  /* "plastid/genomics/roitools.pyx":202
 * 
 * def _get_attr(dict dtmp):
 *     ltmp=[]             # <<<<<<<<<<<<<<
 *     for k, v in sorted(dtmp.items()):
 *         ltmp.append("%s='%s'" % (k, v))
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 202, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_ltmp = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":203
 * def _get_attr(dict dtmp):
 *     ltmp=[]
 *     for k, v in sorted(dtmp.items()):             # <<<<<<<<<<<<<<
 *         ltmp.append("%s='%s'" % (k, v))
 * 
 */
  if (unlikely(__pyx_v_dtmp == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items");
    __PYX_ERR(0, 203, __pyx_L1_error)
  }
  __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_dtmp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 203, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PySequence_List(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 203, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_4 = PyList_Sort(__pyx_t_1); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 203, __pyx_L1_error)
  if (unlikely(__pyx_t_1 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 203, __pyx_L1_error)
  }
  __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 203, __pyx_L1_error)
    #else
    __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 203, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    #endif
    if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
      PyObject* sequence = __pyx_t_1;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 203, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_6);
      #else
      __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 203, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 203, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 203, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
      index = 0; __pyx_t_2 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_2)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_2);
      index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_6);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 203, __pyx_L1_error)
      __pyx_t_8 = NULL;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L6_unpacking_done;
      __pyx_L5_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_8 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 203, __pyx_L1_error)
      __pyx_L6_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":204
 *     ltmp=[]
 *     for k, v in sorted(dtmp.items()):
 *         ltmp.append("%s='%s'" % (k, v))             # <<<<<<<<<<<<<<
 * 
 *     return ",".join(ltmp)
 */
    __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = 0;
    __pyx_t_10 = 127;
    __pyx_t_6 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_k), __pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_10;
    __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_INCREF(__pyx_kp_u_);
    __pyx_t_9 += 2;
    __Pyx_GIVEREF(__pyx_kp_u_);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u_);
    __pyx_t_6 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_v), __pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_10;
    __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_INCREF(__pyx_kp_u__2);
    __pyx_t_9 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__2);
    PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u__2);
    __pyx_t_6 = __Pyx_PyUnicode_Join(__pyx_t_1, 4, __pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_ltmp, __pyx_t_6); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 204, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":203
 * def _get_attr(dict dtmp):
 *     ltmp=[]
 *     for k, v in sorted(dtmp.items()):             # <<<<<<<<<<<<<<
 *         ltmp.append("%s='%s'" % (k, v))
 * 
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":206
 *         ltmp.append("%s='%s'" % (k, v))
 * 
 *     return ",".join(ltmp)             # <<<<<<<<<<<<<<
 * 
 * def _format_segmentchain(SegmentChain segchain):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyUnicode_Join(__pyx_kp_u__3, __pyx_v_ltmp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 206, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":201
 * #===============================================================================
 * 
 * def _get_attr(dict dtmp):             # <<<<<<<<<<<<<<
 *     ltmp=[]
 *     for k, v in sorted(dtmp.items()):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools._get_attr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ltmp);
  __Pyx_XDECREF(__pyx_v_k);
  __Pyx_XDECREF(__pyx_v_v);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":208
 *     return ",".join(ltmp)
 * 
 * def _format_segmentchain(SegmentChain segchain):             # <<<<<<<<<<<<<<
 *     """Formats a |SegmentChain| as a string, which when ``eval`` ed, should
 *     reconstruct the |SegmentChain|.  Used for creating test datasets.
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_3_format_segmentchain(PyObject *__pyx_self, PyObject *__pyx_v_segchain); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_2_format_segmentchain[] = "_format_segmentchain(SegmentChain segchain)\nFormats a |SegmentChain| as a string, which when ``eval`` ed, should\n    reconstruct the |SegmentChain|.  Used for creating test datasets.\n\n    Parameters\n    ----------\n    segchain : |SegmentChain|\n\n    Returns\n    -------\n    str\n    ";
static PyMethodDef __pyx_mdef_7plastid_8genomics_8roitools_3_format_segmentchain = {"_format_segmentchain", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_3_format_segmentchain, METH_O, __pyx_doc_7plastid_8genomics_8roitools_2_format_segmentchain};
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_3_format_segmentchain(PyObject *__pyx_self, PyObject *__pyx_v_segchain) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_format_segmentchain (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_segchain), __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain, 1, "segchain", 0))) __PYX_ERR(0, 208, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_2_format_segmentchain(__pyx_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_segchain));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_2_format_segmentchain(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_segchain) {
  PyObject *__pyx_v_iv_ltmp = NULL;
  PyObject *__pyx_v_iv = NULL;
  PyObject *__pyx_v_stmp = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *(*__pyx_t_3)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  Py_UCS4 __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_format_segmentchain", 0);

  /* "plastid/genomics/roitools.pyx":220
 *     str
 *     """
 *     iv_ltmp = []             # <<<<<<<<<<<<<<
 *     for iv in segchain:
 *         iv_ltmp.append(
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 220, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_iv_ltmp = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":221
 *     """
 *     iv_ltmp = []
 *     for iv in segchain:             # <<<<<<<<<<<<<<
 *         iv_ltmp.append(
 *             "GenomicSegment('%s', %s, %s, '%s')" % (iv.chrom, iv.start, iv.end, iv.strand)
 */
  if (likely(PyList_CheckExact(((PyObject *)__pyx_v_segchain))) || PyTuple_CheckExact(((PyObject *)__pyx_v_segchain))) {
    __pyx_t_1 = ((PyObject *)__pyx_v_segchain); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_segchain)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 221, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 221, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 221, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 221, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 221, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 221, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 221, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_iv, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":223
 *     for iv in segchain:
 *         iv_ltmp.append(
 *             "GenomicSegment('%s', %s, %s, '%s')" % (iv.chrom, iv.start, iv.end, iv.strand)             # <<<<<<<<<<<<<<
 *         )
 * 
 */
    __pyx_t_4 = PyTuple_New(9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = 0;
    __pyx_t_6 = 127;
    __Pyx_INCREF(__pyx_kp_u_GenomicSegment);
    __pyx_t_5 += 16;
    __Pyx_GIVEREF(__pyx_kp_u_GenomicSegment);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_GenomicSegment);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_iv, __pyx_n_s_chrom); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_7), __pyx_empty_unicode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) : __pyx_t_6;
    __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_8);
    __pyx_t_8 = 0;
    __Pyx_INCREF(__pyx_kp_u__4);
    __pyx_t_5 += 3;
    __Pyx_GIVEREF(__pyx_kp_u__4);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u__4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_iv, __pyx_n_s_start); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_8), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
    __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_INCREF(__pyx_kp_u__5);
    __pyx_t_5 += 2;
    __Pyx_GIVEREF(__pyx_kp_u__5);
    PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_kp_u__5);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_iv, __pyx_n_s_end); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_7), __pyx_empty_unicode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) : __pyx_t_6;
    __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_t_8);
    __pyx_t_8 = 0;
    __Pyx_INCREF(__pyx_kp_u__6);
    __pyx_t_5 += 3;
    __Pyx_GIVEREF(__pyx_kp_u__6);
    PyTuple_SET_ITEM(__pyx_t_4, 6, __pyx_kp_u__6);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_iv, __pyx_n_s_strand); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_8), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
    __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_4, 7, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_INCREF(__pyx_kp_u__7);
    __pyx_t_5 += 2;
    __Pyx_GIVEREF(__pyx_kp_u__7);
    PyTuple_SET_ITEM(__pyx_t_4, 8, __pyx_kp_u__7);
    __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_4, 9, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":222
 *     iv_ltmp = []
 *     for iv in segchain:
 *         iv_ltmp.append(             # <<<<<<<<<<<<<<
 *             "GenomicSegment('%s', %s, %s, '%s')" % (iv.chrom, iv.start, iv.end, iv.strand)
 *         )
 */
    __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_iv_ltmp, __pyx_t_7); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 222, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":221
 *     """
 *     iv_ltmp = []
 *     for iv in segchain:             # <<<<<<<<<<<<<<
 *         iv_ltmp.append(
 *             "GenomicSegment('%s', %s, %s, '%s')" % (iv.chrom, iv.start, iv.end, iv.strand)
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":226
 *         )
 * 
 *     stmp = "SegmentChain(%s ,%s)\n" % (",".join(iv_ltmp), _get_attr(segchain.attr))             # <<<<<<<<<<<<<<
 * 
 *     return stmp
 */
  __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = 0;
  __pyx_t_6 = 127;
  __Pyx_INCREF(__pyx_kp_u_SegmentChain);
  __pyx_t_2 += 13;
  __Pyx_GIVEREF(__pyx_kp_u_SegmentChain);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_SegmentChain);
  __pyx_t_7 = PyUnicode_Join(__pyx_kp_u__3, __pyx_v_iv_ltmp); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
  __pyx_t_7 = 0;
  __Pyx_INCREF(__pyx_kp_u__8);
  __pyx_t_2 += 2;
  __Pyx_GIVEREF(__pyx_kp_u__8);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u__8);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_get_attr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_8 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_8, __pyx_v_segchain->attr) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_segchain->attr);
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_7), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_6;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u__9);
  __pyx_t_2 += 2;
  __Pyx_GIVEREF(__pyx_kp_u__9);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__9);
  __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_stmp = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "plastid/genomics/roitools.pyx":228
 *     stmp = "SegmentChain(%s ,%s)\n" % (",".join(iv_ltmp), _get_attr(segchain.attr))
 * 
 *     return stmp             # <<<<<<<<<<<<<<
 * 
 * def _format_transcript(Transcript tx):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_stmp);
  __pyx_r = __pyx_v_stmp;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":208
 *     return ",".join(ltmp)
 * 
 * def _format_segmentchain(SegmentChain segchain):             # <<<<<<<<<<<<<<
 *     """Formats a |SegmentChain| as a string, which when ``eval`` ed, should
 *     reconstruct the |SegmentChain|.  Used for creating test datasets.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("plastid.genomics.roitools._format_segmentchain", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_iv_ltmp);
  __Pyx_XDECREF(__pyx_v_iv);
  __Pyx_XDECREF(__pyx_v_stmp);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":230
 *     return stmp
 * 
 * def _format_transcript(Transcript tx):             # <<<<<<<<<<<<<<
 *     """Formats a |Transcript| as a string, which when ``eval`` ed, should
 *     reconstruct the |Transcript|.  Used for creating test datasets.
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_5_format_transcript(PyObject *__pyx_self, PyObject *__pyx_v_tx); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_4_format_transcript[] = "_format_transcript(Transcript tx)\nFormats a |Transcript| as a string, which when ``eval`` ed, should\n    reconstruct the |Transcript|.  Used for creating test datasets.\n\n    Parameters\n    ----------\n    tx : |Transcript|\n\n    Returns\n    -------\n    str\n    ";
static PyMethodDef __pyx_mdef_7plastid_8genomics_8roitools_5_format_transcript = {"_format_transcript", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_5_format_transcript, METH_O, __pyx_doc_7plastid_8genomics_8roitools_4_format_transcript};
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_5_format_transcript(PyObject *__pyx_self, PyObject *__pyx_v_tx) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_format_transcript (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tx), __pyx_ptype_7plastid_8genomics_8roitools_Transcript, 1, "tx", 0))) __PYX_ERR(0, 230, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_4_format_transcript(__pyx_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_tx));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_4_format_transcript(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_tx) {
  PyObject *__pyx_v_iv_ltmp = NULL;
  PyObject *__pyx_v_iv = NULL;
  PyObject *__pyx_v_stmp = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *(*__pyx_t_3)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  Py_UCS4 __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_format_transcript", 0);

  /* "plastid/genomics/roitools.pyx":242
 *     str
 *     """
 *     iv_ltmp = []             # <<<<<<<<<<<<<<
 *     for iv in tx:
 *         iv_ltmp.append("GenomicSegment('%s', %s, %s, '%s')" % (iv.chrom, iv.start, iv.end, iv.strand))
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 242, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_iv_ltmp = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":243
 *     """
 *     iv_ltmp = []
 *     for iv in tx:             # <<<<<<<<<<<<<<
 *         iv_ltmp.append("GenomicSegment('%s', %s, %s, '%s')" % (iv.chrom, iv.start, iv.end, iv.strand))
 * 
 */
  if (likely(PyList_CheckExact(((PyObject *)__pyx_v_tx))) || PyTuple_CheckExact(((PyObject *)__pyx_v_tx))) {
    __pyx_t_1 = ((PyObject *)__pyx_v_tx); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_tx)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 243, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 243, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 243, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 243, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 243, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 243, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 243, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_iv, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":244
 *     iv_ltmp = []
 *     for iv in tx:
 *         iv_ltmp.append("GenomicSegment('%s', %s, %s, '%s')" % (iv.chrom, iv.start, iv.end, iv.strand))             # <<<<<<<<<<<<<<
 * 
 *     stmp = "Transcript(%s, ID='%s', cds_genome_start=%s, cds_genome_end=%s)\n" % (
 */
    __pyx_t_4 = PyTuple_New(9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = 0;
    __pyx_t_6 = 127;
    __Pyx_INCREF(__pyx_kp_u_GenomicSegment);
    __pyx_t_5 += 16;
    __Pyx_GIVEREF(__pyx_kp_u_GenomicSegment);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_GenomicSegment);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_iv, __pyx_n_s_chrom); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_7), __pyx_empty_unicode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) : __pyx_t_6;
    __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_8);
    __pyx_t_8 = 0;
    __Pyx_INCREF(__pyx_kp_u__4);
    __pyx_t_5 += 3;
    __Pyx_GIVEREF(__pyx_kp_u__4);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u__4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_iv, __pyx_n_s_start); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_8), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
    __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_INCREF(__pyx_kp_u__5);
    __pyx_t_5 += 2;
    __Pyx_GIVEREF(__pyx_kp_u__5);
    PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_kp_u__5);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_iv, __pyx_n_s_end); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_7), __pyx_empty_unicode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) : __pyx_t_6;
    __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_t_8);
    __pyx_t_8 = 0;
    __Pyx_INCREF(__pyx_kp_u__6);
    __pyx_t_5 += 3;
    __Pyx_GIVEREF(__pyx_kp_u__6);
    PyTuple_SET_ITEM(__pyx_t_4, 6, __pyx_kp_u__6);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_iv, __pyx_n_s_strand); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_8), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
    __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_4, 7, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_INCREF(__pyx_kp_u__7);
    __pyx_t_5 += 2;
    __Pyx_GIVEREF(__pyx_kp_u__7);
    PyTuple_SET_ITEM(__pyx_t_4, 8, __pyx_kp_u__7);
    __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_4, 9, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_iv_ltmp, __pyx_t_7); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":243
 *     """
 *     iv_ltmp = []
 *     for iv in tx:             # <<<<<<<<<<<<<<
 *         iv_ltmp.append("GenomicSegment('%s', %s, %s, '%s')" % (iv.chrom, iv.start, iv.end, iv.strand))
 * 
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":246
 *         iv_ltmp.append("GenomicSegment('%s', %s, %s, '%s')" % (iv.chrom, iv.start, iv.end, iv.strand))
 * 
 *     stmp = "Transcript(%s, ID='%s', cds_genome_start=%s, cds_genome_end=%s)\n" % (             # <<<<<<<<<<<<<<
 *         ",".join(iv_ltmp), tx.get_name(), tx.cds_genome_start, tx.cds_genome_end
 *     )
 */
  __pyx_t_1 = PyTuple_New(9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 246, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = 0;
  __pyx_t_6 = 127;
  __Pyx_INCREF(__pyx_kp_u_Transcript);
  __pyx_t_2 += 11;
  __Pyx_GIVEREF(__pyx_kp_u_Transcript);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Transcript);

  /* "plastid/genomics/roitools.pyx":247
 * 
 *     stmp = "Transcript(%s, ID='%s', cds_genome_start=%s, cds_genome_end=%s)\n" % (
 *         ",".join(iv_ltmp), tx.get_name(), tx.cds_genome_start, tx.cds_genome_end             # <<<<<<<<<<<<<<
 *     )
 * 
 */
  __pyx_t_7 = PyUnicode_Join(__pyx_kp_u__3, __pyx_v_iv_ltmp); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
  __pyx_t_7 = 0;
  __Pyx_INCREF(__pyx_kp_u_ID);
  __pyx_t_2 += 6;
  __Pyx_GIVEREF(__pyx_kp_u_ID);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_ID);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_tx), __pyx_n_s_get_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_8 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_7), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_6;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u_cds_genome_start);
  __pyx_t_2 += 20;
  __Pyx_GIVEREF(__pyx_kp_u_cds_genome_start);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_cds_genome_start);
  __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_tx->cds_genome_start), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_6;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u_cds_genome_end);
  __pyx_t_2 += 17;
  __Pyx_GIVEREF(__pyx_kp_u_cds_genome_end);
  PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u_cds_genome_end);
  __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_tx->cds_genome_end), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_6;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 7, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u__9);
  __pyx_t_2 += 2;
  __Pyx_GIVEREF(__pyx_kp_u__9);
  PyTuple_SET_ITEM(__pyx_t_1, 8, __pyx_kp_u__9);

  /* "plastid/genomics/roitools.pyx":246
 *         iv_ltmp.append("GenomicSegment('%s', %s, %s, '%s')" % (iv.chrom, iv.start, iv.end, iv.strand))
 * 
 *     stmp = "Transcript(%s, ID='%s', cds_genome_start=%s, cds_genome_end=%s)\n" % (             # <<<<<<<<<<<<<<
 *         ",".join(iv_ltmp), tx.get_name(), tx.cds_genome_start, tx.cds_genome_end
 *     )
 */
  __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 9, __pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 246, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_stmp = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "plastid/genomics/roitools.pyx":250
 *     )
 * 
 *     return stmp             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_stmp);
  __pyx_r = __pyx_v_stmp;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":230
 *     return stmp
 * 
 * def _format_transcript(Transcript tx):             # <<<<<<<<<<<<<<
 *     """Formats a |Transcript| as a string, which when ``eval`` ed, should
 *     reconstruct the |Transcript|.  Used for creating test datasets.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("plastid.genomics.roitools._format_transcript", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_iv_ltmp);
  __Pyx_XDECREF(__pyx_v_iv);
  __Pyx_XDECREF(__pyx_v_stmp);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":257
 * #==============================================================================
 * 
 * cpdef list merge_segments(list segments):             # <<<<<<<<<<<<<<
 *     """Merge all overlapping |GenomicSegments| in `segments`, so that all
 *     segments returned are guaranteed to be sorted and non-overlapping.
 */

static PyObject *__pyx_pw_7plastid_8genomics_8roitools_7merge_segments(PyObject *__pyx_self, PyObject *__pyx_v_segments); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_merge_segments(PyObject *__pyx_v_segments, CYTHON_UNUSED int __pyx_skip_dispatch) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_left = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_right = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_strand = 0;
  PyObject *__pyx_v_new_segments = 0;
  PyObject *__pyx_v_ssegments = 0;
  int __pyx_v_i;
  int __pyx_v_length;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  long __pyx_t_6;
  long __pyx_t_7;
  long __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("merge_segments", 0);

  /* "plastid/genomics/roitools.pyx":281
 *         str chrom
 *         str strand
 *         list new_segments = []             # <<<<<<<<<<<<<<
 *         list ssegments
 *         int i = 0
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_new_segments = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":283
 *         list new_segments = []
 *         list ssegments
 *         int i = 0             # <<<<<<<<<<<<<<
 *         int length = len(segments)
 * 
 */
  __pyx_v_i = 0;

  /* "plastid/genomics/roitools.pyx":284
 *         list ssegments
 *         int i = 0
 *         int length = len(segments)             # <<<<<<<<<<<<<<
 * 
 *     if length < 2:
 */
  if (unlikely(__pyx_v_segments == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 284, __pyx_L1_error)
  }
  __pyx_t_2 = PyList_GET_SIZE(__pyx_v_segments); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 284, __pyx_L1_error)
  __pyx_v_length = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":286
 *         int length = len(segments)
 * 
 *     if length < 2:             # <<<<<<<<<<<<<<
 *         return segments
 * 
 */
  __pyx_t_3 = ((__pyx_v_length < 2) != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":287
 * 
 *     if length < 2:
 *         return segments             # <<<<<<<<<<<<<<
 * 
 *     ssegments = sorted(segments)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_segments);
    __pyx_r = __pyx_v_segments;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":286
 *         int length = len(segments)
 * 
 *     if length < 2:             # <<<<<<<<<<<<<<
 *         return segments
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":289
 *         return segments
 * 
 *     ssegments = sorted(segments)             # <<<<<<<<<<<<<<
 *     left = ssegments[0]
 *     chrom = left.chrom
 */
  __pyx_t_4 = PySequence_List(__pyx_v_segments); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 289, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_5 = PyList_Sort(__pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 289, __pyx_L1_error)
  __pyx_v_ssegments = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":290
 * 
 *     ssegments = sorted(segments)
 *     left = ssegments[0]             # <<<<<<<<<<<<<<
 *     chrom = left.chrom
 *     strand = left.strand
 */
  if (unlikely(__pyx_v_ssegments == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 290, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_ssegments, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 290, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 290, __pyx_L1_error)
  __pyx_v_left = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":291
 *     ssegments = sorted(segments)
 *     left = ssegments[0]
 *     chrom = left.chrom             # <<<<<<<<<<<<<<
 *     strand = left.strand
 * 
 */
  __pyx_t_1 = __pyx_v_left->chrom;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_chrom = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":292
 *     left = ssegments[0]
 *     chrom = left.chrom
 *     strand = left.strand             # <<<<<<<<<<<<<<
 * 
 *     while i < length - 1:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_left), __pyx_n_s_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 292, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 292, __pyx_L1_error)
  __pyx_v_strand = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":294
 *     strand = left.strand
 * 
 *     while i < length - 1:             # <<<<<<<<<<<<<<
 *         right = ssegments[i + 1]
 *         if right.start > left.end:
 */
  while (1) {
    __pyx_t_3 = ((__pyx_v_i < (__pyx_v_length - 1)) != 0);
    if (!__pyx_t_3) break;

    /* "plastid/genomics/roitools.pyx":295
 * 
 *     while i < length - 1:
 *         right = ssegments[i + 1]             # <<<<<<<<<<<<<<
 *         if right.start > left.end:
 *             new_segments.append(left)
 */
    if (unlikely(__pyx_v_ssegments == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 295, __pyx_L1_error)
    }
    __pyx_t_6 = (__pyx_v_i + 1);
    __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_ssegments, __pyx_t_6, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 295, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 295, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_right, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":296
 *     while i < length - 1:
 *         right = ssegments[i + 1]
 *         if right.start > left.end:             # <<<<<<<<<<<<<<
 *             new_segments.append(left)
 *             left = right
 */
    __pyx_t_3 = ((__pyx_v_right->start > __pyx_v_left->end) != 0);
    if (__pyx_t_3) {

      /* "plastid/genomics/roitools.pyx":297
 *         right = ssegments[i + 1]
 *         if right.start > left.end:
 *             new_segments.append(left)             # <<<<<<<<<<<<<<
 *             left = right
 *         else:
 */
      __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_new_segments, ((PyObject *)__pyx_v_left)); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 297, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":298
 *         if right.start > left.end:
 *             new_segments.append(left)
 *             left = right             # <<<<<<<<<<<<<<
 *         else:
 *             left = GenomicSegment(chrom, left.start, max(left.end, right.end), strand)
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_right));
      __Pyx_DECREF_SET(__pyx_v_left, __pyx_v_right);

      /* "plastid/genomics/roitools.pyx":296
 *     while i < length - 1:
 *         right = ssegments[i + 1]
 *         if right.start > left.end:             # <<<<<<<<<<<<<<
 *             new_segments.append(left)
 *             left = right
 */
      goto __pyx_L6;
    }

    /* "plastid/genomics/roitools.pyx":300
 *             left = right
 *         else:
 *             left = GenomicSegment(chrom, left.start, max(left.end, right.end), strand)             # <<<<<<<<<<<<<<
 * 
 *         i += 1
 */
    /*else*/ {
      __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_left->start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 300, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = __pyx_v_right->end;
      __pyx_t_7 = __pyx_v_left->end;
      if (((__pyx_t_6 > __pyx_t_7) != 0)) {
        __pyx_t_8 = __pyx_t_6;
      } else {
        __pyx_t_8 = __pyx_t_7;
      }
      __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 300, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_9 = PyTuple_New(4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 300, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_INCREF(__pyx_v_chrom);
      __Pyx_GIVEREF(__pyx_v_chrom);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_chrom);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_4);
      __Pyx_INCREF(__pyx_v_strand);
      __Pyx_GIVEREF(__pyx_v_strand);
      PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_v_strand);
      __pyx_t_1 = 0;
      __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 300, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF_SET(__pyx_v_left, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_4));
      __pyx_t_4 = 0;
    }
    __pyx_L6:;

    /* "plastid/genomics/roitools.pyx":302
 *             left = GenomicSegment(chrom, left.start, max(left.end, right.end), strand)
 * 
 *         i += 1             # <<<<<<<<<<<<<<
 * 
 *     new_segments.append(left)
 */
    __pyx_v_i = (__pyx_v_i + 1);
  }

  /* "plastid/genomics/roitools.pyx":304
 *         i += 1
 * 
 *     new_segments.append(left)             # <<<<<<<<<<<<<<
 * 
 *     return new_segments
 */
  __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_new_segments, ((PyObject *)__pyx_v_left)); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 304, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":306
 *     new_segments.append(left)
 * 
 *     return new_segments             # <<<<<<<<<<<<<<
 * 
 * cpdef list positions_to_segments(str chrom, str strand, object positions):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_new_segments);
  __pyx_r = __pyx_v_new_segments;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":257
 * #==============================================================================
 * 
 * cpdef list merge_segments(list segments):             # <<<<<<<<<<<<<<
 *     """Merge all overlapping |GenomicSegments| in `segments`, so that all
 *     segments returned are guaranteed to be sorted and non-overlapping.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("plastid.genomics.roitools.merge_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_left);
  __Pyx_XDECREF((PyObject *)__pyx_v_right);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_strand);
  __Pyx_XDECREF(__pyx_v_new_segments);
  __Pyx_XDECREF(__pyx_v_ssegments);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_7merge_segments(PyObject *__pyx_self, PyObject *__pyx_v_segments); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_6merge_segments[] = "merge_segments(list segments) -> list\nMerge all overlapping |GenomicSegments| in `segments`, so that all\n    segments returned are guaranteed to be sorted and non-overlapping.\n\n    .. note::\n\n        All segments are assumed to be on the same strand and chromosome.\n\n\n    Parameters\n    ----------\n    segments : list\n        List of |GenomicSegments|, all on the same strand and chromosome\n\n    Returns\n    -------\n    list\n        List of sorted, non-overlapping |GenomicSegments|\n    ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_7merge_segments(PyObject *__pyx_self, PyObject *__pyx_v_segments) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("merge_segments (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_segments), (&PyList_Type), 1, "segments", 1))) __PYX_ERR(0, 257, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_6merge_segments(__pyx_self, ((PyObject*)__pyx_v_segments));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_6merge_segments(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_segments) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("merge_segments", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_merge_segments(__pyx_v_segments, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 257, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "plastid/genomics/roitools.pyx":308
 *     return new_segments
 * 
 * cpdef list positions_to_segments(str chrom, str strand, object positions):             # <<<<<<<<<<<<<<
 *     """Construct |GenomicSegments| from a chromosome name, a strand, and a list
 *     of chromosomal positions.
 */

static PyObject *__pyx_pw_7plastid_8genomics_8roitools_9positions_to_segments(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_positions_to_segments(PyObject *__pyx_v_chrom, PyObject *__pyx_v_strand, PyObject *__pyx_v_positions, CYTHON_UNUSED int __pyx_skip_dispatch) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("positions_to_segments", 0);
  __Pyx_INCREF(__pyx_v_positions);

  /* "plastid/genomics/roitools.pyx":329
 *         List of |GenomicSegments| covering `positions`
 *     """
 *     if isinstance(positions, set):             # <<<<<<<<<<<<<<
 *         positions = sorted(positions)
 *     else:
 */
  __pyx_t_1 = PySet_Check(__pyx_v_positions); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":330
 *     """
 *     if isinstance(positions, set):
 *         positions = sorted(positions)             # <<<<<<<<<<<<<<
 *     else:
 *         positions = sorted(set(positions))
 */
    __pyx_t_4 = PySequence_List(__pyx_v_positions); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 330, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_5 = PyList_Sort(__pyx_t_3); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 330, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_positions, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":329
 *         List of |GenomicSegments| covering `positions`
 *     """
 *     if isinstance(positions, set):             # <<<<<<<<<<<<<<
 *         positions = sorted(positions)
 *     else:
 */
    goto __pyx_L3;
  }

  /* "plastid/genomics/roitools.pyx":332
 *         positions = sorted(positions)
 *     else:
 *         positions = sorted(set(positions))             # <<<<<<<<<<<<<<
 * 
 *     return positionlist_to_segments(chrom, strand, positions)
 */
  /*else*/ {
    __pyx_t_4 = PySet_New(__pyx_v_positions); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 332, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = PySequence_List(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 332, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_3 = ((PyObject*)__pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_5 = PyList_Sort(__pyx_t_3); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 332, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_positions, __pyx_t_3);
    __pyx_t_3 = 0;
  }
  __pyx_L3:;

  /* "plastid/genomics/roitools.pyx":334
 *         positions = sorted(set(positions))
 * 
 *     return positionlist_to_segments(chrom, strand, positions)             # <<<<<<<<<<<<<<
 * 
 * cpdef list positionlist_to_segments(str chrom, str strand, list positions):
 */
  __Pyx_XDECREF(__pyx_r);
  if (!(likely(PyList_CheckExact(__pyx_v_positions))||((__pyx_v_positions) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_positions)->tp_name), 0))) __PYX_ERR(0, 334, __pyx_L1_error)
  __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_positionlist_to_segments(__pyx_v_chrom, __pyx_v_strand, ((PyObject*)__pyx_v_positions), 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 334, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":308
 *     return new_segments
 * 
 * cpdef list positions_to_segments(str chrom, str strand, object positions):             # <<<<<<<<<<<<<<
 *     """Construct |GenomicSegments| from a chromosome name, a strand, and a list
 *     of chromosomal positions.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("plastid.genomics.roitools.positions_to_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_positions);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_9positions_to_segments(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_8positions_to_segments[] = "positions_to_segments(unicode chrom, unicode strand, positions) -> list\nConstruct |GenomicSegments| from a chromosome name, a strand, and a list\n    of chromosomal positions.\n\n    Parameters\n    ----------\n    chrom : str\n        Chromosome name\n\n    strand : str\n        Chromosome strand (`'+'`, `'-'`, or `'.'`)\n\n    positions : list of integers\n        **End-inclusive** list, tuple, or set of positions to include in final\n        |GenomicSegment|\n\n    Returns\n    -------\n    list\n        List of |GenomicSegments| covering `positions`\n    ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_9positions_to_segments(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_strand = 0;
  PyObject *__pyx_v_positions = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("positions_to_segments (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_chrom,&__pyx_n_s_strand,&__pyx_n_s_positions,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_strand)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("positions_to_segments", 1, 3, 3, 1); __PYX_ERR(0, 308, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_positions)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("positions_to_segments", 1, 3, 3, 2); __PYX_ERR(0, 308, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "positions_to_segments") < 0)) __PYX_ERR(0, 308, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_chrom = ((PyObject*)values[0]);
    __pyx_v_strand = ((PyObject*)values[1]);
    __pyx_v_positions = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("positions_to_segments", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 308, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.positions_to_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_chrom), (&PyUnicode_Type), 1, "chrom", 1))) __PYX_ERR(0, 308, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_strand), (&PyUnicode_Type), 1, "strand", 1))) __PYX_ERR(0, 308, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_8positions_to_segments(__pyx_self, __pyx_v_chrom, __pyx_v_strand, __pyx_v_positions);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_8positions_to_segments(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_chrom, PyObject *__pyx_v_strand, PyObject *__pyx_v_positions) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("positions_to_segments", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_positions_to_segments(__pyx_v_chrom, __pyx_v_strand, __pyx_v_positions, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "plastid/genomics/roitools.pyx":336
 *     return positionlist_to_segments(chrom, strand, positions)
 * 
 * cpdef list positionlist_to_segments(str chrom, str strand, list positions):             # <<<<<<<<<<<<<<
 *     """Construct |GenomicSegments| from a chromosome name, a strand, and a list
 *     of chromosomal positions.
 */

static PyObject *__pyx_pw_7plastid_8genomics_8roitools_11positionlist_to_segments(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_positionlist_to_segments(PyObject *__pyx_v_chrom, PyObject *__pyx_v_strand, PyObject *__pyx_v_positions, CYTHON_UNUSED int __pyx_skip_dispatch) {
  PyObject *__pyx_v_segments = 0;
  long __pyx_v_start;
  long __pyx_v_last_pos;
  long __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  long __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("positionlist_to_segments", 0);

  /* "plastid/genomics/roitools.pyx":365
 *     """
 *     cdef:
 *         list segments = []             # <<<<<<<<<<<<<<
 *         long start, last_pos, i
 * 
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 365, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_segments = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":368
 *         long start, last_pos, i
 * 
 *     if len(positions) > 0:             # <<<<<<<<<<<<<<
 *         start = positions[0]
 *         last_pos = positions[0]
 */
  if (unlikely(__pyx_v_positions == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 368, __pyx_L1_error)
  }
  __pyx_t_2 = PyList_GET_SIZE(__pyx_v_positions); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 368, __pyx_L1_error)
  __pyx_t_3 = ((__pyx_t_2 > 0) != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":369
 * 
 *     if len(positions) > 0:
 *         start = positions[0]             # <<<<<<<<<<<<<<
 *         last_pos = positions[0]
 *         for i in positions:
 */
    if (unlikely(__pyx_v_positions == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 369, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_positions, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 369, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 369, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_start = __pyx_t_4;

    /* "plastid/genomics/roitools.pyx":370
 *     if len(positions) > 0:
 *         start = positions[0]
 *         last_pos = positions[0]             # <<<<<<<<<<<<<<
 *         for i in positions:
 *             if i == start:
 */
    if (unlikely(__pyx_v_positions == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 370, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_positions, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 370, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 370, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_last_pos = __pyx_t_4;

    /* "plastid/genomics/roitools.pyx":371
 *         start = positions[0]
 *         last_pos = positions[0]
 *         for i in positions:             # <<<<<<<<<<<<<<
 *             if i == start:
 *                 continue
 */
    if (unlikely(__pyx_v_positions == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 371, __pyx_L1_error)
    }
    __pyx_t_1 = __pyx_v_positions; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    for (;;) {
      if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 371, __pyx_L1_error)
      #else
      __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 371, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
      __pyx_t_4 = __Pyx_PyInt_As_long(__pyx_t_5); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 371, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_i = __pyx_t_4;

      /* "plastid/genomics/roitools.pyx":372
 *         last_pos = positions[0]
 *         for i in positions:
 *             if i == start:             # <<<<<<<<<<<<<<
 *                 continue
 *             if i - last_pos == 1:
 */
      __pyx_t_3 = ((__pyx_v_i == __pyx_v_start) != 0);
      if (__pyx_t_3) {

        /* "plastid/genomics/roitools.pyx":373
 *         for i in positions:
 *             if i == start:
 *                 continue             # <<<<<<<<<<<<<<
 *             if i - last_pos == 1:
 *                 last_pos = i
 */
        goto __pyx_L4_continue;

        /* "plastid/genomics/roitools.pyx":372
 *         last_pos = positions[0]
 *         for i in positions:
 *             if i == start:             # <<<<<<<<<<<<<<
 *                 continue
 *             if i - last_pos == 1:
 */
      }

      /* "plastid/genomics/roitools.pyx":374
 *             if i == start:
 *                 continue
 *             if i - last_pos == 1:             # <<<<<<<<<<<<<<
 *                 last_pos = i
 *             else:
 */
      __pyx_t_3 = (((__pyx_v_i - __pyx_v_last_pos) == 1) != 0);
      if (__pyx_t_3) {

        /* "plastid/genomics/roitools.pyx":375
 *                 continue
 *             if i - last_pos == 1:
 *                 last_pos = i             # <<<<<<<<<<<<<<
 *             else:
 *                 segments.append(GenomicSegment(chrom, start, last_pos+1, strand))
 */
        __pyx_v_last_pos = __pyx_v_i;

        /* "plastid/genomics/roitools.pyx":374
 *             if i == start:
 *                 continue
 *             if i - last_pos == 1:             # <<<<<<<<<<<<<<
 *                 last_pos = i
 *             else:
 */
        goto __pyx_L7;
      }

      /* "plastid/genomics/roitools.pyx":377
 *                 last_pos = i
 *             else:
 *                 segments.append(GenomicSegment(chrom, start, last_pos+1, strand))             # <<<<<<<<<<<<<<
 *                 start = i
 *                 last_pos = i
 */
      /*else*/ {
        __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_start); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 377, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = __Pyx_PyInt_From_long((__pyx_v_last_pos + 1)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 377, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 377, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_v_chrom);
        __Pyx_GIVEREF(__pyx_v_chrom);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_chrom);
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_6);
        __Pyx_INCREF(__pyx_v_strand);
        __Pyx_GIVEREF(__pyx_v_strand);
        PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_v_strand);
        __pyx_t_5 = 0;
        __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 377, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_segments, __pyx_t_6); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 377, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "plastid/genomics/roitools.pyx":378
 *             else:
 *                 segments.append(GenomicSegment(chrom, start, last_pos+1, strand))
 *                 start = i             # <<<<<<<<<<<<<<
 *                 last_pos = i
 *         segments.append(GenomicSegment(chrom, start, last_pos+1, strand))
 */
        __pyx_v_start = __pyx_v_i;

        /* "plastid/genomics/roitools.pyx":379
 *                 segments.append(GenomicSegment(chrom, start, last_pos+1, strand))
 *                 start = i
 *                 last_pos = i             # <<<<<<<<<<<<<<
 *         segments.append(GenomicSegment(chrom, start, last_pos+1, strand))
 * 
 */
        __pyx_v_last_pos = __pyx_v_i;
      }
      __pyx_L7:;

      /* "plastid/genomics/roitools.pyx":371
 *         start = positions[0]
 *         last_pos = positions[0]
 *         for i in positions:             # <<<<<<<<<<<<<<
 *             if i == start:
 *                 continue
 */
      __pyx_L4_continue:;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":380
 *                 start = i
 *                 last_pos = i
 *         segments.append(GenomicSegment(chrom, start, last_pos+1, strand))             # <<<<<<<<<<<<<<
 * 
 *     return segments
 */
    __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 380, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyInt_From_long((__pyx_v_last_pos + 1)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 380, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 380, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_v_chrom);
    __Pyx_GIVEREF(__pyx_v_chrom);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_chrom);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_6);
    __Pyx_INCREF(__pyx_v_strand);
    __Pyx_GIVEREF(__pyx_v_strand);
    PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_v_strand);
    __pyx_t_1 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 380, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_segments, __pyx_t_6); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 380, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":368
 *         long start, last_pos, i
 * 
 *     if len(positions) > 0:             # <<<<<<<<<<<<<<
 *         start = positions[0]
 *         last_pos = positions[0]
 */
  }

  /* "plastid/genomics/roitools.pyx":382
 *         segments.append(GenomicSegment(chrom, start, last_pos+1, strand))
 * 
 *     return segments             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_segments);
  __pyx_r = __pyx_v_segments;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":336
 *     return positionlist_to_segments(chrom, strand, positions)
 * 
 * cpdef list positionlist_to_segments(str chrom, str strand, list positions):             # <<<<<<<<<<<<<<
 *     """Construct |GenomicSegments| from a chromosome name, a strand, and a list
 *     of chromosomal positions.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.positionlist_to_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_segments);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_11positionlist_to_segments(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10positionlist_to_segments[] = "positionlist_to_segments(unicode chrom, unicode strand, list positions) -> list\nConstruct |GenomicSegments| from a chromosome name, a strand, and a list\n    of chromosomal positions.\n\n    Parameters\n    ----------\n    chrom : str\n        Chromosome name\n\n    strand : str\n        Chromosome strand (`'+'`, `'-'`, or `'.'`)\n\n    positions : list of unique integers\n        Sorted, **end-inclusive** list of positions to include\n        in final |GenomicSegment|\n\n    Returns\n    -------\n    list\n        List of |GenomicSegments| covering `positions`\n\n\n     .. warning::\n\n        This function is meant to quickly without excessive type conversions.\n        So, the elements `positions` must be **UNIQUE** and **SORTED**. If\n        they are not, use :func:`positions_to_segments` instead.\n    ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_11positionlist_to_segments(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_strand = 0;
  PyObject *__pyx_v_positions = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("positionlist_to_segments (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_chrom,&__pyx_n_s_strand,&__pyx_n_s_positions,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_strand)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("positionlist_to_segments", 1, 3, 3, 1); __PYX_ERR(0, 336, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_positions)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("positionlist_to_segments", 1, 3, 3, 2); __PYX_ERR(0, 336, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "positionlist_to_segments") < 0)) __PYX_ERR(0, 336, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_chrom = ((PyObject*)values[0]);
    __pyx_v_strand = ((PyObject*)values[1]);
    __pyx_v_positions = ((PyObject*)values[2]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("positionlist_to_segments", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 336, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.positionlist_to_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_chrom), (&PyUnicode_Type), 1, "chrom", 1))) __PYX_ERR(0, 336, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_strand), (&PyUnicode_Type), 1, "strand", 1))) __PYX_ERR(0, 336, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_positions), (&PyList_Type), 1, "positions", 1))) __PYX_ERR(0, 336, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10positionlist_to_segments(__pyx_self, __pyx_v_chrom, __pyx_v_strand, __pyx_v_positions);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10positionlist_to_segments(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_chrom, PyObject *__pyx_v_strand, PyObject *__pyx_v_positions) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("positionlist_to_segments", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_positionlist_to_segments(__pyx_v_chrom, __pyx_v_strand, __pyx_v_positions, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "plastid/genomics/roitools.pyx":385
 * 
 * 
 * cpdef Transcript add_three_for_stop_codon(Transcript tx):             # <<<<<<<<<<<<<<
 *     """Extend an annotated CDS region, if present, by three nucleotides
 *     at the threeprime end. Use in cases when annotation files exclude the stop
 */

static PyObject *__pyx_pw_7plastid_8genomics_8roitools_13add_three_for_stop_codon(PyObject *__pyx_self, PyObject *__pyx_v_tx); /*proto*/
static struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_f_7plastid_8genomics_8roitools_add_three_for_stop_codon(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_tx, CYTHON_UNUSED int __pyx_skip_dispatch) {
  long __pyx_v_start;
  long __pyx_v_end;
  long __pyx_v_new_start;
  long __pyx_v_new_end;
  int __pyx_v_n;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_span = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_new_seg = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_old_seg = 0;
  PyObject *__pyx_v_segments = 0;
  PyObject *__pyx_v_attr = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_new_tx = 0;
  PyObject *__pyx_v_chrom = NULL;
  PyObject *__pyx_v_segment = NULL;
  struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  long __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  long __pyx_t_9;
  int __pyx_t_10;
  Py_ssize_t __pyx_t_11;
  PyObject *(*__pyx_t_12)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add_three_for_stop_codon", 0);

  /* "plastid/genomics/roitools.pyx":416
 *         Transcript new_tx
 * 
 *     if tx.cds_genome_end is not None and tx.cds_genome_start is not None:             # <<<<<<<<<<<<<<
 *         new_start = start = <long>tx.cds_genome_start
 *         new_end = end = <long>tx.cds_genome_end
 */
  __pyx_t_2 = (__pyx_v_tx->cds_genome_end != Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (__pyx_v_tx->cds_genome_start != Py_None);
  __pyx_t_2 = (__pyx_t_3 != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "plastid/genomics/roitools.pyx":417
 * 
 *     if tx.cds_genome_end is not None and tx.cds_genome_start is not None:
 *         new_start = start = <long>tx.cds_genome_start             # <<<<<<<<<<<<<<
 *         new_end = end = <long>tx.cds_genome_end
 *         segments  = copy.copy(tx._segments)
 */
    __pyx_t_4 = __Pyx_PyInt_As_long(__pyx_v_tx->cds_genome_start); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 417, __pyx_L1_error)
    __pyx_v_new_start = ((long)__pyx_t_4);
    __pyx_v_start = ((long)__pyx_t_4);

    /* "plastid/genomics/roitools.pyx":418
 *     if tx.cds_genome_end is not None and tx.cds_genome_start is not None:
 *         new_start = start = <long>tx.cds_genome_start
 *         new_end = end = <long>tx.cds_genome_end             # <<<<<<<<<<<<<<
 *         segments  = copy.copy(tx._segments)
 *         attr = copy.deepcopy(tx.attr)
 */
    __pyx_t_4 = __Pyx_PyInt_As_long(__pyx_v_tx->cds_genome_end); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 418, __pyx_L1_error)
    __pyx_v_new_end = ((long)__pyx_t_4);
    __pyx_v_end = ((long)__pyx_t_4);

    /* "plastid/genomics/roitools.pyx":419
 *         new_start = start = <long>tx.cds_genome_start
 *         new_end = end = <long>tx.cds_genome_end
 *         segments  = copy.copy(tx._segments)             # <<<<<<<<<<<<<<
 *         attr = copy.deepcopy(tx.attr)
 *         span = tx.spanning_segment
 */
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_copy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 419, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_copy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 419, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_v_tx->__pyx_base._segments) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_tx->__pyx_base._segments);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 419, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (!(likely(PyList_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 419, __pyx_L1_error)
    __pyx_v_segments = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":420
 *         new_end = end = <long>tx.cds_genome_end
 *         segments  = copy.copy(tx._segments)
 *         attr = copy.deepcopy(tx.attr)             # <<<<<<<<<<<<<<
 *         span = tx.spanning_segment
 *         chrom = span.chrom
 */
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_copy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 420, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 420, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_v_tx->__pyx_base.attr) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_tx->__pyx_base.attr);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 420, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(PyDict_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 420, __pyx_L1_error)
    __pyx_v_attr = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":421
 *         segments  = copy.copy(tx._segments)
 *         attr = copy.deepcopy(tx.attr)
 *         span = tx.spanning_segment             # <<<<<<<<<<<<<<
 *         chrom = span.chrom
 *         if span.c_strand == forward_strand:
 */
    __pyx_t_5 = ((PyObject *)__pyx_v_tx->__pyx_base.spanning_segment);
    __Pyx_INCREF(__pyx_t_5);
    __pyx_v_span = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":422
 *         attr = copy.deepcopy(tx.attr)
 *         span = tx.spanning_segment
 *         chrom = span.chrom             # <<<<<<<<<<<<<<
 *         if span.c_strand == forward_strand:
 *             # if cds at end of transcript, both need to grow by three
 */
    __pyx_t_5 = __pyx_v_span->chrom;
    __Pyx_INCREF(__pyx_t_5);
    __pyx_v_chrom = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":423
 *         span = tx.spanning_segment
 *         chrom = span.chrom
 *         if span.c_strand == forward_strand:             # <<<<<<<<<<<<<<
 *             # if cds at end of transcript, both need to grow by three
 *             if span.end == end:
 */
    __pyx_t_1 = ((__pyx_v_span->c_strand == __pyx_e_7plastid_8genomics_8c_common_forward_strand) != 0);
    if (__pyx_t_1) {

      /* "plastid/genomics/roitools.pyx":425
 *         if span.c_strand == forward_strand:
 *             # if cds at end of transcript, both need to grow by three
 *             if span.end == end:             # <<<<<<<<<<<<<<
 *                 new_end = end + 3
 *                 old_seg = segments[-1]
 */
      __pyx_t_1 = ((__pyx_v_span->end == __pyx_v_end) != 0);
      if (__pyx_t_1) {

        /* "plastid/genomics/roitools.pyx":426
 *             # if cds at end of transcript, both need to grow by three
 *             if span.end == end:
 *                 new_end = end + 3             # <<<<<<<<<<<<<<
 *                 old_seg = segments[-1]
 *                 new_seg = GenomicSegment(chrom, old_seg.start, new_end, span.strand)
 */
        __pyx_v_new_end = (__pyx_v_end + 3);

        /* "plastid/genomics/roitools.pyx":427
 *             if span.end == end:
 *                 new_end = end + 3
 *                 old_seg = segments[-1]             # <<<<<<<<<<<<<<
 *                 new_seg = GenomicSegment(chrom, old_seg.start, new_end, span.strand)
 *                 segments[-1] = new_seg
 */
        if (unlikely(__pyx_v_segments == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 427, __pyx_L1_error)
        }
        __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_segments, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 427, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 427, __pyx_L1_error)
        __pyx_v_old_seg = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_5);
        __pyx_t_5 = 0;

        /* "plastid/genomics/roitools.pyx":428
 *                 new_end = end + 3
 *                 old_seg = segments[-1]
 *                 new_seg = GenomicSegment(chrom, old_seg.start, new_end, span.strand)             # <<<<<<<<<<<<<<
 *                 segments[-1] = new_seg
 *             else:
 */
        __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_old_seg->start); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 428, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_new_end); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 428, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_span), __pyx_n_s_strand); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 428, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = PyTuple_New(4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 428, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_v_chrom);
        __Pyx_GIVEREF(__pyx_v_chrom);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_chrom);
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_7);
        __pyx_t_5 = 0;
        __pyx_t_6 = 0;
        __pyx_t_7 = 0;
        __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 428, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_v_new_seg = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_7);
        __pyx_t_7 = 0;

        /* "plastid/genomics/roitools.pyx":429
 *                 old_seg = segments[-1]
 *                 new_seg = GenomicSegment(chrom, old_seg.start, new_end, span.strand)
 *                 segments[-1] = new_seg             # <<<<<<<<<<<<<<
 *             else:
 *                 # if new end will be end of transcript, set manually
 */
        if (unlikely(__pyx_v_segments == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 429, __pyx_L1_error)
        }
        if (unlikely(__Pyx_SetItemInt(__pyx_v_segments, -1L, ((PyObject *)__pyx_v_new_seg), long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 429, __pyx_L1_error)

        /* "plastid/genomics/roitools.pyx":425
 *         if span.c_strand == forward_strand:
 *             # if cds at end of transcript, both need to grow by three
 *             if span.end == end:             # <<<<<<<<<<<<<<
 *                 new_end = end + 3
 *                 old_seg = segments[-1]
 */
        goto __pyx_L7;
      }

      /* "plastid/genomics/roitools.pyx":433
 *                 # if new end will be end of transcript, set manually
 *                 # because key won't be in position hash
 *                 if tx.cds_end + 3 == tx.length:             # <<<<<<<<<<<<<<
 *                     new_end = span.end
 *                 else:
 */
      /*else*/ {
        __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_v_tx->cds_end, __pyx_int_3, 3, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 433, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyInt_From_long(__pyx_v_tx->__pyx_base.length); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 433, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_6 = PyObject_RichCompare(__pyx_t_7, __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 433, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 433, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__pyx_t_1) {

          /* "plastid/genomics/roitools.pyx":434
 *                 # because key won't be in position hash
 *                 if tx.cds_end + 3 == tx.length:
 *                     new_end = span.end             # <<<<<<<<<<<<<<
 *                 else:
 *                     # position is internal, so we fetch
 */
          __pyx_t_4 = __pyx_v_span->end;
          __pyx_v_new_end = __pyx_t_4;

          /* "plastid/genomics/roitools.pyx":433
 *                 # if new end will be end of transcript, set manually
 *                 # because key won't be in position hash
 *                 if tx.cds_end + 3 == tx.length:             # <<<<<<<<<<<<<<
 *                     new_end = span.end
 *                 else:
 */
          goto __pyx_L8;
        }

        /* "plastid/genomics/roitools.pyx":437
 *                 else:
 *                     # position is internal, so we fetch
 *                     new_end = tx.c_get_genomic_coordinate(tx.cds_end+3, True)             # <<<<<<<<<<<<<<
 *                     # correct for rare cases in which stop codons and at the end
 *                     # of a given exon interval, and are falsely mapped to first position
 */
        /*else*/ {
          __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_v_tx->cds_end, __pyx_int_3, 3, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 437, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_4 = __Pyx_PyInt_As_long(__pyx_t_6); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 437, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_9 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_tx->__pyx_base.__pyx_vtab)->__pyx_base.c_get_genomic_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_tx), __pyx_t_4, 1); if (unlikely(__pyx_t_9 == ((long)-1L))) __PYX_ERR(0, 437, __pyx_L1_error)
          __pyx_v_new_end = __pyx_t_9;

          /* "plastid/genomics/roitools.pyx":442
 *                     # of next exon. Instead, we should map to 1 + the genomic position
 *                     # of the end of the given exon.
 *                     for n, segment in enumerate(tx):             # <<<<<<<<<<<<<<
 *                         if new_end == segment.start:
 *                             new_end = tx[n-1].end
 */
          __pyx_t_10 = 0;
          if (likely(PyList_CheckExact(((PyObject *)__pyx_v_tx))) || PyTuple_CheckExact(((PyObject *)__pyx_v_tx))) {
            __pyx_t_6 = ((PyObject *)__pyx_v_tx); __Pyx_INCREF(__pyx_t_6); __pyx_t_11 = 0;
            __pyx_t_12 = NULL;
          } else {
            __pyx_t_11 = -1; __pyx_t_6 = PyObject_GetIter(((PyObject *)__pyx_v_tx)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 442, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __pyx_t_12 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 442, __pyx_L1_error)
          }
          for (;;) {
            if (likely(!__pyx_t_12)) {
              if (likely(PyList_CheckExact(__pyx_t_6))) {
                if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_6)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_8 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_11); __Pyx_INCREF(__pyx_t_8); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 442, __pyx_L1_error)
                #else
                __pyx_t_8 = PySequence_ITEM(__pyx_t_6, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 442, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_8);
                #endif
              } else {
                if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_11); __Pyx_INCREF(__pyx_t_8); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 442, __pyx_L1_error)
                #else
                __pyx_t_8 = PySequence_ITEM(__pyx_t_6, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 442, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_8);
                #endif
              }
            } else {
              __pyx_t_8 = __pyx_t_12(__pyx_t_6);
              if (unlikely(!__pyx_t_8)) {
                PyObject* exc_type = PyErr_Occurred();
                if (exc_type) {
                  if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                  else __PYX_ERR(0, 442, __pyx_L1_error)
                }
                break;
              }
              __Pyx_GOTREF(__pyx_t_8);
            }
            __Pyx_XDECREF_SET(__pyx_v_segment, __pyx_t_8);
            __pyx_t_8 = 0;
            __pyx_v_n = __pyx_t_10;
            __pyx_t_10 = (__pyx_t_10 + 1);

            /* "plastid/genomics/roitools.pyx":443
 *                     # of the end of the given exon.
 *                     for n, segment in enumerate(tx):
 *                         if new_end == segment.start:             # <<<<<<<<<<<<<<
 *                             new_end = tx[n-1].end
 *         else:
 */
            __pyx_t_8 = __Pyx_PyInt_From_long(__pyx_v_new_end); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 443, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_segment, __pyx_n_s_start); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 443, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);
            __pyx_t_5 = PyObject_RichCompare(__pyx_t_8, __pyx_t_7, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 443, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 443, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            if (__pyx_t_1) {

              /* "plastid/genomics/roitools.pyx":444
 *                     for n, segment in enumerate(tx):
 *                         if new_end == segment.start:
 *                             new_end = tx[n-1].end             # <<<<<<<<<<<<<<
 *         else:
 *             # if cds starts at beginning of transcript, both need to grow by three
 */
              __pyx_t_9 = (__pyx_v_n - 1);
              __pyx_t_5 = __Pyx_GetItemInt(((PyObject *)__pyx_v_tx), __pyx_t_9, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 444, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_5);
              __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_end); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 444, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __pyx_t_9 = __Pyx_PyInt_As_long(__pyx_t_7); if (unlikely((__pyx_t_9 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 444, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
              __pyx_v_new_end = __pyx_t_9;

              /* "plastid/genomics/roitools.pyx":443
 *                     # of the end of the given exon.
 *                     for n, segment in enumerate(tx):
 *                         if new_end == segment.start:             # <<<<<<<<<<<<<<
 *                             new_end = tx[n-1].end
 *         else:
 */
            }

            /* "plastid/genomics/roitools.pyx":442
 *                     # of next exon. Instead, we should map to 1 + the genomic position
 *                     # of the end of the given exon.
 *                     for n, segment in enumerate(tx):             # <<<<<<<<<<<<<<
 *                         if new_end == segment.start:
 *                             new_end = tx[n-1].end
 */
          }
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        }
        __pyx_L8:;
      }
      __pyx_L7:;

      /* "plastid/genomics/roitools.pyx":423
 *         span = tx.spanning_segment
 *         chrom = span.chrom
 *         if span.c_strand == forward_strand:             # <<<<<<<<<<<<<<
 *             # if cds at end of transcript, both need to grow by three
 *             if span.end == end:
 */
      goto __pyx_L6;
    }

    /* "plastid/genomics/roitools.pyx":447
 *         else:
 *             # if cds starts at beginning of transcript, both need to grow by three
 *             if span.start == start:             # <<<<<<<<<<<<<<
 *                 new_start = start - 3
 *                 old_seg = segments[0]
 */
    /*else*/ {
      __pyx_t_1 = ((__pyx_v_span->start == __pyx_v_start) != 0);
      if (__pyx_t_1) {

        /* "plastid/genomics/roitools.pyx":448
 *             # if cds starts at beginning of transcript, both need to grow by three
 *             if span.start == start:
 *                 new_start = start - 3             # <<<<<<<<<<<<<<
 *                 old_seg = segments[0]
 *                 new_seg = GenomicSegment(chrom, new_start, old_seg.end, span.strand)
 */
        __pyx_v_new_start = (__pyx_v_start - 3);

        /* "plastid/genomics/roitools.pyx":449
 *             if span.start == start:
 *                 new_start = start - 3
 *                 old_seg = segments[0]             # <<<<<<<<<<<<<<
 *                 new_seg = GenomicSegment(chrom, new_start, old_seg.end, span.strand)
 *                 segments[0] = new_seg
 */
        if (unlikely(__pyx_v_segments == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 449, __pyx_L1_error)
        }
        __pyx_t_6 = __Pyx_GetItemInt_List(__pyx_v_segments, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 449, __pyx_L1_error)
        __pyx_v_old_seg = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_6);
        __pyx_t_6 = 0;

        /* "plastid/genomics/roitools.pyx":450
 *                 new_start = start - 3
 *                 old_seg = segments[0]
 *                 new_seg = GenomicSegment(chrom, new_start, old_seg.end, span.strand)             # <<<<<<<<<<<<<<
 *                 segments[0] = new_seg
 *             else:
 */
        __pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_new_start); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = __Pyx_PyInt_From_long(__pyx_v_old_seg->end); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_span), __pyx_n_s_strand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_8 = PyTuple_New(4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_v_chrom);
        __Pyx_GIVEREF(__pyx_v_chrom);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_chrom);
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_5);
        __pyx_t_6 = 0;
        __pyx_t_7 = 0;
        __pyx_t_5 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_v_new_seg = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_5);
        __pyx_t_5 = 0;

        /* "plastid/genomics/roitools.pyx":451
 *                 old_seg = segments[0]
 *                 new_seg = GenomicSegment(chrom, new_start, old_seg.end, span.strand)
 *                 segments[0] = new_seg             # <<<<<<<<<<<<<<
 *             else:
 *                 # otherwise, fetch
 */
        if (unlikely(__pyx_v_segments == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 451, __pyx_L1_error)
        }
        if (unlikely(__Pyx_SetItemInt(__pyx_v_segments, 0, ((PyObject *)__pyx_v_new_seg), long, 1, __Pyx_PyInt_From_long, 1, 0, 1) < 0)) __PYX_ERR(0, 451, __pyx_L1_error)

        /* "plastid/genomics/roitools.pyx":447
 *         else:
 *             # if cds starts at beginning of transcript, both need to grow by three
 *             if span.start == start:             # <<<<<<<<<<<<<<
 *                 new_start = start - 3
 *                 old_seg = segments[0]
 */
        goto __pyx_L12;
      }

      /* "plastid/genomics/roitools.pyx":456
 *                 # minus one here might look funny, but is due to minus-strand
 *                 # feature-ness
 *                 new_start = tx.c_get_genomic_coordinate(tx.cds_end + 3 - 1, True)             # <<<<<<<<<<<<<<
 * 
 *         # since `segments` come from an existing transcript, we know they
 */
      /*else*/ {
        __pyx_t_5 = __Pyx_PyInt_AddObjC(__pyx_v_tx->cds_end, __pyx_int_3, 3, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 456, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_8 = __Pyx_PyInt_SubtractObjC(__pyx_t_5, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 456, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_9 = __Pyx_PyInt_As_long(__pyx_t_8); if (unlikely((__pyx_t_9 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 456, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_tx->__pyx_base.__pyx_vtab)->__pyx_base.c_get_genomic_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_tx), __pyx_t_9, 1); if (unlikely(__pyx_t_4 == ((long)-1L))) __PYX_ERR(0, 456, __pyx_L1_error)
        __pyx_v_new_start = __pyx_t_4;
      }
      __pyx_L12:;
    }
    __pyx_L6:;

    /* "plastid/genomics/roitools.pyx":461
 *         # non-overlapping. So, we can bypass checks in __cinit__ and go through
 *         # faster set_segments()
 *         new_tx = Transcript()             # <<<<<<<<<<<<<<
 *         new_tx._set_segments(segments)
 *         new_tx.attr = attr
 */
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 461, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_v_new_tx = ((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_t_8);
    __pyx_t_8 = 0;

    /* "plastid/genomics/roitools.pyx":462
 *         # faster set_segments()
 *         new_tx = Transcript()
 *         new_tx._set_segments(segments)             # <<<<<<<<<<<<<<
 *         new_tx.attr = attr
 *         new_tx.cds_genome_start = new_start
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_new_tx->__pyx_base.__pyx_vtab)->__pyx_base._set_segments(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_new_tx), __pyx_v_segments); if (unlikely(__pyx_t_1 == ((int)0))) __PYX_ERR(0, 462, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":463
 *         new_tx = Transcript()
 *         new_tx._set_segments(segments)
 *         new_tx.attr = attr             # <<<<<<<<<<<<<<
 *         new_tx.cds_genome_start = new_start
 *         new_tx.cds_genome_end = new_end
 */
    __Pyx_INCREF(__pyx_v_attr);
    __Pyx_GIVEREF(__pyx_v_attr);
    __Pyx_GOTREF(__pyx_v_new_tx->__pyx_base.attr);
    __Pyx_DECREF(__pyx_v_new_tx->__pyx_base.attr);
    __pyx_v_new_tx->__pyx_base.attr = __pyx_v_attr;

    /* "plastid/genomics/roitools.pyx":464
 *         new_tx._set_segments(segments)
 *         new_tx.attr = attr
 *         new_tx.cds_genome_start = new_start             # <<<<<<<<<<<<<<
 *         new_tx.cds_genome_end = new_end
 *         new_tx._update_cds()
 */
    __pyx_t_8 = __Pyx_PyInt_From_long(__pyx_v_new_start); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 464, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_new_tx->cds_genome_start);
    __Pyx_DECREF(__pyx_v_new_tx->cds_genome_start);
    __pyx_v_new_tx->cds_genome_start = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "plastid/genomics/roitools.pyx":465
 *         new_tx.attr = attr
 *         new_tx.cds_genome_start = new_start
 *         new_tx.cds_genome_end = new_end             # <<<<<<<<<<<<<<
 *         new_tx._update_cds()
 *         return new_tx
 */
    __pyx_t_8 = __Pyx_PyInt_From_long(__pyx_v_new_end); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_new_tx->cds_genome_end);
    __Pyx_DECREF(__pyx_v_new_tx->cds_genome_end);
    __pyx_v_new_tx->cds_genome_end = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "plastid/genomics/roitools.pyx":466
 *         new_tx.cds_genome_start = new_start
 *         new_tx.cds_genome_end = new_end
 *         new_tx._update_cds()             # <<<<<<<<<<<<<<
 *         return new_tx
 *     else:
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_new_tx->__pyx_base.__pyx_vtab)->_update_cds(__pyx_v_new_tx); if (unlikely(__pyx_t_1 == ((int)0))) __PYX_ERR(0, 466, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":467
 *         new_tx.cds_genome_end = new_end
 *         new_tx._update_cds()
 *         return new_tx             # <<<<<<<<<<<<<<
 *     else:
 *         return tx
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_new_tx));
    __pyx_r = __pyx_v_new_tx;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":416
 *         Transcript new_tx
 * 
 *     if tx.cds_genome_end is not None and tx.cds_genome_start is not None:             # <<<<<<<<<<<<<<
 *         new_start = start = <long>tx.cds_genome_start
 *         new_end = end = <long>tx.cds_genome_end
 */
  }

  /* "plastid/genomics/roitools.pyx":469
 *         return new_tx
 *     else:
 *         return tx             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_tx));
    __pyx_r = __pyx_v_tx;
    goto __pyx_L0;
  }

  /* "plastid/genomics/roitools.pyx":385
 * 
 * 
 * cpdef Transcript add_three_for_stop_codon(Transcript tx):             # <<<<<<<<<<<<<<
 *     """Extend an annotated CDS region, if present, by three nucleotides
 *     at the threeprime end. Use in cases when annotation files exclude the stop
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("plastid.genomics.roitools.add_three_for_stop_codon", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_span);
  __Pyx_XDECREF((PyObject *)__pyx_v_new_seg);
  __Pyx_XDECREF((PyObject *)__pyx_v_old_seg);
  __Pyx_XDECREF(__pyx_v_segments);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF((PyObject *)__pyx_v_new_tx);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_segment);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_13add_three_for_stop_codon(PyObject *__pyx_self, PyObject *__pyx_v_tx); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12add_three_for_stop_codon[] = "add_three_for_stop_codon(Transcript tx) -> Transcript\nExtend an annotated CDS region, if present, by three nucleotides\n    at the threeprime end. Use in cases when annotation files exclude the stop\n    codon from the annotated CDS.\n\n    Parameters\n    ----------\n    tx : |Transcript|\n        query transcript\n\n    Returns\n    -------\n    |Transcript|\n        |Transcript| with same attributes as `tx`, but with CDS extended by one\n        codon\n\n    Raises\n    ------\n    IndexError\n        if a three prime UTR is defined that terminates before the complete\n        stop codon\n    ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_13add_three_for_stop_codon(PyObject *__pyx_self, PyObject *__pyx_v_tx) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("add_three_for_stop_codon (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tx), __pyx_ptype_7plastid_8genomics_8roitools_Transcript, 1, "tx", 0))) __PYX_ERR(0, 385, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12add_three_for_stop_codon(__pyx_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_tx));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12add_three_for_stop_codon(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_tx) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add_three_for_stop_codon", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_f_7plastid_8genomics_8roitools_add_three_for_stop_codon(__pyx_v_tx, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "plastid/genomics/roitools.pyx":478
 * 
 * 
 * cdef dict get_attr_from_bed_column_tuples(list items, int num_bed_columns, int total_columns, list column_tuples):             # <<<<<<<<<<<<<<
 *     """Get SegmentChain attributes from a `BED`_ line with extra columns
 *     specified as a list of (column_name,formatter_func)
 */

static PyObject *__pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed_column_tuples(PyObject *__pyx_v_items, int __pyx_v_num_bed_columns, int __pyx_v_total_columns, PyObject *__pyx_v_column_tuples) {
  PyObject *__pyx_v_attr = 0;
  int __pyx_v_i;
  PyObject *__pyx_v_xorder = 0;
  PyObject *__pyx_v_name = NULL;
  PyObject *__pyx_v_formatter = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  Py_ssize_t __pyx_t_16;
  Py_UCS4 __pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_attr_from_bed_column_tuples", 0);

  /* "plastid/genomics/roitools.pyx":483
 *     """
 *     cdef:
 *         dict attr   = get_standard_bed_attr(items, num_bed_columns)             # <<<<<<<<<<<<<<
 *         int  i
 *         list xorder = []
 */
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_get_standard_bed_attr(__pyx_v_items, __pyx_v_num_bed_columns); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":485
 *         dict attr   = get_standard_bed_attr(items, num_bed_columns)
 *         int  i
 *         list xorder = []             # <<<<<<<<<<<<<<
 * 
 *     for i in range(num_bed_columns,total_columns):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_xorder = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":487
 *         list xorder = []
 * 
 *     for i in range(num_bed_columns,total_columns):             # <<<<<<<<<<<<<<
 *         name, formatter = column_tuples[i - num_bed_columns]
 *         xorder.append(name)
 */
  __pyx_t_2 = __pyx_v_total_columns;
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = __pyx_v_num_bed_columns; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;

    /* "plastid/genomics/roitools.pyx":488
 * 
 *     for i in range(num_bed_columns,total_columns):
 *         name, formatter = column_tuples[i - num_bed_columns]             # <<<<<<<<<<<<<<
 *         xorder.append(name)
 *         try:
 */
    if (unlikely(__pyx_v_column_tuples == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 488, __pyx_L1_error)
    }
    __pyx_t_5 = (__pyx_v_i - __pyx_v_num_bed_columns);
    __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_column_tuples, __pyx_t_5, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 488, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
      PyObject* sequence = __pyx_t_1;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 488, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_7);
      #else
      __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 488, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 488, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 488, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
      index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_6);
      index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_7);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) __PYX_ERR(0, 488, __pyx_L1_error)
      __pyx_t_9 = NULL;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      goto __pyx_L6_unpacking_done;
      __pyx_L5_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_9 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 488, __pyx_L1_error)
      __pyx_L6_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_XDECREF_SET(__pyx_v_formatter, __pyx_t_7);
    __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":489
 *     for i in range(num_bed_columns,total_columns):
 *         name, formatter = column_tuples[i - num_bed_columns]
 *         xorder.append(name)             # <<<<<<<<<<<<<<
 *         try:
 *             attr[name] = formatter(items[i])
 */
    __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_xorder, __pyx_v_name); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 489, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":490
 *         name, formatter = column_tuples[i - num_bed_columns]
 *         xorder.append(name)
 *         try:             # <<<<<<<<<<<<<<
 *             attr[name] = formatter(items[i])
 *         except:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
      __Pyx_XGOTREF(__pyx_t_11);
      __Pyx_XGOTREF(__pyx_t_12);
      __Pyx_XGOTREF(__pyx_t_13);
      /*try:*/ {

        /* "plastid/genomics/roitools.pyx":491
 *         xorder.append(name)
 *         try:
 *             attr[name] = formatter(items[i])             # <<<<<<<<<<<<<<
 *         except:
 *             warn("SegmentChain.from_bed(): Could not format '%s' as '%s'. Defaulting to type 'str'." % (items[i], str(formatter.__name__)), DataWarning)
 */
        if (unlikely(__pyx_v_items == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 491, __pyx_L7_error)
        }
        __pyx_t_7 = __Pyx_GetItemInt_List(__pyx_v_items, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 491, __pyx_L7_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_v_formatter);
        __pyx_t_6 = __pyx_v_formatter; __pyx_t_8 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
          }
        }
        __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7);
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 491, __pyx_L7_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(__pyx_v_attr == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 491, __pyx_L7_error)
        }
        if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_v_name, __pyx_t_1) < 0)) __PYX_ERR(0, 491, __pyx_L7_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "plastid/genomics/roitools.pyx":490
 *         name, formatter = column_tuples[i - num_bed_columns]
 *         xorder.append(name)
 *         try:             # <<<<<<<<<<<<<<
 *             attr[name] = formatter(items[i])
 *         except:
 */
      }
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      goto __pyx_L14_try_end;
      __pyx_L7_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "plastid/genomics/roitools.pyx":492
 *         try:
 *             attr[name] = formatter(items[i])
 *         except:             # <<<<<<<<<<<<<<
 *             warn("SegmentChain.from_bed(): Could not format '%s' as '%s'. Defaulting to type 'str'." % (items[i], str(formatter.__name__)), DataWarning)
 *             attr[name] = items[i]
 */
      /*except:*/ {
        __Pyx_AddTraceback("plastid.genomics.roitools.get_attr_from_bed_column_tuples", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 492, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_GOTREF(__pyx_t_7);

        /* "plastid/genomics/roitools.pyx":493
 *             attr[name] = formatter(items[i])
 *         except:
 *             warn("SegmentChain.from_bed(): Could not format '%s' as '%s'. Defaulting to type 'str'." % (items[i], str(formatter.__name__)), DataWarning)             # <<<<<<<<<<<<<<
 *             attr[name] = items[i]
 * 
 */
        __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_warn); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 493, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_15 = PyTuple_New(5); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 493, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_15);
        __pyx_t_16 = 0;
        __pyx_t_17 = 127;
        __Pyx_INCREF(__pyx_kp_u_SegmentChain_from_bed_Could_not);
        __pyx_t_16 += 43;
        __Pyx_GIVEREF(__pyx_kp_u_SegmentChain_from_bed_Could_not);
        PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_kp_u_SegmentChain_from_bed_Could_not);
        if (unlikely(__pyx_v_items == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 493, __pyx_L9_except_error)
        }
        __pyx_t_18 = __Pyx_GetItemInt_List(__pyx_v_items, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 493, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_18);
        __pyx_t_19 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_18), __pyx_empty_unicode); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 493, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_19);
        __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
        __pyx_t_17 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_19) > __pyx_t_17) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_19) : __pyx_t_17;
        __pyx_t_16 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_19);
        __Pyx_GIVEREF(__pyx_t_19);
        PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_19);
        __pyx_t_19 = 0;
        __Pyx_INCREF(__pyx_kp_u_as);
        __pyx_t_16 += 6;
        __Pyx_GIVEREF(__pyx_kp_u_as);
        PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_kp_u_as);
        __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_v_formatter, __pyx_n_s_name); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 493, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_19);
        __pyx_t_18 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_19); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 493, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_18);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        __pyx_t_17 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_18) > __pyx_t_17) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_18) : __pyx_t_17;
        __pyx_t_16 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_18);
        __Pyx_GIVEREF(__pyx_t_18);
        PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_18);
        __pyx_t_18 = 0;
        __Pyx_INCREF(__pyx_kp_u_Defaulting_to_type_str);
        __pyx_t_16 += 28;
        __Pyx_GIVEREF(__pyx_kp_u_Defaulting_to_type_str);
        PyTuple_SET_ITEM(__pyx_t_15, 4, __pyx_kp_u_Defaulting_to_type_str);
        __pyx_t_18 = __Pyx_PyUnicode_Join(__pyx_t_15, 5, __pyx_t_16, __pyx_t_17); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 493, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_18);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_DataWarning); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 493, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_15);
        __pyx_t_19 = NULL;
        __pyx_t_5 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) {
          __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_14);
          if (likely(__pyx_t_19)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
            __Pyx_INCREF(__pyx_t_19);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_14, function);
            __pyx_t_5 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_14)) {
          PyObject *__pyx_temp[3] = {__pyx_t_19, __pyx_t_18, __pyx_t_15};
          __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 493, __pyx_L9_except_error)
          __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) {
          PyObject *__pyx_temp[3] = {__pyx_t_19, __pyx_t_18, __pyx_t_15};
          __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 493, __pyx_L9_except_error)
          __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        } else
        #endif
        {
          __pyx_t_20 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 493, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_20);
          if (__pyx_t_19) {
            __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_19); __pyx_t_19 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_18);
          PyTuple_SET_ITEM(__pyx_t_20, 0+__pyx_t_5, __pyx_t_18);
          __Pyx_GIVEREF(__pyx_t_15);
          PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_5, __pyx_t_15);
          __pyx_t_18 = 0;
          __pyx_t_15 = 0;
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_20, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 493, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        }
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

        /* "plastid/genomics/roitools.pyx":494
 *         except:
 *             warn("SegmentChain.from_bed(): Could not format '%s' as '%s'. Defaulting to type 'str'." % (items[i], str(formatter.__name__)), DataWarning)
 *             attr[name] = items[i]             # <<<<<<<<<<<<<<
 * 
 *     attr["_bedx_column_order"] = xorder
 */
        if (unlikely(__pyx_v_items == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 494, __pyx_L9_except_error)
        }
        __pyx_t_8 = __Pyx_GetItemInt_List(__pyx_v_items, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 494, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_8);
        if (unlikely(__pyx_v_attr == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 494, __pyx_L9_except_error)
        }
        if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_v_name, __pyx_t_8) < 0)) __PYX_ERR(0, 494, __pyx_L9_except_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L8_exception_handled;
      }
      __pyx_L9_except_error:;

      /* "plastid/genomics/roitools.pyx":490
 *         name, formatter = column_tuples[i - num_bed_columns]
 *         xorder.append(name)
 *         try:             # <<<<<<<<<<<<<<
 *             attr[name] = formatter(items[i])
 *         except:
 */
      __Pyx_XGIVEREF(__pyx_t_11);
      __Pyx_XGIVEREF(__pyx_t_12);
      __Pyx_XGIVEREF(__pyx_t_13);
      __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
      goto __pyx_L1_error;
      __pyx_L8_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_11);
      __Pyx_XGIVEREF(__pyx_t_12);
      __Pyx_XGIVEREF(__pyx_t_13);
      __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
      __pyx_L14_try_end:;
    }
  }

  /* "plastid/genomics/roitools.pyx":496
 *             attr[name] = items[i]
 * 
 *     attr["_bedx_column_order"] = xorder             # <<<<<<<<<<<<<<
 *     return attr
 * 
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 496, __pyx_L1_error)
  }
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_bedx_column_order, __pyx_v_xorder) < 0)) __PYX_ERR(0, 496, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":497
 * 
 *     attr["_bedx_column_order"] = xorder
 *     return attr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_attr);
  __pyx_r = __pyx_v_attr;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":478
 * 
 * 
 * cdef dict get_attr_from_bed_column_tuples(list items, int num_bed_columns, int total_columns, list column_tuples):             # <<<<<<<<<<<<<<
 *     """Get SegmentChain attributes from a `BED`_ line with extra columns
 *     specified as a list of (column_name,formatter_func)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_AddTraceback("plastid.genomics.roitools.get_attr_from_bed_column_tuples", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_v_xorder);
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XDECREF(__pyx_v_formatter);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":500
 * 
 * 
 * cdef dict get_attr_from_bed_column_names(list items, int num_bed_columns, list column_names):             # <<<<<<<<<<<<<<
 *     """Get SegmentChain attributes from a `BED`_ line with extra column names
 *     given by a list of column names
 */

static PyObject *__pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed_column_names(PyObject *__pyx_v_items, int __pyx_v_num_bed_columns, PyObject *__pyx_v_column_names) {
  PyObject *__pyx_v_attr = 0;
  int __pyx_v_n;
  PyObject *__pyx_v_name = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_attr_from_bed_column_names", 0);

  /* "plastid/genomics/roitools.pyx":505
 *     """
 *     cdef:
 *         dict attr   = get_standard_bed_attr(items, num_bed_columns)             # <<<<<<<<<<<<<<
 *         int  n
 *         str  name
 */
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_get_standard_bed_attr(__pyx_v_items, __pyx_v_num_bed_columns); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":509
 *         str  name
 * 
 *     for n, name in enumerate(column_names):             # <<<<<<<<<<<<<<
 *         attr[name] = items[n + num_bed_columns]
 * 
 */
  __pyx_t_2 = 0;
  __pyx_t_1 = __pyx_v_column_names; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
  for (;;) {
    if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 509, __pyx_L1_error)
    #else
    __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 509, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    if (!(likely(PyUnicode_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 509, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_name, ((PyObject*)__pyx_t_4));
    __pyx_t_4 = 0;
    __pyx_v_n = __pyx_t_2;
    __pyx_t_2 = (__pyx_t_2 + 1);

    /* "plastid/genomics/roitools.pyx":510
 * 
 *     for n, name in enumerate(column_names):
 *         attr[name] = items[n + num_bed_columns]             # <<<<<<<<<<<<<<
 * 
 *     attr["_bedx_column_order"] = column_names
 */
    if (unlikely(__pyx_v_items == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 510, __pyx_L1_error)
    }
    __pyx_t_5 = (__pyx_v_n + __pyx_v_num_bed_columns);
    __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_v_items, __pyx_t_5, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (unlikely(__pyx_v_attr == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 510, __pyx_L1_error)
    }
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_v_name, __pyx_t_4) < 0)) __PYX_ERR(0, 510, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":509
 *         str  name
 * 
 *     for n, name in enumerate(column_names):             # <<<<<<<<<<<<<<
 *         attr[name] = items[n + num_bed_columns]
 * 
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":512
 *         attr[name] = items[n + num_bed_columns]
 * 
 *     attr["_bedx_column_order"] = column_names             # <<<<<<<<<<<<<<
 *     return attr
 * 
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 512, __pyx_L1_error)
  }
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_bedx_column_order, __pyx_v_column_names) < 0)) __PYX_ERR(0, 512, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":513
 * 
 *     attr["_bedx_column_order"] = column_names
 *     return attr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_attr);
  __pyx_r = __pyx_v_attr;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":500
 * 
 * 
 * cdef dict get_attr_from_bed_column_names(list items, int num_bed_columns, list column_names):             # <<<<<<<<<<<<<<
 *     """Get SegmentChain attributes from a `BED`_ line with extra column names
 *     given by a list of column names
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("plastid.genomics.roitools.get_attr_from_bed_column_names", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":516
 * 
 * 
 * cdef dict get_attr_from_bed_column_number(list items, int num_bed_columns, int num_extra_columns):             # <<<<<<<<<<<<<<
 *     """Get SegmentChain attributes from a `BED`_ line, given a number of extra
 *     columns
 */

static PyObject *__pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed_column_number(PyObject *__pyx_v_items, int __pyx_v_num_bed_columns, int __pyx_v_num_extra_columns) {
  PyObject *__pyx_v_attr = 0;
  int __pyx_v_i;
  PyObject *__pyx_v_name = 0;
  PyObject *__pyx_v_xorder = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_attr_from_bed_column_number", 0);

  /* "plastid/genomics/roitools.pyx":521
 *     """
 *     cdef:
 *         dict attr   = get_standard_bed_attr(items, num_bed_columns)             # <<<<<<<<<<<<<<
 *         int  i
 *         str  name
 */
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_get_standard_bed_attr(__pyx_v_items, __pyx_v_num_bed_columns); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 521, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":524
 *         int  i
 *         str  name
 *         list xorder = []             # <<<<<<<<<<<<<<
 * 
 *     for i in range(num_extra_columns):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 524, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_xorder = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":526
 *         list xorder = []
 * 
 *     for i in range(num_extra_columns):             # <<<<<<<<<<<<<<
 *         name = "custom%s" % i
 *         attr[name] = items[i + num_bed_columns]
 */
  __pyx_t_2 = __pyx_v_num_extra_columns;
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;

    /* "plastid/genomics/roitools.pyx":527
 * 
 *     for i in range(num_extra_columns):
 *         name = "custom%s" % i             # <<<<<<<<<<<<<<
 *         attr[name] = items[i + num_bed_columns]
 *         xorder.append(name)
 */
    __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 527, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyUnicode_Format(__pyx_kp_u_custom_s, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 527, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_name, ((PyObject*)__pyx_t_5));
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":528
 *     for i in range(num_extra_columns):
 *         name = "custom%s" % i
 *         attr[name] = items[i + num_bed_columns]             # <<<<<<<<<<<<<<
 *         xorder.append(name)
 * 
 */
    if (unlikely(__pyx_v_items == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 528, __pyx_L1_error)
    }
    __pyx_t_6 = (__pyx_v_i + __pyx_v_num_bed_columns);
    __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_items, __pyx_t_6, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 528, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(__pyx_v_attr == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 528, __pyx_L1_error)
    }
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_v_name, __pyx_t_5) < 0)) __PYX_ERR(0, 528, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":529
 *         name = "custom%s" % i
 *         attr[name] = items[i + num_bed_columns]
 *         xorder.append(name)             # <<<<<<<<<<<<<<
 * 
 *     attr["_bedx_column_order"] = xorder
 */
    __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_xorder, __pyx_v_name); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 529, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":531
 *         xorder.append(name)
 * 
 *     attr["_bedx_column_order"] = xorder             # <<<<<<<<<<<<<<
 *     return attr
 * 
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 531, __pyx_L1_error)
  }
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_bedx_column_order, __pyx_v_xorder) < 0)) __PYX_ERR(0, 531, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":532
 * 
 *     attr["_bedx_column_order"] = xorder
 *     return attr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_attr);
  __pyx_r = __pyx_v_attr;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":516
 * 
 * 
 * cdef dict get_attr_from_bed_column_number(list items, int num_bed_columns, int num_extra_columns):             # <<<<<<<<<<<<<<
 *     """Get SegmentChain attributes from a `BED`_ line, given a number of extra
 *     columns
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.get_attr_from_bed_column_number", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XDECREF(__pyx_v_xorder);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":535
 * 
 * 
 * cdef dict get_standard_bed_attr(list items, int num_bed_columns):             # <<<<<<<<<<<<<<
 *     """Get SegmentChain attributes from standard BED columns in `BED`_ line"""
 *     cdef:
 */

static PyObject *__pyx_f_7plastid_8genomics_8roitools_get_standard_bed_attr(PyObject *__pyx_v_items, int __pyx_v_num_bed_columns) {
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_strand = 0;
  PyObject *__pyx_v_default_id = 0;
  long __pyx_v_chrom_start;
  long __pyx_v_thickstart;
  long __pyx_v_thickend;
  PyObject *__pyx_v_tup = 0;
  int __pyx_v_i;
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_v__default_bed_columns = 0;
  PyObject *__pyx_v_chrom_end = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_v_default = NULL;
  PyObject *__pyx_v_func = NULL;
  PyObject *__pyx_7genexpr__pyx_v_KEY = NULL;
  PyObject *__pyx_7genexpr__pyx_v_DEFAULT = NULL;
  CYTHON_UNUSED PyObject *__pyx_7genexpr__pyx_v__ = NULL;
  PyObject *__pyx_8genexpr1__pyx_v_X = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  Py_UCS4 __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  Py_ssize_t __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  PyObject *(*__pyx_t_22)(PyObject *);
  int __pyx_t_23;
  int __pyx_t_24;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_standard_bed_attr", 0);

  /* "plastid/genomics/roitools.pyx":546
 *         dict    attr, _default_bed_columns
 * 
 *     if num_bed_columns < 3:             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "BED format requires at least 3 columns. Found only %s.\n\t    %s"
 */
  __pyx_t_1 = ((__pyx_v_num_bed_columns < 3) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "plastid/genomics/roitools.pyx":548
 *     if num_bed_columns < 3:
 *         raise ValueError(
 *             "BED format requires at least 3 columns. Found only %s.\n\t    %s"             # <<<<<<<<<<<<<<
 *             % (num_bed_columns, items)
 *         )
 */
    __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 548, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = 0;
    __pyx_t_4 = 127;
    __Pyx_INCREF(__pyx_kp_u_BED_format_requires_at_least_3_c);
    __pyx_t_3 += 51;
    __Pyx_GIVEREF(__pyx_kp_u_BED_format_requires_at_least_3_c);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_BED_format_requires_at_least_3_c);

    /* "plastid/genomics/roitools.pyx":549
 *         raise ValueError(
 *             "BED format requires at least 3 columns. Found only %s.\n\t    %s"
 *             % (num_bed_columns, items)             # <<<<<<<<<<<<<<
 *         )
 * 
 */
    __pyx_t_5 = __Pyx_PyUnicode_From_int(__pyx_v_num_bed_columns, 0, ' ', 'd'); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u__10);
    __pyx_t_3 += 7;
    __Pyx_GIVEREF(__pyx_kp_u__10);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u__10);
    __pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_items), __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_4;
    __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":548
 *     if num_bed_columns < 3:
 *         raise ValueError(
 *             "BED format requires at least 3 columns. Found only %s.\n\t    %s"             # <<<<<<<<<<<<<<
 *             % (num_bed_columns, items)
 *         )
 */
    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_2, 4, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 548, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "plastid/genomics/roitools.pyx":547
 * 
 *     if num_bed_columns < 3:
 *         raise ValueError(             # <<<<<<<<<<<<<<
 *             "BED format requires at least 3 columns. Found only %s.\n\t    %s"
 *             % (num_bed_columns, items)
 */
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 547, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 547, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":546
 *         dict    attr, _default_bed_columns
 * 
 *     if num_bed_columns < 3:             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "BED format requires at least 3 columns. Found only %s.\n\t    %s"
 */
  }

  /* "plastid/genomics/roitools.pyx":552
 *         )
 * 
 *     chrom         = items[0]             # <<<<<<<<<<<<<<
 *     strand        = "." if num_bed_columns < 6 else items[5]
 *     chrom_start   = long(items[1])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 552, __pyx_L1_error)
  }
  __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_items, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 552, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 552, __pyx_L1_error)
  __pyx_v_chrom = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":553
 * 
 *     chrom         = items[0]
 *     strand        = "." if num_bed_columns < 6 else items[5]             # <<<<<<<<<<<<<<
 *     chrom_start   = long(items[1])
 *     chrom_end     = long(items[2])
 */
  if (((__pyx_v_num_bed_columns < 6) != 0)) {
    __Pyx_INCREF(__pyx_kp_u__11);
    __pyx_t_2 = __pyx_kp_u__11;
  } else {
    if (unlikely(__pyx_v_items == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 553, __pyx_L1_error)
    }
    __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_items, 5, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 553, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (!(likely(PyUnicode_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 553, __pyx_L1_error)
    __pyx_t_2 = __pyx_t_5;
    __pyx_t_5 = 0;
  }
  __pyx_v_strand = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":554
 *     chrom         = items[0]
 *     strand        = "." if num_bed_columns < 6 else items[5]
 *     chrom_start   = long(items[1])             # <<<<<<<<<<<<<<
 *     chrom_end     = long(items[2])
 * 
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 554, __pyx_L1_error)
  }
  __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_items, 1, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 554, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 554, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyInt_As_long(__pyx_t_5); if (unlikely((__pyx_t_6 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 554, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_chrom_start = __pyx_t_6;

  /* "plastid/genomics/roitools.pyx":555
 *     strand        = "." if num_bed_columns < 6 else items[5]
 *     chrom_start   = long(items[1])
 *     chrom_end     = long(items[2])             # <<<<<<<<<<<<<<
 * 
 *     default_id  = "%s:%s-%s(%s)" % (chrom, chrom_start, chrom_end, strand)
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 555, __pyx_L1_error)
  }
  __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_items, 2, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 555, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 555, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_chrom_end = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":557
 *     chrom_end     = long(items[2])
 * 
 *     default_id  = "%s:%s-%s(%s)" % (chrom, chrom_start, chrom_end, strand)             # <<<<<<<<<<<<<<
 * 
 *     _default_bed_columns = {
 */
  __pyx_t_2 = PyTuple_New(8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = 0;
  __pyx_t_4 = 127;
  __pyx_t_5 = __Pyx_PyUnicode_Unicode(__pyx_v_chrom); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_4;
  __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __Pyx_INCREF(__pyx_kp_u__12);
  __pyx_t_3 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__12);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_kp_u__12);
  __pyx_t_5 = __Pyx_PyUnicode_From_long(__pyx_v_chrom_start, 0, ' ', 'd'); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5);
  __pyx_t_5 = 0;
  __Pyx_INCREF(__pyx_kp_u__13);
  __pyx_t_3 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__13);
  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_kp_u__13);
  __pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_chrom_end), __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_4;
  __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_t_5);
  __pyx_t_5 = 0;
  __Pyx_INCREF(__pyx_kp_u__14);
  __pyx_t_3 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__14);
  PyTuple_SET_ITEM(__pyx_t_2, 5, __pyx_kp_u__14);
  __pyx_t_5 = __Pyx_PyUnicode_Unicode(__pyx_v_strand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_4;
  __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 6, __pyx_t_5);
  __pyx_t_5 = 0;
  __Pyx_INCREF(__pyx_kp_u__15);
  __pyx_t_3 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__15);
  PyTuple_SET_ITEM(__pyx_t_2, 7, __pyx_kp_u__15);
  __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_2, 8, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_default_id = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "plastid/genomics/roitools.pyx":560
 * 
 *     _default_bed_columns = {
 *         3 :  ("ID",         default_id,                  str),             # <<<<<<<<<<<<<<
 *         4 :  ("score",      numpy.nan,                   float),
 *         #5 :  ("strand",    ".", strand),
 */
  __pyx_t_5 = __Pyx_PyDict_NewPresized(8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_u_ID_2);
  __Pyx_GIVEREF(__pyx_n_u_ID_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_ID_2);
  __Pyx_INCREF(__pyx_v_default_id);
  __Pyx_GIVEREF(__pyx_v_default_id);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_default_id);
  __Pyx_INCREF(((PyObject *)(&PyUnicode_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyUnicode_Type)));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)(&PyUnicode_Type)));
  if (PyDict_SetItem(__pyx_t_5, __pyx_int_3, __pyx_t_2) < 0) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":561
 *     _default_bed_columns = {
 *         3 :  ("ID",         default_id,                  str),
 *         4 :  ("score",      numpy.nan,                   float),             # <<<<<<<<<<<<<<
 *         #5 :  ("strand",    ".", strand),
 *         6 :  ("thickstart", -1,                          long),
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_nan); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_u_score);
  __Pyx_GIVEREF(__pyx_n_u_score);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_score);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7);
  __Pyx_INCREF(((PyObject *)(&PyFloat_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyFloat_Type)));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)(&PyFloat_Type)));
  __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_int_4, __pyx_t_2) < 0) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":563
 *         4 :  ("score",      numpy.nan,                   float),
 *         #5 :  ("strand",    ".", strand),
 *         6 :  ("thickstart", -1,                          long),             # <<<<<<<<<<<<<<
 *         7 :  ("thickend",   -1,                          long),
 *         8 :  ("color",      "0,0,0",                     str),
 */
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 563, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_u_thickstart);
  __Pyx_GIVEREF(__pyx_n_u_thickstart);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_thickstart);
  __Pyx_INCREF(__pyx_int_neg_1);
  __Pyx_GIVEREF(__pyx_int_neg_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_neg_1);
  __Pyx_INCREF(((PyObject *)(&PyLong_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyLong_Type)));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)(&PyLong_Type)));
  if (PyDict_SetItem(__pyx_t_5, __pyx_int_6, __pyx_t_2) < 0) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":564
 *         #5 :  ("strand",    ".", strand),
 *         6 :  ("thickstart", -1,                          long),
 *         7 :  ("thickend",   -1,                          long),             # <<<<<<<<<<<<<<
 *         8 :  ("color",      "0,0,0",                     str),
 *         9 :  ("blocks",     "1",                         int),
 */
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_u_thickend);
  __Pyx_GIVEREF(__pyx_n_u_thickend);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_thickend);
  __Pyx_INCREF(__pyx_int_neg_1);
  __Pyx_GIVEREF(__pyx_int_neg_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_neg_1);
  __Pyx_INCREF(((PyObject *)(&PyLong_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyLong_Type)));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)(&PyLong_Type)));
  if (PyDict_SetItem(__pyx_t_5, __pyx_int_7, __pyx_t_2) < 0) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":565
 *         6 :  ("thickstart", -1,                          long),
 *         7 :  ("thickend",   -1,                          long),
 *         8 :  ("color",      "0,0,0",                     str),             # <<<<<<<<<<<<<<
 *         9 :  ("blocks",     "1",                         int),
 *         10 : ("blocksizes", str(chrom_end - chrom_start),str),
 */
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 565, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_u_color);
  __Pyx_GIVEREF(__pyx_n_u_color);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_color);
  __Pyx_INCREF(__pyx_kp_u_0_0_0);
  __Pyx_GIVEREF(__pyx_kp_u_0_0_0);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_kp_u_0_0_0);
  __Pyx_INCREF(((PyObject *)(&PyUnicode_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyUnicode_Type)));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)(&PyUnicode_Type)));
  if (PyDict_SetItem(__pyx_t_5, __pyx_int_8, __pyx_t_2) < 0) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":566
 *         7 :  ("thickend",   -1,                          long),
 *         8 :  ("color",      "0,0,0",                     str),
 *         9 :  ("blocks",     "1",                         int),             # <<<<<<<<<<<<<<
 *         10 : ("blocksizes", str(chrom_end - chrom_start),str),
 *         11 : ("blockstarts","0",                         str),
 */
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 566, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_u_blocks);
  __Pyx_GIVEREF(__pyx_n_u_blocks);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_blocks);
  __Pyx_INCREF(__pyx_kp_u_1);
  __Pyx_GIVEREF(__pyx_kp_u_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_kp_u_1);
  __Pyx_INCREF(((PyObject *)(&PyInt_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyInt_Type)));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)(&PyInt_Type)));
  if (PyDict_SetItem(__pyx_t_5, __pyx_int_9, __pyx_t_2) < 0) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":567
 *         8 :  ("color",      "0,0,0",                     str),
 *         9 :  ("blocks",     "1",                         int),
 *         10 : ("blocksizes", str(chrom_end - chrom_start),str),             # <<<<<<<<<<<<<<
 *         11 : ("blockstarts","0",                         str),
 *     }
 */
  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_chrom_start); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = PyNumber_Subtract(__pyx_v_chrom_end, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_n_u_blocksizes);
  __Pyx_GIVEREF(__pyx_n_u_blocksizes);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_n_u_blocksizes);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_2);
  __Pyx_INCREF(((PyObject *)(&PyUnicode_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyUnicode_Type)));
  PyTuple_SET_ITEM(__pyx_t_7, 2, ((PyObject *)(&PyUnicode_Type)));
  __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_int_10, __pyx_t_7) < 0) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "plastid/genomics/roitools.pyx":568
 *         9 :  ("blocks",     "1",                         int),
 *         10 : ("blocksizes", str(chrom_end - chrom_start),str),
 *         11 : ("blockstarts","0",                         str),             # <<<<<<<<<<<<<<
 *     }
 * 
 */
  __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 568, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_n_u_blockstarts);
  __Pyx_GIVEREF(__pyx_n_u_blockstarts);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_n_u_blockstarts);
  __Pyx_INCREF(__pyx_kp_u_0);
  __Pyx_GIVEREF(__pyx_kp_u_0);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_kp_u_0);
  __Pyx_INCREF(((PyObject *)(&PyUnicode_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyUnicode_Type)));
  PyTuple_SET_ITEM(__pyx_t_7, 2, ((PyObject *)(&PyUnicode_Type)));
  if (PyDict_SetItem(__pyx_t_5, __pyx_int_11, __pyx_t_7) < 0) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v__default_bed_columns = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "plastid/genomics/roitools.pyx":574
 *     # these values are used if any optional columns 4-12 are ommited
 *     # set attr defaults in case we're dealing with BED4-BED9 format
 *     attr = { KEY : DEFAULT for KEY, DEFAULT,_ in _default_bed_columns.values() }             # <<<<<<<<<<<<<<
 * 
 *     for i in (3, 4, 6, 7, 8, 9, 10, 11):
 */
  { /* enter inner scope */
    __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 574, __pyx_L6_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = 0;
    __pyx_t_2 = __Pyx_dict_iterator(__pyx_v__default_bed_columns, 1, __pyx_n_s_values, (&__pyx_t_8), (&__pyx_t_9)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 574, __pyx_L6_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_7);
    __pyx_t_7 = __pyx_t_2;
    __pyx_t_2 = 0;
    while (1) {
      __pyx_t_10 = __Pyx_dict_iter_next(__pyx_t_7, __pyx_t_8, &__pyx_t_3, NULL, &__pyx_t_2, NULL, __pyx_t_9);
      if (unlikely(__pyx_t_10 == 0)) break;
      if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 574, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_2);
      if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
        PyObject* sequence = __pyx_t_2;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 3)) {
          if (size > 3) __Pyx_RaiseTooManyValuesError(3);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 574, __pyx_L6_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_12 = PyTuple_GET_ITEM(sequence, 1); 
          __pyx_t_13 = PyTuple_GET_ITEM(sequence, 2); 
        } else {
          __pyx_t_11 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_12 = PyList_GET_ITEM(sequence, 1); 
          __pyx_t_13 = PyList_GET_ITEM(sequence, 2); 
        }
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(__pyx_t_12);
        __Pyx_INCREF(__pyx_t_13);
        #else
        __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 574, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_12 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 574, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_13 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 574, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_13);
        #endif
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_14 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 574, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext;
        index = 0; __pyx_t_11 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_11)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_11);
        index = 1; __pyx_t_12 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_12)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_12);
        index = 2; __pyx_t_13 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_13)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_13);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 3) < 0) __PYX_ERR(0, 574, __pyx_L6_error)
        __pyx_t_15 = NULL;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        goto __pyx_L10_unpacking_done;
        __pyx_L9_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_15 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 574, __pyx_L6_error)
        __pyx_L10_unpacking_done:;
      }
      if (!(likely(PyUnicode_CheckExact(__pyx_t_11))||((__pyx_t_11) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_11)->tp_name), 0))) __PYX_ERR(0, 574, __pyx_L6_error)
      __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_KEY, ((PyObject*)__pyx_t_11));
      __pyx_t_11 = 0;
      __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_DEFAULT, __pyx_t_12);
      __pyx_t_12 = 0;
      __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v__, __pyx_t_13);
      __pyx_t_13 = 0;
      if (unlikely(PyDict_SetItem(__pyx_t_5, (PyObject*)__pyx_7genexpr__pyx_v_KEY, (PyObject*)__pyx_7genexpr__pyx_v_DEFAULT))) __PYX_ERR(0, 574, __pyx_L6_error)
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_DEFAULT); __pyx_7genexpr__pyx_v_DEFAULT = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_KEY); __pyx_7genexpr__pyx_v_KEY = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v__); __pyx_7genexpr__pyx_v__ = 0;
    goto __pyx_L11_exit_scope;
    __pyx_L6_error:;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_DEFAULT); __pyx_7genexpr__pyx_v_DEFAULT = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_KEY); __pyx_7genexpr__pyx_v_KEY = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v__); __pyx_7genexpr__pyx_v__ = 0;
    goto __pyx_L1_error;
    __pyx_L11_exit_scope:;
  } /* exit inner scope */
  __pyx_v_attr = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "plastid/genomics/roitools.pyx":576
 *     attr = { KEY : DEFAULT for KEY, DEFAULT,_ in _default_bed_columns.values() }
 * 
 *     for i in (3, 4, 6, 7, 8, 9, 10, 11):             # <<<<<<<<<<<<<<
 *         # populate attr with real values from BED columns that are present
 *         if i >= num_bed_columns:
 */
  __pyx_t_5 = __pyx_tuple__16; __Pyx_INCREF(__pyx_t_5); __pyx_t_8 = 0;
  for (;;) {
    if (__pyx_t_8 >= 8) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 576, __pyx_L1_error)
    #else
    __pyx_t_7 = PySequence_ITEM(__pyx_t_5, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 576, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    #endif
    __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 576, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_i = __pyx_t_9;

    /* "plastid/genomics/roitools.pyx":578
 *     for i in (3, 4, 6, 7, 8, 9, 10, 11):
 *         # populate attr with real values from BED columns that are present
 *         if i >= num_bed_columns:             # <<<<<<<<<<<<<<
 *             break
 * 
 */
    __pyx_t_1 = ((__pyx_v_i >= __pyx_v_num_bed_columns) != 0);
    if (__pyx_t_1) {

      /* "plastid/genomics/roitools.pyx":579
 *         # populate attr with real values from BED columns that are present
 *         if i >= num_bed_columns:
 *             break             # <<<<<<<<<<<<<<
 * 
 *         tup = _default_bed_columns[i]
 */
      goto __pyx_L13_break;

      /* "plastid/genomics/roitools.pyx":578
 *     for i in (3, 4, 6, 7, 8, 9, 10, 11):
 *         # populate attr with real values from BED columns that are present
 *         if i >= num_bed_columns:             # <<<<<<<<<<<<<<
 *             break
 * 
 */
    }

    /* "plastid/genomics/roitools.pyx":581
 *             break
 * 
 *         tup = _default_bed_columns[i]             # <<<<<<<<<<<<<<
 *         key     = tup[0]
 *         default = tup[1]
 */
    __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 581, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v__default_bed_columns, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 581, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (!(likely(PyTuple_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 581, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_tup, ((PyObject*)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "plastid/genomics/roitools.pyx":582
 * 
 *         tup = _default_bed_columns[i]
 *         key     = tup[0]             # <<<<<<<<<<<<<<
 *         default = tup[1]
 *         func    = tup[2]
 */
    if (unlikely(__pyx_v_tup == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 582, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_GetItemInt_Tuple(__pyx_v_tup, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 582, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "plastid/genomics/roitools.pyx":583
 *         tup = _default_bed_columns[i]
 *         key     = tup[0]
 *         default = tup[1]             # <<<<<<<<<<<<<<
 *         func    = tup[2]
 *         try:
 */
    if (unlikely(__pyx_v_tup == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 583, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_GetItemInt_Tuple(__pyx_v_tup, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 583, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_default, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "plastid/genomics/roitools.pyx":584
 *         key     = tup[0]
 *         default = tup[1]
 *         func    = tup[2]             # <<<<<<<<<<<<<<
 *         try:
 *             attr[key] = func(items[i])
 */
    if (unlikely(__pyx_v_tup == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 584, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_GetItemInt_Tuple(__pyx_v_tup, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 584, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_func, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "plastid/genomics/roitools.pyx":585
 *         default = tup[1]
 *         func    = tup[2]
 *         try:             # <<<<<<<<<<<<<<
 *             attr[key] = func(items[i])
 *         except IndexError:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
      __Pyx_XGOTREF(__pyx_t_16);
      __Pyx_XGOTREF(__pyx_t_17);
      __Pyx_XGOTREF(__pyx_t_18);
      /*try:*/ {

        /* "plastid/genomics/roitools.pyx":586
 *         func    = tup[2]
 *         try:
 *             attr[key] = func(items[i])             # <<<<<<<<<<<<<<
 *         except IndexError:
 *             # fall back to default value if real value isn't present
 */
        if (unlikely(__pyx_v_items == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 586, __pyx_L15_error)
        }
        __pyx_t_7 = __Pyx_GetItemInt_List(__pyx_v_items, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 586, __pyx_L15_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_v_func);
        __pyx_t_13 = __pyx_v_func; __pyx_t_12 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) {
          __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_13);
          if (likely(__pyx_t_12)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
            __Pyx_INCREF(__pyx_t_12);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_13, function);
          }
        }
        __pyx_t_2 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_12, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_7);
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 586, __pyx_L15_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_v_key, __pyx_t_2) < 0)) __PYX_ERR(0, 586, __pyx_L15_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "plastid/genomics/roitools.pyx":585
 *         default = tup[1]
 *         func    = tup[2]
 *         try:             # <<<<<<<<<<<<<<
 *             attr[key] = func(items[i])
 *         except IndexError:
 */
      }
      __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
      goto __pyx_L22_try_end;
      __pyx_L15_error:;
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "plastid/genomics/roitools.pyx":587
 *         try:
 *             attr[key] = func(items[i])
 *         except IndexError:             # <<<<<<<<<<<<<<
 *             # fall back to default value if real value isn't present
 *             attr[key] = default
 */
      __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_IndexError);
      if (__pyx_t_9) {
        __Pyx_AddTraceback("plastid.genomics.roitools.get_standard_bed_attr", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_13, &__pyx_t_7) < 0) __PYX_ERR(0, 587, __pyx_L17_except_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_GOTREF(__pyx_t_7);

        /* "plastid/genomics/roitools.pyx":589
 *         except IndexError:
 *             # fall back to default value if real value isn't present
 *             attr[key] = default             # <<<<<<<<<<<<<<
 *         except ValueError:
 *             # fall back to default value if real value cannot be parsed
 */
        if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_v_key, __pyx_v_default) < 0)) __PYX_ERR(0, 589, __pyx_L17_except_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L16_exception_handled;
      }

      /* "plastid/genomics/roitools.pyx":590
 *             # fall back to default value if real value isn't present
 *             attr[key] = default
 *         except ValueError:             # <<<<<<<<<<<<<<
 *             # fall back to default value if real value cannot be parsed
 *             warn(
 */
      __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
      if (__pyx_t_9) {
        __Pyx_AddTraceback("plastid.genomics.roitools.get_standard_bed_attr", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_13, &__pyx_t_2) < 0) __PYX_ERR(0, 590, __pyx_L17_except_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_GOTREF(__pyx_t_2);

        /* "plastid/genomics/roitools.pyx":592
 *         except ValueError:
 *             # fall back to default value if real value cannot be parsed
 *             warn(             # <<<<<<<<<<<<<<
 *                 "get_standard_bed_attr: Could not format column %s with '%s'. Falling back to default value '%s'."
 *                 % (items[i], str(func.__name__), default),
 */
        __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_warn); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 592, __pyx_L17_except_error)
        __Pyx_GOTREF(__pyx_t_11);

        /* "plastid/genomics/roitools.pyx":593
 *             # fall back to default value if real value cannot be parsed
 *             warn(
 *                 "get_standard_bed_attr: Could not format column %s with '%s'. Falling back to default value '%s'."             # <<<<<<<<<<<<<<
 *                 % (items[i], str(func.__name__), default),
 *                 DataWarning
 */
        __pyx_t_14 = PyTuple_New(7); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 593, __pyx_L17_except_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_3 = 0;
        __pyx_t_4 = 127;
        __Pyx_INCREF(__pyx_kp_u_get_standard_bed_attr_Could_not);
        __pyx_t_3 += 47;
        __Pyx_GIVEREF(__pyx_kp_u_get_standard_bed_attr_Could_not);
        PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_kp_u_get_standard_bed_attr_Could_not);

        /* "plastid/genomics/roitools.pyx":594
 *             warn(
 *                 "get_standard_bed_attr: Could not format column %s with '%s'. Falling back to default value '%s'."
 *                 % (items[i], str(func.__name__), default),             # <<<<<<<<<<<<<<
 *                 DataWarning
 *             )
 */
        if (unlikely(__pyx_v_items == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 594, __pyx_L17_except_error)
        }
        __pyx_t_19 = __Pyx_GetItemInt_List(__pyx_v_items, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 594, __pyx_L17_except_error)
        __Pyx_GOTREF(__pyx_t_19);
        __pyx_t_20 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_19), __pyx_empty_unicode); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 594, __pyx_L17_except_error)
        __Pyx_GOTREF(__pyx_t_20);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_20) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_20) : __pyx_t_4;
        __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_20);
        __Pyx_GIVEREF(__pyx_t_20);
        PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_20);
        __pyx_t_20 = 0;
        __Pyx_INCREF(__pyx_kp_u_with);
        __pyx_t_3 += 7;
        __Pyx_GIVEREF(__pyx_kp_u_with);
        PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_kp_u_with);
        __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_func, __pyx_n_s_name); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 594, __pyx_L17_except_error)
        __Pyx_GOTREF(__pyx_t_20);
        __pyx_t_19 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_20); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 594, __pyx_L17_except_error)
        __Pyx_GOTREF(__pyx_t_19);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_19) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_19) : __pyx_t_4;
        __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_19);
        __Pyx_GIVEREF(__pyx_t_19);
        PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_t_19);
        __pyx_t_19 = 0;
        __Pyx_INCREF(__pyx_kp_u_Falling_back_to_default_value);
        __pyx_t_3 += 34;
        __Pyx_GIVEREF(__pyx_kp_u_Falling_back_to_default_value);
        PyTuple_SET_ITEM(__pyx_t_14, 4, __pyx_kp_u_Falling_back_to_default_value);
        __pyx_t_19 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_default), __pyx_empty_unicode); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 594, __pyx_L17_except_error)
        __Pyx_GOTREF(__pyx_t_19);
        __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_19) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_19) : __pyx_t_4;
        __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_19);
        __Pyx_GIVEREF(__pyx_t_19);
        PyTuple_SET_ITEM(__pyx_t_14, 5, __pyx_t_19);
        __pyx_t_19 = 0;
        __Pyx_INCREF(__pyx_kp_u__17);
        __pyx_t_3 += 2;
        __Pyx_GIVEREF(__pyx_kp_u__17);
        PyTuple_SET_ITEM(__pyx_t_14, 6, __pyx_kp_u__17);

        /* "plastid/genomics/roitools.pyx":593
 *             # fall back to default value if real value cannot be parsed
 *             warn(
 *                 "get_standard_bed_attr: Could not format column %s with '%s'. Falling back to default value '%s'."             # <<<<<<<<<<<<<<
 *                 % (items[i], str(func.__name__), default),
 *                 DataWarning
 */
        __pyx_t_19 = __Pyx_PyUnicode_Join(__pyx_t_14, 7, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 593, __pyx_L17_except_error)
        __Pyx_GOTREF(__pyx_t_19);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

        /* "plastid/genomics/roitools.pyx":595
 *                 "get_standard_bed_attr: Could not format column %s with '%s'. Falling back to default value '%s'."
 *                 % (items[i], str(func.__name__), default),
 *                 DataWarning             # <<<<<<<<<<<<<<
 *             )
 *             attr[key] = default
 */
        __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_DataWarning); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 595, __pyx_L17_except_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_20 = NULL;
        __pyx_t_9 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
          __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_11);
          if (likely(__pyx_t_20)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
            __Pyx_INCREF(__pyx_t_20);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_11, function);
            __pyx_t_9 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_11)) {
          PyObject *__pyx_temp[3] = {__pyx_t_20, __pyx_t_19, __pyx_t_14};
          __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 592, __pyx_L17_except_error)
          __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
          PyObject *__pyx_temp[3] = {__pyx_t_20, __pyx_t_19, __pyx_t_14};
          __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 592, __pyx_L17_except_error)
          __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        } else
        #endif
        {
          __pyx_t_21 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 592, __pyx_L17_except_error)
          __Pyx_GOTREF(__pyx_t_21);
          if (__pyx_t_20) {
            __Pyx_GIVEREF(__pyx_t_20); PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_20); __pyx_t_20 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_19);
          PyTuple_SET_ITEM(__pyx_t_21, 0+__pyx_t_9, __pyx_t_19);
          __Pyx_GIVEREF(__pyx_t_14);
          PyTuple_SET_ITEM(__pyx_t_21, 1+__pyx_t_9, __pyx_t_14);
          __pyx_t_19 = 0;
          __pyx_t_14 = 0;
          __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_21, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 592, __pyx_L17_except_error)
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
        }
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

        /* "plastid/genomics/roitools.pyx":597
 *                 DataWarning
 *             )
 *             attr[key] = default             # <<<<<<<<<<<<<<
 * 
 *     # convert color to hex string
 */
        if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_v_key, __pyx_v_default) < 0)) __PYX_ERR(0, 597, __pyx_L17_except_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        goto __pyx_L16_exception_handled;
      }
      goto __pyx_L17_except_error;
      __pyx_L17_except_error:;

      /* "plastid/genomics/roitools.pyx":585
 *         default = tup[1]
 *         func    = tup[2]
 *         try:             # <<<<<<<<<<<<<<
 *             attr[key] = func(items[i])
 *         except IndexError:
 */
      __Pyx_XGIVEREF(__pyx_t_16);
      __Pyx_XGIVEREF(__pyx_t_17);
      __Pyx_XGIVEREF(__pyx_t_18);
      __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
      goto __pyx_L1_error;
      __pyx_L16_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_16);
      __Pyx_XGIVEREF(__pyx_t_17);
      __Pyx_XGIVEREF(__pyx_t_18);
      __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
      __pyx_L22_try_end:;
    }

    /* "plastid/genomics/roitools.pyx":576
 *     attr = { KEY : DEFAULT for KEY, DEFAULT,_ in _default_bed_columns.values() }
 * 
 *     for i in (3, 4, 6, 7, 8, 9, 10, 11):             # <<<<<<<<<<<<<<
 *         # populate attr with real values from BED columns that are present
 *         if i >= num_bed_columns:
 */
  }
  __pyx_L13_break:;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "plastid/genomics/roitools.pyx":600
 * 
 *     # convert color to hex string
 *     try:             # <<<<<<<<<<<<<<
 *         attr["color"] = get_str_from_rgb255(tuple([int(X) for X in attr["color"].split(",")]))
 *     except ValueError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_18, &__pyx_t_17, &__pyx_t_16);
    __Pyx_XGOTREF(__pyx_t_18);
    __Pyx_XGOTREF(__pyx_t_17);
    __Pyx_XGOTREF(__pyx_t_16);
    /*try:*/ {

      /* "plastid/genomics/roitools.pyx":601
 *     # convert color to hex string
 *     try:
 *         attr["color"] = get_str_from_rgb255(tuple([int(X) for X in attr["color"].split(",")]))             # <<<<<<<<<<<<<<
 *     except ValueError:
 *         attr["color"] = "#000000"
 */
      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_get_str_from_rgb255); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 601, __pyx_L27_error)
      __Pyx_GOTREF(__pyx_t_2);
      { /* enter inner scope */
        __pyx_t_13 = PyList_New(0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 601, __pyx_L35_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_12 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_color); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 601, __pyx_L35_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_split); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 601, __pyx_L35_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_12 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
          __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
          if (likely(__pyx_t_12)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
            __Pyx_INCREF(__pyx_t_12);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_11, function);
          }
        }
        __pyx_t_7 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_12, __pyx_kp_u__3) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_kp_u__3);
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 601, __pyx_L35_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
          __pyx_t_11 = __pyx_t_7; __Pyx_INCREF(__pyx_t_11); __pyx_t_8 = 0;
          __pyx_t_22 = NULL;
        } else {
          __pyx_t_8 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 601, __pyx_L35_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_22 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 601, __pyx_L35_error)
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        for (;;) {
          if (likely(!__pyx_t_22)) {
            if (likely(PyList_CheckExact(__pyx_t_11))) {
              if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_11)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_7 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 601, __pyx_L35_error)
              #else
              __pyx_t_7 = PySequence_ITEM(__pyx_t_11, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 601, __pyx_L35_error)
              __Pyx_GOTREF(__pyx_t_7);
              #endif
            } else {
              if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_11)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 601, __pyx_L35_error)
              #else
              __pyx_t_7 = PySequence_ITEM(__pyx_t_11, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 601, __pyx_L35_error)
              __Pyx_GOTREF(__pyx_t_7);
              #endif
            }
          } else {
            __pyx_t_7 = __pyx_t_22(__pyx_t_11);
            if (unlikely(!__pyx_t_7)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 601, __pyx_L35_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_7);
          }
          __Pyx_XDECREF_SET(__pyx_8genexpr1__pyx_v_X, __pyx_t_7);
          __pyx_t_7 = 0;
          __pyx_t_7 = __Pyx_PyNumber_Int(__pyx_8genexpr1__pyx_v_X); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 601, __pyx_L35_error)
          __Pyx_GOTREF(__pyx_t_7);
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_13, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 601, __pyx_L35_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        }
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_X); __pyx_8genexpr1__pyx_v_X = 0;
        goto __pyx_L38_exit_scope;
        __pyx_L35_error:;
        __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_X); __pyx_8genexpr1__pyx_v_X = 0;
        goto __pyx_L27_error;
        __pyx_L38_exit_scope:;
      } /* exit inner scope */
      __pyx_t_11 = PyList_AsTuple(((PyObject*)__pyx_t_13)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 601, __pyx_L27_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      __pyx_t_5 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_13, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_11);
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 601, __pyx_L27_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_color, __pyx_t_5) < 0)) __PYX_ERR(0, 601, __pyx_L27_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "plastid/genomics/roitools.pyx":600
 * 
 *     # convert color to hex string
 *     try:             # <<<<<<<<<<<<<<
 *         attr["color"] = get_str_from_rgb255(tuple([int(X) for X in attr["color"].split(",")]))
 *     except ValueError:
 */
    }
    __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
    __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
    goto __pyx_L32_try_end;
    __pyx_L27_error:;
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":602
 *     try:
 *         attr["color"] = get_str_from_rgb255(tuple([int(X) for X in attr["color"].split(",")]))
 *     except ValueError:             # <<<<<<<<<<<<<<
 *         attr["color"] = "#000000"
 * 
 */
    __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_9) {
      __Pyx_AddTraceback("plastid.genomics.roitools.get_standard_bed_attr", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_2, &__pyx_t_11) < 0) __PYX_ERR(0, 602, __pyx_L29_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_t_11);

      /* "plastid/genomics/roitools.pyx":603
 *         attr["color"] = get_str_from_rgb255(tuple([int(X) for X in attr["color"].split(",")]))
 *     except ValueError:
 *         attr["color"] = "#000000"             # <<<<<<<<<<<<<<
 * 
 *     # sanity check on thickstart and thickend
 */
      if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_color, __pyx_kp_u_000000) < 0)) __PYX_ERR(0, 603, __pyx_L29_except_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      goto __pyx_L28_exception_handled;
    }
    goto __pyx_L29_except_error;
    __pyx_L29_except_error:;

    /* "plastid/genomics/roitools.pyx":600
 * 
 *     # convert color to hex string
 *     try:             # <<<<<<<<<<<<<<
 *         attr["color"] = get_str_from_rgb255(tuple([int(X) for X in attr["color"].split(",")]))
 *     except ValueError:
 */
    __Pyx_XGIVEREF(__pyx_t_18);
    __Pyx_XGIVEREF(__pyx_t_17);
    __Pyx_XGIVEREF(__pyx_t_16);
    __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_17, __pyx_t_16);
    goto __pyx_L1_error;
    __pyx_L28_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_18);
    __Pyx_XGIVEREF(__pyx_t_17);
    __Pyx_XGIVEREF(__pyx_t_16);
    __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_17, __pyx_t_16);
    __pyx_L32_try_end:;
  }

  /* "plastid/genomics/roitools.pyx":606
 * 
 *     # sanity check on thickstart and thickend
 *     thickstart = attr["thickstart"]             # <<<<<<<<<<<<<<
 *     thickend   = attr["thickend"]
 * 
 */
  __pyx_t_11 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_thickstart); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 606, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_6 = __Pyx_PyInt_As_long(__pyx_t_11); if (unlikely((__pyx_t_6 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 606, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_v_thickstart = __pyx_t_6;

  /* "plastid/genomics/roitools.pyx":607
 *     # sanity check on thickstart and thickend
 *     thickstart = attr["thickstart"]
 *     thickend   = attr["thickend"]             # <<<<<<<<<<<<<<
 * 
 *     if thickstart == thickend or None in (thickstart, thickend) \
 */
  __pyx_t_11 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_thickend); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 607, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_6 = __Pyx_PyInt_As_long(__pyx_t_11); if (unlikely((__pyx_t_6 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 607, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_v_thickend = __pyx_t_6;

  /* "plastid/genomics/roitools.pyx":609
 *     thickend   = attr["thickend"]
 * 
 *     if thickstart == thickend or None in (thickstart, thickend) \             # <<<<<<<<<<<<<<
 *     or thickstart < 0 or thickend < 0:
 *         attr["thickstart"] = attr["thickend"] = chrom_start
 */
  __pyx_t_23 = ((__pyx_v_thickstart == __pyx_v_thickend) != 0);
  if (!__pyx_t_23) {
  } else {
    __pyx_t_1 = __pyx_t_23;
    goto __pyx_L42_bool_binop_done;
  }

  /* "plastid/genomics/roitools.pyx":610
 * 
 *     if thickstart == thickend or None in (thickstart, thickend) \
 *     or thickstart < 0 or thickend < 0:             # <<<<<<<<<<<<<<
 *         attr["thickstart"] = attr["thickend"] = chrom_start
 * 
 */
  __Pyx_INCREF(Py_None);
  __pyx_t_11 = Py_None;

  /* "plastid/genomics/roitools.pyx":609
 *     thickend   = attr["thickend"]
 * 
 *     if thickstart == thickend or None in (thickstart, thickend) \             # <<<<<<<<<<<<<<
 *     or thickstart < 0 or thickend < 0:
 *         attr["thickstart"] = attr["thickend"] = chrom_start
 */
  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_thickstart); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 609, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_11, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 609, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_24 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_24 < 0)) __PYX_ERR(0, 609, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_24) {
  } else {
    __pyx_t_23 = __pyx_t_24;
    goto __pyx_L45_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_thickend); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 609, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_11, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 609, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_24 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_24 < 0)) __PYX_ERR(0, 609, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_23 = __pyx_t_24;
  __pyx_L45_bool_binop_done:;
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_24 = (__pyx_t_23 != 0);
  if (!__pyx_t_24) {
  } else {
    __pyx_t_1 = __pyx_t_24;
    goto __pyx_L42_bool_binop_done;
  }

  /* "plastid/genomics/roitools.pyx":610
 * 
 *     if thickstart == thickend or None in (thickstart, thickend) \
 *     or thickstart < 0 or thickend < 0:             # <<<<<<<<<<<<<<
 *         attr["thickstart"] = attr["thickend"] = chrom_start
 * 
 */
  __pyx_t_24 = ((__pyx_v_thickstart < 0) != 0);
  if (!__pyx_t_24) {
  } else {
    __pyx_t_1 = __pyx_t_24;
    goto __pyx_L42_bool_binop_done;
  }
  __pyx_t_24 = ((__pyx_v_thickend < 0) != 0);
  __pyx_t_1 = __pyx_t_24;
  __pyx_L42_bool_binop_done:;

  /* "plastid/genomics/roitools.pyx":609
 *     thickend   = attr["thickend"]
 * 
 *     if thickstart == thickend or None in (thickstart, thickend) \             # <<<<<<<<<<<<<<
 *     or thickstart < 0 or thickend < 0:
 *         attr["thickstart"] = attr["thickend"] = chrom_start
 */
  if (__pyx_t_1) {

    /* "plastid/genomics/roitools.pyx":611
 *     if thickstart == thickend or None in (thickstart, thickend) \
 *     or thickstart < 0 or thickend < 0:
 *         attr["thickstart"] = attr["thickend"] = chrom_start             # <<<<<<<<<<<<<<
 * 
 *     # stash these temporarily. I don't like this, but hey
 */
    __pyx_t_11 = __Pyx_PyInt_From_long(__pyx_v_chrom_start); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 611, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_thickstart, __pyx_t_11) < 0)) __PYX_ERR(0, 611, __pyx_L1_error)
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_thickend, __pyx_t_11) < 0)) __PYX_ERR(0, 611, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

    /* "plastid/genomics/roitools.pyx":609
 *     thickend   = attr["thickend"]
 * 
 *     if thickstart == thickend or None in (thickstart, thickend) \             # <<<<<<<<<<<<<<
 *     or thickstart < 0 or thickend < 0:
 *         attr["thickstart"] = attr["thickend"] = chrom_start
 */
  }

  /* "plastid/genomics/roitools.pyx":614
 * 
 *     # stash these temporarily. I don't like this, but hey
 *     attr["chrom"]       = chrom             # <<<<<<<<<<<<<<
 *     attr["chrom_start"] = chrom_start
 *     attr["strand"]      = strand
 */
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_chrom, __pyx_v_chrom) < 0)) __PYX_ERR(0, 614, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":615
 *     # stash these temporarily. I don't like this, but hey
 *     attr["chrom"]       = chrom
 *     attr["chrom_start"] = chrom_start             # <<<<<<<<<<<<<<
 *     attr["strand"]      = strand
 *     return attr
 */
  __pyx_t_11 = __Pyx_PyInt_From_long(__pyx_v_chrom_start); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 615, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_chrom_start, __pyx_t_11) < 0)) __PYX_ERR(0, 615, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

  /* "plastid/genomics/roitools.pyx":616
 *     attr["chrom"]       = chrom
 *     attr["chrom_start"] = chrom_start
 *     attr["strand"]      = strand             # <<<<<<<<<<<<<<
 *     return attr
 * 
 */
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_strand, __pyx_v_strand) < 0)) __PYX_ERR(0, 616, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":617
 *     attr["chrom_start"] = chrom_start
 *     attr["strand"]      = strand
 *     return attr             # <<<<<<<<<<<<<<
 * 
 * cdef dict get_attr_from_bed(str line, object extra_columns=0):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_attr);
  __pyx_r = __pyx_v_attr;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":535
 * 
 * 
 * cdef dict get_standard_bed_attr(list items, int num_bed_columns):             # <<<<<<<<<<<<<<
 *     """Get SegmentChain attributes from standard BED columns in `BED`_ line"""
 *     cdef:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_AddTraceback("plastid.genomics.roitools.get_standard_bed_attr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_strand);
  __Pyx_XDECREF(__pyx_v_default_id);
  __Pyx_XDECREF(__pyx_v_tup);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_v__default_bed_columns);
  __Pyx_XDECREF(__pyx_v_chrom_end);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XDECREF(__pyx_v_default);
  __Pyx_XDECREF(__pyx_v_func);
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_KEY);
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_DEFAULT);
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v__);
  __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_X);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":619
 *     return attr
 * 
 * cdef dict get_attr_from_bed(str line, object extra_columns=0):             # <<<<<<<<<<<<<<
 *     """See the `UCSC file format faq <http://genome.ucsc.edu/FAQ/FAQformat.html>`_
 *     for more details.
 */

static PyObject *__pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed(PyObject *__pyx_v_line, struct __pyx_opt_args_7plastid_8genomics_8roitools_get_attr_from_bed *__pyx_optional_args) {
  PyObject *__pyx_v_extra_columns = ((PyObject *)__pyx_int_0);
  PyObject *__pyx_v_items = 0;
  int __pyx_v_total_columns;
  int __pyx_v_num_bed_columns;
  int __pyx_v_num_extra_columns;
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_v_types = 0;
  PyObject *__pyx_8genexpr2__pyx_v_X = NULL;
  PyObject *__pyx_8genexpr3__pyx_v_X = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  PyObject *(*__pyx_t_10)(PyObject *);
  Py_ssize_t __pyx_t_11;
  Py_UCS4 __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_attr_from_bed", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_extra_columns = __pyx_optional_args->extra_columns;
    }
  }

  /* "plastid/genomics/roitools.pyx":658
 *     """
 *     cdef:
 *         list  items         = line.strip("\n").split("\t")             # <<<<<<<<<<<<<<
 *         int   total_columns = len(items)
 *         int   num_bed_columns, num_extra_columns
 */
  __pyx_t_2 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyUnicode_Type_strip, __pyx_v_line, __pyx_kp_u__18); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u__19) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u__19);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 658, __pyx_L1_error)
  __pyx_v_items = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":659
 *     cdef:
 *         list  items         = line.strip("\n").split("\t")
 *         int   total_columns = len(items)             # <<<<<<<<<<<<<<
 *         int   num_bed_columns, num_extra_columns
 *         dict  attr
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 659, __pyx_L1_error)
  }
  __pyx_t_4 = PyList_GET_SIZE(__pyx_v_items); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 659, __pyx_L1_error)
  __pyx_v_total_columns = __pyx_t_4;

  /* "plastid/genomics/roitools.pyx":664
 *         set   types
 * 
 *     if extra_columns == 0:             # <<<<<<<<<<<<<<
 *         attr = get_standard_bed_attr(items, len(items))
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_v_extra_columns, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 664, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 664, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_5) {

    /* "plastid/genomics/roitools.pyx":665
 * 
 *     if extra_columns == 0:
 *         attr = get_standard_bed_attr(items, len(items))             # <<<<<<<<<<<<<<
 * 
 *     elif isinstance(extra_columns, int):
 */
    if (unlikely(__pyx_v_items == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 665, __pyx_L1_error)
    }
    __pyx_t_4 = PyList_GET_SIZE(__pyx_v_items); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 665, __pyx_L1_error)
    __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_get_standard_bed_attr(__pyx_v_items, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_attr = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":664
 *         set   types
 * 
 *     if extra_columns == 0:             # <<<<<<<<<<<<<<
 *         attr = get_standard_bed_attr(items, len(items))
 * 
 */
    goto __pyx_L3;
  }

  /* "plastid/genomics/roitools.pyx":667
 *         attr = get_standard_bed_attr(items, len(items))
 * 
 *     elif isinstance(extra_columns, int):             # <<<<<<<<<<<<<<
 *         attr = get_attr_from_bed_column_number(items, total_columns - extra_columns, extra_columns)
 * 
 */
  __pyx_t_5 = PyInt_Check(__pyx_v_extra_columns); 
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "plastid/genomics/roitools.pyx":668
 * 
 *     elif isinstance(extra_columns, int):
 *         attr = get_attr_from_bed_column_number(items, total_columns - extra_columns, extra_columns)             # <<<<<<<<<<<<<<
 * 
 *     elif isinstance(extra_columns, (list, tuple)):
 */
    __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_total_columns); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 668, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Subtract(__pyx_t_1, __pyx_v_extra_columns); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 668, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 668, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_extra_columns); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 668, __pyx_L1_error)
    __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed_column_number(__pyx_v_items, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 668, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_attr = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":667
 *         attr = get_standard_bed_attr(items, len(items))
 * 
 *     elif isinstance(extra_columns, int):             # <<<<<<<<<<<<<<
 *         attr = get_attr_from_bed_column_number(items, total_columns - extra_columns, extra_columns)
 * 
 */
    goto __pyx_L3;
  }

  /* "plastid/genomics/roitools.pyx":670
 *         attr = get_attr_from_bed_column_number(items, total_columns - extra_columns, extra_columns)
 * 
 *     elif isinstance(extra_columns, (list, tuple)):             # <<<<<<<<<<<<<<
 *         if len(extra_columns) == 0:
 *             attr = get_standard_bed_attr(items, len(items))
 */
  __pyx_t_5 = PyList_Check(__pyx_v_extra_columns); 
  __pyx_t_9 = (__pyx_t_5 != 0);
  if (!__pyx_t_9) {
  } else {
    __pyx_t_6 = __pyx_t_9;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_9 = PyTuple_Check(__pyx_v_extra_columns); 
  __pyx_t_5 = (__pyx_t_9 != 0);
  __pyx_t_6 = __pyx_t_5;
  __pyx_L4_bool_binop_done:;
  __pyx_t_5 = (__pyx_t_6 != 0);
  if (likely(__pyx_t_5)) {

    /* "plastid/genomics/roitools.pyx":671
 * 
 *     elif isinstance(extra_columns, (list, tuple)):
 *         if len(extra_columns) == 0:             # <<<<<<<<<<<<<<
 *             attr = get_standard_bed_attr(items, len(items))
 *         else:
 */
    __pyx_t_4 = PyObject_Length(__pyx_v_extra_columns); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 671, __pyx_L1_error)
    __pyx_t_5 = ((__pyx_t_4 == 0) != 0);
    if (__pyx_t_5) {

      /* "plastid/genomics/roitools.pyx":672
 *     elif isinstance(extra_columns, (list, tuple)):
 *         if len(extra_columns) == 0:
 *             attr = get_standard_bed_attr(items, len(items))             # <<<<<<<<<<<<<<
 *         else:
 *             types = set([type(X) for X in extra_columns])
 */
      if (unlikely(__pyx_v_items == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
        __PYX_ERR(0, 672, __pyx_L1_error)
      }
      __pyx_t_4 = PyList_GET_SIZE(__pyx_v_items); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 672, __pyx_L1_error)
      __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_get_standard_bed_attr(__pyx_v_items, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 672, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_v_attr = ((PyObject*)__pyx_t_3);
      __pyx_t_3 = 0;

      /* "plastid/genomics/roitools.pyx":671
 * 
 *     elif isinstance(extra_columns, (list, tuple)):
 *         if len(extra_columns) == 0:             # <<<<<<<<<<<<<<
 *             attr = get_standard_bed_attr(items, len(items))
 *         else:
 */
      goto __pyx_L6;
    }

    /* "plastid/genomics/roitools.pyx":674
 *             attr = get_standard_bed_attr(items, len(items))
 *         else:
 *             types = set([type(X) for X in extra_columns])             # <<<<<<<<<<<<<<
 *             num_extra_columns = len(extra_columns)
 *             num_bed_columns   = total_columns - num_extra_columns
 */
    /*else*/ {
      { /* enter inner scope */
        __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 674, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (likely(PyList_CheckExact(__pyx_v_extra_columns)) || PyTuple_CheckExact(__pyx_v_extra_columns)) {
          __pyx_t_1 = __pyx_v_extra_columns; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
          __pyx_t_10 = NULL;
        } else {
          __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_extra_columns); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 674, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_10 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 674, __pyx_L9_error)
        }
        for (;;) {
          if (likely(!__pyx_t_10)) {
            if (likely(PyList_CheckExact(__pyx_t_1))) {
              if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 674, __pyx_L9_error)
              #else
              __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L9_error)
              __Pyx_GOTREF(__pyx_t_2);
              #endif
            } else {
              if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 674, __pyx_L9_error)
              #else
              __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L9_error)
              __Pyx_GOTREF(__pyx_t_2);
              #endif
            }
          } else {
            __pyx_t_2 = __pyx_t_10(__pyx_t_1);
            if (unlikely(!__pyx_t_2)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 674, __pyx_L9_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_2);
          }
          __Pyx_XDECREF_SET(__pyx_8genexpr2__pyx_v_X, __pyx_t_2);
          __pyx_t_2 = 0;
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)((PyObject *)Py_TYPE(__pyx_8genexpr2__pyx_v_X))))) __PYX_ERR(0, 674, __pyx_L9_error)
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_X); __pyx_8genexpr2__pyx_v_X = 0;
        goto __pyx_L12_exit_scope;
        __pyx_L9_error:;
        __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_X); __pyx_8genexpr2__pyx_v_X = 0;
        goto __pyx_L1_error;
        __pyx_L12_exit_scope:;
      } /* exit inner scope */
      __pyx_t_1 = PySet_New(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 674, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_types = ((PyObject*)__pyx_t_1);
      __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":675
 *         else:
 *             types = set([type(X) for X in extra_columns])
 *             num_extra_columns = len(extra_columns)             # <<<<<<<<<<<<<<
 *             num_bed_columns   = total_columns - num_extra_columns
 * 
 */
      __pyx_t_4 = PyObject_Length(__pyx_v_extra_columns); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 675, __pyx_L1_error)
      __pyx_v_num_extra_columns = __pyx_t_4;

      /* "plastid/genomics/roitools.pyx":676
 *             types = set([type(X) for X in extra_columns])
 *             num_extra_columns = len(extra_columns)
 *             num_bed_columns   = total_columns - num_extra_columns             # <<<<<<<<<<<<<<
 * 
 *             if len(types) > 1:
 */
      __pyx_v_num_bed_columns = (__pyx_v_total_columns - __pyx_v_num_extra_columns);

      /* "plastid/genomics/roitools.pyx":678
 *             num_bed_columns   = total_columns - num_extra_columns
 * 
 *             if len(types) > 1:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "get_attr_from_bed: List of `extra_columns` contains mixed types. All items need to be the same type, either str or tuple."
 */
      __pyx_t_4 = PySet_GET_SIZE(__pyx_v_types); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 678, __pyx_L1_error)
      __pyx_t_5 = ((__pyx_t_4 > 1) != 0);
      if (unlikely(__pyx_t_5)) {

        /* "plastid/genomics/roitools.pyx":679
 * 
 *             if len(types) > 1:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "get_attr_from_bed: List of `extra_columns` contains mixed types. All items need to be the same type, either str or tuple."
 *                 )
 */
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 679, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_Raise(__pyx_t_1, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __PYX_ERR(0, 679, __pyx_L1_error)

        /* "plastid/genomics/roitools.pyx":678
 *             num_bed_columns   = total_columns - num_extra_columns
 * 
 *             if len(types) > 1:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "get_attr_from_bed: List of `extra_columns` contains mixed types. All items need to be the same type, either str or tuple."
 */
      }

      /* "plastid/genomics/roitools.pyx":682
 *                     "get_attr_from_bed: List of `extra_columns` contains mixed types. All items need to be the same type, either str or tuple."
 *                 )
 *             elif types == { str }:             # <<<<<<<<<<<<<<
 *                 attr = get_attr_from_bed_column_names(items, num_bed_columns, extra_columns)
 *             elif types == { tuple }:
 */
      __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 682, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PySet_Add(__pyx_t_1, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 682, __pyx_L1_error)
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_types, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 682, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 682, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_5) {

        /* "plastid/genomics/roitools.pyx":683
 *                 )
 *             elif types == { str }:
 *                 attr = get_attr_from_bed_column_names(items, num_bed_columns, extra_columns)             # <<<<<<<<<<<<<<
 *             elif types == { tuple }:
 *                 if all([len(X) == 2 for X in extra_columns]) == False:
 */
        if (!(likely(PyList_CheckExact(__pyx_v_extra_columns))||((__pyx_v_extra_columns) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_extra_columns)->tp_name), 0))) __PYX_ERR(0, 683, __pyx_L1_error)
        __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed_column_names(__pyx_v_items, __pyx_v_num_bed_columns, ((PyObject*)__pyx_v_extra_columns)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 683, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_v_attr = ((PyObject*)__pyx_t_3);
        __pyx_t_3 = 0;

        /* "plastid/genomics/roitools.pyx":682
 *                     "get_attr_from_bed: List of `extra_columns` contains mixed types. All items need to be the same type, either str or tuple."
 *                 )
 *             elif types == { str }:             # <<<<<<<<<<<<<<
 *                 attr = get_attr_from_bed_column_names(items, num_bed_columns, extra_columns)
 *             elif types == { tuple }:
 */
        goto __pyx_L13;
      }

      /* "plastid/genomics/roitools.pyx":684
 *             elif types == { str }:
 *                 attr = get_attr_from_bed_column_names(items, num_bed_columns, extra_columns)
 *             elif types == { tuple }:             # <<<<<<<<<<<<<<
 *                 if all([len(X) == 2 for X in extra_columns]) == False:
 *                     raise ValueError(
 */
      __pyx_t_3 = PySet_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 684, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PySet_Add(__pyx_t_3, ((PyObject *)(&PyTuple_Type))) < 0) __PYX_ERR(0, 684, __pyx_L1_error)
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_types, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 684, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 684, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (likely(__pyx_t_5)) {

        /* "plastid/genomics/roitools.pyx":685
 *                 attr = get_attr_from_bed_column_names(items, num_bed_columns, extra_columns)
 *             elif types == { tuple }:
 *                 if all([len(X) == 2 for X in extra_columns]) == False:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "get_attr_from_bed: Cannot make SegmentChain from BED input: if a list, extra_columns must be a list of tuples of (column_name,formatter_func)"
 */
        { /* enter inner scope */
          __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 685, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (likely(PyList_CheckExact(__pyx_v_extra_columns)) || PyTuple_CheckExact(__pyx_v_extra_columns)) {
            __pyx_t_3 = __pyx_v_extra_columns; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
            __pyx_t_10 = NULL;
          } else {
            __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_extra_columns); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 685, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 685, __pyx_L17_error)
          }
          for (;;) {
            if (likely(!__pyx_t_10)) {
              if (likely(PyList_CheckExact(__pyx_t_3))) {
                if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 685, __pyx_L17_error)
                #else
                __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 685, __pyx_L17_error)
                __Pyx_GOTREF(__pyx_t_2);
                #endif
              } else {
                if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 685, __pyx_L17_error)
                #else
                __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 685, __pyx_L17_error)
                __Pyx_GOTREF(__pyx_t_2);
                #endif
              }
            } else {
              __pyx_t_2 = __pyx_t_10(__pyx_t_3);
              if (unlikely(!__pyx_t_2)) {
                PyObject* exc_type = PyErr_Occurred();
                if (exc_type) {
                  if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                  else __PYX_ERR(0, 685, __pyx_L17_error)
                }
                break;
              }
              __Pyx_GOTREF(__pyx_t_2);
            }
            __Pyx_XDECREF_SET(__pyx_8genexpr3__pyx_v_X, __pyx_t_2);
            __pyx_t_2 = 0;
            __pyx_t_11 = PyObject_Length(__pyx_8genexpr3__pyx_v_X); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 685, __pyx_L17_error)
            __pyx_t_2 = __Pyx_PyBool_FromLong((__pyx_t_11 == 2)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 685, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_2);
            if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 685, __pyx_L17_error)
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          }
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_X); __pyx_8genexpr3__pyx_v_X = 0;
          goto __pyx_L20_exit_scope;
          __pyx_L17_error:;
          __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_X); __pyx_8genexpr3__pyx_v_X = 0;
          goto __pyx_L1_error;
          __pyx_L20_exit_scope:;
        } /* exit inner scope */
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_all, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 685, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, Py_False, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 685, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 685, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(__pyx_t_5)) {

          /* "plastid/genomics/roitools.pyx":686
 *             elif types == { tuple }:
 *                 if all([len(X) == 2 for X in extra_columns]) == False:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "get_attr_from_bed: Cannot make SegmentChain from BED input: if a list, extra_columns must be a list of tuples of (column_name,formatter_func)"
 *                     )
 */
          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 686, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_Raise(__pyx_t_1, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __PYX_ERR(0, 686, __pyx_L1_error)

          /* "plastid/genomics/roitools.pyx":685
 *                 attr = get_attr_from_bed_column_names(items, num_bed_columns, extra_columns)
 *             elif types == { tuple }:
 *                 if all([len(X) == 2 for X in extra_columns]) == False:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "get_attr_from_bed: Cannot make SegmentChain from BED input: if a list, extra_columns must be a list of tuples of (column_name,formatter_func)"
 */
        }

        /* "plastid/genomics/roitools.pyx":693
 *                     num_bed_columns,
 *                     total_columns,
 *                     extra_columns             # <<<<<<<<<<<<<<
 *                 )
 *             else:
 */
        if (!(likely(PyList_CheckExact(__pyx_v_extra_columns))||((__pyx_v_extra_columns) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_extra_columns)->tp_name), 0))) __PYX_ERR(0, 693, __pyx_L1_error)

        /* "plastid/genomics/roitools.pyx":689
 *                         "get_attr_from_bed: Cannot make SegmentChain from BED input: if a list, extra_columns must be a list of tuples of (column_name,formatter_func)"
 *                     )
 *                 attr = get_attr_from_bed_column_tuples(             # <<<<<<<<<<<<<<
 *                     items,
 *                     num_bed_columns,
 */
        __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed_column_tuples(__pyx_v_items, __pyx_v_num_bed_columns, __pyx_v_total_columns, ((PyObject*)__pyx_v_extra_columns)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 689, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_v_attr = ((PyObject*)__pyx_t_1);
        __pyx_t_1 = 0;

        /* "plastid/genomics/roitools.pyx":684
 *             elif types == { str }:
 *                 attr = get_attr_from_bed_column_names(items, num_bed_columns, extra_columns)
 *             elif types == { tuple }:             # <<<<<<<<<<<<<<
 *                 if all([len(X) == 2 for X in extra_columns]) == False:
 *                     raise ValueError(
 */
        goto __pyx_L13;
      }

      /* "plastid/genomics/roitools.pyx":696
 *                 )
 *             else:
 *                 raise TypeError(             # <<<<<<<<<<<<<<
 *                     "get_attr_from_bed: Couldn't figure out types from input '%s' of types '%s'"
 *                     % (extra_columns, types)
 */
      /*else*/ {

        /* "plastid/genomics/roitools.pyx":697
 *             else:
 *                 raise TypeError(
 *                     "get_attr_from_bed: Couldn't figure out types from input '%s' of types '%s'"             # <<<<<<<<<<<<<<
 *                     % (extra_columns, types)
 *                 )
 */
        __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 697, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = 0;
        __pyx_t_12 = 127;
        __Pyx_INCREF(__pyx_kp_u_get_attr_from_bed_Couldn_t_figur);
        __pyx_t_4 += 57;
        __Pyx_GIVEREF(__pyx_kp_u_get_attr_from_bed_Couldn_t_figur);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_get_attr_from_bed_Couldn_t_figur);

        /* "plastid/genomics/roitools.pyx":698
 *                 raise TypeError(
 *                     "get_attr_from_bed: Couldn't figure out types from input '%s' of types '%s'"
 *                     % (extra_columns, types)             # <<<<<<<<<<<<<<
 *                 )
 *     else:
 */
        __pyx_t_3 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_extra_columns), __pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 698, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_12 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_12) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_12;
        __pyx_t_4 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
        __pyx_t_3 = 0;
        __Pyx_INCREF(__pyx_kp_u_of_types);
        __pyx_t_4 += 12;
        __Pyx_GIVEREF(__pyx_kp_u_of_types);
        PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_of_types);
        __pyx_t_3 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_types), __pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 698, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_12 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_12) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_12;
        __pyx_t_4 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_3);
        __pyx_t_3 = 0;
        __Pyx_INCREF(__pyx_kp_u__2);
        __pyx_t_4 += 1;
        __Pyx_GIVEREF(__pyx_kp_u__2);
        PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__2);

        /* "plastid/genomics/roitools.pyx":697
 *             else:
 *                 raise TypeError(
 *                     "get_attr_from_bed: Couldn't figure out types from input '%s' of types '%s'"             # <<<<<<<<<<<<<<
 *                     % (extra_columns, types)
 *                 )
 */
        __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_4, __pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 697, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "plastid/genomics/roitools.pyx":696
 *                 )
 *             else:
 *                 raise TypeError(             # <<<<<<<<<<<<<<
 *                     "get_attr_from_bed: Couldn't figure out types from input '%s' of types '%s'"
 *                     % (extra_columns, types)
 */
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 696, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_Raise(__pyx_t_1, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __PYX_ERR(0, 696, __pyx_L1_error)
      }
      __pyx_L13:;
    }
    __pyx_L6:;

    /* "plastid/genomics/roitools.pyx":670
 *         attr = get_attr_from_bed_column_number(items, total_columns - extra_columns, extra_columns)
 * 
 *     elif isinstance(extra_columns, (list, tuple)):             # <<<<<<<<<<<<<<
 *         if len(extra_columns) == 0:
 *             attr = get_standard_bed_attr(items, len(items))
 */
    goto __pyx_L3;
  }

  /* "plastid/genomics/roitools.pyx":701
 *                 )
 *     else:
 *         raise TypeError(             # <<<<<<<<<<<<<<
 *             "get_attr_from_bed: Cannot make SegmentChain from BED input: extra_columns must be an int or list. Got a %s"
 *             % type(extra_columns)
 */
  /*else*/ {

    /* "plastid/genomics/roitools.pyx":703
 *         raise TypeError(
 *             "get_attr_from_bed: Cannot make SegmentChain from BED input: extra_columns must be an int or list. Got a %s"
 *             % type(extra_columns)             # <<<<<<<<<<<<<<
 *         )
 * 
 */
    __pyx_t_1 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_get_attr_from_bed_Cannot_make_Se_2, ((PyObject *)Py_TYPE(__pyx_v_extra_columns))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 703, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "plastid/genomics/roitools.pyx":701
 *                 )
 *     else:
 *         raise TypeError(             # <<<<<<<<<<<<<<
 *             "get_attr_from_bed: Cannot make SegmentChain from BED input: extra_columns must be an int or list. Got a %s"
 *             % type(extra_columns)
 */
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 701, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 701, __pyx_L1_error)
  }
  __pyx_L3:;

  /* "plastid/genomics/roitools.pyx":706
 *         )
 * 
 *     if attr is None:             # <<<<<<<<<<<<<<
 *         raise ValueError("Could not parse BED line:\n\t    '%s'" % line)
 * 
 */
  __pyx_t_5 = (__pyx_v_attr == ((PyObject*)Py_None));
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (unlikely(__pyx_t_6)) {

    /* "plastid/genomics/roitools.pyx":707
 * 
 *     if attr is None:
 *         raise ValueError("Could not parse BED line:\n\t    '%s'" % line)             # <<<<<<<<<<<<<<
 * 
 *     return attr
 */
    __pyx_t_3 = PyUnicode_Format(__pyx_kp_u_Could_not_parse_BED_line_s, __pyx_v_line); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 707, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 707, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 707, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":706
 *         )
 * 
 *     if attr is None:             # <<<<<<<<<<<<<<
 *         raise ValueError("Could not parse BED line:\n\t    '%s'" % line)
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":709
 *         raise ValueError("Could not parse BED line:\n\t    '%s'" % line)
 * 
 *     return attr             # <<<<<<<<<<<<<<
 * 
 * cdef list get_segments_from_bed(dict attr):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_attr);
  __pyx_r = __pyx_v_attr;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":619
 *     return attr
 * 
 * cdef dict get_attr_from_bed(str line, object extra_columns=0):             # <<<<<<<<<<<<<<
 *     """See the `UCSC file format faq <http://genome.ucsc.edu/FAQ/FAQformat.html>`_
 *     for more details.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.get_attr_from_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_items);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_v_types);
  __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_X);
  __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_X);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":711
 *     return attr
 * 
 * cdef list get_segments_from_bed(dict attr):             # <<<<<<<<<<<<<<
 *     """Construct a list of |GenomicSegments| given a dictionary of attributes,
 *     as made from :meth:`get_attr_from_bed` or other methods above. i.e.  `attr`
 */

static PyObject *__pyx_f_7plastid_8genomics_8roitools_get_segments_from_bed(PyObject *__pyx_v_attr) {
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_strand = 0;
  PyObject *__pyx_v_segments = 0;
  long __pyx_v_chrom_start;
  PyObject *__pyx_v_num_frags = NULL;
  PyObject *__pyx_v_seg_sizes = NULL;
  PyObject *__pyx_v_seg_offsets = NULL;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_seg_start = NULL;
  PyObject *__pyx_v_seg_end = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  long __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_segments_from_bed", 0);

  /* "plastid/genomics/roitools.pyx":718
 *     """
 *     cdef:
 *         str  chrom       = attr["chrom"]             # <<<<<<<<<<<<<<
 *         str  strand      = attr["strand"]
 *         list segments    = []
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 718, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_chrom); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 718, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 718, __pyx_L1_error)
  __pyx_v_chrom = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":719
 *     cdef:
 *         str  chrom       = attr["chrom"]
 *         str  strand      = attr["strand"]             # <<<<<<<<<<<<<<
 *         list segments    = []
 *         long chrom_start = attr["chrom_start"]
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 719, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 719, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 719, __pyx_L1_error)
  __pyx_v_strand = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":720
 *         str  chrom       = attr["chrom"]
 *         str  strand      = attr["strand"]
 *         list segments    = []             # <<<<<<<<<<<<<<
 *         long chrom_start = attr["chrom_start"]
 * 
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 720, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_segments = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":721
 *         str  strand      = attr["strand"]
 *         list segments    = []
 *         long chrom_start = attr["chrom_start"]             # <<<<<<<<<<<<<<
 * 
 *     # convert blocks to GenomicSegments
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 721, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_chrom_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 721, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 721, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_chrom_start = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":724
 * 
 *     # convert blocks to GenomicSegments
 *     num_frags   = int(attr["blocks"])             # <<<<<<<<<<<<<<
 *     seg_sizes   = attr["blocksizes"].strip(",").split(",")
 *     seg_offsets = attr["blockstarts"].strip(",").split(",")
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 724, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_blocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 724, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 724, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_num_frags = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":725
 *     # convert blocks to GenomicSegments
 *     num_frags   = int(attr["blocks"])
 *     seg_sizes   = attr["blocksizes"].strip(",").split(",")             # <<<<<<<<<<<<<<
 *     seg_offsets = attr["blockstarts"].strip(",").split(",")
 *     for i in range(0,num_frags):
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 725, __pyx_L1_error)
  }
  __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_blocksizes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 725, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_strip); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 725, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_kp_u__3) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u__3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 725, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_split); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 725, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_1, __pyx_kp_u__3) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u__3);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 725, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_seg_sizes = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":726
 *     num_frags   = int(attr["blocks"])
 *     seg_sizes   = attr["blocksizes"].strip(",").split(",")
 *     seg_offsets = attr["blockstarts"].strip(",").split(",")             # <<<<<<<<<<<<<<
 *     for i in range(0,num_frags):
 *         seg_start = chrom_start + int(seg_offsets[i])
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 726, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_blockstarts); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 726, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_strip); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 726, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_kp_u__3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u__3);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 726, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_split); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 726, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_kp_u__3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u__3);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 726, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_seg_offsets = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":727
 *     seg_sizes   = attr["blocksizes"].strip(",").split(",")
 *     seg_offsets = attr["blockstarts"].strip(",").split(",")
 *     for i in range(0,num_frags):             # <<<<<<<<<<<<<<
 *         seg_start = chrom_start + int(seg_offsets[i])
 *         seg_end   = seg_start   + int(seg_sizes[i])
 */
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 727, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_0);
  __Pyx_INCREF(__pyx_v_num_frags);
  __Pyx_GIVEREF(__pyx_v_num_frags);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_num_frags);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 727, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_3 = __pyx_t_4; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 727, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 727, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 727, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 727, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 727, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_7(__pyx_t_3);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 727, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":728
 *     seg_offsets = attr["blockstarts"].strip(",").split(",")
 *     for i in range(0,num_frags):
 *         seg_start = chrom_start + int(seg_offsets[i])             # <<<<<<<<<<<<<<
 *         seg_end   = seg_start   + int(seg_sizes[i])
 *         segments.append(GenomicSegment(chrom, seg_start, seg_end, strand))
 */
    __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_chrom_start); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 728, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_seg_offsets, __pyx_v_i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 728, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 728, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 728, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_seg_start, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":729
 *     for i in range(0,num_frags):
 *         seg_start = chrom_start + int(seg_offsets[i])
 *         seg_end   = seg_start   + int(seg_sizes[i])             # <<<<<<<<<<<<<<
 *         segments.append(GenomicSegment(chrom, seg_start, seg_end, strand))
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_seg_sizes, __pyx_v_i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 729, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 729, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_Add(__pyx_v_seg_start, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 729, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_seg_end, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":730
 *         seg_start = chrom_start + int(seg_offsets[i])
 *         seg_end   = seg_start   + int(seg_sizes[i])
 *         segments.append(GenomicSegment(chrom, seg_start, seg_end, strand))             # <<<<<<<<<<<<<<
 * 
 *     # clean up attr
 */
    __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_chrom);
    __Pyx_GIVEREF(__pyx_v_chrom);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_chrom);
    __Pyx_INCREF(__pyx_v_seg_start);
    __Pyx_GIVEREF(__pyx_v_seg_start);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_seg_start);
    __Pyx_INCREF(__pyx_v_seg_end);
    __Pyx_GIVEREF(__pyx_v_seg_end);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_seg_end);
    __Pyx_INCREF(__pyx_v_strand);
    __Pyx_GIVEREF(__pyx_v_strand);
    PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_strand);
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_segments, __pyx_t_1); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 730, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":727
 *     seg_sizes   = attr["blocksizes"].strip(",").split(",")
 *     seg_offsets = attr["blockstarts"].strip(",").split(",")
 *     for i in range(0,num_frags):             # <<<<<<<<<<<<<<
 *         seg_start = chrom_start + int(seg_offsets[i])
 *         seg_end   = seg_start   + int(seg_sizes[i])
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":733
 * 
 *     # clean up attr
 *     for key in ("blocks", "blocksizes", "blockstarts", "chrom_start", "strand", "chrom"):             # <<<<<<<<<<<<<<
 *         attr.pop(key)
 * 
 */
  __pyx_t_3 = __pyx_tuple__22; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0;
  for (;;) {
    if (__pyx_t_6 >= 6) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 733, __pyx_L1_error)
    #else
    __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 733, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_key, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":734
 *     # clean up attr
 *     for key in ("blocks", "blocksizes", "blockstarts", "chrom_start", "strand", "chrom"):
 *         attr.pop(key)             # <<<<<<<<<<<<<<
 * 
 *     return segments
 */
    if (unlikely(__pyx_v_attr == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "pop");
      __PYX_ERR(0, 734, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_PyDict_Pop(__pyx_v_attr, __pyx_v_key, ((PyObject *)NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 734, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":733
 * 
 *     # clean up attr
 *     for key in ("blocks", "blocksizes", "blockstarts", "chrom_start", "strand", "chrom"):             # <<<<<<<<<<<<<<
 *         attr.pop(key)
 * 
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":736
 *         attr.pop(key)
 * 
 *     return segments             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_segments);
  __pyx_r = __pyx_v_segments;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":711
 *     return attr
 * 
 * cdef list get_segments_from_bed(dict attr):             # <<<<<<<<<<<<<<
 *     """Construct a list of |GenomicSegments| given a dictionary of attributes,
 *     as made from :meth:`get_attr_from_bed` or other methods above. i.e.  `attr`
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.get_segments_from_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_strand);
  __Pyx_XDECREF(__pyx_v_segments);
  __Pyx_XDECREF(__pyx_v_num_frags);
  __Pyx_XDECREF(__pyx_v_seg_sizes);
  __Pyx_XDECREF(__pyx_v_seg_offsets);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_seg_start);
  __Pyx_XDECREF(__pyx_v_seg_end);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":743
 * #==============================================================================
 * 
 * cdef void nonecheck(object obj, str place, str valname):             # <<<<<<<<<<<<<<
 *     """Propagate errors if incoming objects are None"""
 *     if obj is None:
 */

static void __pyx_f_7plastid_8genomics_8roitools_nonecheck(PyObject *__pyx_v_obj, PyObject *__pyx_v_place, PyObject *__pyx_v_valname) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  Py_UCS4 __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("nonecheck", 0);

  /* "plastid/genomics/roitools.pyx":745
 * cdef void nonecheck(object obj, str place, str valname):
 *     """Propagate errors if incoming objects are None"""
 *     if obj is None:             # <<<<<<<<<<<<<<
 *         raise ValueError("%s: value of %s cannot be None" % (place, valname))
 * 
 */
  __pyx_t_1 = (__pyx_v_obj == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (unlikely(__pyx_t_2)) {

    /* "plastid/genomics/roitools.pyx":746
 *     """Propagate errors if incoming objects are None"""
 *     if obj is None:
 *         raise ValueError("%s: value of %s cannot be None" % (place, valname))             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 746, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = 0;
    __pyx_t_5 = 127;
    __pyx_t_6 = __Pyx_PyUnicode_Unicode(__pyx_v_place); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 746, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_5) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_5;
    __pyx_t_4 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_INCREF(__pyx_kp_u_value_of);
    __pyx_t_4 += 11;
    __Pyx_GIVEREF(__pyx_kp_u_value_of);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_u_value_of);
    __pyx_t_6 = __Pyx_PyUnicode_Unicode(__pyx_v_valname); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 746, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_5) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_5;
    __pyx_t_4 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_INCREF(__pyx_kp_u_cannot_be_None);
    __pyx_t_4 += 15;
    __Pyx_GIVEREF(__pyx_kp_u_cannot_be_None);
    PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_kp_u_cannot_be_None);
    __pyx_t_6 = __Pyx_PyUnicode_Join(__pyx_t_3, 4, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 746, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 746, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 746, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":745
 * cdef void nonecheck(object obj, str place, str valname):
 *     """Propagate errors if incoming objects are None"""
 *     if obj is None:             # <<<<<<<<<<<<<<
 *         raise ValueError("%s: value of %s cannot be None" % (place, valname))
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":743
 * #==============================================================================
 * 
 * cdef void nonecheck(object obj, str place, str valname):             # <<<<<<<<<<<<<<
 *     """Propagate errors if incoming objects are None"""
 *     if obj is None:
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_WriteUnraisable("plastid.genomics.roitools.nonecheck", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "plastid/genomics/roitools.pyx":749
 * 
 * 
 * cdef bint check_segments(SegmentChain chain, tuple segments) except False:             # <<<<<<<<<<<<<<
 *     cdef:
 *         GenomicSegment seg, seg0
 */

static int __pyx_f_7plastid_8genomics_8roitools_check_segments(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_chain, PyObject *__pyx_v_segments) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_seg = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_seg0 = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_span = 0;
  PyObject *__pyx_v_my_chrom = 0;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_v_my_strand;
  int __pyx_v_i;
  int __pyx_v_length;
  int __pyx_v_prob;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_8genexpr4__pyx_v_X = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("check_segments", 0);

  /* "plastid/genomics/roitools.pyx":752
 *     cdef:
 *         GenomicSegment seg, seg0
 *         GenomicSegment span = chain.spanning_segment             # <<<<<<<<<<<<<<
 *         str my_chrom  = span.chrom
 *         Strand my_strand = span.c_strand
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_chain->spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_span = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":753
 *         GenomicSegment seg, seg0
 *         GenomicSegment span = chain.spanning_segment
 *         str my_chrom  = span.chrom             # <<<<<<<<<<<<<<
 *         Strand my_strand = span.c_strand
 *         int i = 0
 */
  __pyx_t_1 = __pyx_v_span->chrom;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_my_chrom = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":754
 *         GenomicSegment span = chain.spanning_segment
 *         str my_chrom  = span.chrom
 *         Strand my_strand = span.c_strand             # <<<<<<<<<<<<<<
 *         int i = 0
 *         int length = len(segments)
 */
  __pyx_t_2 = __pyx_v_span->c_strand;
  __pyx_v_my_strand = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":755
 *         str my_chrom  = span.chrom
 *         Strand my_strand = span.c_strand
 *         int i = 0             # <<<<<<<<<<<<<<
 *         int length = len(segments)
 *         bint prob = False
 */
  __pyx_v_i = 0;

  /* "plastid/genomics/roitools.pyx":756
 *         Strand my_strand = span.c_strand
 *         int i = 0
 *         int length = len(segments)             # <<<<<<<<<<<<<<
 *         bint prob = False
 * 
 */
  if (unlikely(__pyx_v_segments == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 756, __pyx_L1_error)
  }
  __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v_segments); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 756, __pyx_L1_error)
  __pyx_v_length = __pyx_t_3;

  /* "plastid/genomics/roitools.pyx":757
 *         int i = 0
 *         int length = len(segments)
 *         bint prob = False             # <<<<<<<<<<<<<<
 * 
 *     if length > 0:
 */
  __pyx_v_prob = 0;

  /* "plastid/genomics/roitools.pyx":759
 *         bint prob = False
 * 
 *     if length > 0:             # <<<<<<<<<<<<<<
 *         msg = "SegmentChain.add_segments: incoming segments (%s) mismatch chain '%s'"
 *         seg0 = segments[0]
 */
  __pyx_t_4 = ((__pyx_v_length > 0) != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":760
 * 
 *     if length > 0:
 *         msg = "SegmentChain.add_segments: incoming segments (%s) mismatch chain '%s'"             # <<<<<<<<<<<<<<
 *         seg0 = segments[0]
 *         if len(chain._segments) == 0:
 */
    __Pyx_INCREF(__pyx_kp_u_SegmentChain_add_segments_incomi);
    __pyx_v_msg = __pyx_kp_u_SegmentChain_add_segments_incomi;

    /* "plastid/genomics/roitools.pyx":761
 *     if length > 0:
 *         msg = "SegmentChain.add_segments: incoming segments (%s) mismatch chain '%s'"
 *         seg0 = segments[0]             # <<<<<<<<<<<<<<
 *         if len(chain._segments) == 0:
 *             my_chrom  = seg0.chrom
 */
    if (unlikely(__pyx_v_segments == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 761, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_segments, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 761, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 761, __pyx_L1_error)
    __pyx_v_seg0 = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":762
 *         msg = "SegmentChain.add_segments: incoming segments (%s) mismatch chain '%s'"
 *         seg0 = segments[0]
 *         if len(chain._segments) == 0:             # <<<<<<<<<<<<<<
 *             my_chrom  = seg0.chrom
 *             my_strand = seg0.c_strand
 */
    __pyx_t_1 = __pyx_v_chain->_segments;
    __Pyx_INCREF(__pyx_t_1);
    if (unlikely(__pyx_t_1 == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 762, __pyx_L1_error)
    }
    __pyx_t_3 = PyList_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 762, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = ((__pyx_t_3 == 0) != 0);
    if (__pyx_t_4) {

      /* "plastid/genomics/roitools.pyx":763
 *         seg0 = segments[0]
 *         if len(chain._segments) == 0:
 *             my_chrom  = seg0.chrom             # <<<<<<<<<<<<<<
 *             my_strand = seg0.c_strand
 * 
 */
      __pyx_t_1 = __pyx_v_seg0->chrom;
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_DECREF_SET(__pyx_v_my_chrom, ((PyObject*)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":764
 *         if len(chain._segments) == 0:
 *             my_chrom  = seg0.chrom
 *             my_strand = seg0.c_strand             # <<<<<<<<<<<<<<
 * 
 *         while i < length:
 */
      __pyx_t_2 = __pyx_v_seg0->c_strand;
      __pyx_v_my_strand = __pyx_t_2;

      /* "plastid/genomics/roitools.pyx":762
 *         msg = "SegmentChain.add_segments: incoming segments (%s) mismatch chain '%s'"
 *         seg0 = segments[0]
 *         if len(chain._segments) == 0:             # <<<<<<<<<<<<<<
 *             my_chrom  = seg0.chrom
 *             my_strand = seg0.c_strand
 */
    }

    /* "plastid/genomics/roitools.pyx":766
 *             my_strand = seg0.c_strand
 * 
 *         while i < length:             # <<<<<<<<<<<<<<
 *             seg = segments[i]
 *             if seg.chrom != my_chrom:
 */
    while (1) {
      __pyx_t_4 = ((__pyx_v_i < __pyx_v_length) != 0);
      if (!__pyx_t_4) break;

      /* "plastid/genomics/roitools.pyx":767
 * 
 *         while i < length:
 *             seg = segments[i]             # <<<<<<<<<<<<<<
 *             if seg.chrom != my_chrom:
 *                 msg += "; wrong and/or multiple chromosomes"
 */
      if (unlikely(__pyx_v_segments == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 767, __pyx_L1_error)
      }
      __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_segments, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 767, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 767, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_seg, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":768
 *         while i < length:
 *             seg = segments[i]
 *             if seg.chrom != my_chrom:             # <<<<<<<<<<<<<<
 *                 msg += "; wrong and/or multiple chromosomes"
 *                 prob = True
 */
      __pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_v_seg->chrom, __pyx_v_my_chrom, Py_NE)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 768, __pyx_L1_error)
      __pyx_t_5 = (__pyx_t_4 != 0);
      if (__pyx_t_5) {

        /* "plastid/genomics/roitools.pyx":769
 *             seg = segments[i]
 *             if seg.chrom != my_chrom:
 *                 msg += "; wrong and/or multiple chromosomes"             # <<<<<<<<<<<<<<
 *                 prob = True
 *                 break
 */
        __pyx_t_1 = __Pyx_PyUnicode_Concat(__pyx_v_msg, __pyx_kp_u_wrong_and_or_multiple_chromosom); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 769, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF_SET(__pyx_v_msg, ((PyObject*)__pyx_t_1));
        __pyx_t_1 = 0;

        /* "plastid/genomics/roitools.pyx":770
 *             if seg.chrom != my_chrom:
 *                 msg += "; wrong and/or multiple chromosomes"
 *                 prob = True             # <<<<<<<<<<<<<<
 *                 break
 * 
 */
        __pyx_v_prob = 1;

        /* "plastid/genomics/roitools.pyx":771
 *                 msg += "; wrong and/or multiple chromosomes"
 *                 prob = True
 *                 break             # <<<<<<<<<<<<<<
 * 
 *             if seg.c_strand != my_strand:
 */
        goto __pyx_L6_break;

        /* "plastid/genomics/roitools.pyx":768
 *         while i < length:
 *             seg = segments[i]
 *             if seg.chrom != my_chrom:             # <<<<<<<<<<<<<<
 *                 msg += "; wrong and/or multiple chromosomes"
 *                 prob = True
 */
      }

      /* "plastid/genomics/roitools.pyx":773
 *                 break
 * 
 *             if seg.c_strand != my_strand:             # <<<<<<<<<<<<<<
 *                 msg += "; wrong and/or multiple strands"
 *                 prob = True
 */
      __pyx_t_5 = ((__pyx_v_seg->c_strand != __pyx_v_my_strand) != 0);
      if (__pyx_t_5) {

        /* "plastid/genomics/roitools.pyx":774
 * 
 *             if seg.c_strand != my_strand:
 *                 msg += "; wrong and/or multiple strands"             # <<<<<<<<<<<<<<
 *                 prob = True
 *                 break
 */
        __pyx_t_1 = __Pyx_PyUnicode_Concat(__pyx_v_msg, __pyx_kp_u_wrong_and_or_multiple_strands); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 774, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF_SET(__pyx_v_msg, ((PyObject*)__pyx_t_1));
        __pyx_t_1 = 0;

        /* "plastid/genomics/roitools.pyx":775
 *             if seg.c_strand != my_strand:
 *                 msg += "; wrong and/or multiple strands"
 *                 prob = True             # <<<<<<<<<<<<<<
 *                 break
 * 
 */
        __pyx_v_prob = 1;

        /* "plastid/genomics/roitools.pyx":776
 *                 msg += "; wrong and/or multiple strands"
 *                 prob = True
 *                 break             # <<<<<<<<<<<<<<
 * 
 *             i += 1
 */
        goto __pyx_L6_break;

        /* "plastid/genomics/roitools.pyx":773
 *                 break
 * 
 *             if seg.c_strand != my_strand:             # <<<<<<<<<<<<<<
 *                 msg += "; wrong and/or multiple strands"
 *                 prob = True
 */
      }

      /* "plastid/genomics/roitools.pyx":778
 *                 break
 * 
 *             i += 1             # <<<<<<<<<<<<<<
 * 
 *         if prob == True:
 */
      __pyx_v_i = (__pyx_v_i + 1);
    }
    __pyx_L6_break:;

    /* "plastid/genomics/roitools.pyx":780
 *             i += 1
 * 
 *         if prob == True:             # <<<<<<<<<<<<<<
 *             msg = msg % (", ".join([str(X) for X in segments]), chain)
 *             raise ValueError(msg)
 */
    __pyx_t_5 = ((__pyx_v_prob == 1) != 0);
    if (unlikely(__pyx_t_5)) {

      /* "plastid/genomics/roitools.pyx":781
 * 
 *         if prob == True:
 *             msg = msg % (", ".join([str(X) for X in segments]), chain)             # <<<<<<<<<<<<<<
 *             raise ValueError(msg)
 * 
 */
      { /* enter inner scope */
        __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 781, __pyx_L12_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(__pyx_v_segments == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 781, __pyx_L12_error)
        }
        __pyx_t_6 = __pyx_v_segments; __Pyx_INCREF(__pyx_t_6); __pyx_t_3 = 0;
        for (;;) {
          if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 781, __pyx_L12_error)
          #else
          __pyx_t_7 = PySequence_ITEM(__pyx_t_6, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 781, __pyx_L12_error)
          __Pyx_GOTREF(__pyx_t_7);
          #endif
          __Pyx_XDECREF_SET(__pyx_8genexpr4__pyx_v_X, __pyx_t_7);
          __pyx_t_7 = 0;
          __pyx_t_7 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_8genexpr4__pyx_v_X); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 781, __pyx_L12_error)
          __Pyx_GOTREF(__pyx_t_7);
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 781, __pyx_L12_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        }
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_8genexpr4__pyx_v_X); __pyx_8genexpr4__pyx_v_X = 0;
        goto __pyx_L15_exit_scope;
        __pyx_L12_error:;
        __Pyx_XDECREF(__pyx_8genexpr4__pyx_v_X); __pyx_8genexpr4__pyx_v_X = 0;
        goto __pyx_L1_error;
        __pyx_L15_exit_scope:;
      } /* exit inner scope */
      __pyx_t_6 = PyUnicode_Join(__pyx_kp_u__5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 781, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 781, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6);
      __Pyx_INCREF(((PyObject *)__pyx_v_chain));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_chain));
      PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_chain));
      __pyx_t_6 = 0;
      __pyx_t_6 = PyUnicode_Format(__pyx_v_msg, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 781, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF_SET(__pyx_v_msg, ((PyObject*)__pyx_t_6));
      __pyx_t_6 = 0;

      /* "plastid/genomics/roitools.pyx":782
 *         if prob == True:
 *             msg = msg % (", ".join([str(X) for X in segments]), chain)
 *             raise ValueError(msg)             # <<<<<<<<<<<<<<
 * 
 *     return True
 */
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_v_msg); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 782, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __PYX_ERR(0, 782, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":780
 *             i += 1
 * 
 *         if prob == True:             # <<<<<<<<<<<<<<
 *             msg = msg % (", ".join([str(X) for X in segments]), chain)
 *             raise ValueError(msg)
 */
    }

    /* "plastid/genomics/roitools.pyx":759
 *         bint prob = False
 * 
 *     if length > 0:             # <<<<<<<<<<<<<<
 *         msg = "SegmentChain.add_segments: incoming segments (%s) mismatch chain '%s'"
 *         seg0 = segments[0]
 */
  }

  /* "plastid/genomics/roitools.pyx":784
 *             raise ValueError(msg)
 * 
 *     return True             # <<<<<<<<<<<<<<
 * 
 * cdef ExBool chain_richcmp(SegmentChain chain1, SegmentChain chain2, int cmpval) except bool_exception:
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":749
 * 
 * 
 * cdef bint check_segments(SegmentChain chain, tuple segments) except False:             # <<<<<<<<<<<<<<
 *     cdef:
 *         GenomicSegment seg, seg0
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.check_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_seg);
  __Pyx_XDECREF((PyObject *)__pyx_v_seg0);
  __Pyx_XDECREF((PyObject *)__pyx_v_span);
  __Pyx_XDECREF(__pyx_v_my_chrom);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_8genexpr4__pyx_v_X);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":786
 *     return True
 * 
 * cdef ExBool chain_richcmp(SegmentChain chain1, SegmentChain chain2, int cmpval) except bool_exception:             # <<<<<<<<<<<<<<
 *     """Helper method for rich comparisons (==, !=, <, >, <=, >=) of |SegmentChains|
 * 
 */

static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_chain1, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_chain2, int __pyx_v_cmpval) {
  PyObject *__pyx_v_sspan = 0;
  PyObject *__pyx_v_ospan = 0;
  PyObject *__pyx_v_sname = 0;
  PyObject *__pyx_v_oname = 0;
  long __pyx_v_slen;
  long __pyx_v_olen;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_7;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_8;
  long __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("chain_richcmp", 0);

  /* "plastid/genomics/roitools.pyx":819
 *     """
 *     cdef:
 *         sspan = chain1.spanning_segment             # <<<<<<<<<<<<<<
 *         ospan = chain2.spanning_segment
 *         str sname, oname
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_chain1->spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_sspan = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":820
 *     cdef:
 *         sspan = chain1.spanning_segment
 *         ospan = chain2.spanning_segment             # <<<<<<<<<<<<<<
 *         str sname, oname
 *         long slen, olen
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_chain2->spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_ospan = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":824
 *         long slen, olen
 * 
 *     if cmpval == EQ:             # <<<<<<<<<<<<<<
 *         if len(chain1) == 0 or len(chain2) == 0:
 *             return false
 */
  switch (__pyx_v_cmpval) {
    case 2:

    /* "plastid/genomics/roitools.pyx":825
 * 
 *     if cmpval == EQ:
 *         if len(chain1) == 0 or len(chain2) == 0:             # <<<<<<<<<<<<<<
 *             return false
 *         else:
 */
    __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_chain1)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 825, __pyx_L1_error)
    __pyx_t_4 = ((__pyx_t_3 == 0) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L4_bool_binop_done;
    }
    __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_chain2)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 825, __pyx_L1_error)
    __pyx_t_4 = ((__pyx_t_3 == 0) != 0);
    __pyx_t_2 = __pyx_t_4;
    __pyx_L4_bool_binop_done:;
    if (__pyx_t_2) {

      /* "plastid/genomics/roitools.pyx":826
 *     if cmpval == EQ:
 *         if len(chain1) == 0 or len(chain2) == 0:
 *             return false             # <<<<<<<<<<<<<<
 *         else:
 *             if sspan.chrom == ospan.chrom and\
 */
      __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
      goto __pyx_L0;

      /* "plastid/genomics/roitools.pyx":825
 * 
 *     if cmpval == EQ:
 *         if len(chain1) == 0 or len(chain2) == 0:             # <<<<<<<<<<<<<<
 *             return false
 *         else:
 */
    }

    /* "plastid/genomics/roitools.pyx":828
 *             return false
 *         else:
 *             if sspan.chrom == ospan.chrom and\             # <<<<<<<<<<<<<<
 *                sspan.c_strand == ospan.c_strand and\
 *                chain1._segments == chain2._segments:
 */
    /*else*/ {
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_sspan, __pyx_n_s_chrom); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 828, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_ospan, __pyx_n_s_chrom); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 828, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 828, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 828, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_4) {
      } else {
        __pyx_t_2 = __pyx_t_4;
        goto __pyx_L7_bool_binop_done;
      }

      /* "plastid/genomics/roitools.pyx":829
 *         else:
 *             if sspan.chrom == ospan.chrom and\
 *                sspan.c_strand == ospan.c_strand and\             # <<<<<<<<<<<<<<
 *                chain1._segments == chain2._segments:
 *                     return true
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_sspan, __pyx_n_s_c_strand); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 829, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_ospan, __pyx_n_s_c_strand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 829, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 829, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 829, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_4) {
      } else {
        __pyx_t_2 = __pyx_t_4;
        goto __pyx_L7_bool_binop_done;
      }

      /* "plastid/genomics/roitools.pyx":830
 *             if sspan.chrom == ospan.chrom and\
 *                sspan.c_strand == ospan.c_strand and\
 *                chain1._segments == chain2._segments:             # <<<<<<<<<<<<<<
 *                     return true
 *             return false
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_chain1->_segments, __pyx_v_chain2->_segments, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 830, __pyx_L1_error)
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 830, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_2 = __pyx_t_4;
      __pyx_L7_bool_binop_done:;

      /* "plastid/genomics/roitools.pyx":828
 *             return false
 *         else:
 *             if sspan.chrom == ospan.chrom and\             # <<<<<<<<<<<<<<
 *                sspan.c_strand == ospan.c_strand and\
 *                chain1._segments == chain2._segments:
 */
      if (__pyx_t_2) {

        /* "plastid/genomics/roitools.pyx":831
 *                sspan.c_strand == ospan.c_strand and\
 *                chain1._segments == chain2._segments:
 *                     return true             # <<<<<<<<<<<<<<
 *             return false
 *     elif cmpval == NEQ:
 */
        __pyx_r = __pyx_e_7plastid_8genomics_8c_common_true;
        goto __pyx_L0;

        /* "plastid/genomics/roitools.pyx":828
 *             return false
 *         else:
 *             if sspan.chrom == ospan.chrom and\             # <<<<<<<<<<<<<<
 *                sspan.c_strand == ospan.c_strand and\
 *                chain1._segments == chain2._segments:
 */
      }

      /* "plastid/genomics/roitools.pyx":832
 *                chain1._segments == chain2._segments:
 *                     return true
 *             return false             # <<<<<<<<<<<<<<
 *     elif cmpval == NEQ:
 *         return true if chain_richcmp(chain1, chain2, EQ) == false else true
 */
      __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
      goto __pyx_L0;
    }

    /* "plastid/genomics/roitools.pyx":824
 *         long slen, olen
 * 
 *     if cmpval == EQ:             # <<<<<<<<<<<<<<
 *         if len(chain1) == 0 or len(chain2) == 0:
 *             return false
 */
    break;
    case 3:

    /* "plastid/genomics/roitools.pyx":834
 *             return false
 *     elif cmpval == NEQ:
 *         return true if chain_richcmp(chain1, chain2, EQ) == false else true             # <<<<<<<<<<<<<<
 *     elif cmpval == LT:
 *         if sspan < ospan:
 */
    __pyx_t_8 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(__pyx_v_chain1, __pyx_v_chain2, 2); if (unlikely(__pyx_t_8 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 834, __pyx_L1_error)
    if (((__pyx_t_8 == __pyx_e_7plastid_8genomics_8c_common_false) != 0)) {
      __pyx_t_7 = __pyx_e_7plastid_8genomics_8c_common_true;
    } else {
      __pyx_t_7 = __pyx_e_7plastid_8genomics_8c_common_true;
    }
    __pyx_r = __pyx_t_7;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":833
 *                     return true
 *             return false
 *     elif cmpval == NEQ:             # <<<<<<<<<<<<<<
 *         return true if chain_richcmp(chain1, chain2, EQ) == false else true
 *     elif cmpval == LT:
 */
    break;
    case 0:

    /* "plastid/genomics/roitools.pyx":836
 *         return true if chain_richcmp(chain1, chain2, EQ) == false else true
 *     elif cmpval == LT:
 *         if sspan < ospan:             # <<<<<<<<<<<<<<
 *             return true
 *         elif sspan > ospan:
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_sspan, __pyx_v_ospan, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 836, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 836, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {

      /* "plastid/genomics/roitools.pyx":837
 *     elif cmpval == LT:
 *         if sspan < ospan:
 *             return true             # <<<<<<<<<<<<<<
 *         elif sspan > ospan:
 *             return false
 */
      __pyx_r = __pyx_e_7plastid_8genomics_8c_common_true;
      goto __pyx_L0;

      /* "plastid/genomics/roitools.pyx":836
 *         return true if chain_richcmp(chain1, chain2, EQ) == false else true
 *     elif cmpval == LT:
 *         if sspan < ospan:             # <<<<<<<<<<<<<<
 *             return true
 *         elif sspan > ospan:
 */
    }

    /* "plastid/genomics/roitools.pyx":838
 *         if sspan < ospan:
 *             return true
 *         elif sspan > ospan:             # <<<<<<<<<<<<<<
 *             return false
 *         else:
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_sspan, __pyx_v_ospan, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 838, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 838, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {

      /* "plastid/genomics/roitools.pyx":839
 *             return true
 *         elif sspan > ospan:
 *             return false             # <<<<<<<<<<<<<<
 *         else:
 *             slen = chain1.length
 */
      __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
      goto __pyx_L0;

      /* "plastid/genomics/roitools.pyx":838
 *         if sspan < ospan:
 *             return true
 *         elif sspan > ospan:             # <<<<<<<<<<<<<<
 *             return false
 *         else:
 */
    }

    /* "plastid/genomics/roitools.pyx":841
 *             return false
 *         else:
 *             slen = chain1.length             # <<<<<<<<<<<<<<
 *             olen = chain2.length
 *             if slen < olen:
 */
    /*else*/ {
      __pyx_t_9 = __pyx_v_chain1->length;
      __pyx_v_slen = __pyx_t_9;

      /* "plastid/genomics/roitools.pyx":842
 *         else:
 *             slen = chain1.length
 *             olen = chain2.length             # <<<<<<<<<<<<<<
 *             if slen < olen:
 *                 return true
 */
      __pyx_t_9 = __pyx_v_chain2->length;
      __pyx_v_olen = __pyx_t_9;

      /* "plastid/genomics/roitools.pyx":843
 *             slen = chain1.length
 *             olen = chain2.length
 *             if slen < olen:             # <<<<<<<<<<<<<<
 *                 return true
 *             elif slen > olen:
 */
      __pyx_t_2 = ((__pyx_v_slen < __pyx_v_olen) != 0);
      if (__pyx_t_2) {

        /* "plastid/genomics/roitools.pyx":844
 *             olen = chain2.length
 *             if slen < olen:
 *                 return true             # <<<<<<<<<<<<<<
 *             elif slen > olen:
 *                 return false
 */
        __pyx_r = __pyx_e_7plastid_8genomics_8c_common_true;
        goto __pyx_L0;

        /* "plastid/genomics/roitools.pyx":843
 *             slen = chain1.length
 *             olen = chain2.length
 *             if slen < olen:             # <<<<<<<<<<<<<<
 *                 return true
 *             elif slen > olen:
 */
      }

      /* "plastid/genomics/roitools.pyx":845
 *             if slen < olen:
 *                 return true
 *             elif slen > olen:             # <<<<<<<<<<<<<<
 *                 return false
 *             else:
 */
      __pyx_t_2 = ((__pyx_v_slen > __pyx_v_olen) != 0);
      if (__pyx_t_2) {

        /* "plastid/genomics/roitools.pyx":846
 *                 return true
 *             elif slen > olen:
 *                 return false             # <<<<<<<<<<<<<<
 *             else:
 *                 sname = chain1.get_name()
 */
        __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
        goto __pyx_L0;

        /* "plastid/genomics/roitools.pyx":845
 *             if slen < olen:
 *                 return true
 *             elif slen > olen:             # <<<<<<<<<<<<<<
 *                 return false
 *             else:
 */
      }

      /* "plastid/genomics/roitools.pyx":848
 *                 return false
 *             else:
 *                 sname = chain1.get_name()             # <<<<<<<<<<<<<<
 *                 oname = chain2.get_name()
 *                 if sname < oname:
 */
      /*else*/ {
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_chain1), __pyx_n_s_get_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 848, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
          }
        }
        __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 848, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 848, __pyx_L1_error)
        __pyx_v_sname = ((PyObject*)__pyx_t_1);
        __pyx_t_1 = 0;

        /* "plastid/genomics/roitools.pyx":849
 *             else:
 *                 sname = chain1.get_name()
 *                 oname = chain2.get_name()             # <<<<<<<<<<<<<<
 *                 if sname < oname:
 *                     return true
 */
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_chain2), __pyx_n_s_get_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 849, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
          }
        }
        __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 849, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 849, __pyx_L1_error)
        __pyx_v_oname = ((PyObject*)__pyx_t_1);
        __pyx_t_1 = 0;

        /* "plastid/genomics/roitools.pyx":850
 *                 sname = chain1.get_name()
 *                 oname = chain2.get_name()
 *                 if sname < oname:             # <<<<<<<<<<<<<<
 *                     return true
 *                 else:
 */
        __pyx_t_1 = PyObject_RichCompare(__pyx_v_sname, __pyx_v_oname, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 850, __pyx_L1_error)
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 850, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (__pyx_t_2) {

          /* "plastid/genomics/roitools.pyx":851
 *                 oname = chain2.get_name()
 *                 if sname < oname:
 *                     return true             # <<<<<<<<<<<<<<
 *                 else:
 *                     return false
 */
          __pyx_r = __pyx_e_7plastid_8genomics_8c_common_true;
          goto __pyx_L0;

          /* "plastid/genomics/roitools.pyx":850
 *                 sname = chain1.get_name()
 *                 oname = chain2.get_name()
 *                 if sname < oname:             # <<<<<<<<<<<<<<
 *                     return true
 *                 else:
 */
        }

        /* "plastid/genomics/roitools.pyx":853
 *                     return true
 *                 else:
 *                     return false             # <<<<<<<<<<<<<<
 *     elif cmpval == LEQ:
 *         return true if chain_richcmp(chain1, chain2, LT) == true \
 */
        /*else*/ {
          __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
          goto __pyx_L0;
        }
      }
    }

    /* "plastid/genomics/roitools.pyx":835
 *     elif cmpval == NEQ:
 *         return true if chain_richcmp(chain1, chain2, EQ) == false else true
 *     elif cmpval == LT:             # <<<<<<<<<<<<<<
 *         if sspan < ospan:
 *             return true
 */
    break;
    case 1:

    /* "plastid/genomics/roitools.pyx":855
 *                     return false
 *     elif cmpval == LEQ:
 *         return true if chain_richcmp(chain1, chain2, LT) == true \             # <<<<<<<<<<<<<<
 *                     or chain_richcmp(chain1, chain2, EQ) == true \
 *                     else false
 */
    __pyx_t_8 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(__pyx_v_chain1, __pyx_v_chain2, 0); if (unlikely(__pyx_t_8 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 855, __pyx_L1_error)
    __pyx_t_4 = ((__pyx_t_8 == __pyx_e_7plastid_8genomics_8c_common_true) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L13_bool_binop_done;
    }

    /* "plastid/genomics/roitools.pyx":856
 *     elif cmpval == LEQ:
 *         return true if chain_richcmp(chain1, chain2, LT) == true \
 *                     or chain_richcmp(chain1, chain2, EQ) == true \             # <<<<<<<<<<<<<<
 *                     else false
 *     elif cmpval == GT:
 */
    __pyx_t_8 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(__pyx_v_chain1, __pyx_v_chain2, 2); if (unlikely(__pyx_t_8 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 856, __pyx_L1_error)
    __pyx_t_4 = ((__pyx_t_8 == __pyx_e_7plastid_8genomics_8c_common_true) != 0);
    __pyx_t_2 = __pyx_t_4;
    __pyx_L13_bool_binop_done:;
    if (__pyx_t_2) {

      /* "plastid/genomics/roitools.pyx":855
 *                     return false
 *     elif cmpval == LEQ:
 *         return true if chain_richcmp(chain1, chain2, LT) == true \             # <<<<<<<<<<<<<<
 *                     or chain_richcmp(chain1, chain2, EQ) == true \
 *                     else false
 */
      __pyx_t_7 = __pyx_e_7plastid_8genomics_8c_common_true;
    } else {

      /* "plastid/genomics/roitools.pyx":857
 *         return true if chain_richcmp(chain1, chain2, LT) == true \
 *                     or chain_richcmp(chain1, chain2, EQ) == true \
 *                     else false             # <<<<<<<<<<<<<<
 *     elif cmpval == GT:
 *         return chain_richcmp(chain2,chain1,LT)
 */
      __pyx_t_7 = __pyx_e_7plastid_8genomics_8c_common_false;
    }
    __pyx_r = __pyx_t_7;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":854
 *                 else:
 *                     return false
 *     elif cmpval == LEQ:             # <<<<<<<<<<<<<<
 *         return true if chain_richcmp(chain1, chain2, LT) == true \
 *                     or chain_richcmp(chain1, chain2, EQ) == true \
 */
    break;
    case 4:

    /* "plastid/genomics/roitools.pyx":859
 *                     else false
 *     elif cmpval == GT:
 *         return chain_richcmp(chain2,chain1,LT)             # <<<<<<<<<<<<<<
 *     elif cmpval == GEQ:
 *         return true if chain_richcmp(chain2, chain1, LT) == true \
 */
    __pyx_t_7 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(__pyx_v_chain2, __pyx_v_chain1, 0); if (unlikely(__pyx_t_7 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 859, __pyx_L1_error)
    __pyx_r = __pyx_t_7;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":858
 *                     or chain_richcmp(chain1, chain2, EQ) == true \
 *                     else false
 *     elif cmpval == GT:             # <<<<<<<<<<<<<<
 *         return chain_richcmp(chain2,chain1,LT)
 *     elif cmpval == GEQ:
 */
    break;
    case 5:

    /* "plastid/genomics/roitools.pyx":861
 *         return chain_richcmp(chain2,chain1,LT)
 *     elif cmpval == GEQ:
 *         return true if chain_richcmp(chain2, chain1, LT) == true \             # <<<<<<<<<<<<<<
 *                     or chain_richcmp(chain1, chain2, EQ) == true \
 *                     else false
 */
    __pyx_t_8 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(__pyx_v_chain2, __pyx_v_chain1, 0); if (unlikely(__pyx_t_8 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 861, __pyx_L1_error)
    __pyx_t_4 = ((__pyx_t_8 == __pyx_e_7plastid_8genomics_8c_common_true) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L15_bool_binop_done;
    }

    /* "plastid/genomics/roitools.pyx":862
 *     elif cmpval == GEQ:
 *         return true if chain_richcmp(chain2, chain1, LT) == true \
 *                     or chain_richcmp(chain1, chain2, EQ) == true \             # <<<<<<<<<<<<<<
 *                     else false
 *     else:
 */
    __pyx_t_8 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(__pyx_v_chain1, __pyx_v_chain2, 2); if (unlikely(__pyx_t_8 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 862, __pyx_L1_error)
    __pyx_t_4 = ((__pyx_t_8 == __pyx_e_7plastid_8genomics_8c_common_true) != 0);
    __pyx_t_2 = __pyx_t_4;
    __pyx_L15_bool_binop_done:;
    if (__pyx_t_2) {

      /* "plastid/genomics/roitools.pyx":861
 *         return chain_richcmp(chain2,chain1,LT)
 *     elif cmpval == GEQ:
 *         return true if chain_richcmp(chain2, chain1, LT) == true \             # <<<<<<<<<<<<<<
 *                     or chain_richcmp(chain1, chain2, EQ) == true \
 *                     else false
 */
      __pyx_t_7 = __pyx_e_7plastid_8genomics_8c_common_true;
    } else {

      /* "plastid/genomics/roitools.pyx":863
 *         return true if chain_richcmp(chain2, chain1, LT) == true \
 *                     or chain_richcmp(chain1, chain2, EQ) == true \
 *                     else false             # <<<<<<<<<<<<<<
 *     else:
 *         raise ValueError("This operation is not defined for SegmentChains.")
 */
      __pyx_t_7 = __pyx_e_7plastid_8genomics_8c_common_false;
    }
    __pyx_r = __pyx_t_7;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":860
 *     elif cmpval == GT:
 *         return chain_richcmp(chain2,chain1,LT)
 *     elif cmpval == GEQ:             # <<<<<<<<<<<<<<
 *         return true if chain_richcmp(chain2, chain1, LT) == true \
 *                     or chain_richcmp(chain1, chain2, EQ) == true \
 */
    break;
    default:

    /* "plastid/genomics/roitools.pyx":865
 *                     else false
 *     else:
 *         raise ValueError("This operation is not defined for SegmentChains.")             # <<<<<<<<<<<<<<
 * 
 * cdef ExBool transcript_richcmp(Transcript chain1, Transcript chain2, int cmpval) except bool_exception:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 865, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 865, __pyx_L1_error)
    break;
  }

  /* "plastid/genomics/roitools.pyx":786
 *     return True
 * 
 * cdef ExBool chain_richcmp(SegmentChain chain1, SegmentChain chain2, int cmpval) except bool_exception:             # <<<<<<<<<<<<<<
 *     """Helper method for rich comparisons (==, !=, <, >, <=, >=) of |SegmentChains|
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("plastid.genomics.roitools.chain_richcmp", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = __pyx_e_7plastid_8genomics_8c_common_bool_exception;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_sspan);
  __Pyx_XDECREF(__pyx_v_ospan);
  __Pyx_XDECREF(__pyx_v_sname);
  __Pyx_XDECREF(__pyx_v_oname);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":867
 *         raise ValueError("This operation is not defined for SegmentChains.")
 * 
 * cdef ExBool transcript_richcmp(Transcript chain1, Transcript chain2, int cmpval) except bool_exception:             # <<<<<<<<<<<<<<
 *     """Helper method for rich comparisons (==, !=, <, >, <=, >=) of |Transcripts|
 * 
 */

static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_transcript_richcmp(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_chain1, struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_chain2, int __pyx_v_cmpval) {
  CYTHON_UNUSED PyObject *__pyx_v_sspan = 0;
  CYTHON_UNUSED PyObject *__pyx_v_ospan = 0;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("transcript_richcmp", 0);

  /* "plastid/genomics/roitools.pyx":899
 *     """
 *     cdef:
 *         sspan = chain1.spanning_segment             # <<<<<<<<<<<<<<
 *         ospan = chain2.spanning_segment
 * 
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_chain1->__pyx_base.spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_sspan = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":900
 *     cdef:
 *         sspan = chain1.spanning_segment
 *         ospan = chain2.spanning_segment             # <<<<<<<<<<<<<<
 * 
 *     if cmpval == EQ:
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_chain2->__pyx_base.spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_ospan = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":902
 *         ospan = chain2.spanning_segment
 * 
 *     if cmpval == EQ:             # <<<<<<<<<<<<<<
 *         if chain_richcmp(chain1, chain2, cmpval) == true and \
 *                (
 */
  switch (__pyx_v_cmpval) {
    case 2:

    /* "plastid/genomics/roitools.pyx":903
 * 
 *     if cmpval == EQ:
 *         if chain_richcmp(chain1, chain2, cmpval) == true and \             # <<<<<<<<<<<<<<
 *                (
 *                    (
 */
    __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain1), ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2), __pyx_v_cmpval); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 903, __pyx_L1_error)
    __pyx_t_4 = ((__pyx_t_3 == __pyx_e_7plastid_8genomics_8c_common_true) != 0);
    if (__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L4_bool_binop_done;
    }

    /* "plastid/genomics/roitools.pyx":906
 *                (
 *                    (
 *                        chain1.cds_genome_start is None \             # <<<<<<<<<<<<<<
 *                        and chain2.cds_genome_start is None \
 *                        and chain1.cds_genome_end is None \
 */
    __pyx_t_4 = (__pyx_v_chain1->cds_genome_start == Py_None);
    __pyx_t_5 = (__pyx_t_4 != 0);
    if (!__pyx_t_5) {
      goto __pyx_L6_next_or;
    } else {
    }

    /* "plastid/genomics/roitools.pyx":907
 *                    (
 *                        chain1.cds_genome_start is None \
 *                        and chain2.cds_genome_start is None \             # <<<<<<<<<<<<<<
 *                        and chain1.cds_genome_end is None \
 *                        and chain2.cds_genome_end is None
 */
    __pyx_t_5 = (__pyx_v_chain2->cds_genome_start == Py_None);
    __pyx_t_4 = (__pyx_t_5 != 0);
    if (!__pyx_t_4) {
      goto __pyx_L6_next_or;
    } else {
    }

    /* "plastid/genomics/roitools.pyx":908
 *                        chain1.cds_genome_start is None \
 *                        and chain2.cds_genome_start is None \
 *                        and chain1.cds_genome_end is None \             # <<<<<<<<<<<<<<
 *                        and chain2.cds_genome_end is None
 *                    ) \
 */
    __pyx_t_4 = (__pyx_v_chain1->cds_genome_end == Py_None);
    __pyx_t_5 = (__pyx_t_4 != 0);
    if (!__pyx_t_5) {
      goto __pyx_L6_next_or;
    } else {
    }

    /* "plastid/genomics/roitools.pyx":909
 *                        and chain2.cds_genome_start is None \
 *                        and chain1.cds_genome_end is None \
 *                        and chain2.cds_genome_end is None             # <<<<<<<<<<<<<<
 *                    ) \
 *                    or (
 */
    __pyx_t_5 = (__pyx_v_chain2->cds_genome_end == Py_None);
    __pyx_t_4 = (__pyx_t_5 != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L4_bool_binop_done;
    }
    __pyx_L6_next_or:;

    /* "plastid/genomics/roitools.pyx":912
 *                    ) \
 *                    or (
 *                        chain1.cds_genome_start == chain2.cds_genome_start \             # <<<<<<<<<<<<<<
 *                        and chain1.cds_genome_end == chain2.cds_genome_end
 *                    )
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_chain1->cds_genome_start, __pyx_v_chain2->cds_genome_start, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 912, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 912, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L4_bool_binop_done;
    }

    /* "plastid/genomics/roitools.pyx":913
 *                    or (
 *                        chain1.cds_genome_start == chain2.cds_genome_start \
 *                        and chain1.cds_genome_end == chain2.cds_genome_end             # <<<<<<<<<<<<<<
 *                    )
 *                 ):
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_chain1->cds_genome_end, __pyx_v_chain2->cds_genome_end, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 913, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 913, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_2 = __pyx_t_4;
    __pyx_L4_bool_binop_done:;

    /* "plastid/genomics/roitools.pyx":903
 * 
 *     if cmpval == EQ:
 *         if chain_richcmp(chain1, chain2, cmpval) == true and \             # <<<<<<<<<<<<<<
 *                (
 *                    (
 */
    if (__pyx_t_2) {

      /* "plastid/genomics/roitools.pyx":916
 *                    )
 *                 ):
 *                     return true             # <<<<<<<<<<<<<<
 *         return false
 *     elif cmpval == NEQ:
 */
      __pyx_r = __pyx_e_7plastid_8genomics_8c_common_true;
      goto __pyx_L0;

      /* "plastid/genomics/roitools.pyx":903
 * 
 *     if cmpval == EQ:
 *         if chain_richcmp(chain1, chain2, cmpval) == true and \             # <<<<<<<<<<<<<<
 *                (
 *                    (
 */
    }

    /* "plastid/genomics/roitools.pyx":917
 *                 ):
 *                     return true
 *         return false             # <<<<<<<<<<<<<<
 *     elif cmpval == NEQ:
 *         return true if transcript_richcmp(chain1, chain2, EQ) == false else true
 */
    __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":902
 *         ospan = chain2.spanning_segment
 * 
 *     if cmpval == EQ:             # <<<<<<<<<<<<<<
 *         if chain_richcmp(chain1, chain2, cmpval) == true and \
 *                (
 */
    break;
    case 3:

    /* "plastid/genomics/roitools.pyx":919
 *         return false
 *     elif cmpval == NEQ:
 *         return true if transcript_richcmp(chain1, chain2, EQ) == false else true             # <<<<<<<<<<<<<<
 *     elif cmpval == LT:
 *         return chain_richcmp(chain1, chain2, cmpval)
 */
    __pyx_t_6 = __pyx_f_7plastid_8genomics_8roitools_transcript_richcmp(__pyx_v_chain1, __pyx_v_chain2, 2); if (unlikely(__pyx_t_6 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 919, __pyx_L1_error)
    if (((__pyx_t_6 == __pyx_e_7plastid_8genomics_8c_common_false) != 0)) {
      __pyx_t_3 = __pyx_e_7plastid_8genomics_8c_common_true;
    } else {
      __pyx_t_3 = __pyx_e_7plastid_8genomics_8c_common_true;
    }
    __pyx_r = __pyx_t_3;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":918
 *                     return true
 *         return false
 *     elif cmpval == NEQ:             # <<<<<<<<<<<<<<
 *         return true if transcript_richcmp(chain1, chain2, EQ) == false else true
 *     elif cmpval == LT:
 */
    break;
    case 0:

    /* "plastid/genomics/roitools.pyx":921
 *         return true if transcript_richcmp(chain1, chain2, EQ) == false else true
 *     elif cmpval == LT:
 *         return chain_richcmp(chain1, chain2, cmpval)             # <<<<<<<<<<<<<<
 *     elif cmpval == LEQ:
 *         return true if chain_richcmp(chain1, chain2, LT) == true \
 */
    __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain1), ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2), __pyx_v_cmpval); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 921, __pyx_L1_error)
    __pyx_r = __pyx_t_3;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":920
 *     elif cmpval == NEQ:
 *         return true if transcript_richcmp(chain1, chain2, EQ) == false else true
 *     elif cmpval == LT:             # <<<<<<<<<<<<<<
 *         return chain_richcmp(chain1, chain2, cmpval)
 *     elif cmpval == LEQ:
 */
    break;
    case 1:

    /* "plastid/genomics/roitools.pyx":923
 *         return chain_richcmp(chain1, chain2, cmpval)
 *     elif cmpval == LEQ:
 *         return true if chain_richcmp(chain1, chain2, LT) == true \             # <<<<<<<<<<<<<<
 *                     or transcript_richcmp(chain1, chain2, EQ) == true \
 *                     else false
 */
    __pyx_t_6 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain1), ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2), 0); if (unlikely(__pyx_t_6 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 923, __pyx_L1_error)
    __pyx_t_4 = ((__pyx_t_6 == __pyx_e_7plastid_8genomics_8c_common_true) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L11_bool_binop_done;
    }

    /* "plastid/genomics/roitools.pyx":924
 *     elif cmpval == LEQ:
 *         return true if chain_richcmp(chain1, chain2, LT) == true \
 *                     or transcript_richcmp(chain1, chain2, EQ) == true \             # <<<<<<<<<<<<<<
 *                     else false
 *     elif cmpval == GT:
 */
    __pyx_t_6 = __pyx_f_7plastid_8genomics_8roitools_transcript_richcmp(__pyx_v_chain1, __pyx_v_chain2, 2); if (unlikely(__pyx_t_6 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 924, __pyx_L1_error)
    __pyx_t_4 = ((__pyx_t_6 == __pyx_e_7plastid_8genomics_8c_common_true) != 0);
    __pyx_t_2 = __pyx_t_4;
    __pyx_L11_bool_binop_done:;
    if (__pyx_t_2) {

      /* "plastid/genomics/roitools.pyx":923
 *         return chain_richcmp(chain1, chain2, cmpval)
 *     elif cmpval == LEQ:
 *         return true if chain_richcmp(chain1, chain2, LT) == true \             # <<<<<<<<<<<<<<
 *                     or transcript_richcmp(chain1, chain2, EQ) == true \
 *                     else false
 */
      __pyx_t_3 = __pyx_e_7plastid_8genomics_8c_common_true;
    } else {

      /* "plastid/genomics/roitools.pyx":925
 *         return true if chain_richcmp(chain1, chain2, LT) == true \
 *                     or transcript_richcmp(chain1, chain2, EQ) == true \
 *                     else false             # <<<<<<<<<<<<<<
 *     elif cmpval == GT:
 *         return chain_richcmp(chain2, chain1, LT)
 */
      __pyx_t_3 = __pyx_e_7plastid_8genomics_8c_common_false;
    }
    __pyx_r = __pyx_t_3;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":922
 *     elif cmpval == LT:
 *         return chain_richcmp(chain1, chain2, cmpval)
 *     elif cmpval == LEQ:             # <<<<<<<<<<<<<<
 *         return true if chain_richcmp(chain1, chain2, LT) == true \
 *                     or transcript_richcmp(chain1, chain2, EQ) == true \
 */
    break;
    case 4:

    /* "plastid/genomics/roitools.pyx":927
 *                     else false
 *     elif cmpval == GT:
 *         return chain_richcmp(chain2, chain1, LT)             # <<<<<<<<<<<<<<
 *     elif cmpval == GEQ:
 *         return true if chain_richcmp(chain2, chain1, LT) == true \
 */
    __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2), ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain1), 0); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 927, __pyx_L1_error)
    __pyx_r = __pyx_t_3;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":926
 *                     or transcript_richcmp(chain1, chain2, EQ) == true \
 *                     else false
 *     elif cmpval == GT:             # <<<<<<<<<<<<<<
 *         return chain_richcmp(chain2, chain1, LT)
 *     elif cmpval == GEQ:
 */
    break;
    case 5:

    /* "plastid/genomics/roitools.pyx":929
 *         return chain_richcmp(chain2, chain1, LT)
 *     elif cmpval == GEQ:
 *         return true if chain_richcmp(chain2, chain1, LT) == true \             # <<<<<<<<<<<<<<
 *                     or transcript_richcmp(chain1, chain2, EQ) == true\
 *                     else false
 */
    __pyx_t_6 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2), ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain1), 0); if (unlikely(__pyx_t_6 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 929, __pyx_L1_error)
    __pyx_t_4 = ((__pyx_t_6 == __pyx_e_7plastid_8genomics_8c_common_true) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L13_bool_binop_done;
    }

    /* "plastid/genomics/roitools.pyx":930
 *     elif cmpval == GEQ:
 *         return true if chain_richcmp(chain2, chain1, LT) == true \
 *                     or transcript_richcmp(chain1, chain2, EQ) == true\             # <<<<<<<<<<<<<<
 *                     else false
 *     else:
 */
    __pyx_t_6 = __pyx_f_7plastid_8genomics_8roitools_transcript_richcmp(__pyx_v_chain1, __pyx_v_chain2, 2); if (unlikely(__pyx_t_6 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 930, __pyx_L1_error)
    __pyx_t_4 = ((__pyx_t_6 == __pyx_e_7plastid_8genomics_8c_common_true) != 0);
    __pyx_t_2 = __pyx_t_4;
    __pyx_L13_bool_binop_done:;
    if (__pyx_t_2) {

      /* "plastid/genomics/roitools.pyx":929
 *         return chain_richcmp(chain2, chain1, LT)
 *     elif cmpval == GEQ:
 *         return true if chain_richcmp(chain2, chain1, LT) == true \             # <<<<<<<<<<<<<<
 *                     or transcript_richcmp(chain1, chain2, EQ) == true\
 *                     else false
 */
      __pyx_t_3 = __pyx_e_7plastid_8genomics_8c_common_true;
    } else {

      /* "plastid/genomics/roitools.pyx":931
 *         return true if chain_richcmp(chain2, chain1, LT) == true \
 *                     or transcript_richcmp(chain1, chain2, EQ) == true\
 *                     else false             # <<<<<<<<<<<<<<
 *     else:
 *         raise ValueError("This operation is not defined for Transcripts.")
 */
      __pyx_t_3 = __pyx_e_7plastid_8genomics_8c_common_false;
    }
    __pyx_r = __pyx_t_3;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":928
 *     elif cmpval == GT:
 *         return chain_richcmp(chain2, chain1, LT)
 *     elif cmpval == GEQ:             # <<<<<<<<<<<<<<
 *         return true if chain_richcmp(chain2, chain1, LT) == true \
 *                     or transcript_richcmp(chain1, chain2, EQ) == true\
 */
    break;
    default:

    /* "plastid/genomics/roitools.pyx":933
 *                     else false
 *     else:
 *         raise ValueError("This operation is not defined for Transcripts.")             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 933, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 933, __pyx_L1_error)
    break;
  }

  /* "plastid/genomics/roitools.pyx":867
 *         raise ValueError("This operation is not defined for SegmentChains.")
 * 
 * cdef ExBool transcript_richcmp(Transcript chain1, Transcript chain2, int cmpval) except bool_exception:             # <<<<<<<<<<<<<<
 *     """Helper method for rich comparisons (==, !=, <, >, <=, >=) of |Transcripts|
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.transcript_richcmp", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = __pyx_e_7plastid_8genomics_8c_common_bool_exception;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_sspan);
  __Pyx_XDECREF(__pyx_v_ospan);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1004
 *     chromosome.
 *     """
 *     def __cinit__(self, str chrom, long start, long end, str strand):             # <<<<<<<<<<<<<<
 *         """Create a |GenomicSegment|
 * 
 */

/* Python wrapper */
static int __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_chrom = 0;
  long __pyx_v_start;
  long __pyx_v_end;
  PyObject *__pyx_v_strand = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_chrom,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_strand,0};
    PyObject* values[4] = {0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 1); __PYX_ERR(0, 1004, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 2); __PYX_ERR(0, 1004, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_strand)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 3); __PYX_ERR(0, 1004, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 1004, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
    }
    __pyx_v_chrom = ((PyObject*)values[0]);
    __pyx_v_start = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v_start == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1004, __pyx_L3_error)
    __pyx_v_end = __Pyx_PyInt_As_long(values[2]); if (unlikely((__pyx_v_end == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1004, __pyx_L3_error)
    __pyx_v_strand = ((PyObject*)values[3]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1004, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_chrom), (&PyUnicode_Type), 1, "chrom", 1))) __PYX_ERR(0, 1004, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_strand), (&PyUnicode_Type), 1, "strand", 1))) __PYX_ERR(0, 1004, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment___cinit__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self), __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_strand);

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

static int __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment___cinit__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, PyObject *__pyx_v_chrom, long __pyx_v_start, long __pyx_v_end, PyObject *__pyx_v_strand) {
  PyObject *__pyx_v_my_chrom = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  Py_UCS4 __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "plastid/genomics/roitools.pyx":1022
 *             Chromosome strand (`'+'`, `'-'`, or `'.'`)
 *         """
 *         if end < start:             # <<<<<<<<<<<<<<
 *             raise ValueError("GenomicSegment: start coordinate (%s) must be >= end (%s)." % (start, end))
 *         my_chrom = chrom
 */
  __pyx_t_1 = ((__pyx_v_end < __pyx_v_start) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "plastid/genomics/roitools.pyx":1023
 *         """
 *         if end < start:
 *             raise ValueError("GenomicSegment: start coordinate (%s) must be >= end (%s)." % (start, end))             # <<<<<<<<<<<<<<
 *         my_chrom = chrom
 *         self.chrom  = my_chrom
 */
    __pyx_t_2 = PyTuple_New(5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1023, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = 0;
    __pyx_t_4 = 127;
    __Pyx_INCREF(__pyx_kp_u_GenomicSegment_start_coordinate);
    __pyx_t_3 += 34;
    __Pyx_GIVEREF(__pyx_kp_u_GenomicSegment_start_coordinate);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_GenomicSegment_start_coordinate);
    __pyx_t_5 = __Pyx_PyUnicode_From_long(__pyx_v_start, 0, ' ', 'd'); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1023, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u_must_be_end);
    __pyx_t_3 += 18;
    __Pyx_GIVEREF(__pyx_kp_u_must_be_end);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_must_be_end);
    __pyx_t_5 = __Pyx_PyUnicode_From_long(__pyx_v_end, 0, ' ', 'd'); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1023, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u__25);
    __pyx_t_3 += 2;
    __Pyx_GIVEREF(__pyx_kp_u__25);
    PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_kp_u__25);
    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_2, 5, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1023, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1023, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1023, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":1022
 *             Chromosome strand (`'+'`, `'-'`, or `'.'`)
 *         """
 *         if end < start:             # <<<<<<<<<<<<<<
 *             raise ValueError("GenomicSegment: start coordinate (%s) must be >= end (%s)." % (start, end))
 *         my_chrom = chrom
 */
  }

  /* "plastid/genomics/roitools.pyx":1024
 *         if end < start:
 *             raise ValueError("GenomicSegment: start coordinate (%s) must be >= end (%s)." % (start, end))
 *         my_chrom = chrom             # <<<<<<<<<<<<<<
 *         self.chrom  = my_chrom
 *         self.start  = start
 */
  __Pyx_INCREF(__pyx_v_chrom);
  __pyx_v_my_chrom = __pyx_v_chrom;

  /* "plastid/genomics/roitools.pyx":1025
 *             raise ValueError("GenomicSegment: start coordinate (%s) must be >= end (%s)." % (start, end))
 *         my_chrom = chrom
 *         self.chrom  = my_chrom             # <<<<<<<<<<<<<<
 *         self.start  = start
 *         self.end    = end
 */
  __Pyx_INCREF(__pyx_v_my_chrom);
  __Pyx_GIVEREF(__pyx_v_my_chrom);
  __Pyx_GOTREF(__pyx_v_self->chrom);
  __Pyx_DECREF(__pyx_v_self->chrom);
  __pyx_v_self->chrom = __pyx_v_my_chrom;

  /* "plastid/genomics/roitools.pyx":1026
 *         my_chrom = chrom
 *         self.chrom  = my_chrom
 *         self.start  = start             # <<<<<<<<<<<<<<
 *         self.end    = end
 *         self.c_strand = str_to_strand(strand)
 */
  __pyx_v_self->start = __pyx_v_start;

  /* "plastid/genomics/roitools.pyx":1027
 *         self.chrom  = my_chrom
 *         self.start  = start
 *         self.end    = end             # <<<<<<<<<<<<<<
 *         self.c_strand = str_to_strand(strand)
 * 
 */
  __pyx_v_self->end = __pyx_v_end;

  /* "plastid/genomics/roitools.pyx":1028
 *         self.start  = start
 *         self.end    = end
 *         self.c_strand = str_to_strand(strand)             # <<<<<<<<<<<<<<
 * 
 *     def __reduce__(self): # enables pickling
 */
  __pyx_t_6 = __pyx_f_7plastid_8genomics_8c_common_str_to_strand(__pyx_v_strand); if (unlikely(__pyx_t_6 == ((enum __pyx_t_7plastid_8genomics_8c_common_Strand)__pyx_e_7plastid_8genomics_8c_common_error_strand))) __PYX_ERR(0, 1028, __pyx_L1_error)
  __pyx_v_self->c_strand = __pyx_t_6;

  /* "plastid/genomics/roitools.pyx":1004
 *     chromosome.
 *     """
 *     def __cinit__(self, str chrom, long start, long end, str strand):             # <<<<<<<<<<<<<<
 *         """Create a |GenomicSegment|
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_my_chrom);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1030
 *         self.c_strand = str_to_strand(strand)
 * 
 *     def __reduce__(self): # enables pickling             # <<<<<<<<<<<<<<
 *         return (GenomicSegment, (self.chrom, self.start, self.end, self.strand))
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_3__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_2__reduce__[] = "GenomicSegment.__reduce__(self)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_3__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_2__reduce__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_2__reduce__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce__", 0);

  /* "plastid/genomics/roitools.pyx":1031
 * 
 *     def __reduce__(self): # enables pickling
 *         return (GenomicSegment, (self.chrom, self.start, self.end, self.strand))             # <<<<<<<<<<<<<<
 * 
 *     def __repr__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1031, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_self->end); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1031, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1031, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1031, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_self->chrom);
  __Pyx_GIVEREF(__pyx_v_self->chrom);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_self->chrom);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1031, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment));
  __Pyx_GIVEREF(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment));
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1030
 *         self.c_strand = str_to_strand(strand)
 * 
 *     def __reduce__(self): # enables pickling             # <<<<<<<<<<<<<<
 *         return (GenomicSegment, (self.chrom, self.start, self.end, self.strand))
 * 
 */

  /* 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("plastid.genomics.roitools.GenomicSegment.__reduce__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1033
 *         return (GenomicSegment, (self.chrom, self.start, self.end, self.strand))
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return "<%s %s:%s-%s strand='%s'>" % (
 *             "GenomicSegment", self.chrom, self.start, self.end, self.strand
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_5__repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_5__repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_4__repr__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_4__repr__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  Py_UCS4 __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__repr__", 0);

  /* "plastid/genomics/roitools.pyx":1034
 * 
 *     def __repr__(self):
 *         return "<%s %s:%s-%s strand='%s'>" % (             # <<<<<<<<<<<<<<
 *             "GenomicSegment", self.chrom, self.start, self.end, self.strand
 *         )
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1034, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = 0;
  __pyx_t_3 = 127;
  __Pyx_INCREF(__pyx_kp_u_GenomicSegment_2);
  __pyx_t_2 += 16;
  __Pyx_GIVEREF(__pyx_kp_u_GenomicSegment_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_GenomicSegment_2);

  /* "plastid/genomics/roitools.pyx":1035
 *     def __repr__(self):
 *         return "<%s %s:%s-%s strand='%s'>" % (
 *             "GenomicSegment", self.chrom, self.start, self.end, self.strand             # <<<<<<<<<<<<<<
 *         )
 * 
 */
  __pyx_t_4 = __Pyx_PyUnicode_Unicode(__pyx_v_self->chrom); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1035, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u__12);
  __pyx_t_2 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__12);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u__12);
  __pyx_t_4 = __Pyx_PyUnicode_From_long(__pyx_v_self->start, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1035, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u__13);
  __pyx_t_2 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__13);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__13);
  __pyx_t_4 = __Pyx_PyUnicode_From_long(__pyx_v_self->end, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1035, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u_strand_2);
  __pyx_t_2 += 9;
  __Pyx_GIVEREF(__pyx_kp_u_strand_2);
  PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u_strand_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1035, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_4), __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1035, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_3;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 7, __pyx_t_5);
  __pyx_t_5 = 0;
  __Pyx_INCREF(__pyx_kp_u__26);
  __pyx_t_2 += 2;
  __Pyx_GIVEREF(__pyx_kp_u__26);
  PyTuple_SET_ITEM(__pyx_t_1, 8, __pyx_kp_u__26);

  /* "plastid/genomics/roitools.pyx":1034
 * 
 *     def __repr__(self):
 *         return "<%s %s:%s-%s strand='%s'>" % (             # <<<<<<<<<<<<<<
 *             "GenomicSegment", self.chrom, self.start, self.end, self.strand
 *         )
 */
  __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_1, 9, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1034, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1033
 *         return (GenomicSegment, (self.chrom, self.start, self.end, self.strand))
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return "<%s %s:%s-%s strand='%s'>" % (
 *             "GenomicSegment", self.chrom, self.start, self.end, self.strand
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1038
 *         )
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "%s:%s-%s(%s)" % (self.chrom, self.start, self.end, self.strand)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_7__str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_7__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_6__str__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_6__str__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  Py_UCS4 __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__str__", 0);

  /* "plastid/genomics/roitools.pyx":1039
 * 
 *     def __str__(self):
 *         return "%s:%s-%s(%s)" % (self.chrom, self.start, self.end, self.strand)             # <<<<<<<<<<<<<<
 * 
 *     def __hash__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1039, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = 0;
  __pyx_t_3 = 127;
  __pyx_t_4 = __Pyx_PyUnicode_Unicode(__pyx_v_self->chrom); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1039, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u__12);
  __pyx_t_2 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__12);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u__12);
  __pyx_t_4 = __Pyx_PyUnicode_From_long(__pyx_v_self->start, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1039, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u__13);
  __pyx_t_2 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__13);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u__13);
  __pyx_t_4 = __Pyx_PyUnicode_From_long(__pyx_v_self->end, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1039, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u__14);
  __pyx_t_2 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__14);
  PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_kp_u__14);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1039, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_4), __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1039, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_3;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_t_5);
  __pyx_t_5 = 0;
  __Pyx_INCREF(__pyx_kp_u__15);
  __pyx_t_2 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__15);
  PyTuple_SET_ITEM(__pyx_t_1, 7, __pyx_kp_u__15);
  __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_1, 8, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1039, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1038
 *         )
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "%s:%s-%s(%s)" % (self.chrom, self.start, self.end, self.strand)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1041
 *         return "%s:%s-%s(%s)" % (self.chrom, self.start, self.end, self.strand)
 * 
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         # generate unique hash from a tuple,  which are hashable
 *         # and already implement hashing for us
 */

/* Python wrapper */
static Py_hash_t __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_9__hash__(PyObject *__pyx_v_self); /*proto*/
static Py_hash_t __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_9__hash__(PyObject *__pyx_v_self) {
  Py_hash_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_8__hash__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self));

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

static Py_hash_t __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_8__hash__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self) {
  Py_hash_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_hash_t __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__hash__", 0);

  /* "plastid/genomics/roitools.pyx":1044
 *         # generate unique hash from a tuple,  which are hashable
 *         # and already implement hashing for us
 *         return hash((self.__class__.__name__, self.chrom, self.start, self.end, self.strand))             # <<<<<<<<<<<<<<
 * 
 *     @staticmethod
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_self->end); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __Pyx_INCREF(__pyx_v_self->chrom);
  __Pyx_GIVEREF(__pyx_v_self->chrom);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_self->chrom);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_t_4);
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_6 = PyObject_Hash(__pyx_t_5); if (unlikely(__pyx_t_6 == ((Py_hash_t)-1))) __PYX_ERR(0, 1044, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = __pyx_t_6;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1041
 *         return "%s:%s-%s(%s)" % (self.chrom, self.start, self.end, self.strand)
 * 
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         # generate unique hash from a tuple,  which are hashable
 *         # and already implement hashing for us
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1047
 * 
 *     @staticmethod
 *     def from_str(str inp):             # <<<<<<<<<<<<<<
 *         """Construct a |GenomicSegment| from its ``str()`` representation
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_11from_str(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_10from_str[] = "GenomicSegment.from_str(unicode inp)\nConstruct a |GenomicSegment| from its ``str()`` representation\n\n        Parameters\n        ----------\n        inp : str\n            String representation of |GenomicSegment| as `chrom:start-end(strand)`\n            where `start` and `end` are in 0-indexed, half-open coordinates\n\n        Returns\n        -------\n        |GenomicSegment|\n        ";
static PyMethodDef __pyx_mdef_7plastid_8genomics_8roitools_14GenomicSegment_11from_str = {"from_str", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_11from_str, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_10from_str};
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_11from_str(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_inp = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_str (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_inp,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_inp)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "from_str") < 0)) __PYX_ERR(0, 1047, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_inp = ((PyObject*)values[0]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("from_str", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1047, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.from_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_inp), (&PyUnicode_Type), 1, "inp", 1))) __PYX_ERR(0, 1047, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_10from_str(__pyx_v_inp);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_10from_str(PyObject *__pyx_v_inp) {
  long __pyx_v_start;
  long __pyx_v_end;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_strand = 0;
  PyObject *__pyx_v_s_start = 0;
  PyObject *__pyx_v_s_end = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *(*__pyx_t_7)(PyObject *);
  long __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("from_str", 0);

  /* "plastid/genomics/roitools.pyx":1063
 *             long start, end
 *             str chrom, strand, s_start, s_end
 *         chrom, s_start, s_end, strand = segpat.search(inp).groups()             # <<<<<<<<<<<<<<
 *         start = long(s_start)
 *         end   = long(s_end)
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_segpat); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1063, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_search); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1063, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_inp) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_inp);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1063, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_groups); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1063, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1063, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
    PyObject* sequence = __pyx_t_1;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 1063, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_5 = PyTuple_GET_ITEM(sequence, 3); 
    } else {
      __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_5 = PyList_GET_ITEM(sequence, 3); 
    }
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_5);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_4,&__pyx_t_2,&__pyx_t_3,&__pyx_t_5};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1063, __pyx_L1_error)
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    Py_ssize_t index = -1;
    PyObject** temps[4] = {&__pyx_t_4,&__pyx_t_2,&__pyx_t_3,&__pyx_t_5};
    __pyx_t_6 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext;
    for (index=0; index < 4; index++) {
      PyObject* item = __pyx_t_7(__pyx_t_6); if (unlikely(!item)) goto __pyx_L3_unpacking_failed;
      __Pyx_GOTREF(item);
      *(temps[index]) = item;
    }
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 4) < 0) __PYX_ERR(0, 1063, __pyx_L1_error)
    __pyx_t_7 = NULL;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    goto __pyx_L4_unpacking_done;
    __pyx_L3_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 1063, __pyx_L1_error)
    __pyx_L4_unpacking_done:;
  }
  if (!(likely(PyUnicode_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 1063, __pyx_L1_error)
  if (!(likely(PyUnicode_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 1063, __pyx_L1_error)
  if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 1063, __pyx_L1_error)
  if (!(likely(PyUnicode_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 1063, __pyx_L1_error)
  __pyx_v_chrom = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_v_s_start = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_v_s_end = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_v_strand = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "plastid/genomics/roitools.pyx":1064
 *             str chrom, strand, s_start, s_end
 *         chrom, s_start, s_end, strand = segpat.search(inp).groups()
 *         start = long(s_start)             # <<<<<<<<<<<<<<
 *         end   = long(s_end)
 *         return GenomicSegment(chrom, start, end, strand)
 */
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_v_s_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1064, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_8 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1064, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_start = __pyx_t_8;

  /* "plastid/genomics/roitools.pyx":1065
 *         chrom, s_start, s_end, strand = segpat.search(inp).groups()
 *         start = long(s_start)
 *         end   = long(s_end)             # <<<<<<<<<<<<<<
 *         return GenomicSegment(chrom, start, end, strand)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_v_s_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1065, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_8 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1065, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_end = __pyx_t_8;

  /* "plastid/genomics/roitools.pyx":1066
 *         start = long(s_start)
 *         end   = long(s_end)
 *         return GenomicSegment(chrom, start, end, strand)             # <<<<<<<<<<<<<<
 * 
 *     def __copy__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1066, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_end); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1066, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1066, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_5);
  __Pyx_INCREF(__pyx_v_strand);
  __Pyx_GIVEREF(__pyx_v_strand);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_strand);
  __pyx_t_1 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1066, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1047
 * 
 *     @staticmethod
 *     def from_str(str inp):             # <<<<<<<<<<<<<<
 *         """Construct a |GenomicSegment| from its ``str()`` representation
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.from_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_strand);
  __Pyx_XDECREF(__pyx_v_s_start);
  __Pyx_XDECREF(__pyx_v_s_end);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1068
 *         return GenomicSegment(chrom, start, end, strand)
 * 
 *     def __copy__(self):             # <<<<<<<<<<<<<<
 *         cdef str newchrom, newstrand
 *         cdef long newstart, newend
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_13__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_12__copy__[] = "GenomicSegment.__copy__(self)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_13__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__copy__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_12__copy__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_12__copy__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self) {
  PyObject *__pyx_v_newchrom = 0;
  PyObject *__pyx_v_newstrand = 0;
  long __pyx_v_newstart;
  long __pyx_v_newend;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  long __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__copy__", 0);

  /* "plastid/genomics/roitools.pyx":1071
 *         cdef str newchrom, newstrand
 *         cdef long newstart, newend
 *         newchrom = copy.copy(self.chrom)             # <<<<<<<<<<<<<<
 *         newstrand = self.strand
 *         newstart = self.start
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1071, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_copy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1071, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_self->chrom) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->chrom);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1071, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 1071, __pyx_L1_error)
  __pyx_v_newchrom = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1072
 *         cdef long newstart, newend
 *         newchrom = copy.copy(self.chrom)
 *         newstrand = self.strand             # <<<<<<<<<<<<<<
 *         newstart = self.start
 *         newend = self.end
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1072, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 1072, __pyx_L1_error)
  __pyx_v_newstrand = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1073
 *         newchrom = copy.copy(self.chrom)
 *         newstrand = self.strand
 *         newstart = self.start             # <<<<<<<<<<<<<<
 *         newend = self.end
 *         return GenomicSegment(newchrom, newstart, newend, newstrand)
 */
  __pyx_t_4 = __pyx_v_self->start;
  __pyx_v_newstart = __pyx_t_4;

  /* "plastid/genomics/roitools.pyx":1074
 *         newstrand = self.strand
 *         newstart = self.start
 *         newend = self.end             # <<<<<<<<<<<<<<
 *         return GenomicSegment(newchrom, newstart, newend, newstrand)
 * 
 */
  __pyx_t_4 = __pyx_v_self->end;
  __pyx_v_newend = __pyx_t_4;

  /* "plastid/genomics/roitools.pyx":1075
 *         newstart = self.start
 *         newend = self.end
 *         return GenomicSegment(newchrom, newstart, newend, newstrand)             # <<<<<<<<<<<<<<
 * 
 *     def __deepcopy__(self, memo):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_newstart); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_newend); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_newchrom);
  __Pyx_GIVEREF(__pyx_v_newchrom);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_newchrom);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_3);
  __Pyx_INCREF(__pyx_v_newstrand);
  __Pyx_GIVEREF(__pyx_v_newstrand);
  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_newstrand);
  __pyx_t_1 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1068
 *         return GenomicSegment(chrom, start, end, strand)
 * 
 *     def __copy__(self):             # <<<<<<<<<<<<<<
 *         cdef str newchrom, newstrand
 *         cdef long newstart, newend
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.__copy__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_newchrom);
  __Pyx_XDECREF(__pyx_v_newstrand);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1077
 *         return GenomicSegment(newchrom, newstart, newend, newstrand)
 * 
 *     def __deepcopy__(self, memo):             # <<<<<<<<<<<<<<
 *         return self.__copy__()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_15__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_14__deepcopy__[] = "GenomicSegment.__deepcopy__(self, memo)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_15__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__deepcopy__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_14__deepcopy__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self), ((PyObject *)__pyx_v_memo));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_14__deepcopy__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__deepcopy__", 0);

  /* "plastid/genomics/roitools.pyx":1078
 * 
 *     def __deepcopy__(self, memo):
 *         return self.__copy__()             # <<<<<<<<<<<<<<
 * 
 *     def __len__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_copy_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1078, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1078, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1077
 *         return GenomicSegment(newchrom, newstart, newend, newstrand)
 * 
 *     def __deepcopy__(self, memo):             # <<<<<<<<<<<<<<
 *         return self.__copy__()
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.__deepcopy__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1080
 *         return self.__copy__()
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         """Return length, in nucleotides, of |GenomicSegment|"""
 *         cdef long len
 */

/* Python wrapper */
static Py_ssize_t __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_17__len__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_16__len__[] = "Return length, in nucleotides, of |GenomicSegment|";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_7plastid_8genomics_8roitools_14GenomicSegment_16__len__;
#endif
static Py_ssize_t __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_17__len__(PyObject *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_16__len__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self));

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

static Py_ssize_t __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_16__len__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self) {
  long __pyx_v_len;
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__", 0);

  /* "plastid/genomics/roitools.pyx":1083
 *         """Return length, in nucleotides, of |GenomicSegment|"""
 *         cdef long len
 *         len = self.end - self.start             # <<<<<<<<<<<<<<
 *         return len
 * 
 */
  __pyx_v_len = (__pyx_v_self->end - __pyx_v_self->start);

  /* "plastid/genomics/roitools.pyx":1084
 *         cdef long len
 *         len = self.end - self.start
 *         return len             # <<<<<<<<<<<<<<
 * 
 *     def __richcmp__(self, GenomicSegment other,  int cmptype):
 */
  __pyx_r = __pyx_v_len;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1080
 *         return self.__copy__()
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         """Return length, in nucleotides, of |GenomicSegment|"""
 *         cdef long len
 */

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

/* "plastid/genomics/roitools.pyx":1086
 *         return len
 * 
 *     def __richcmp__(self, GenomicSegment other,  int cmptype):             # <<<<<<<<<<<<<<
 *         if other is None or not isinstance(other, GenomicSegment):
 *             return False
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_19__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_cmptype); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_19__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_cmptype) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment, 1, "other", 0))) __PYX_ERR(0, 1086, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_18__richcmp__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self), ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_other), ((int)__pyx_v_cmptype));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_18__richcmp__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other, int __pyx_v_cmptype) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__richcmp__", 0);

  /* "plastid/genomics/roitools.pyx":1087
 * 
 *     def __richcmp__(self, GenomicSegment other,  int cmptype):
 *         if other is None or not isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return False
 * 
 */
  __pyx_t_2 = (((PyObject *)__pyx_v_other) == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_TypeCheck(((PyObject *)__pyx_v_other), __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment); 
  __pyx_t_2 = ((!(__pyx_t_3 != 0)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "plastid/genomics/roitools.pyx":1088
 *     def __richcmp__(self, GenomicSegment other,  int cmptype):
 *         if other is None or not isinstance(other, GenomicSegment):
 *             return False             # <<<<<<<<<<<<<<
 * 
 *         return self._cmp_helper(other,cmptype)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_False);
    __pyx_r = Py_False;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1087
 * 
 *     def __richcmp__(self, GenomicSegment other,  int cmptype):
 *         if other is None or not isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return False
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":1090
 *             return False
 * 
 *         return self._cmp_helper(other,cmptype)             # <<<<<<<<<<<<<<
 * 
 *     cpdef bint _cmp_helper(self, GenomicSegment other, int cmptype):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyBool_FromLong(((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self->__pyx_vtab)->_cmp_helper(__pyx_v_self, __pyx_v_other, __pyx_v_cmptype, 0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1090, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1086
 *         return len
 * 
 *     def __richcmp__(self, GenomicSegment other,  int cmptype):             # <<<<<<<<<<<<<<
 *         if other is None or not isinstance(other, GenomicSegment):
 *             return False
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1092
 *         return self._cmp_helper(other,cmptype)
 * 
 *     cpdef bint _cmp_helper(self, GenomicSegment other, int cmptype):             # <<<<<<<<<<<<<<
 *         nonecheck(other, "GenomicSegment eq/neq", "other")
 *         schrom = self.chrom
 */

static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_21_cmp_helper(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_7plastid_8genomics_8roitools_14GenomicSegment__cmp_helper(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other, int __pyx_v_cmptype, int __pyx_skip_dispatch) {
  PyObject *__pyx_v_schrom = NULL;
  PyObject *__pyx_v_ochrom = NULL;
  long __pyx_v_sstart;
  long __pyx_v_ostart;
  long __pyx_v_send;
  long __pyx_v_oend;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  long __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_cmp_helper", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cmp_helper); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1092, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_21_cmp_helper)) {
        __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_cmptype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1092, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL;
        __pyx_t_6 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
            __pyx_t_6 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_other), __pyx_t_3};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1092, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_other), __pyx_t_3};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1092, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1092, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          if (__pyx_t_5) {
            __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
          }
          __Pyx_INCREF(((PyObject *)__pyx_v_other));
          __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
          PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, ((PyObject *)__pyx_v_other));
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1092, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        }
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1092, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_r = __pyx_t_8;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "plastid/genomics/roitools.pyx":1093
 * 
 *     cpdef bint _cmp_helper(self, GenomicSegment other, int cmptype):
 *         nonecheck(other, "GenomicSegment eq/neq", "other")             # <<<<<<<<<<<<<<
 *         schrom = self.chrom
 *         ochrom = other.chrom
 */
  __pyx_f_7plastid_8genomics_8roitools_nonecheck(((PyObject *)__pyx_v_other), __pyx_kp_u_GenomicSegment_eq_neq, __pyx_n_u_other);

  /* "plastid/genomics/roitools.pyx":1094
 *     cpdef bint _cmp_helper(self, GenomicSegment other, int cmptype):
 *         nonecheck(other, "GenomicSegment eq/neq", "other")
 *         schrom = self.chrom             # <<<<<<<<<<<<<<
 *         ochrom = other.chrom
 *         if cmptype == EQ:
 */
  __pyx_t_1 = __pyx_v_self->chrom;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_schrom = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1095
 *         nonecheck(other, "GenomicSegment eq/neq", "other")
 *         schrom = self.chrom
 *         ochrom = other.chrom             # <<<<<<<<<<<<<<
 *         if cmptype == EQ:
 *             return self.start      == other.start \
 */
  __pyx_t_1 = __pyx_v_other->chrom;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_ochrom = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1096
 *         schrom = self.chrom
 *         ochrom = other.chrom
 *         if cmptype == EQ:             # <<<<<<<<<<<<<<
 *             return self.start      == other.start \
 *                 and self.end       == other.end \
 */
  switch (__pyx_v_cmptype) {
    case 2:

    /* "plastid/genomics/roitools.pyx":1097
 *         ochrom = other.chrom
 *         if cmptype == EQ:
 *             return self.start      == other.start \             # <<<<<<<<<<<<<<
 *                 and self.end       == other.end \
 *                 and schrom         == ochrom \
 */
    __pyx_t_9 = ((__pyx_v_self->start == __pyx_v_other->start) != 0);
    if (__pyx_t_9) {
    } else {
      __pyx_t_8 = __pyx_t_9;
      goto __pyx_L3_bool_binop_done;
    }

    /* "plastid/genomics/roitools.pyx":1098
 *         if cmptype == EQ:
 *             return self.start      == other.start \
 *                 and self.end       == other.end \             # <<<<<<<<<<<<<<
 *                 and schrom         == ochrom \
 *                 and self.c_strand  == other.c_strand
 */
    __pyx_t_9 = ((__pyx_v_self->end == __pyx_v_other->end) != 0);
    if (__pyx_t_9) {
    } else {
      __pyx_t_8 = __pyx_t_9;
      goto __pyx_L3_bool_binop_done;
    }

    /* "plastid/genomics/roitools.pyx":1099
 *             return self.start      == other.start \
 *                 and self.end       == other.end \
 *                 and schrom         == ochrom \             # <<<<<<<<<<<<<<
 *                 and self.c_strand  == other.c_strand
 *         elif cmptype == NEQ:
 */
    __pyx_t_9 = (__Pyx_PyUnicode_Equals(__pyx_v_schrom, __pyx_v_ochrom, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1099, __pyx_L1_error)
    __pyx_t_10 = (__pyx_t_9 != 0);
    if (__pyx_t_10) {
    } else {
      __pyx_t_8 = __pyx_t_10;
      goto __pyx_L3_bool_binop_done;
    }

    /* "plastid/genomics/roitools.pyx":1100
 *                 and self.end       == other.end \
 *                 and schrom         == ochrom \
 *                 and self.c_strand  == other.c_strand             # <<<<<<<<<<<<<<
 *         elif cmptype == NEQ:
 *             return self._cmp_helper(other, EQ) == False
 */
    __pyx_t_10 = ((__pyx_v_self->c_strand == __pyx_v_other->c_strand) != 0);
    __pyx_t_8 = __pyx_t_10;
    __pyx_L3_bool_binop_done:;
    __pyx_r = __pyx_t_8;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1096
 *         schrom = self.chrom
 *         ochrom = other.chrom
 *         if cmptype == EQ:             # <<<<<<<<<<<<<<
 *             return self.start      == other.start \
 *                 and self.end       == other.end \
 */
    break;
    case 3:

    /* "plastid/genomics/roitools.pyx":1102
 *                 and self.c_strand  == other.c_strand
 *         elif cmptype == NEQ:
 *             return self._cmp_helper(other, EQ) == False             # <<<<<<<<<<<<<<
 *         elif cmptype == LT:
 *             if schrom < ochrom:
 */
    __pyx_r = (((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self->__pyx_vtab)->_cmp_helper(__pyx_v_self, __pyx_v_other, 2, 0) == 0);
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1101
 *                 and schrom         == ochrom \
 *                 and self.c_strand  == other.c_strand
 *         elif cmptype == NEQ:             # <<<<<<<<<<<<<<
 *             return self._cmp_helper(other, EQ) == False
 *         elif cmptype == LT:
 */
    break;
    case 0:

    /* "plastid/genomics/roitools.pyx":1104
 *             return self._cmp_helper(other, EQ) == False
 *         elif cmptype == LT:
 *             if schrom < ochrom:             # <<<<<<<<<<<<<<
 *                 return True
 *             elif schrom > ochrom:
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_schrom, __pyx_v_ochrom, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1104, __pyx_L1_error)
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1104, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_8) {

      /* "plastid/genomics/roitools.pyx":1105
 *         elif cmptype == LT:
 *             if schrom < ochrom:
 *                 return True             # <<<<<<<<<<<<<<
 *             elif schrom > ochrom:
 *                 return False
 */
      __pyx_r = 1;
      goto __pyx_L0;

      /* "plastid/genomics/roitools.pyx":1104
 *             return self._cmp_helper(other, EQ) == False
 *         elif cmptype == LT:
 *             if schrom < ochrom:             # <<<<<<<<<<<<<<
 *                 return True
 *             elif schrom > ochrom:
 */
    }

    /* "plastid/genomics/roitools.pyx":1106
 *             if schrom < ochrom:
 *                 return True
 *             elif schrom > ochrom:             # <<<<<<<<<<<<<<
 *                 return False
 *             elif schrom == ochrom:
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_schrom, __pyx_v_ochrom, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1106, __pyx_L1_error)
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1106, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_8) {

      /* "plastid/genomics/roitools.pyx":1107
 *                 return True
 *             elif schrom > ochrom:
 *                 return False             # <<<<<<<<<<<<<<
 *             elif schrom == ochrom:
 *                 sstart = self.start
 */
      __pyx_r = 0;
      goto __pyx_L0;

      /* "plastid/genomics/roitools.pyx":1106
 *             if schrom < ochrom:
 *                 return True
 *             elif schrom > ochrom:             # <<<<<<<<<<<<<<
 *                 return False
 *             elif schrom == ochrom:
 */
    }

    /* "plastid/genomics/roitools.pyx":1108
 *             elif schrom > ochrom:
 *                 return False
 *             elif schrom == ochrom:             # <<<<<<<<<<<<<<
 *                 sstart = self.start
 *                 ostart = other.start
 */
    __pyx_t_8 = (__Pyx_PyUnicode_Equals(__pyx_v_schrom, __pyx_v_ochrom, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1108, __pyx_L1_error)
    __pyx_t_10 = (__pyx_t_8 != 0);
    if (__pyx_t_10) {

      /* "plastid/genomics/roitools.pyx":1109
 *                 return False
 *             elif schrom == ochrom:
 *                 sstart = self.start             # <<<<<<<<<<<<<<
 *                 ostart = other.start
 *                 if sstart < ostart:
 */
      __pyx_t_11 = __pyx_v_self->start;
      __pyx_v_sstart = __pyx_t_11;

      /* "plastid/genomics/roitools.pyx":1110
 *             elif schrom == ochrom:
 *                 sstart = self.start
 *                 ostart = other.start             # <<<<<<<<<<<<<<
 *                 if sstart < ostart:
 *                     return True
 */
      __pyx_t_11 = __pyx_v_other->start;
      __pyx_v_ostart = __pyx_t_11;

      /* "plastid/genomics/roitools.pyx":1111
 *                 sstart = self.start
 *                 ostart = other.start
 *                 if sstart < ostart:             # <<<<<<<<<<<<<<
 *                     return True
 *                 elif sstart > ostart:
 */
      __pyx_t_10 = ((__pyx_v_sstart < __pyx_v_ostart) != 0);
      if (__pyx_t_10) {

        /* "plastid/genomics/roitools.pyx":1112
 *                 ostart = other.start
 *                 if sstart < ostart:
 *                     return True             # <<<<<<<<<<<<<<
 *                 elif sstart > ostart:
 *                     return False
 */
        __pyx_r = 1;
        goto __pyx_L0;

        /* "plastid/genomics/roitools.pyx":1111
 *                 sstart = self.start
 *                 ostart = other.start
 *                 if sstart < ostart:             # <<<<<<<<<<<<<<
 *                     return True
 *                 elif sstart > ostart:
 */
      }

      /* "plastid/genomics/roitools.pyx":1113
 *                 if sstart < ostart:
 *                     return True
 *                 elif sstart > ostart:             # <<<<<<<<<<<<<<
 *                     return False
 *                 elif sstart == ostart:
 */
      __pyx_t_10 = ((__pyx_v_sstart > __pyx_v_ostart) != 0);
      if (__pyx_t_10) {

        /* "plastid/genomics/roitools.pyx":1114
 *                     return True
 *                 elif sstart > ostart:
 *                     return False             # <<<<<<<<<<<<<<
 *                 elif sstart == ostart:
 *                     send = self.end
 */
        __pyx_r = 0;
        goto __pyx_L0;

        /* "plastid/genomics/roitools.pyx":1113
 *                 if sstart < ostart:
 *                     return True
 *                 elif sstart > ostart:             # <<<<<<<<<<<<<<
 *                     return False
 *                 elif sstart == ostart:
 */
      }

      /* "plastid/genomics/roitools.pyx":1115
 *                 elif sstart > ostart:
 *                     return False
 *                 elif sstart == ostart:             # <<<<<<<<<<<<<<
 *                     send = self.end
 *                     oend = other.end
 */
      __pyx_t_10 = ((__pyx_v_sstart == __pyx_v_ostart) != 0);
      if (__pyx_t_10) {

        /* "plastid/genomics/roitools.pyx":1116
 *                     return False
 *                 elif sstart == ostart:
 *                     send = self.end             # <<<<<<<<<<<<<<
 *                     oend = other.end
 *                     if send < oend:
 */
        __pyx_t_11 = __pyx_v_self->end;
        __pyx_v_send = __pyx_t_11;

        /* "plastid/genomics/roitools.pyx":1117
 *                 elif sstart == ostart:
 *                     send = self.end
 *                     oend = other.end             # <<<<<<<<<<<<<<
 *                     if send < oend:
 *                         return True
 */
        __pyx_t_11 = __pyx_v_other->end;
        __pyx_v_oend = __pyx_t_11;

        /* "plastid/genomics/roitools.pyx":1118
 *                     send = self.end
 *                     oend = other.end
 *                     if send < oend:             # <<<<<<<<<<<<<<
 *                         return True
 *                     elif send > oend:
 */
        __pyx_t_10 = ((__pyx_v_send < __pyx_v_oend) != 0);
        if (__pyx_t_10) {

          /* "plastid/genomics/roitools.pyx":1119
 *                     oend = other.end
 *                     if send < oend:
 *                         return True             # <<<<<<<<<<<<<<
 *                     elif send > oend:
 *                         return False
 */
          __pyx_r = 1;
          goto __pyx_L0;

          /* "plastid/genomics/roitools.pyx":1118
 *                     send = self.end
 *                     oend = other.end
 *                     if send < oend:             # <<<<<<<<<<<<<<
 *                         return True
 *                     elif send > oend:
 */
        }

        /* "plastid/genomics/roitools.pyx":1120
 *                     if send < oend:
 *                         return True
 *                     elif send > oend:             # <<<<<<<<<<<<<<
 *                         return False
 *                     elif send == oend:
 */
        __pyx_t_10 = ((__pyx_v_send > __pyx_v_oend) != 0);
        if (__pyx_t_10) {

          /* "plastid/genomics/roitools.pyx":1121
 *                         return True
 *                     elif send > oend:
 *                         return False             # <<<<<<<<<<<<<<
 *                     elif send == oend:
 *                         return self.c_strand < other.c_strand
 */
          __pyx_r = 0;
          goto __pyx_L0;

          /* "plastid/genomics/roitools.pyx":1120
 *                     if send < oend:
 *                         return True
 *                     elif send > oend:             # <<<<<<<<<<<<<<
 *                         return False
 *                     elif send == oend:
 */
        }

        /* "plastid/genomics/roitools.pyx":1122
 *                     elif send > oend:
 *                         return False
 *                     elif send == oend:             # <<<<<<<<<<<<<<
 *                         return self.c_strand < other.c_strand
 *         elif cmptype == GT:
 */
        __pyx_t_10 = ((__pyx_v_send == __pyx_v_oend) != 0);
        if (__pyx_t_10) {

          /* "plastid/genomics/roitools.pyx":1123
 *                         return False
 *                     elif send == oend:
 *                         return self.c_strand < other.c_strand             # <<<<<<<<<<<<<<
 *         elif cmptype == GT:
 *             return other._cmp_helper(self, LT) # (other < self)
 */
          __pyx_r = (__pyx_v_self->c_strand < __pyx_v_other->c_strand);
          goto __pyx_L0;

          /* "plastid/genomics/roitools.pyx":1122
 *                     elif send > oend:
 *                         return False
 *                     elif send == oend:             # <<<<<<<<<<<<<<
 *                         return self.c_strand < other.c_strand
 *         elif cmptype == GT:
 */
        }

        /* "plastid/genomics/roitools.pyx":1115
 *                 elif sstart > ostart:
 *                     return False
 *                 elif sstart == ostart:             # <<<<<<<<<<<<<<
 *                     send = self.end
 *                     oend = other.end
 */
      }

      /* "plastid/genomics/roitools.pyx":1108
 *             elif schrom > ochrom:
 *                 return False
 *             elif schrom == ochrom:             # <<<<<<<<<<<<<<
 *                 sstart = self.start
 *                 ostart = other.start
 */
    }

    /* "plastid/genomics/roitools.pyx":1103
 *         elif cmptype == NEQ:
 *             return self._cmp_helper(other, EQ) == False
 *         elif cmptype == LT:             # <<<<<<<<<<<<<<
 *             if schrom < ochrom:
 *                 return True
 */
    break;
    case 4:

    /* "plastid/genomics/roitools.pyx":1125
 *                         return self.c_strand < other.c_strand
 *         elif cmptype == GT:
 *             return other._cmp_helper(self, LT) # (other < self)             # <<<<<<<<<<<<<<
 *         elif cmptype == LEQ:
 *             return self._cmp_helper(other, LT) or self._cmp_helper(other, EQ)
 */
    __pyx_r = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_other->__pyx_vtab)->_cmp_helper(__pyx_v_other, __pyx_v_self, 0, 0);
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1124
 *                     elif send == oend:
 *                         return self.c_strand < other.c_strand
 *         elif cmptype == GT:             # <<<<<<<<<<<<<<
 *             return other._cmp_helper(self, LT) # (other < self)
 *         elif cmptype == LEQ:
 */
    break;
    case 1:

    /* "plastid/genomics/roitools.pyx":1127
 *             return other._cmp_helper(self, LT) # (other < self)
 *         elif cmptype == LEQ:
 *             return self._cmp_helper(other, LT) or self._cmp_helper(other, EQ)             # <<<<<<<<<<<<<<
 *         elif cmptype == GEQ:
 *             return other._cmp_helper(self, LT) or self._cmp_helper(other, EQ)
 */
    __pyx_t_8 = (((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self->__pyx_vtab)->_cmp_helper(__pyx_v_self, __pyx_v_other, 0, 0) != 0);
    if (!__pyx_t_8) {
    } else {
      __pyx_t_10 = __pyx_t_8;
      goto __pyx_L10_bool_binop_done;
    }
    __pyx_t_8 = (((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self->__pyx_vtab)->_cmp_helper(__pyx_v_self, __pyx_v_other, 2, 0) != 0);
    __pyx_t_10 = __pyx_t_8;
    __pyx_L10_bool_binop_done:;
    __pyx_r = __pyx_t_10;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1126
 *         elif cmptype == GT:
 *             return other._cmp_helper(self, LT) # (other < self)
 *         elif cmptype == LEQ:             # <<<<<<<<<<<<<<
 *             return self._cmp_helper(other, LT) or self._cmp_helper(other, EQ)
 *         elif cmptype == GEQ:
 */
    break;
    case 5:

    /* "plastid/genomics/roitools.pyx":1129
 *             return self._cmp_helper(other, LT) or self._cmp_helper(other, EQ)
 *         elif cmptype == GEQ:
 *             return other._cmp_helper(self, LT) or self._cmp_helper(other, EQ)             # <<<<<<<<<<<<<<
 *         else:
 *             raise AttributeError("Comparison operation not defined")
 */
    __pyx_t_8 = (((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_other->__pyx_vtab)->_cmp_helper(__pyx_v_other, __pyx_v_self, 0, 0) != 0);
    if (!__pyx_t_8) {
    } else {
      __pyx_t_10 = __pyx_t_8;
      goto __pyx_L12_bool_binop_done;
    }
    __pyx_t_8 = (((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self->__pyx_vtab)->_cmp_helper(__pyx_v_self, __pyx_v_other, 2, 0) != 0);
    __pyx_t_10 = __pyx_t_8;
    __pyx_L12_bool_binop_done:;
    __pyx_r = __pyx_t_10;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1128
 *         elif cmptype == LEQ:
 *             return self._cmp_helper(other, LT) or self._cmp_helper(other, EQ)
 *         elif cmptype == GEQ:             # <<<<<<<<<<<<<<
 *             return other._cmp_helper(self, LT) or self._cmp_helper(other, EQ)
 *         else:
 */
    break;
    default:

    /* "plastid/genomics/roitools.pyx":1131
 *             return other._cmp_helper(self, LT) or self._cmp_helper(other, EQ)
 *         else:
 *             raise AttributeError("Comparison operation not defined")             # <<<<<<<<<<<<<<
 * 
 *     def __contains__(self, other):
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_AttributeError, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1131, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1131, __pyx_L1_error)
    break;
  }

  /* "plastid/genomics/roitools.pyx":1092
 *         return self._cmp_helper(other,cmptype)
 * 
 *     cpdef bint _cmp_helper(self, GenomicSegment other, int cmptype):             # <<<<<<<<<<<<<<
 *         nonecheck(other, "GenomicSegment eq/neq", "other")
 *         schrom = self.chrom
 */

  /* 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_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_WriteUnraisable("plastid.genomics.roitools.GenomicSegment._cmp_helper", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_schrom);
  __Pyx_XDECREF(__pyx_v_ochrom);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_21_cmp_helper(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_20_cmp_helper[] = "GenomicSegment._cmp_helper(self, GenomicSegment other, int cmptype) -> bool";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_21_cmp_helper(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other = 0;
  int __pyx_v_cmptype;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_cmp_helper (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_other,&__pyx_n_s_cmptype,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_cmptype)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_cmp_helper", 1, 2, 2, 1); __PYX_ERR(0, 1092, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_cmp_helper") < 0)) __PYX_ERR(0, 1092, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_other = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)values[0]);
    __pyx_v_cmptype = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_cmptype == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1092, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_cmp_helper", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1092, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment._cmp_helper", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment, 1, "other", 0))) __PYX_ERR(0, 1092, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_20_cmp_helper(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self), __pyx_v_other, __pyx_v_cmptype);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_20_cmp_helper(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other, int __pyx_v_cmptype) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_cmp_helper", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_f_7plastid_8genomics_8roitools_14GenomicSegment__cmp_helper(__pyx_v_self, __pyx_v_other, __pyx_v_cmptype, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment._cmp_helper", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1133
 *             raise AttributeError("Comparison operation not defined")
 * 
 *     def __contains__(self, other):             # <<<<<<<<<<<<<<
 *         """Test whether this segment contains `other`, where containment is
 *         defined as all positions in `other` being present in self, when both
 */

/* Python wrapper */
static int __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_23__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_22__contains__[] = "Test whether this segment contains `other`, where containment is\n        defined as all positions in `other` being present in self, when both\n        `self` and `other` share the same chromosome and strand.\n\n        Parameters\n        ----------\n        other : |GenomicSegment|\n            Query segment\n\n        Returns\n        -------\n        bool\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_7plastid_8genomics_8roitools_14GenomicSegment_22__contains__;
#endif
static int __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_23__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_22__contains__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self), ((PyObject *)__pyx_v_other));

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

static int __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_22__contains__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, PyObject *__pyx_v_other) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__contains__", 0);

  /* "plastid/genomics/roitools.pyx":1147
 *         bool
 *         """
 *         nonecheck(other, "GenomicSegment.__eq__", "other")             # <<<<<<<<<<<<<<
 *         return self.contains(other)
 * 
 */
  __pyx_f_7plastid_8genomics_8roitools_nonecheck(__pyx_v_other, __pyx_kp_u_GenomicSegment___eq, __pyx_n_u_other);

  /* "plastid/genomics/roitools.pyx":1148
 *         """
 *         nonecheck(other, "GenomicSegment.__eq__", "other")
 *         return self.contains(other)             # <<<<<<<<<<<<<<
 * 
 *     cpdef bint contains(self, GenomicSegment other):
 */
  if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 1148, __pyx_L1_error)
  __pyx_r = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self->__pyx_vtab)->contains(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_other), 0);
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1133
 *             raise AttributeError("Comparison operation not defined")
 * 
 *     def __contains__(self, other):             # <<<<<<<<<<<<<<
 *         """Test whether this segment contains `other`, where containment is
 *         defined as all positions in `other` being present in self, when both
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1150
 *         return self.contains(other)
 * 
 *     cpdef bint contains(self, GenomicSegment other):             # <<<<<<<<<<<<<<
 *         """Test whether this segment contains `other`, where containment is
 *         defined as all positions in `other` being present in self, when both
 */

static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_25contains(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static int __pyx_f_7plastid_8genomics_8roitools_14GenomicSegment_contains(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other, int __pyx_skip_dispatch) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("contains", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contains); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1150, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_25contains)) {
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, ((PyObject *)__pyx_v_other)) : __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_other));
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1150, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1150, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_r = __pyx_t_5;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "plastid/genomics/roitools.pyx":1164
 *         bool
 *         """
 *         nonecheck(other, "GenomicSegment.contains", "other")             # <<<<<<<<<<<<<<
 *         return self.chrom == other.chrom \
 *             and self.c_strand == other.c_strand \
 */
  __pyx_f_7plastid_8genomics_8roitools_nonecheck(((PyObject *)__pyx_v_other), __pyx_kp_u_GenomicSegment_contains, __pyx_n_u_other);

  /* "plastid/genomics/roitools.pyx":1165
 *         """
 *         nonecheck(other, "GenomicSegment.contains", "other")
 *         return self.chrom == other.chrom \             # <<<<<<<<<<<<<<
 *             and self.c_strand == other.c_strand \
 *             and other.start >= self.start \
 */
  __pyx_t_6 = (__Pyx_PyUnicode_Equals(__pyx_v_self->chrom, __pyx_v_other->chrom, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1165, __pyx_L1_error)
  __pyx_t_7 = (__pyx_t_6 != 0);
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L3_bool_binop_done;
  }

  /* "plastid/genomics/roitools.pyx":1166
 *         nonecheck(other, "GenomicSegment.contains", "other")
 *         return self.chrom == other.chrom \
 *             and self.c_strand == other.c_strand \             # <<<<<<<<<<<<<<
 *             and other.start >= self.start \
 *             and other.end <= self.end \
 */
  __pyx_t_7 = ((__pyx_v_self->c_strand == __pyx_v_other->c_strand) != 0);
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L3_bool_binop_done;
  }

  /* "plastid/genomics/roitools.pyx":1167
 *         return self.chrom == other.chrom \
 *             and self.c_strand == other.c_strand \
 *             and other.start >= self.start \             # <<<<<<<<<<<<<<
 *             and other.end <= self.end \
 *             and  other.end >= other.start
 */
  __pyx_t_7 = ((__pyx_v_other->start >= __pyx_v_self->start) != 0);
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L3_bool_binop_done;
  }

  /* "plastid/genomics/roitools.pyx":1168
 *             and self.c_strand == other.c_strand \
 *             and other.start >= self.start \
 *             and other.end <= self.end \             # <<<<<<<<<<<<<<
 *             and  other.end >= other.start
 * 
 */
  __pyx_t_7 = ((__pyx_v_other->end <= __pyx_v_self->end) != 0);
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L3_bool_binop_done;
  }

  /* "plastid/genomics/roitools.pyx":1169
 *             and other.start >= self.start \
 *             and other.end <= self.end \
 *             and  other.end >= other.start             # <<<<<<<<<<<<<<
 * 
 *     cpdef bint overlaps(self, GenomicSegment other):
 */
  __pyx_t_7 = ((__pyx_v_other->end >= __pyx_v_other->start) != 0);
  __pyx_t_5 = __pyx_t_7;
  __pyx_L3_bool_binop_done:;
  __pyx_r = __pyx_t_5;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1150
 *         return self.contains(other)
 * 
 *     cpdef bint contains(self, GenomicSegment other):             # <<<<<<<<<<<<<<
 *         """Test whether this segment contains `other`, where containment is
 *         defined as all positions in `other` being present in self, when both
 */

  /* 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_WriteUnraisable("plastid.genomics.roitools.GenomicSegment.contains", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_25contains(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_24contains[] = "GenomicSegment.contains(self, GenomicSegment other) -> bool\nTest whether this segment contains `other`, where containment is\n        defined as all positions in `other` being present in self, when both\n        `self` and `other` share the same chromosome and strand.\n\n        Parameters\n        ----------\n        other : |GenomicSegment|\n            Query segment\n\n        Returns\n        -------\n        bool\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_25contains(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("contains (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment, 1, "other", 0))) __PYX_ERR(0, 1150, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_24contains(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self), ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_other));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_24contains(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("contains", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_f_7plastid_8genomics_8roitools_14GenomicSegment_contains(__pyx_v_self, __pyx_v_other, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1150, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.contains", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1171
 *             and  other.end >= other.start
 * 
 *     cpdef bint overlaps(self, GenomicSegment other):             # <<<<<<<<<<<<<<
 *         """Test whether this segment overlaps `other`, where overlap is defined
 *         as sharing: a chromosome, a strand, and a subset of coordinates.
 */

static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_27overlaps(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static int __pyx_f_7plastid_8genomics_8roitools_14GenomicSegment_overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other, int __pyx_skip_dispatch) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("overlaps", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_overlaps); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1171, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_27overlaps)) {
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, ((PyObject *)__pyx_v_other)) : __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_other));
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1171, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1171, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_r = __pyx_t_5;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "plastid/genomics/roitools.pyx":1184
 *         bool
 *         """
 *         nonecheck(other, "GenomicSegment.overlaps", "other")             # <<<<<<<<<<<<<<
 *         if self.chrom == other.chrom and self.c_strand == other.c_strand:
 *             if (self.start >= other.start and self.start < other.end) \
 */
  __pyx_f_7plastid_8genomics_8roitools_nonecheck(((PyObject *)__pyx_v_other), __pyx_kp_u_GenomicSegment_overlaps, __pyx_n_u_other);

  /* "plastid/genomics/roitools.pyx":1185
 *         """
 *         nonecheck(other, "GenomicSegment.overlaps", "other")
 *         if self.chrom == other.chrom and self.c_strand == other.c_strand:             # <<<<<<<<<<<<<<
 *             if (self.start >= other.start and self.start < other.end) \
 *                or (other.start >= self.start and other.start < self.end):
 */
  __pyx_t_6 = (__Pyx_PyUnicode_Equals(__pyx_v_self->chrom, __pyx_v_other->chrom, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1185, __pyx_L1_error)
  __pyx_t_7 = (__pyx_t_6 != 0);
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_7 = ((__pyx_v_self->c_strand == __pyx_v_other->c_strand) != 0);
  __pyx_t_5 = __pyx_t_7;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_5) {

    /* "plastid/genomics/roitools.pyx":1186
 *         nonecheck(other, "GenomicSegment.overlaps", "other")
 *         if self.chrom == other.chrom and self.c_strand == other.c_strand:
 *             if (self.start >= other.start and self.start < other.end) \             # <<<<<<<<<<<<<<
 *                or (other.start >= self.start and other.start < self.end):
 *                     return True
 */
    __pyx_t_7 = ((__pyx_v_self->start >= __pyx_v_other->start) != 0);
    if (!__pyx_t_7) {
      goto __pyx_L8_next_or;
    } else {
    }
    __pyx_t_7 = ((__pyx_v_self->start < __pyx_v_other->end) != 0);
    if (!__pyx_t_7) {
    } else {
      __pyx_t_5 = __pyx_t_7;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_L8_next_or:;

    /* "plastid/genomics/roitools.pyx":1187
 *         if self.chrom == other.chrom and self.c_strand == other.c_strand:
 *             if (self.start >= other.start and self.start < other.end) \
 *                or (other.start >= self.start and other.start < self.end):             # <<<<<<<<<<<<<<
 *                     return True
 * 
 */
    __pyx_t_7 = ((__pyx_v_other->start >= __pyx_v_self->start) != 0);
    if (__pyx_t_7) {
    } else {
      __pyx_t_5 = __pyx_t_7;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_7 = ((__pyx_v_other->start < __pyx_v_self->end) != 0);
    __pyx_t_5 = __pyx_t_7;
    __pyx_L7_bool_binop_done:;

    /* "plastid/genomics/roitools.pyx":1186
 *         nonecheck(other, "GenomicSegment.overlaps", "other")
 *         if self.chrom == other.chrom and self.c_strand == other.c_strand:
 *             if (self.start >= other.start and self.start < other.end) \             # <<<<<<<<<<<<<<
 *                or (other.start >= self.start and other.start < self.end):
 *                     return True
 */
    if (__pyx_t_5) {

      /* "plastid/genomics/roitools.pyx":1188
 *             if (self.start >= other.start and self.start < other.end) \
 *                or (other.start >= self.start and other.start < self.end):
 *                     return True             # <<<<<<<<<<<<<<
 * 
 *         return False
 */
      __pyx_r = 1;
      goto __pyx_L0;

      /* "plastid/genomics/roitools.pyx":1186
 *         nonecheck(other, "GenomicSegment.overlaps", "other")
 *         if self.chrom == other.chrom and self.c_strand == other.c_strand:
 *             if (self.start >= other.start and self.start < other.end) \             # <<<<<<<<<<<<<<
 *                or (other.start >= self.start and other.start < self.end):
 *                     return True
 */
    }

    /* "plastid/genomics/roitools.pyx":1185
 *         """
 *         nonecheck(other, "GenomicSegment.overlaps", "other")
 *         if self.chrom == other.chrom and self.c_strand == other.c_strand:             # <<<<<<<<<<<<<<
 *             if (self.start >= other.start and self.start < other.end) \
 *                or (other.start >= self.start and other.start < self.end):
 */
  }

  /* "plastid/genomics/roitools.pyx":1190
 *                     return True
 * 
 *         return False             # <<<<<<<<<<<<<<
 * 
 *     cpdef str as_igv_str(self):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1171
 *             and  other.end >= other.start
 * 
 *     cpdef bint overlaps(self, GenomicSegment other):             # <<<<<<<<<<<<<<
 *         """Test whether this segment overlaps `other`, where overlap is defined
 *         as sharing: a chromosome, a strand, and a subset of coordinates.
 */

  /* 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_WriteUnraisable("plastid.genomics.roitools.GenomicSegment.overlaps", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_27overlaps(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_26overlaps[] = "GenomicSegment.overlaps(self, GenomicSegment other) -> bool\nTest whether this segment overlaps `other`, where overlap is defined\n        as sharing: a chromosome, a strand, and a subset of coordinates.\n\n        Parameters\n        ----------\n        other : |GenomicSegment|\n            Query segment\n\n        Returns\n        -------\n        bool\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_27overlaps(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("overlaps (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment, 1, "other", 0))) __PYX_ERR(0, 1171, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_26overlaps(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self), ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_other));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_26overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_other) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("overlaps", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_f_7plastid_8genomics_8roitools_14GenomicSegment_overlaps(__pyx_v_self, __pyx_v_other, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1171, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.overlaps", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1192
 *         return False
 * 
 *     cpdef str as_igv_str(self):             # <<<<<<<<<<<<<<
 *         """Format as an IGV location string"""
 *         return "%s:%s-%s" % (self.chrom, self.start + 1, self.end+1)
 */

static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_29as_igv_str(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_14GenomicSegment_as_igv_str(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self, int __pyx_skip_dispatch) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  Py_UCS4 __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("as_igv_str", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_as_igv_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1192, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_29as_igv_str)) {
        __Pyx_XDECREF(__pyx_r);
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1192, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (!(likely(PyUnicode_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 1192, __pyx_L1_error)
        __pyx_r = ((PyObject*)__pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "plastid/genomics/roitools.pyx":1194
 *     cpdef str as_igv_str(self):
 *         """Format as an IGV location string"""
 *         return "%s:%s-%s" % (self.chrom, self.start + 1, self.end+1)             # <<<<<<<<<<<<<<
 * 
 *     @staticmethod
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = 0;
  __pyx_t_6 = 127;
  __pyx_t_2 = __Pyx_PyUnicode_Unicode(__pyx_v_self->chrom); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_6;
  __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __Pyx_INCREF(__pyx_kp_u__12);
  __pyx_t_5 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__12);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u__12);
  __pyx_t_2 = __Pyx_PyUnicode_From_long((__pyx_v_self->start + 1), 0, ' ', 'd'); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_2);
  __pyx_t_2 = 0;
  __Pyx_INCREF(__pyx_kp_u__13);
  __pyx_t_5 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__13);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u__13);
  __pyx_t_2 = __Pyx_PyUnicode_From_long((__pyx_v_self->end + 1), 0, ' ', 'd'); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1192
 *         return False
 * 
 *     cpdef str as_igv_str(self):             # <<<<<<<<<<<<<<
 *         """Format as an IGV location string"""
 *         return "%s:%s-%s" % (self.chrom, self.start + 1, self.end+1)
 */

  /* 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("plastid.genomics.roitools.GenomicSegment.as_igv_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_29as_igv_str(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_28as_igv_str[] = "GenomicSegment.as_igv_str(self) -> unicode\nFormat as an IGV location string";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_29as_igv_str(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("as_igv_str (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_28as_igv_str(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_28as_igv_str(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__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_RefNannySetupContext("as_igv_str", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_14GenomicSegment_as_igv_str(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.as_igv_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1197
 * 
 *     @staticmethod
 *     def from_igv_str(str loc_str, str strand="."):             # <<<<<<<<<<<<<<
 *         """Construct |GenomicSegment| from IGV location string
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_31from_igv_str(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_30from_igv_str[] = "GenomicSegment.from_igv_str(unicode loc_str, unicode strand=u'.')\nConstruct |GenomicSegment| from IGV location string\n\n        Parameters\n        ----------\n        igvloc : str\n            IGV location string, in format `'chromosome:start-end'`,\n            where `start` and `end` are 1-indexed and half-open\n\n        strand : str\n            The chromosome strand (`'+'`, `'-'`, or `'.'`)\n\n        Returns\n        -------\n        |GenomicSegment|\n        ";
static PyMethodDef __pyx_mdef_7plastid_8genomics_8roitools_14GenomicSegment_31from_igv_str = {"from_igv_str", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_31from_igv_str, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_30from_igv_str};
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_31from_igv_str(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_loc_str = 0;
  PyObject *__pyx_v_strand = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_igv_str (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_loc_str,&__pyx_n_s_strand,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject*)__pyx_kp_u__11);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_loc_str)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_strand);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "from_igv_str") < 0)) __PYX_ERR(0, 1197, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_loc_str = ((PyObject*)values[0]);
    __pyx_v_strand = ((PyObject*)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("from_igv_str", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1197, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.from_igv_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_loc_str), (&PyUnicode_Type), 1, "loc_str", 1))) __PYX_ERR(0, 1197, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_strand), (&PyUnicode_Type), 1, "strand", 1))) __PYX_ERR(0, 1197, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_30from_igv_str(__pyx_v_loc_str, __pyx_v_strand);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_30from_igv_str(PyObject *__pyx_v_loc_str, PyObject *__pyx_v_strand) {
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_s_start = 0;
  PyObject *__pyx_v_s_end = 0;
  long __pyx_v_start;
  long __pyx_v_end;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *(*__pyx_t_6)(PyObject *);
  long __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("from_igv_str", 0);

  /* "plastid/genomics/roitools.pyx":1217
 *             long start, end
 * 
 *         chrom, s_start, s_end = igvpat.search(loc_str).groups()             # <<<<<<<<<<<<<<
 *         start = long(s_start) - 1
 *         end   = long(s_end) - 1
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_igvpat); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1217, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_search); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1217, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_loc_str) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_loc_str);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1217, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_groups); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1217, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1217, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
    PyObject* sequence = __pyx_t_1;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 1217, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); 
    } else {
      __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 2); 
    }
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_3);
    #else
    __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext;
    index = 0; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L3_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    index = 1; __pyx_t_2 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 2; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 3) < 0) __PYX_ERR(0, 1217, __pyx_L1_error)
    __pyx_t_6 = NULL;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L4_unpacking_done;
    __pyx_L3_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 1217, __pyx_L1_error)
    __pyx_L4_unpacking_done:;
  }
  if (!(likely(PyUnicode_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 1217, __pyx_L1_error)
  if (!(likely(PyUnicode_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 1217, __pyx_L1_error)
  if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 1217, __pyx_L1_error)
  __pyx_v_chrom = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_v_s_start = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_v_s_end = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":1218
 * 
 *         chrom, s_start, s_end = igvpat.search(loc_str).groups()
 *         start = long(s_start) - 1             # <<<<<<<<<<<<<<
 *         end   = long(s_end) - 1
 *         return GenomicSegment(chrom, start, end, strand)
 */
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_v_s_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1218, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyNumber_Subtract(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1218, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_t_3); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1218, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_start = __pyx_t_7;

  /* "plastid/genomics/roitools.pyx":1219
 *         chrom, s_start, s_end = igvpat.search(loc_str).groups()
 *         start = long(s_start) - 1
 *         end   = long(s_end) - 1             # <<<<<<<<<<<<<<
 *         return GenomicSegment(chrom, start, end, strand)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_v_s_end); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyNumber_Subtract(__pyx_t_3, __pyx_int_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_7 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_7 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1219, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_end = __pyx_t_7;

  /* "plastid/genomics/roitools.pyx":1220
 *         start = long(s_start) - 1
 *         end   = long(s_end) - 1
 *         return GenomicSegment(chrom, start, end, strand)             # <<<<<<<<<<<<<<
 * 
 *     property start:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1220, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_end); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1220, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1220, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_3);
  __Pyx_INCREF(__pyx_v_strand);
  __Pyx_GIVEREF(__pyx_v_strand);
  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_strand);
  __pyx_t_1 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1220, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1197
 * 
 *     @staticmethod
 *     def from_igv_str(str loc_str, str strand="."):             # <<<<<<<<<<<<<<
 *         """Construct |GenomicSegment| from IGV location string
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.from_igv_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_s_start);
  __Pyx_XDECREF(__pyx_v_s_end);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1224
 *     property start:
 *         """Zero-indexed (Pythonic) start coordinate of |GenomicSegment|"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.start
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_5start_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_5start_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_5start___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_5start___get__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__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_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":1225
 *         """Zero-indexed (Pythonic) start coordinate of |GenomicSegment|"""
 *         def __get__(self):
 *             return self.start             # <<<<<<<<<<<<<<
 * 
 *     property end:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1224
 *     property start:
 *         """Zero-indexed (Pythonic) start coordinate of |GenomicSegment|"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.start
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.start.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1229
 *     property end:
 *         """Zero-indexed, half-open (Pythonic) end coordinate of |GenomicSegment|"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.end
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_3end_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_3end_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_3end___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_3end___get__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__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_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":1230
 *         """Zero-indexed, half-open (Pythonic) end coordinate of |GenomicSegment|"""
 *         def __get__(self):
 *             return self.end             # <<<<<<<<<<<<<<
 * 
 *     property chrom:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1230, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1229
 *     property end:
 *         """Zero-indexed, half-open (Pythonic) end coordinate of |GenomicSegment|"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.end
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.end.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1234
 *     property chrom:
 *         """Chromosome where |GenomicSegment| resides"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.chrom
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_5chrom_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_5chrom_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_5chrom___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_5chrom___get__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":1235
 *         """Chromosome where |GenomicSegment| resides"""
 *         def __get__(self):
 *             return self.chrom             # <<<<<<<<<<<<<<
 * 
 *     property strand:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->chrom);
  __pyx_r = __pyx_v_self->chrom;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1234
 *     property chrom:
 *         """Chromosome where |GenomicSegment| resides"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.chrom
 * 
 */

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

/* "plastid/genomics/roitools.pyx":1244
 *           - '.' for unstranded / both strands
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return strand_to_str(self.c_strand)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_6strand_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_6strand_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_6strand___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_6strand___get__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__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_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":1245
 *         """
 *         def __get__(self):
 *             return strand_to_str(self.c_strand)             # <<<<<<<<<<<<<<
 * 
 *     property c_strand:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8c_common_strand_to_str(__pyx_v_self->c_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1245, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1244
 *           - '.' for unstranded / both strands
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return strand_to_str(self.c_strand)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.strand.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1248
 * 
 *     property c_strand:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.c_strand
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_8c_strand_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_8c_strand_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_8c_strand___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_14GenomicSegment_8c_strand___get__(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__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_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":1249
 *     property c_strand:
 *         def __get__(self):
 *             return self.c_strand             # <<<<<<<<<<<<<<
 * 
 * cdef class SegmentChain(object):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_enum____pyx_t_7plastid_8genomics_8c_common_Strand(__pyx_v_self->c_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1249, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1248
 * 
 *     property c_strand:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.c_strand
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.GenomicSegment.c_strand.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1333
 *     """
 * 
 *     def __cinit__(self, *segments, **attr):             # <<<<<<<<<<<<<<
 *         """Create an |SegmentChain| from zero or more |GenomicSegment| objects
 * 
 */

/* Python wrapper */
static int __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_segments = 0;
  PyObject *__pyx_v_attr = 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_attr = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New(); if (unlikely(!__pyx_v_attr)) return -1;
  __Pyx_GOTREF(__pyx_v_attr);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_segments = __pyx_args;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain___cinit__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_segments, __pyx_v_attr);

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

static int __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain___cinit__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_segments, PyObject *__pyx_v_attr) {
  int __pyx_v_num_segs;
  PyObject *__pyx_v_new_segments = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "plastid/genomics/roitools.pyx":1365
 *         """
 *         cdef:
 *             int num_segs = len(segments)             # <<<<<<<<<<<<<<
 *             list new_segments
 * 
 */
  __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_segments); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1365, __pyx_L1_error)
  __pyx_v_num_segs = __pyx_t_1;

  /* "plastid/genomics/roitools.pyx":1368
 *             list new_segments
 * 
 *         if "type" not in attr:             # <<<<<<<<<<<<<<
 *             attr["type"] = "exon"
 * 
 */
  __pyx_t_2 = (__Pyx_PyDict_ContainsTF(__pyx_n_u_type, __pyx_v_attr, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1368, __pyx_L1_error)
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":1369
 * 
 *         if "type" not in attr:
 *             attr["type"] = "exon"             # <<<<<<<<<<<<<<
 * 
 *         self.attr = attr
 */
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_type, __pyx_n_u_exon) < 0)) __PYX_ERR(0, 1369, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":1368
 *             list new_segments
 * 
 *         if "type" not in attr:             # <<<<<<<<<<<<<<
 *             attr["type"] = "exon"
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":1371
 *             attr["type"] = "exon"
 * 
 *         self.attr = attr             # <<<<<<<<<<<<<<
 *         self._mask_segments = None
 *         self._segments      = []
 */
  __Pyx_INCREF(__pyx_v_attr);
  __Pyx_GIVEREF(__pyx_v_attr);
  __Pyx_GOTREF(__pyx_v_self->attr);
  __Pyx_DECREF(__pyx_v_self->attr);
  __pyx_v_self->attr = __pyx_v_attr;

  /* "plastid/genomics/roitools.pyx":1372
 * 
 *         self.attr = attr
 *         self._mask_segments = None             # <<<<<<<<<<<<<<
 *         self._segments      = []
 *         self.length         = 0
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_mask_segments);
  __Pyx_DECREF(__pyx_v_self->_mask_segments);
  __pyx_v_self->_mask_segments = ((PyObject*)Py_None);

  /* "plastid/genomics/roitools.pyx":1373
 *         self.attr = attr
 *         self._mask_segments = None
 *         self._segments      = []             # <<<<<<<<<<<<<<
 *         self.length         = 0
 *         self.masked_length  = 0
 */
  __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1373, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_GOTREF(__pyx_v_self->_segments);
  __Pyx_DECREF(__pyx_v_self->_segments);
  __pyx_v_self->_segments = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "plastid/genomics/roitools.pyx":1374
 *         self._mask_segments = None
 *         self._segments      = []
 *         self.length         = 0             # <<<<<<<<<<<<<<
 *         self.masked_length  = 0
 *         self.spanning_segment = NullSegment
 */
  __pyx_v_self->length = 0;

  /* "plastid/genomics/roitools.pyx":1375
 *         self._segments      = []
 *         self.length         = 0
 *         self.masked_length  = 0             # <<<<<<<<<<<<<<
 *         self.spanning_segment = NullSegment
 *         self._position_mask = None
 */
  __pyx_v_self->masked_length = 0;

  /* "plastid/genomics/roitools.pyx":1376
 *         self.length         = 0
 *         self.masked_length  = 0
 *         self.spanning_segment = NullSegment             # <<<<<<<<<<<<<<
 *         self._position_mask = None
 *         self._position_hash = None
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_7plastid_8genomics_8roitools_NullSegment));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_7plastid_8genomics_8roitools_NullSegment));
  __Pyx_GOTREF(__pyx_v_self->spanning_segment);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->spanning_segment));
  __pyx_v_self->spanning_segment = __pyx_v_7plastid_8genomics_8roitools_NullSegment;

  /* "plastid/genomics/roitools.pyx":1377
 *         self.masked_length  = 0
 *         self.spanning_segment = NullSegment
 *         self._position_mask = None             # <<<<<<<<<<<<<<
 *         self._position_hash = None
 *         if num_segs == 0:
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_position_mask);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->_position_mask));
  __pyx_v_self->_position_mask = ((arrayobject *)Py_None);

  /* "plastid/genomics/roitools.pyx":1378
 *         self.spanning_segment = NullSegment
 *         self._position_mask = None
 *         self._position_hash = None             # <<<<<<<<<<<<<<
 *         if num_segs == 0:
 *             pass
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_position_hash);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->_position_hash));
  __pyx_v_self->_position_hash = ((arrayobject *)Py_None);

  /* "plastid/genomics/roitools.pyx":1379
 *         self._position_mask = None
 *         self._position_hash = None
 *         if num_segs == 0:             # <<<<<<<<<<<<<<
 *             pass
 *         elif num_segs == 1:
 */
  switch (__pyx_v_num_segs) {
    case 0:
    break;
    case 1:

    /* "plastid/genomics/roitools.pyx":1382
 *             pass
 *         elif num_segs == 1:
 *             self._set_segments(list(segments))             # <<<<<<<<<<<<<<
 *         else:
 *             check_segments(self, segments)
 */
    __pyx_t_4 = PySequence_List(__pyx_v_segments); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1382, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_set_segments(__pyx_v_self, ((PyObject*)__pyx_t_4)); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 1382, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":1381
 *         if num_segs == 0:
 *             pass
 *         elif num_segs == 1:             # <<<<<<<<<<<<<<
 *             self._set_segments(list(segments))
 *         else:
 */
    break;
    default:

    /* "plastid/genomics/roitools.pyx":1384
 *             self._set_segments(list(segments))
 *         else:
 *             check_segments(self, segments)             # <<<<<<<<<<<<<<
 *             new_segments = merge_segments(list(segments))
 *             self._set_segments(new_segments)
 */
    __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_check_segments(__pyx_v_self, __pyx_v_segments); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 1384, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":1385
 *         else:
 *             check_segments(self, segments)
 *             new_segments = merge_segments(list(segments))             # <<<<<<<<<<<<<<
 *             self._set_segments(new_segments)
 * 
 */
    __pyx_t_4 = PySequence_List(__pyx_v_segments); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1385, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __pyx_f_7plastid_8genomics_8roitools_merge_segments(((PyObject*)__pyx_t_4), 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1385, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_new_segments = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":1386
 *             check_segments(self, segments)
 *             new_segments = merge_segments(list(segments))
 *             self._set_segments(new_segments)             # <<<<<<<<<<<<<<
 * 
 *     cdef bint _set_segments(self, list segments) except False:
 */
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_set_segments(__pyx_v_self, __pyx_v_new_segments); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 1386, __pyx_L1_error)
    break;
  }

  /* "plastid/genomics/roitools.pyx":1333
 *     """
 * 
 *     def __cinit__(self, *segments, **attr):             # <<<<<<<<<<<<<<
 *         """Create an |SegmentChain| from zero or more |GenomicSegment| objects
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_new_segments);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1388
 *             self._set_segments(new_segments)
 * 
 *     cdef bint _set_segments(self, list segments) except False:             # <<<<<<<<<<<<<<
 *         """Set `self._segments` assuming `segments` have passed the following criteria:
 * 
 */

static int __pyx_f_7plastid_8genomics_8roitools_12SegmentChain__set_segments(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_segments) {
  int __pyx_v_num_segs;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_seg0 = 0;
  long __pyx_v_length;
  PyObject *__pyx_v_segs = NULL;
  PyObject *__pyx_8genexpr5__pyx_v_X = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  long __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_set_segments", 0);

  /* "plastid/genomics/roitools.pyx":1428
 *         """
 *         cdef:
 *             int num_segs = len(segments)             # <<<<<<<<<<<<<<
 *             GenomicSegment segment, seg0
 *             long length = sum([len(X) for X in segments])
 */
  if (unlikely(__pyx_v_segments == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 1428, __pyx_L1_error)
  }
  __pyx_t_1 = PyList_GET_SIZE(__pyx_v_segments); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1428, __pyx_L1_error)
  __pyx_v_num_segs = __pyx_t_1;

  /* "plastid/genomics/roitools.pyx":1430
 *             int num_segs = len(segments)
 *             GenomicSegment segment, seg0
 *             long length = sum([len(X) for X in segments])             # <<<<<<<<<<<<<<
 * 
 *         self._segments = segments
 */
  { /* enter inner scope */
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1430, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (unlikely(__pyx_v_segments == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 1430, __pyx_L5_error)
    }
    __pyx_t_3 = __pyx_v_segments; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0;
    for (;;) {
      if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 1430, __pyx_L5_error)
      #else
      __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1430, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_4);
      #endif
      __Pyx_XDECREF_SET(__pyx_8genexpr5__pyx_v_X, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_5 = PyObject_Length(__pyx_8genexpr5__pyx_v_X); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1430, __pyx_L5_error)
      __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1430, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 1430, __pyx_L5_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_8genexpr5__pyx_v_X); __pyx_8genexpr5__pyx_v_X = 0;
    goto __pyx_L8_exit_scope;
    __pyx_L5_error:;
    __Pyx_XDECREF(__pyx_8genexpr5__pyx_v_X); __pyx_8genexpr5__pyx_v_X = 0;
    goto __pyx_L1_error;
    __pyx_L8_exit_scope:;
  } /* exit inner scope */
  __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_sum, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1430, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyInt_As_long(__pyx_t_3); if (unlikely((__pyx_t_6 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1430, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_length = __pyx_t_6;

  /* "plastid/genomics/roitools.pyx":1432
 *             long length = sum([len(X) for X in segments])
 * 
 *         self._segments = segments             # <<<<<<<<<<<<<<
 *         self.length = length
 *         self._position_hash = None
 */
  __Pyx_INCREF(__pyx_v_segments);
  __Pyx_GIVEREF(__pyx_v_segments);
  __Pyx_GOTREF(__pyx_v_self->_segments);
  __Pyx_DECREF(__pyx_v_self->_segments);
  __pyx_v_self->_segments = __pyx_v_segments;

  /* "plastid/genomics/roitools.pyx":1433
 * 
 *         self._segments = segments
 *         self.length = length             # <<<<<<<<<<<<<<
 *         self._position_hash = None
 *         self.c_reset_masks()
 */
  __pyx_v_self->length = __pyx_v_length;

  /* "plastid/genomics/roitools.pyx":1434
 *         self._segments = segments
 *         self.length = length
 *         self._position_hash = None             # <<<<<<<<<<<<<<
 *         self.c_reset_masks()
 * 
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_position_hash);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->_position_hash));
  __pyx_v_self->_position_hash = ((arrayobject *)Py_None);

  /* "plastid/genomics/roitools.pyx":1435
 *         self.length = length
 *         self._position_hash = None
 *         self.c_reset_masks()             # <<<<<<<<<<<<<<
 * 
 *         if num_segs == 0:
 */
  ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_reset_masks(__pyx_v_self);

  /* "plastid/genomics/roitools.pyx":1437
 *         self.c_reset_masks()
 * 
 *         if num_segs == 0:             # <<<<<<<<<<<<<<
 *             self.spanning_segment = NullSegment
 *         elif num_segs == 1:
 */
  switch (__pyx_v_num_segs) {
    case 0:

    /* "plastid/genomics/roitools.pyx":1438
 * 
 *         if num_segs == 0:
 *             self.spanning_segment = NullSegment             # <<<<<<<<<<<<<<
 *         elif num_segs == 1:
 *             self.spanning_segment = self._segments[0]
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_7plastid_8genomics_8roitools_NullSegment));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_7plastid_8genomics_8roitools_NullSegment));
    __Pyx_GOTREF(__pyx_v_self->spanning_segment);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->spanning_segment));
    __pyx_v_self->spanning_segment = __pyx_v_7plastid_8genomics_8roitools_NullSegment;

    /* "plastid/genomics/roitools.pyx":1437
 *         self.c_reset_masks()
 * 
 *         if num_segs == 0:             # <<<<<<<<<<<<<<
 *             self.spanning_segment = NullSegment
 *         elif num_segs == 1:
 */
    break;
    case 1:

    /* "plastid/genomics/roitools.pyx":1440
 *             self.spanning_segment = NullSegment
 *         elif num_segs == 1:
 *             self.spanning_segment = self._segments[0]             # <<<<<<<<<<<<<<
 *         else:
 *             segs = self._segments
 */
    if (unlikely(__pyx_v_self->_segments == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 1440, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_self->_segments, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1440, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 1440, __pyx_L1_error)
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_GOTREF(__pyx_v_self->spanning_segment);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->spanning_segment));
    __pyx_v_self->spanning_segment = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":1439
 *         if num_segs == 0:
 *             self.spanning_segment = NullSegment
 *         elif num_segs == 1:             # <<<<<<<<<<<<<<
 *             self.spanning_segment = self._segments[0]
 *         else:
 */
    break;
    default:

    /* "plastid/genomics/roitools.pyx":1442
 *             self.spanning_segment = self._segments[0]
 *         else:
 *             segs = self._segments             # <<<<<<<<<<<<<<
 *             seg0 = segs[0]
 *             self.spanning_segment = GenomicSegment(
 */
    __pyx_t_3 = __pyx_v_self->_segments;
    __Pyx_INCREF(__pyx_t_3);
    __pyx_v_segs = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":1443
 *         else:
 *             segs = self._segments
 *             seg0 = segs[0]             # <<<<<<<<<<<<<<
 *             self.spanning_segment = GenomicSegment(
 *                 seg0.chrom, seg0.start, segs[-1].end, seg0.strand
 */
    if (unlikely(__pyx_v_segs == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 1443, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_segs, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1443, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 1443, __pyx_L1_error)
    __pyx_v_seg0 = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":1445
 *             seg0 = segs[0]
 *             self.spanning_segment = GenomicSegment(
 *                 seg0.chrom, seg0.start, segs[-1].end, seg0.strand             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_seg0->start); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1445, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (unlikely(__pyx_v_segs == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 1445, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_segs, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1445, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_end); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1445, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_seg0), __pyx_n_s_strand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1445, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "plastid/genomics/roitools.pyx":1444
 *             segs = self._segments
 *             seg0 = segs[0]
 *             self.spanning_segment = GenomicSegment(             # <<<<<<<<<<<<<<
 *                 seg0.chrom, seg0.start, segs[-1].end, seg0.strand
 *             )
 */
    __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1444, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_v_seg0->chrom);
    __Pyx_GIVEREF(__pyx_v_seg0->chrom);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_seg0->chrom);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_t_2);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1444, __pyx_L1_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->spanning_segment);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->spanning_segment));
    __pyx_v_self->spanning_segment = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_2);
    __pyx_t_2 = 0;
    break;
  }

  /* "plastid/genomics/roitools.pyx":1448
 *             )
 * 
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     cdef array.array _get_position_hash(self):
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1388
 *             self._set_segments(new_segments)
 * 
 *     cdef bint _set_segments(self, list segments) except False:             # <<<<<<<<<<<<<<
 *         """Set `self._segments` assuming `segments` have passed the following criteria:
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain._set_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_seg0);
  __Pyx_XDECREF(__pyx_v_segs);
  __Pyx_XDECREF(__pyx_8genexpr5__pyx_v_X);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1450
 *         return True
 * 
 *     cdef array.array _get_position_hash(self):             # <<<<<<<<<<<<<<
 *         """Populate hash mapping coordinates in `self` to corresponding genomic coordinates,
 *         leftmost first (i.e. position 0 is that with the lowest corresponding genomic coordinate,
 */

static arrayobject *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain__get_position_hash(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_segment = 0;
  long __pyx_v_x;
  long __pyx_v_c;
  arrayobject *__pyx_v_my_hash = 0;
  __Pyx_memviewslice __pyx_v_my_view = { 0, 0, { 0 }, { 0 }, { 0 } };
  arrayobject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_memviewslice __pyx_t_5 = { 0, 0, { 0 }, { 0 }, { 0 } };
  Py_ssize_t __pyx_t_6;
  long __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_get_position_hash", 0);

  /* "plastid/genomics/roitools.pyx":1465
 *             leftmost first (i.e. in genomic order, not transcript order).
 *         """
 *         if self._position_hash is not None:             # <<<<<<<<<<<<<<
 *             return self._position_hash
 * 
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->_position_hash) != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1466
 *         """
 *         if self._position_hash is not None:
 *             return self._position_hash             # <<<<<<<<<<<<<<
 * 
 *         cdef:
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_self->_position_hash));
    __pyx_r = __pyx_v_self->_position_hash;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1465
 *             leftmost first (i.e. in genomic order, not transcript order).
 *         """
 *         if self._position_hash is not None:             # <<<<<<<<<<<<<<
 *             return self._position_hash
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":1471
 *             GenomicSegment segment
 *             long x, c
 *             array.array my_hash = array.clone(hash_template, self.length, False)             # <<<<<<<<<<<<<<
 *             long [:] my_view = my_hash
 * 
 */
  if (!(likely(((__pyx_v_7plastid_8genomics_8roitools_hash_template) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_7plastid_8genomics_8roitools_hash_template, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 1471, __pyx_L1_error)
  __pyx_t_3 = __pyx_v_7plastid_8genomics_8roitools_hash_template;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = ((PyObject *)__pyx_f_7cpython_5array_clone(((arrayobject *)__pyx_t_3), __pyx_v_self->length, 0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1471, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_my_hash = ((arrayobject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "plastid/genomics/roitools.pyx":1472
 *             long x, c
 *             array.array my_hash = array.clone(hash_template, self.length, False)
 *             long [:] my_view = my_hash             # <<<<<<<<<<<<<<
 * 
 *         self._position_hash = my_hash
 */
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(((PyObject *)__pyx_v_my_hash), PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 1472, __pyx_L1_error)
  __pyx_v_my_view = __pyx_t_5;
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;

  /* "plastid/genomics/roitools.pyx":1474
 *             long [:] my_view = my_hash
 * 
 *         self._position_hash = my_hash             # <<<<<<<<<<<<<<
 * 
 *         c = 0
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_my_hash));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_my_hash));
  __Pyx_GOTREF(__pyx_v_self->_position_hash);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->_position_hash));
  __pyx_v_self->_position_hash = __pyx_v_my_hash;

  /* "plastid/genomics/roitools.pyx":1476
 *         self._position_hash = my_hash
 * 
 *         c = 0             # <<<<<<<<<<<<<<
 *         for segment in self._segments:
 *             x = segment.start
 */
  __pyx_v_c = 0;

  /* "plastid/genomics/roitools.pyx":1477
 * 
 *         c = 0
 *         for segment in self._segments:             # <<<<<<<<<<<<<<
 *             x = segment.start
 *             while x < segment.end:
 */
  if (unlikely(__pyx_v_self->_segments == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 1477, __pyx_L1_error)
  }
  __pyx_t_4 = __pyx_v_self->_segments; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0;
  for (;;) {
    if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_4)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1477, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1477, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 1477, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_segment, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":1478
 *         c = 0
 *         for segment in self._segments:
 *             x = segment.start             # <<<<<<<<<<<<<<
 *             while x < segment.end:
 *                 my_view[c] = x
 */
    __pyx_t_7 = __pyx_v_segment->start;
    __pyx_v_x = __pyx_t_7;

    /* "plastid/genomics/roitools.pyx":1479
 *         for segment in self._segments:
 *             x = segment.start
 *             while x < segment.end:             # <<<<<<<<<<<<<<
 *                 my_view[c] = x
 *                 c += 1
 */
    while (1) {
      __pyx_t_2 = ((__pyx_v_x < __pyx_v_segment->end) != 0);
      if (!__pyx_t_2) break;

      /* "plastid/genomics/roitools.pyx":1480
 *             x = segment.start
 *             while x < segment.end:
 *                 my_view[c] = x             # <<<<<<<<<<<<<<
 *                 c += 1
 *                 x += 1
 */
      __pyx_t_8 = __pyx_v_c;
      __pyx_t_9 = -1;
      if (__pyx_t_8 < 0) {
        __pyx_t_8 += __pyx_v_my_view.shape[0];
        if (unlikely(__pyx_t_8 < 0)) __pyx_t_9 = 0;
      } else if (unlikely(__pyx_t_8 >= __pyx_v_my_view.shape[0])) __pyx_t_9 = 0;
      if (unlikely(__pyx_t_9 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_9);
        __PYX_ERR(0, 1480, __pyx_L1_error)
      }
      *((long *) ( /* dim=0 */ (__pyx_v_my_view.data + __pyx_t_8 * __pyx_v_my_view.strides[0]) )) = __pyx_v_x;

      /* "plastid/genomics/roitools.pyx":1481
 *             while x < segment.end:
 *                 my_view[c] = x
 *                 c += 1             # <<<<<<<<<<<<<<
 *                 x += 1
 * 
 */
      __pyx_v_c = (__pyx_v_c + 1);

      /* "plastid/genomics/roitools.pyx":1482
 *                 my_view[c] = x
 *                 c += 1
 *                 x += 1             # <<<<<<<<<<<<<<
 * 
 *         return self._position_hash
 */
      __pyx_v_x = (__pyx_v_x + 1);
    }

    /* "plastid/genomics/roitools.pyx":1477
 * 
 *         c = 0
 *         for segment in self._segments:             # <<<<<<<<<<<<<<
 *             x = segment.start
 *             while x < segment.end:
 */
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "plastid/genomics/roitools.pyx":1484
 *                 x += 1
 * 
 *         return self._position_hash             # <<<<<<<<<<<<<<
 * 
 *     def sort(self): # this should never need to be called, now that _segments and _mask_segments are managed
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_self->_position_hash));
  __pyx_r = __pyx_v_self->_position_hash;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1450
 *         return True
 * 
 *     cdef array.array _get_position_hash(self):             # <<<<<<<<<<<<<<
 *         """Populate hash mapping coordinates in `self` to corresponding genomic coordinates,
 *         leftmost first (i.e. position 0 is that with the lowest corresponding genomic coordinate,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain._get_position_hash", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_segment);
  __Pyx_XDECREF((PyObject *)__pyx_v_my_hash);
  __PYX_XDEC_MEMVIEW(&__pyx_v_my_view, 1);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1486
 *         return self._position_hash
 * 
 *     def sort(self): # this should never need to be called, now that _segments and _mask_segments are managed             # <<<<<<<<<<<<<<
 *         self._segments.sort()
 *         if self._mask_segments is not None:
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_3sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_2sort[] = "SegmentChain.sort(self)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_3sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sort (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_2sort(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_2sort(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sort", 0);

  /* "plastid/genomics/roitools.pyx":1487
 * 
 *     def sort(self): # this should never need to be called, now that _segments and _mask_segments are managed
 *         self._segments.sort()             # <<<<<<<<<<<<<<
 *         if self._mask_segments is not None:
 *             self._mask_segments.sort()
 */
  if (unlikely(__pyx_v_self->_segments == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "sort");
    __PYX_ERR(0, 1487, __pyx_L1_error)
  }
  __pyx_t_1 = PyList_Sort(__pyx_v_self->_segments); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 1487, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":1488
 *     def sort(self): # this should never need to be called, now that _segments and _mask_segments are managed
 *         self._segments.sort()
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             self._mask_segments.sort()
 * 
 */
  __pyx_t_2 = (__pyx_v_self->_mask_segments != ((PyObject*)Py_None));
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":1489
 *         self._segments.sort()
 *         if self._mask_segments is not None:
 *             self._mask_segments.sort()             # <<<<<<<<<<<<<<
 * 
 *     property chrom:
 */
    if (unlikely(__pyx_v_self->_mask_segments == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "sort");
      __PYX_ERR(0, 1489, __pyx_L1_error)
    }
    __pyx_t_1 = PyList_Sort(__pyx_v_self->_mask_segments); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 1489, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":1488
 *     def sort(self): # this should never need to be called, now that _segments and _mask_segments are managed
 *         self._segments.sort()
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             self._mask_segments.sort()
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":1486
 *         return self._position_hash
 * 
 *     def sort(self): # this should never need to be called, now that _segments and _mask_segments are managed             # <<<<<<<<<<<<<<
 *         self._segments.sort()
 *         if self._mask_segments is not None:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.sort", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1493
 *     property chrom:
 *         """Chromosome the SegmentChain resides on"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.spanning_segment.chrom
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_5chrom_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_5chrom_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_5chrom___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_5chrom___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":1494
 *         """Chromosome the SegmentChain resides on"""
 *         def __get__(self):
 *             return self.spanning_segment.chrom             # <<<<<<<<<<<<<<
 * 
 *     property strand:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->spanning_segment->chrom);
  __pyx_r = __pyx_v_self->spanning_segment->chrom;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1493
 *     property chrom:
 *         """Chromosome the SegmentChain resides on"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.spanning_segment.chrom
 * 
 */

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

/* "plastid/genomics/roitools.pyx":1498
 *     property strand:
 *         """Strand of the SegmentChain"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return strand_to_str(self.spanning_segment.c_strand)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_6strand_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_6strand_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6strand___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6strand___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__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_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":1499
 *         """Strand of the SegmentChain"""
 *         def __get__(self):
 *             return strand_to_str(self.spanning_segment.c_strand)             # <<<<<<<<<<<<<<
 * 
 *     property c_strand:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8c_common_strand_to_str(__pyx_v_self->spanning_segment->c_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1499, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1498
 *     property strand:
 *         """Strand of the SegmentChain"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return strand_to_str(self.spanning_segment.c_strand)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.strand.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1502
 * 
 *     property c_strand:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.spanning_segment.c_strand
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_8c_strand_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_8c_strand_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_8c_strand___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_8c_strand___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__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_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":1503
 *     property c_strand:
 *         def __get__(self):
 *             return self.spanning_segment.c_strand             # <<<<<<<<<<<<<<
 * 
 *     property segments:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_enum____pyx_t_7plastid_8genomics_8c_common_Strand(__pyx_v_self->spanning_segment->c_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1502
 * 
 *     property c_strand:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.spanning_segment.c_strand
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_strand.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1509
 *         Changing this list will do nothing to `self`.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return copy.deepcopy(self._segments)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_8segments_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_8segments_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_8segments___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_8segments___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":1510
 *         """
 *         def __get__(self):
 *             return copy.deepcopy(self._segments)             # <<<<<<<<<<<<<<
 * 
 *     property mask_segments:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1510, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1510, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_self->_segments) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->_segments);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1510, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1509
 *         Changing this list will do nothing to `self`.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return copy.deepcopy(self._segments)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.segments.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1516
 *         Changing this list will do nothing to the masks in `self`.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self._mask_segments is None:
 *                 return []
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_13mask_segments_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_13mask_segments_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_13mask_segments___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_13mask_segments___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":1517
 *         """
 *         def __get__(self):
 *             if self._mask_segments is None:             # <<<<<<<<<<<<<<
 *                 return []
 * 
 */
  __pyx_t_1 = (__pyx_v_self->_mask_segments == ((PyObject*)Py_None));
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1518
 *         def __get__(self):
 *             if self._mask_segments is None:
 *                 return []             # <<<<<<<<<<<<<<
 * 
 *             return copy.deepcopy(self._mask_segments)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1518, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1517
 *         """
 *         def __get__(self):
 *             if self._mask_segments is None:             # <<<<<<<<<<<<<<
 *                 return []
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":1520
 *                 return []
 * 
 *             return copy.deepcopy(self._mask_segments)             # <<<<<<<<<<<<<<
 * 
 *     def __reduce__(self): # enable pickling
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_v_self->_mask_segments) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_self->_mask_segments);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1516
 *         Changing this list will do nothing to the masks in `self`.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self._mask_segments is None:
 *                 return []
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.mask_segments.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1522
 *             return copy.deepcopy(self._mask_segments)
 * 
 *     def __reduce__(self): # enable pickling             # <<<<<<<<<<<<<<
 *         return (self.__class__, tuple(), self.__getstate__())
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_5__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_4__reduce__[] = "SegmentChain.__reduce__(self)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_5__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_4__reduce__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_4__reduce__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce__", 0);

  /* "plastid/genomics/roitools.pyx":1523
 * 
 *     def __reduce__(self): # enable pickling
 *         return (self.__class__, tuple(), self.__getstate__())             # <<<<<<<<<<<<<<
 * 
 *     def __getstate__(self): # save state for pickling
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1523, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_CallNoArg(((PyObject *)(&PyTuple_Type))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1523, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getstate); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1523, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1523, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1523, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1522
 *             return copy.deepcopy(self._mask_segments)
 * 
 *     def __reduce__(self): # enable pickling             # <<<<<<<<<<<<<<
 *         return (self.__class__, tuple(), self.__getstate__())
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__reduce__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1525
 *         return (self.__class__, tuple(), self.__getstate__())
 * 
 *     def __getstate__(self): # save state for pickling             # <<<<<<<<<<<<<<
 *         cdef:
 *             list segstrs  = [str(X) for X in self._segments]
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_6__getstate__[] = "SegmentChain.__getstate__(self)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getstate__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6__getstate__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6__getstate__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_v_segstrs = 0;
  PyObject *__pyx_v_maskstrs = 0;
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_8genexpr6__pyx_v_X = NULL;
  PyObject *__pyx_8genexpr7__pyx_v_X = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getstate__", 0);

  /* "plastid/genomics/roitools.pyx":1527
 *     def __getstate__(self): # save state for pickling
 *         cdef:
 *             list segstrs  = [str(X) for X in self._segments]             # <<<<<<<<<<<<<<
 *             list maskstrs = []
 *             dict attr = self.attr
 */
  { /* enter inner scope */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1527, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (unlikely(__pyx_v_self->_segments == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 1527, __pyx_L5_error)
    }
    __pyx_t_2 = __pyx_v_self->_segments; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
    for (;;) {
      if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1527, __pyx_L5_error)
      #else
      __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1527, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_4);
      #endif
      __Pyx_XDECREF_SET(__pyx_8genexpr6__pyx_v_X, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_8genexpr6__pyx_v_X); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1527, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 1527, __pyx_L5_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_8genexpr6__pyx_v_X); __pyx_8genexpr6__pyx_v_X = 0;
    goto __pyx_L8_exit_scope;
    __pyx_L5_error:;
    __Pyx_XDECREF(__pyx_8genexpr6__pyx_v_X); __pyx_8genexpr6__pyx_v_X = 0;
    goto __pyx_L1_error;
    __pyx_L8_exit_scope:;
  } /* exit inner scope */
  __pyx_v_segstrs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1528
 *         cdef:
 *             list segstrs  = [str(X) for X in self._segments]
 *             list maskstrs = []             # <<<<<<<<<<<<<<
 *             dict attr = self.attr
 * 
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_maskstrs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1529
 *             list segstrs  = [str(X) for X in self._segments]
 *             list maskstrs = []
 *             dict attr = self.attr             # <<<<<<<<<<<<<<
 * 
 *         if self._mask_segments is not None:
 */
  __pyx_t_1 = __pyx_v_self->attr;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1531
 *             dict attr = self.attr
 * 
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             maskstrs = [str(X) for X in self._mask_segments]
 * 
 */
  __pyx_t_5 = (__pyx_v_self->_mask_segments != ((PyObject*)Py_None));
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "plastid/genomics/roitools.pyx":1532
 * 
 *         if self._mask_segments is not None:
 *             maskstrs = [str(X) for X in self._mask_segments]             # <<<<<<<<<<<<<<
 * 
 * 
 */
    { /* enter inner scope */
      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1532, __pyx_L12_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (unlikely(__pyx_v_self->_mask_segments == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 1532, __pyx_L12_error)
      }
      __pyx_t_2 = __pyx_v_self->_mask_segments; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
      for (;;) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1532, __pyx_L12_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1532, __pyx_L12_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
        __Pyx_XDECREF_SET(__pyx_8genexpr7__pyx_v_X, __pyx_t_4);
        __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_8genexpr7__pyx_v_X); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1532, __pyx_L12_error)
        __Pyx_GOTREF(__pyx_t_4);
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 1532, __pyx_L12_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_8genexpr7__pyx_v_X); __pyx_8genexpr7__pyx_v_X = 0;
      goto __pyx_L15_exit_scope;
      __pyx_L12_error:;
      __Pyx_XDECREF(__pyx_8genexpr7__pyx_v_X); __pyx_8genexpr7__pyx_v_X = 0;
      goto __pyx_L1_error;
      __pyx_L15_exit_scope:;
    } /* exit inner scope */
    __Pyx_DECREF_SET(__pyx_v_maskstrs, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":1531
 *             dict attr = self.attr
 * 
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             maskstrs = [str(X) for X in self._mask_segments]
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":1535
 * 
 * 
 *         return (segstrs, maskstrs, attr)             # <<<<<<<<<<<<<<
 * 
 *     def __setstate__(self, state): # revive state from pickling
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1535, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_segstrs);
  __Pyx_GIVEREF(__pyx_v_segstrs);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_segstrs);
  __Pyx_INCREF(__pyx_v_maskstrs);
  __Pyx_GIVEREF(__pyx_v_maskstrs);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_maskstrs);
  __Pyx_INCREF(__pyx_v_attr);
  __Pyx_GIVEREF(__pyx_v_attr);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_attr);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1525
 *         return (self.__class__, tuple(), self.__getstate__())
 * 
 *     def __getstate__(self): # save state for pickling             # <<<<<<<<<<<<<<
 *         cdef:
 *             list segstrs  = [str(X) for X in self._segments]
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__getstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_segstrs);
  __Pyx_XDECREF(__pyx_v_maskstrs);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_8genexpr6__pyx_v_X);
  __Pyx_XDECREF(__pyx_8genexpr7__pyx_v_X);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1537
 *         return (segstrs, maskstrs, attr)
 * 
 *     def __setstate__(self, state): # revive state from pickling             # <<<<<<<<<<<<<<
 *         cdef:
 *             list segs  = [GenomicSegment.from_str(X) for X in state[0]]
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_8__setstate__[] = "SegmentChain.__setstate__(self, state)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_8__setstate__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((PyObject *)__pyx_v_state));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_8__setstate__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_state) {
  PyObject *__pyx_v_segs = 0;
  PyObject *__pyx_v_masks = 0;
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_8genexpr8__pyx_v_X = NULL;
  PyObject *__pyx_8genexpr9__pyx_v_X = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate__", 0);

  /* "plastid/genomics/roitools.pyx":1539
 *     def __setstate__(self, state): # revive state from pickling
 *         cdef:
 *             list segs  = [GenomicSegment.from_str(X) for X in state[0]]             # <<<<<<<<<<<<<<
 *             list masks = [GenomicSegment.from_str(X) for X in state[1]]
 *             dict attr = state[2]
 */
  { /* enter inner scope */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1539, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1539, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
      __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1539, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1539, __pyx_L5_error)
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_3))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1539, __pyx_L5_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1539, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1539, __pyx_L5_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1539, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_5(__pyx_t_3);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1539, __pyx_L5_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_8genexpr8__pyx_v_X, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_n_s_from_str); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1539, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_2 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_8genexpr8__pyx_v_X) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_8genexpr8__pyx_v_X);
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1539, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 1539, __pyx_L5_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_8genexpr8__pyx_v_X); __pyx_8genexpr8__pyx_v_X = 0;
    goto __pyx_L8_exit_scope;
    __pyx_L5_error:;
    __Pyx_XDECREF(__pyx_8genexpr8__pyx_v_X); __pyx_8genexpr8__pyx_v_X = 0;
    goto __pyx_L1_error;
    __pyx_L8_exit_scope:;
  } /* exit inner scope */
  __pyx_v_segs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1540
 *         cdef:
 *             list segs  = [GenomicSegment.from_str(X) for X in state[0]]
 *             list masks = [GenomicSegment.from_str(X) for X in state[1]]             # <<<<<<<<<<<<<<
 *             dict attr = state[2]
 * 
 */
  { /* enter inner scope */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1540, __pyx_L11_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1540, __pyx_L11_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
      __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1540, __pyx_L11_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1540, __pyx_L11_error)
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1540, __pyx_L11_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1540, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1540, __pyx_L11_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1540, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        }
      } else {
        __pyx_t_3 = __pyx_t_5(__pyx_t_2);
        if (unlikely(!__pyx_t_3)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1540, __pyx_L11_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_XDECREF_SET(__pyx_8genexpr9__pyx_v_X, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_n_s_from_str); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1540, __pyx_L11_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_8genexpr9__pyx_v_X) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_8genexpr9__pyx_v_X);
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1540, __pyx_L11_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 1540, __pyx_L11_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_8genexpr9__pyx_v_X); __pyx_8genexpr9__pyx_v_X = 0;
    goto __pyx_L14_exit_scope;
    __pyx_L11_error:;
    __Pyx_XDECREF(__pyx_8genexpr9__pyx_v_X); __pyx_8genexpr9__pyx_v_X = 0;
    goto __pyx_L1_error;
    __pyx_L14_exit_scope:;
  } /* exit inner scope */
  __pyx_v_masks = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1541
 *             list segs  = [GenomicSegment.from_str(X) for X in state[0]]
 *             list masks = [GenomicSegment.from_str(X) for X in state[1]]
 *             dict attr = state[2]             # <<<<<<<<<<<<<<
 * 
 *         self.attr = attr
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1541, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 1541, __pyx_L1_error)
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1543
 *             dict attr = state[2]
 * 
 *         self.attr = attr             # <<<<<<<<<<<<<<
 *         self._set_segments(segs)
 *         self._set_masks(masks)
 */
  __Pyx_INCREF(__pyx_v_attr);
  __Pyx_GIVEREF(__pyx_v_attr);
  __Pyx_GOTREF(__pyx_v_self->attr);
  __Pyx_DECREF(__pyx_v_self->attr);
  __pyx_v_self->attr = __pyx_v_attr;

  /* "plastid/genomics/roitools.pyx":1544
 * 
 *         self.attr = attr
 *         self._set_segments(segs)             # <<<<<<<<<<<<<<
 *         self._set_masks(masks)
 * 
 */
  __pyx_t_8 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_set_segments(__pyx_v_self, __pyx_v_segs); if (unlikely(__pyx_t_8 == ((int)0))) __PYX_ERR(0, 1544, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":1545
 *         self.attr = attr
 *         self._set_segments(segs)
 *         self._set_masks(masks)             # <<<<<<<<<<<<<<
 * 
 *     def __copy__(self):
 */
  __pyx_t_8 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_set_masks(__pyx_v_self, __pyx_v_masks); if (unlikely(__pyx_t_8 == ((int)0))) __PYX_ERR(0, 1545, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":1537
 *         return (segstrs, maskstrs, attr)
 * 
 *     def __setstate__(self, state): # revive state from pickling             # <<<<<<<<<<<<<<
 *         cdef:
 *             list segs  = [GenomicSegment.from_str(X) for X in state[0]]
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__setstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_segs);
  __Pyx_XDECREF(__pyx_v_masks);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_8genexpr8__pyx_v_X);
  __Pyx_XDECREF(__pyx_8genexpr9__pyx_v_X);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1547
 *         self._set_masks(masks)
 * 
 *     def __copy__(self):             # <<<<<<<<<<<<<<
 *         chain2 = SegmentChain()
 *         chain2.attr = self.attr
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_11__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_10__copy__[] = "SegmentChain.__copy__(self)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_11__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__copy__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_10__copy__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_10__copy__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_chain2 = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__copy__", 0);

  /* "plastid/genomics/roitools.pyx":1548
 * 
 *     def __copy__(self):
 *         chain2 = SegmentChain()             # <<<<<<<<<<<<<<
 *         chain2.attr = self.attr
 *         chain2._set_segments(self._segments)
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1548, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_chain2 = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1549
 *     def __copy__(self):
 *         chain2 = SegmentChain()
 *         chain2.attr = self.attr             # <<<<<<<<<<<<<<
 *         chain2._set_segments(self._segments)
 *         if self._mask_segments is not None:
 */
  __pyx_t_1 = __pyx_v_self->attr;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_chain2->attr);
  __Pyx_DECREF(__pyx_v_chain2->attr);
  __pyx_v_chain2->attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1550
 *         chain2 = SegmentChain()
 *         chain2.attr = self.attr
 *         chain2._set_segments(self._segments)             # <<<<<<<<<<<<<<
 *         if self._mask_segments is not None:
 *             chain2._set_masks(self._mask_segments)
 */
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2->__pyx_vtab)->_set_segments(__pyx_v_chain2, ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(0, 1550, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1551
 *         chain2.attr = self.attr
 *         chain2._set_segments(self._segments)
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             chain2._set_masks(self._mask_segments)
 *         return chain2
 */
  __pyx_t_2 = (__pyx_v_self->_mask_segments != ((PyObject*)Py_None));
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":1552
 *         chain2._set_segments(self._segments)
 *         if self._mask_segments is not None:
 *             chain2._set_masks(self._mask_segments)             # <<<<<<<<<<<<<<
 *         return chain2
 * 
 */
    __pyx_t_1 = __pyx_v_self->_mask_segments;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2->__pyx_vtab)->_set_masks(__pyx_v_chain2, ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 1552, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":1551
 *         chain2.attr = self.attr
 *         chain2._set_segments(self._segments)
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             chain2._set_masks(self._mask_segments)
 *         return chain2
 */
  }

  /* "plastid/genomics/roitools.pyx":1553
 *         if self._mask_segments is not None:
 *             chain2._set_masks(self._mask_segments)
 *         return chain2             # <<<<<<<<<<<<<<
 * 
 *     def __deepcopy__(self, memo):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_chain2));
  __pyx_r = ((PyObject *)__pyx_v_chain2);
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1547
 *         self._set_masks(masks)
 * 
 *     def __copy__(self):             # <<<<<<<<<<<<<<
 *         chain2 = SegmentChain()
 *         chain2.attr = self.attr
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__copy__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_chain2);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1555
 *         return chain2
 * 
 *     def __deepcopy__(self, memo):             # <<<<<<<<<<<<<<
 *         chain2 = SegmentChain()
 *         chain2.attr = copy.deepcopy(self.attr)
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_13__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_12__deepcopy__[] = "SegmentChain.__deepcopy__(self, memo)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_13__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__deepcopy__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_12__deepcopy__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((PyObject *)__pyx_v_memo));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_12__deepcopy__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo) {
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_chain2 = 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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__deepcopy__", 0);

  /* "plastid/genomics/roitools.pyx":1556
 * 
 *     def __deepcopy__(self, memo):
 *         chain2 = SegmentChain()             # <<<<<<<<<<<<<<
 *         chain2.attr = copy.deepcopy(self.attr)
 *         chain2._set_segments(self._segments)
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1556, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_chain2 = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1557
 *     def __deepcopy__(self, memo):
 *         chain2 = SegmentChain()
 *         chain2.attr = copy.deepcopy(self.attr)             # <<<<<<<<<<<<<<
 *         chain2._set_segments(self._segments)
 *         if self._mask_segments is not None:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_self->attr) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->attr);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 1557, __pyx_L1_error)
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_chain2->attr);
  __Pyx_DECREF(__pyx_v_chain2->attr);
  __pyx_v_chain2->attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1558
 *         chain2 = SegmentChain()
 *         chain2.attr = copy.deepcopy(self.attr)
 *         chain2._set_segments(self._segments)             # <<<<<<<<<<<<<<
 *         if self._mask_segments is not None:
 *             chain2._set_masks(copy.deepcopy(self._mask_segments))
 */
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2->__pyx_vtab)->_set_segments(__pyx_v_chain2, ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_4 == ((int)0))) __PYX_ERR(0, 1558, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1559
 *         chain2.attr = copy.deepcopy(self.attr)
 *         chain2._set_segments(self._segments)
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             chain2._set_masks(copy.deepcopy(self._mask_segments))
 *         return chain2
 */
  __pyx_t_4 = (__pyx_v_self->_mask_segments != ((PyObject*)Py_None));
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "plastid/genomics/roitools.pyx":1560
 *         chain2._set_segments(self._segments)
 *         if self._mask_segments is not None:
 *             chain2._set_masks(copy.deepcopy(self._mask_segments))             # <<<<<<<<<<<<<<
 *         return chain2
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_copy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_self->_mask_segments) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_self->_mask_segments);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 1560, __pyx_L1_error)
    __pyx_t_5 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2->__pyx_vtab)->_set_masks(__pyx_v_chain2, ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(0, 1560, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":1559
 *         chain2.attr = copy.deepcopy(self.attr)
 *         chain2._set_segments(self._segments)
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             chain2._set_masks(copy.deepcopy(self._mask_segments))
 *         return chain2
 */
  }

  /* "plastid/genomics/roitools.pyx":1561
 *         if self._mask_segments is not None:
 *             chain2._set_masks(copy.deepcopy(self._mask_segments))
 *         return chain2             # <<<<<<<<<<<<<<
 * 
 *     def __richcmp__(self, object other, int cmpval):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_chain2));
  __pyx_r = ((PyObject *)__pyx_v_chain2);
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1555
 *         return chain2
 * 
 *     def __deepcopy__(self, memo):             # <<<<<<<<<<<<<<
 *         chain2 = SegmentChain()
 *         chain2.attr = copy.deepcopy(self.attr)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__deepcopy__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_chain2);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1563
 *         return chain2
 * 
 *     def __richcmp__(self, object other, int cmpval):             # <<<<<<<<<<<<<<
 *         """Test whether `self` and `other` are equal or unequal. Equality is
 *         defined as identity of positions, chromosomes, and strands. Two
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_15__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_cmpval); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_15__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_cmpval) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_14__richcmp__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((PyObject *)__pyx_v_other), ((int)__pyx_v_cmpval));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_14__richcmp__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_cmpval) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__richcmp__", 0);

  /* "plastid/genomics/roitools.pyx":1577
 *         bool
 *         """
 *         if isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             return chain_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, GenomicSegment):
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1578
 *         """
 *         if isinstance(other, SegmentChain):
 *             return chain_richcmp(self, other, cmpval) == true             # <<<<<<<<<<<<<<
 *         elif isinstance(other, GenomicSegment):
 *             return chain_richcmp(self, SegmentChain(other), cmpval) == true
 */
    __Pyx_XDECREF(__pyx_r);
    if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 1578, __pyx_L1_error)
    __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_other), __pyx_v_cmpval); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1578, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyBool_FromLong((__pyx_t_3 == __pyx_e_7plastid_8genomics_8c_common_true)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1578, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1577
 *         bool
 *         """
 *         if isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             return chain_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, GenomicSegment):
 */
  }

  /* "plastid/genomics/roitools.pyx":1579
 *         if isinstance(other, SegmentChain):
 *             return chain_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return chain_richcmp(self, SegmentChain(other), cmpval) == true
 *         else:
 */
  __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment); 
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (likely(__pyx_t_1)) {

    /* "plastid/genomics/roitools.pyx":1580
 *             return chain_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, GenomicSegment):
 *             return chain_richcmp(self, SegmentChain(other), cmpval) == true             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError(
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_v_other); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_4), __pyx_v_cmpval); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1580, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyBool_FromLong((__pyx_t_3 == __pyx_e_7plastid_8genomics_8c_common_true)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1579
 *         if isinstance(other, SegmentChain):
 *             return chain_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return chain_richcmp(self, SegmentChain(other), cmpval) == true
 *         else:
 */
  }

  /* "plastid/genomics/roitools.pyx":1582
 *             return chain_richcmp(self, SegmentChain(other), cmpval) == true
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain eq/ineq/et c is only defined for other SegmentChains or GenomicSegments."
 *             )
 */
  /*else*/ {
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1582, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 1582, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":1563
 *         return chain2
 * 
 *     def __richcmp__(self, object other, int cmpval):             # <<<<<<<<<<<<<<
 *         """Test whether `self` and `other` are equal or unequal. Equality is
 *         defined as identity of positions, chromosomes, and strands. Two
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1586
 *             )
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         cdef:
 *             str sout = "<%s segments=%s" % (self.__class__.__name__, len(self._segments))
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_17__repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_17__repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_16__repr__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_16__repr__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_v_sout = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_span = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  Py_UCS4 __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__repr__", 0);

  /* "plastid/genomics/roitools.pyx":1588
 *     def __repr__(self):
 *         cdef:
 *             str sout = "<%s segments=%s" % (self.__class__.__name__, len(self._segments))             # <<<<<<<<<<<<<<
 *             GenomicSegment span = self.spanning_segment
 * 
 */
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1588, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = 0;
  __pyx_t_3 = 127;
  __Pyx_INCREF(__pyx_kp_u__29);
  __pyx_t_2 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__29);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u__29);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_class); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1588, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1588, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_5), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1588, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u_segments);
  __pyx_t_2 += 10;
  __Pyx_GIVEREF(__pyx_kp_u_segments);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_segments);
  __pyx_t_4 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_4);
  if (unlikely(__pyx_t_4 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 1588, __pyx_L1_error)
  }
  __pyx_t_6 = PyList_GET_SIZE(__pyx_t_4); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1588, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyUnicode_From_Py_ssize_t(__pyx_t_6, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1588, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 4, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1588, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_sout = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "plastid/genomics/roitools.pyx":1589
 *         cdef:
 *             str sout = "<%s segments=%s" % (self.__class__.__name__, len(self._segments))
 *             GenomicSegment span = self.spanning_segment             # <<<<<<<<<<<<<<
 * 
 *         if len(self) > 0:
 */
  __pyx_t_4 = ((PyObject *)__pyx_v_self->spanning_segment);
  __Pyx_INCREF(__pyx_t_4);
  __pyx_v_span = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "plastid/genomics/roitools.pyx":1591
 *             GenomicSegment span = self.spanning_segment
 * 
 *         if len(self) > 0:             # <<<<<<<<<<<<<<
 *             sout += " bounds=%s:%s-%s(%s)" % (span.chrom, span.start, span.end, span.strand)
 *             sout += " name=%s" % self.get_name()
 */
  __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1591, __pyx_L1_error)
  __pyx_t_7 = ((__pyx_t_2 > 0) != 0);
  if (__pyx_t_7) {

    /* "plastid/genomics/roitools.pyx":1592
 * 
 *         if len(self) > 0:
 *             sout += " bounds=%s:%s-%s(%s)" % (span.chrom, span.start, span.end, span.strand)             # <<<<<<<<<<<<<<
 *             sout += " name=%s" % self.get_name()
 *         sout += ">"
 */
    __pyx_t_4 = PyTuple_New(9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1592, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = 0;
    __pyx_t_3 = 127;
    __Pyx_INCREF(__pyx_kp_u_bounds);
    __pyx_t_2 += 8;
    __Pyx_GIVEREF(__pyx_kp_u_bounds);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_bounds);
    __pyx_t_1 = __Pyx_PyUnicode_Unicode(__pyx_v_span->chrom); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1592, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) : __pyx_t_3;
    __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_kp_u__12);
    __pyx_t_2 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__12);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u__12);
    __pyx_t_1 = __Pyx_PyUnicode_From_long(__pyx_v_span->start, 0, ' ', 'd'); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1592, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_kp_u__13);
    __pyx_t_2 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__13);
    PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_kp_u__13);
    __pyx_t_1 = __Pyx_PyUnicode_From_long(__pyx_v_span->end, 0, ' ', 'd'); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1592, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_kp_u__14);
    __pyx_t_2 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__14);
    PyTuple_SET_ITEM(__pyx_t_4, 6, __pyx_kp_u__14);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_span), __pyx_n_s_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1592, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_1), __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1592, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_3;
    __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 7, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u__15);
    __pyx_t_2 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__15);
    PyTuple_SET_ITEM(__pyx_t_4, 8, __pyx_kp_u__15);
    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_4, 9, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1592, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyUnicode_Concat(__pyx_v_sout, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1592, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_sout, ((PyObject*)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":1593
 *         if len(self) > 0:
 *             sout += " bounds=%s:%s-%s(%s)" % (span.chrom, span.start, span.end, span.strand)
 *             sout += " name=%s" % self.get_name()             # <<<<<<<<<<<<<<
 *         sout += ">"
 *         return sout
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1593, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1593, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_name_s, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1593, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyUnicode_Concat(__pyx_v_sout, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1593, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_sout, ((PyObject*)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":1591
 *             GenomicSegment span = self.spanning_segment
 * 
 *         if len(self) > 0:             # <<<<<<<<<<<<<<
 *             sout += " bounds=%s:%s-%s(%s)" % (span.chrom, span.start, span.end, span.strand)
 *             sout += " name=%s" % self.get_name()
 */
  }

  /* "plastid/genomics/roitools.pyx":1594
 *             sout += " bounds=%s:%s-%s(%s)" % (span.chrom, span.start, span.end, span.strand)
 *             sout += " name=%s" % self.get_name()
 *         sout += ">"             # <<<<<<<<<<<<<<
 *         return sout
 * 
 */
  __pyx_t_4 = __Pyx_PyUnicode_Concat(__pyx_v_sout, __pyx_kp_u__30); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1594, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF_SET(__pyx_v_sout, ((PyObject*)__pyx_t_4));
  __pyx_t_4 = 0;

  /* "plastid/genomics/roitools.pyx":1595
 *             sout += " name=%s" % self.get_name()
 *         sout += ">"
 *         return sout             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_sout);
  __pyx_r = __pyx_v_sout;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1586
 *             )
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         cdef:
 *             str sout = "<%s segments=%s" % (self.__class__.__name__, len(self._segments))
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_sout);
  __Pyx_XDECREF((PyObject *)__pyx_v_span);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1597
 *         return sout
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         """String representation of |SegmentChain|. Inverse of
 *         :meth:`.from_str` Chains are represented as:
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_19__str__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_18__str__[] = "String representation of |SegmentChain|. Inverse of\n        :meth:`.from_str` Chains are represented as:\n\n            `'chrom_name:segment1_start-segment1_end^segment2_start-segment2_end^...^(strand)'`\n\n        Where all coordinates are zero-indexed and half-open. Masked segments\n        are not saved in this representation; nor are attributes in `self.attr`\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_18__str__;
#endif
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_19__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_18__str__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_18__str__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_v_ltmp = NULL;
  PyObject *__pyx_v_stmp = NULL;
  PyObject *__pyx_v_sout = NULL;
  PyObject *__pyx_9genexpr10__pyx_v_segment = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  Py_UCS4 __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__str__", 0);

  /* "plastid/genomics/roitools.pyx":1606
 *         are not saved in this representation; nor are attributes in `self.attr`
 *         """
 *         if len(self) > 0:             # <<<<<<<<<<<<<<
 *             ltmp = ["%s-%s" % (segment.start, segment.end) for segment in self]
 *             stmp = "^".join(ltmp)
 */
  __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1606, __pyx_L1_error)
  __pyx_t_2 = ((__pyx_t_1 > 0) != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1607
 *         """
 *         if len(self) > 0:
 *             ltmp = ["%s-%s" % (segment.start, segment.end) for segment in self]             # <<<<<<<<<<<<<<
 *             stmp = "^".join(ltmp)
 *             sout = "%s:%s(%s)" % (self.chrom, stmp, self.strand)
 */
    { /* enter inner scope */
      __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1607, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (likely(PyList_CheckExact(((PyObject *)__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_v_self))) {
        __pyx_t_4 = ((PyObject *)__pyx_v_self); __Pyx_INCREF(__pyx_t_4); __pyx_t_1 = 0;
        __pyx_t_5 = NULL;
      } else {
        __pyx_t_1 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1607, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1607, __pyx_L6_error)
      }
      for (;;) {
        if (likely(!__pyx_t_5)) {
          if (likely(PyList_CheckExact(__pyx_t_4))) {
            if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_4)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_1); __Pyx_INCREF(__pyx_t_6); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 1607, __pyx_L6_error)
            #else
            __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1607, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_6);
            #endif
          } else {
            if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_1); __Pyx_INCREF(__pyx_t_6); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 1607, __pyx_L6_error)
            #else
            __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1607, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_6);
            #endif
          }
        } else {
          __pyx_t_6 = __pyx_t_5(__pyx_t_4);
          if (unlikely(!__pyx_t_6)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 1607, __pyx_L6_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_6);
        }
        __Pyx_XDECREF_SET(__pyx_9genexpr10__pyx_v_segment, __pyx_t_6);
        __pyx_t_6 = 0;
        __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1607, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = 0;
        __pyx_t_8 = 127;
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr10__pyx_v_segment, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1607, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_10 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_9), __pyx_empty_unicode); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1607, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) : __pyx_t_8;
        __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_10);
        __pyx_t_10 = 0;
        __Pyx_INCREF(__pyx_kp_u__13);
        __pyx_t_7 += 1;
        __Pyx_GIVEREF(__pyx_kp_u__13);
        PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_kp_u__13);
        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr10__pyx_v_segment, __pyx_n_s_end); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1607, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_9 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_10), __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1607, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) : __pyx_t_8;
        __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_9);
        __pyx_t_9 = 0;
        __pyx_t_9 = __Pyx_PyUnicode_Join(__pyx_t_6, 3, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1607, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_9))) __PYX_ERR(0, 1607, __pyx_L6_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_9genexpr10__pyx_v_segment); __pyx_9genexpr10__pyx_v_segment = 0;
      goto __pyx_L9_exit_scope;
      __pyx_L6_error:;
      __Pyx_XDECREF(__pyx_9genexpr10__pyx_v_segment); __pyx_9genexpr10__pyx_v_segment = 0;
      goto __pyx_L1_error;
      __pyx_L9_exit_scope:;
    } /* exit inner scope */
    __pyx_v_ltmp = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":1608
 *         if len(self) > 0:
 *             ltmp = ["%s-%s" % (segment.start, segment.end) for segment in self]
 *             stmp = "^".join(ltmp)             # <<<<<<<<<<<<<<
 *             sout = "%s:%s(%s)" % (self.chrom, stmp, self.strand)
 *         else:
 */
    __pyx_t_3 = PyUnicode_Join(__pyx_kp_u__31, __pyx_v_ltmp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1608, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_stmp = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":1609
 *             ltmp = ["%s-%s" % (segment.start, segment.end) for segment in self]
 *             stmp = "^".join(ltmp)
 *             sout = "%s:%s(%s)" % (self.chrom, stmp, self.strand)             # <<<<<<<<<<<<<<
 *         else:
 *             sout = "na"
 */
    __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1609, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = 0;
    __pyx_t_8 = 127;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_chrom); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1609, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_9 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_4), __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1609, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) : __pyx_t_8;
    __pyx_t_1 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9);
    __pyx_t_9 = 0;
    __Pyx_INCREF(__pyx_kp_u__12);
    __pyx_t_1 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__12);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_u__12);
    __pyx_t_9 = __Pyx_PyUnicode_Unicode(__pyx_v_stmp); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1609, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) : __pyx_t_8;
    __pyx_t_1 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_9);
    __pyx_t_9 = 0;
    __Pyx_INCREF(__pyx_kp_u__14);
    __pyx_t_1 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__14);
    PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_kp_u__14);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1609, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_9), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1609, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_8;
    __pyx_t_1 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_t_4);
    __pyx_t_4 = 0;
    __Pyx_INCREF(__pyx_kp_u__15);
    __pyx_t_1 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__15);
    PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_kp_u__15);
    __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_3, 6, __pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1609, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_sout = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":1606
 *         are not saved in this representation; nor are attributes in `self.attr`
 *         """
 *         if len(self) > 0:             # <<<<<<<<<<<<<<
 *             ltmp = ["%s-%s" % (segment.start, segment.end) for segment in self]
 *             stmp = "^".join(ltmp)
 */
    goto __pyx_L3;
  }

  /* "plastid/genomics/roitools.pyx":1611
 *             sout = "%s:%s(%s)" % (self.chrom, stmp, self.strand)
 *         else:
 *             sout = "na"             # <<<<<<<<<<<<<<
 *         return sout
 * 
 */
  /*else*/ {
    __Pyx_INCREF(__pyx_n_u_na);
    __pyx_v_sout = __pyx_n_u_na;
  }
  __pyx_L3:;

  /* "plastid/genomics/roitools.pyx":1612
 *         else:
 *             sout = "na"
 *         return sout             # <<<<<<<<<<<<<<
 * 
 *     def __getitem__(self, int index):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_sout);
  __pyx_r = __pyx_v_sout;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1597
 *         return sout
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         """String representation of |SegmentChain|. Inverse of
 *         :meth:`.from_str` Chains are represented as:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ltmp);
  __Pyx_XDECREF(__pyx_v_stmp);
  __Pyx_XDECREF(__pyx_v_sout);
  __Pyx_XDECREF(__pyx_9genexpr10__pyx_v_segment);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1614
 *         return sout
 * 
 *     def __getitem__(self, int index):             # <<<<<<<<<<<<<<
 *         """Fetch a |GenomicSegment| from the |SegmentChain|
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_21__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_20__getitem__[] = "Fetch a |GenomicSegment| from the |SegmentChain|\n\n        Parameters\n        ----------\n        index : int\n            Index of interval to select, from left-to-right in genome\n\n        Returns\n        -------\n        |GenomicSegment|\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_20__getitem__;
#endif
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_21__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index) {
  int __pyx_v_index;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
  assert(__pyx_arg_index); {
    __pyx_v_index = __Pyx_PyInt_As_int(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1614, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_20__getitem__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((int)__pyx_v_index));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_20__getitem__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, int __pyx_v_index) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getitem__", 0);

  /* "plastid/genomics/roitools.pyx":1626
 *         |GenomicSegment|
 *         """
 *         return self._segments[index]             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  if (unlikely(__pyx_v_self->_segments == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 1626, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_self->_segments, __pyx_v_index, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1626, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1614
 *         return sout
 * 
 *     def __getitem__(self, int index):             # <<<<<<<<<<<<<<
 *         """Fetch a |GenomicSegment| from the |SegmentChain|
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1628
 *         return self._segments[index]
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         """Interation over each |GenomicSegment| in the |SegmentChain|, from
 *         left to right on the chromsome
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_23__iter__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_22__iter__[] = "Interation over each |GenomicSegment| in the |SegmentChain|, from\n        left to right on the chromsome\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_22__iter__;
#endif
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_23__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_22__iter__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_22__iter__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 0);

  /* "plastid/genomics/roitools.pyx":1632
 *         left to right on the chromsome
 *         """
 *         return iter(self._segments)             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1632, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1628
 *         return self._segments[index]
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         """Interation over each |GenomicSegment| in the |SegmentChain|, from
 *         left to right on the chromsome
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1634
 *         return iter(self._segments)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """Return next |GenomicSegment| in the |SegmentChain|, from left to
 *         right on the chromsome
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_25__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_24__next__[] = "Return next |GenomicSegment| in the |SegmentChain|, from left to\n        right on the chromsome\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_24__next__;
#endif
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_25__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_24__next__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_24__next__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 0);

  /* "plastid/genomics/roitools.pyx":1638
 *         right on the chromsome
 *         """
 *         return next(self._segments)             # <<<<<<<<<<<<<<
 * 
 *     def next(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyIter_Next(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1634
 *         return iter(self._segments)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """Return next |GenomicSegment| in the |SegmentChain|, from left to
 *         right on the chromsome
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1640
 *         return next(self._segments)
 * 
 *     def next(self):             # <<<<<<<<<<<<<<
 *         """Return next |GenomicSegment| in the |SegmentChain|, from left to
 *         right on the chromsome
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_27next(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_26next[] = "SegmentChain.next(self)\nReturn next |GenomicSegment| in the |SegmentChain|, from left to\n        right on the chromsome\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_27next(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("next (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_26next(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_26next(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("next", 0);

  /* "plastid/genomics/roitools.pyx":1644
 *         right on the chromsome
 *         """
 *         return self.__next__()             # <<<<<<<<<<<<<<
 * 
 *     def __len__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1644, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1644, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1640
 *         return next(self._segments)
 * 
 *     def next(self):             # <<<<<<<<<<<<<<
 *         """Return next |GenomicSegment| in the |SegmentChain|, from left to
 *         right on the chromsome
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.next", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1646
 *         return self.__next__()
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         """Return the number of |GenomicSegments| in the |SegmentChain|"""
 *         return len(self._segments)
 */

/* Python wrapper */
static Py_ssize_t __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_29__len__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_28__len__[] = "Return the number of |GenomicSegments| in the |SegmentChain|";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_28__len__;
#endif
static Py_ssize_t __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_29__len__(PyObject *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_28__len__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static Py_ssize_t __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_28__len__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__len__", 0);

  /* "plastid/genomics/roitools.pyx":1648
 *     def __len__(self):
 *         """Return the number of |GenomicSegments| in the |SegmentChain|"""
 *         return len(self._segments)             # <<<<<<<<<<<<<<
 * 
 *     def __contains__(self, object other):
 */
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  if (unlikely(__pyx_t_1 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 1648, __pyx_L1_error)
  }
  __pyx_t_2 = PyList_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1648, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1646
 *         return self.__next__()
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         """Return the number of |GenomicSegments| in the |SegmentChain|"""
 *         return len(self._segments)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1650
 *         return len(self._segments)
 * 
 *     def __contains__(self, object other):             # <<<<<<<<<<<<<<
 *         """Tests whether |SegmentChain| contains another |SegmentChain|
 *         or |GenomicSegment|. Containment is defined for each type as follows:
 */

/* Python wrapper */
static int __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_31__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_30__contains__[] = "Tests whether |SegmentChain| contains another |SegmentChain|\n        or |GenomicSegment|. Containment is defined for each type as follows:\n\n        =====================   =======================================================\n        **Type of `other`**     **True if**\n        ---------------------   -------------------------------------------------------\n        |SegmentChain|          If `self` and `other` both contain more than one segment,\n                                all segment-segment junctions in `other` must be\n                                represented in `self`, in identical order, and all\n                                positions covered by `other` must be present in `self`.\n                                If `other` contains one segment, it must be fully\n                                contained by one segment in `self`.\n\n        |GenomicSegment|        `other` must be completely contained\n                                within one of the segments in `self`\n        =====================   =======================================================\n\n\n        Parameters\n        ----------\n        other : |SegmentChain| or |GenomicSegment|\n        \tQuery feature\n\n\n        Returns\n        -------\n        bool\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_30__contains__;
#endif
static int __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_31__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_30__contains__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((PyObject *)__pyx_v_other));

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

static int __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_30__contains__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other) {
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_v_retval;
  int __pyx_r;
  __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_t_7;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  Py_UCS4 __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__contains__", 0);

  /* "plastid/genomics/roitools.pyx":1680
 *         """
 *         cdef ExBool retval
 *         if isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return self.__contains__(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1681
 *         cdef ExBool retval
 *         if isinstance(other, GenomicSegment):
 *             return self.__contains__(SegmentChain(other))             # <<<<<<<<<<<<<<
 *         elif isinstance(other, SegmentChain):
 *             retval = self.c_contains(other)
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contains_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_v_other); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1681, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_7;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1680
 *         """
 *         cdef ExBool retval
 *         if isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return self.__contains__(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):
 */
  }

  /* "plastid/genomics/roitools.pyx":1682
 *         if isinstance(other, GenomicSegment):
 *             return self.__contains__(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             retval = self.c_contains(other)
 *             if retval == bool_exception:
 */
  __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain); 
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (likely(__pyx_t_1)) {

    /* "plastid/genomics/roitools.pyx":1683
 *             return self.__contains__(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):
 *             retval = self.c_contains(other)             # <<<<<<<<<<<<<<
 *             if retval == bool_exception:
 *                 raise RuntimeError("SegmentChain.unstranded_overlaps() errored on chain '%s' and object '%s'" % (self, other))
 */
    if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 1683, __pyx_L1_error)
    __pyx_t_8 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_contains(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_other)); if (unlikely(__pyx_t_8 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1683, __pyx_L1_error)
    __pyx_v_retval = __pyx_t_8;

    /* "plastid/genomics/roitools.pyx":1684
 *         elif isinstance(other, SegmentChain):
 *             retval = self.c_contains(other)
 *             if retval == bool_exception:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError("SegmentChain.unstranded_overlaps() errored on chain '%s' and object '%s'" % (self, other))
 *             return retval == true
 */
    __pyx_t_1 = ((__pyx_v_retval == __pyx_e_7plastid_8genomics_8c_common_bool_exception) != 0);
    if (unlikely(__pyx_t_1)) {

      /* "plastid/genomics/roitools.pyx":1685
 *             retval = self.c_contains(other)
 *             if retval == bool_exception:
 *                 raise RuntimeError("SegmentChain.unstranded_overlaps() errored on chain '%s' and object '%s'" % (self, other))             # <<<<<<<<<<<<<<
 *             return retval == true
 *         else:
 */
      __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1685, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = 0;
      __pyx_t_10 = 127;
      __Pyx_INCREF(__pyx_kp_u_SegmentChain_unstranded_overlaps);
      __pyx_t_9 += 53;
      __Pyx_GIVEREF(__pyx_kp_u_SegmentChain_unstranded_overlaps);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_SegmentChain_unstranded_overlaps);
      __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1685, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_10;
      __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4);
      __pyx_t_4 = 0;
      __Pyx_INCREF(__pyx_kp_u_and_object);
      __pyx_t_9 += 14;
      __Pyx_GIVEREF(__pyx_kp_u_and_object);
      PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_and_object);
      __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_other), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1685, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_10;
      __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_4);
      __pyx_t_4 = 0;
      __Pyx_INCREF(__pyx_kp_u__2);
      __pyx_t_9 += 1;
      __Pyx_GIVEREF(__pyx_kp_u__2);
      PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_kp_u__2);
      __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_3, 5, __pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1685, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1685, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(0, 1685, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":1684
 *         elif isinstance(other, SegmentChain):
 *             retval = self.c_contains(other)
 *             if retval == bool_exception:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError("SegmentChain.unstranded_overlaps() errored on chain '%s' and object '%s'" % (self, other))
 *             return retval == true
 */
    }

    /* "plastid/genomics/roitools.pyx":1686
 *             if retval == bool_exception:
 *                 raise RuntimeError("SegmentChain.unstranded_overlaps() errored on chain '%s' and object '%s'" % (self, other))
 *             return retval == true             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError("The 'in'/containment operator is only defined for GenomicSegments and SegmentChains")
 */
    __pyx_r = (__pyx_v_retval == __pyx_e_7plastid_8genomics_8c_common_true);
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1682
 *         if isinstance(other, GenomicSegment):
 *             return self.__contains__(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             retval = self.c_contains(other)
 *             if retval == bool_exception:
 */
  }

  /* "plastid/genomics/roitools.pyx":1688
 *             return retval == true
 *         else:
 *             raise TypeError("The 'in'/containment operator is only defined for GenomicSegments and SegmentChains")             # <<<<<<<<<<<<<<
 * 
 *     cdef ExBool c_contains(self, SegmentChain other) except bool_exception:
 */
  /*else*/ {
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1688, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 1688, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":1650
 *         return len(self._segments)
 * 
 *     def __contains__(self, object other):             # <<<<<<<<<<<<<<
 *         """Tests whether |SegmentChain| contains another |SegmentChain|
 *         or |GenomicSegment|. Containment is defined for each type as follows:
 */

  /* 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("plastid.genomics.roitools.SegmentChain.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1690
 *             raise TypeError("The 'in'/containment operator is only defined for GenomicSegments and SegmentChains")
 * 
 *     cdef ExBool c_contains(self, SegmentChain other) except bool_exception:             # <<<<<<<<<<<<<<
 *         cdef:
 *             set selfpos, opos
 */

static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_contains(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_other) {
  PyObject *__pyx_v_selfpos = 0;
  PyObject *__pyx_v_opos = 0;
  PyObject *__pyx_v_myjuncs = 0;
  PyObject *__pyx_v_ojuncs = 0;
  int __pyx_v_i;
  int __pyx_v_mystart;
  int __pyx_v_found;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_sspan = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_ospan = 0;
  CYTHON_UNUSED PyObject *__pyx_v_mine = 0;
  PyObject *__pyx_v_segment = NULL;
  PyObject *__pyx_v_myjunc = NULL;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_contains", 0);

  /* "plastid/genomics/roitools.pyx":1696
 *             int i, mystart
 *             bint found
 *             GenomicSegment sspan = self.spanning_segment             # <<<<<<<<<<<<<<
 *             GenomicSegment ospan = other.spanning_segment
 *             list mine = self._segments
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_sspan = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1697
 *             bint found
 *             GenomicSegment sspan = self.spanning_segment
 *             GenomicSegment ospan = other.spanning_segment             # <<<<<<<<<<<<<<
 *             list mine = self._segments
 * 
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_other->spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_ospan = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1698
 *             GenomicSegment sspan = self.spanning_segment
 *             GenomicSegment ospan = other.spanning_segment
 *             list mine = self._segments             # <<<<<<<<<<<<<<
 * 
 *         if len(self) == 0 or len(other) == 0:
 */
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_mine = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1700
 *             list mine = self._segments
 * 
 *         if len(self) == 0 or len(other) == 0:             # <<<<<<<<<<<<<<
 *             return false
 *         elif sspan.chrom != ospan.chrom:
 */
  __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1700, __pyx_L1_error)
  __pyx_t_4 = ((__pyx_t_3 == 0) != 0);
  if (!__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_other)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1700, __pyx_L1_error)
  __pyx_t_4 = ((__pyx_t_3 == 0) != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1701
 * 
 *         if len(self) == 0 or len(other) == 0:
 *             return false             # <<<<<<<<<<<<<<
 *         elif sspan.chrom != ospan.chrom:
 *             return false
 */
    __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1700
 *             list mine = self._segments
 * 
 *         if len(self) == 0 or len(other) == 0:             # <<<<<<<<<<<<<<
 *             return false
 *         elif sspan.chrom != ospan.chrom:
 */
  }

  /* "plastid/genomics/roitools.pyx":1702
 *         if len(self) == 0 or len(other) == 0:
 *             return false
 *         elif sspan.chrom != ospan.chrom:             # <<<<<<<<<<<<<<
 *             return false
 *         elif sspan.c_strand != ospan.c_strand:
 */
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_sspan->chrom, __pyx_v_ospan->chrom, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1702, __pyx_L1_error)
  __pyx_t_4 = (__pyx_t_2 != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":1703
 *             return false
 *         elif sspan.chrom != ospan.chrom:
 *             return false             # <<<<<<<<<<<<<<
 *         elif sspan.c_strand != ospan.c_strand:
 *             return false
 */
    __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1702
 *         if len(self) == 0 or len(other) == 0:
 *             return false
 *         elif sspan.chrom != ospan.chrom:             # <<<<<<<<<<<<<<
 *             return false
 *         elif sspan.c_strand != ospan.c_strand:
 */
  }

  /* "plastid/genomics/roitools.pyx":1704
 *         elif sspan.chrom != ospan.chrom:
 *             return false
 *         elif sspan.c_strand != ospan.c_strand:             # <<<<<<<<<<<<<<
 *             return false
 *         elif other.length > self.length:
 */
  __pyx_t_4 = ((__pyx_v_sspan->c_strand != __pyx_v_ospan->c_strand) != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":1705
 *             return false
 *         elif sspan.c_strand != ospan.c_strand:
 *             return false             # <<<<<<<<<<<<<<
 *         elif other.length > self.length:
 *             return false
 */
    __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1704
 *         elif sspan.chrom != ospan.chrom:
 *             return false
 *         elif sspan.c_strand != ospan.c_strand:             # <<<<<<<<<<<<<<
 *             return false
 *         elif other.length > self.length:
 */
  }

  /* "plastid/genomics/roitools.pyx":1706
 *         elif sspan.c_strand != ospan.c_strand:
 *             return false
 *         elif other.length > self.length:             # <<<<<<<<<<<<<<
 *             return false
 * 
 */
  __pyx_t_4 = ((__pyx_v_other->length > __pyx_v_self->length) != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":1707
 *             return false
 *         elif other.length > self.length:
 *             return false             # <<<<<<<<<<<<<<
 * 
 *         # TODO: better algorithm here
 */
    __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1706
 *         elif sspan.c_strand != ospan.c_strand:
 *             return false
 *         elif other.length > self.length:             # <<<<<<<<<<<<<<
 *             return false
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":1710
 * 
 *         # TODO: better algorithm here
 *         elif len(other) == 1:             # <<<<<<<<<<<<<<
 *             for segment in self:
 *                 if segment.contains(other[0]):
 */
  __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_other)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1710, __pyx_L1_error)
  __pyx_t_4 = ((__pyx_t_3 == 1) != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":1711
 *         # TODO: better algorithm here
 *         elif len(other) == 1:
 *             for segment in self:             # <<<<<<<<<<<<<<
 *                 if segment.contains(other[0]):
 *                     return true
 */
    if (likely(PyList_CheckExact(((PyObject *)__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_v_self))) {
      __pyx_t_1 = ((PyObject *)__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1711, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1711, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1711, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1711, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        } else {
          if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1711, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1711, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_5(__pyx_t_1);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1711, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_XDECREF_SET(__pyx_v_segment, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "plastid/genomics/roitools.pyx":1712
 *         elif len(other) == 1:
 *             for segment in self:
 *                 if segment.contains(other[0]):             # <<<<<<<<<<<<<<
 *                     return true
 *             return false
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_segment, __pyx_n_s_contains); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1712, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_GetItemInt(((PyObject *)__pyx_v_other), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1712, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
        }
      }
      __pyx_t_6 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_9, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8);
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1712, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1712, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_4) {

        /* "plastid/genomics/roitools.pyx":1713
 *             for segment in self:
 *                 if segment.contains(other[0]):
 *                     return true             # <<<<<<<<<<<<<<
 *             return false
 *         else:
 */
        __pyx_r = __pyx_e_7plastid_8genomics_8c_common_true;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;

        /* "plastid/genomics/roitools.pyx":1712
 *         elif len(other) == 1:
 *             for segment in self:
 *                 if segment.contains(other[0]):             # <<<<<<<<<<<<<<
 *                     return true
 *             return false
 */
      }

      /* "plastid/genomics/roitools.pyx":1711
 *         # TODO: better algorithm here
 *         elif len(other) == 1:
 *             for segment in self:             # <<<<<<<<<<<<<<
 *                 if segment.contains(other[0]):
 *                     return true
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":1714
 *                 if segment.contains(other[0]):
 *                     return true
 *             return false             # <<<<<<<<<<<<<<
 *         else:
 *             selfpos = self.c_get_position_set()
 */
    __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1710
 * 
 *         # TODO: better algorithm here
 *         elif len(other) == 1:             # <<<<<<<<<<<<<<
 *             for segment in self:
 *                 if segment.contains(other[0]):
 */
  }

  /* "plastid/genomics/roitools.pyx":1716
 *             return false
 *         else:
 *             selfpos = self.c_get_position_set()             # <<<<<<<<<<<<<<
 *             opos    = other.c_get_position_set()
 * 
 */
  /*else*/ {
    __pyx_t_1 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_get_position_set(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1716, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_selfpos = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":1717
 *         else:
 *             selfpos = self.c_get_position_set()
 *             opos    = other.c_get_position_set()             # <<<<<<<<<<<<<<
 * 
 *             if opos & selfpos == opos:
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_other->__pyx_vtab)->c_get_position_set(__pyx_v_other); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1717, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_opos = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":1719
 *             opos    = other.c_get_position_set()
 * 
 *             if opos & selfpos == opos:             # <<<<<<<<<<<<<<
 *                 myjuncs = self.get_junctions()
 *                 ojuncs  = other.get_junctions()
 */
    __pyx_t_1 = PyNumber_And(__pyx_v_opos, __pyx_v_selfpos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1719, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_v_opos, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1719, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1719, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_4) {

      /* "plastid/genomics/roitools.pyx":1720
 * 
 *             if opos & selfpos == opos:
 *                 myjuncs = self.get_junctions()             # <<<<<<<<<<<<<<
 *                 ojuncs  = other.get_junctions()
 * 
 */
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_junctions); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1720, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
        }
      }
      __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1720, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (!(likely(PyList_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 1720, __pyx_L1_error)
      __pyx_v_myjuncs = ((PyObject*)__pyx_t_6);
      __pyx_t_6 = 0;

      /* "plastid/genomics/roitools.pyx":1721
 *             if opos & selfpos == opos:
 *                 myjuncs = self.get_junctions()
 *                 ojuncs  = other.get_junctions()             # <<<<<<<<<<<<<<
 * 
 *                 found = False
 */
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_get_junctions); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1721, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
        }
      }
      __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1721, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (!(likely(PyList_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 1721, __pyx_L1_error)
      __pyx_v_ojuncs = ((PyObject*)__pyx_t_6);
      __pyx_t_6 = 0;

      /* "plastid/genomics/roitools.pyx":1723
 *                 ojuncs  = other.get_junctions()
 * 
 *                 found = False             # <<<<<<<<<<<<<<
 *                 for i, myjunc in enumerate(myjuncs):
 *                     if ojuncs[0] == myjunc:
 */
      __pyx_v_found = 0;

      /* "plastid/genomics/roitools.pyx":1724
 * 
 *                 found = False
 *                 for i, myjunc in enumerate(myjuncs):             # <<<<<<<<<<<<<<
 *                     if ojuncs[0] == myjunc:
 *                         mystart = i
 */
      __pyx_t_10 = 0;
      __pyx_t_6 = __pyx_v_myjuncs; __Pyx_INCREF(__pyx_t_6); __pyx_t_3 = 0;
      for (;;) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_6)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1724, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_6, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1724, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
        __Pyx_XDECREF_SET(__pyx_v_myjunc, __pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_v_i = __pyx_t_10;
        __pyx_t_10 = (__pyx_t_10 + 1);

        /* "plastid/genomics/roitools.pyx":1725
 *                 found = False
 *                 for i, myjunc in enumerate(myjuncs):
 *                     if ojuncs[0] == myjunc:             # <<<<<<<<<<<<<<
 *                         mystart = i
 *                         found   = True
 */
        if (unlikely(__pyx_v_ojuncs == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 1725, __pyx_L1_error)
        }
        __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_ojuncs, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1725, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = PyObject_RichCompare(__pyx_t_1, __pyx_v_myjunc, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1725, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1725, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (__pyx_t_4) {

          /* "plastid/genomics/roitools.pyx":1726
 *                 for i, myjunc in enumerate(myjuncs):
 *                     if ojuncs[0] == myjunc:
 *                         mystart = i             # <<<<<<<<<<<<<<
 *                         found   = True
 *                         break
 */
          __pyx_v_mystart = __pyx_v_i;

          /* "plastid/genomics/roitools.pyx":1727
 *                     if ojuncs[0] == myjunc:
 *                         mystart = i
 *                         found   = True             # <<<<<<<<<<<<<<
 *                         break
 *             else:
 */
          __pyx_v_found = 1;

          /* "plastid/genomics/roitools.pyx":1728
 *                         mystart = i
 *                         found   = True
 *                         break             # <<<<<<<<<<<<<<
 *             else:
 *                 return false
 */
          goto __pyx_L11_break;

          /* "plastid/genomics/roitools.pyx":1725
 *                 found = False
 *                 for i, myjunc in enumerate(myjuncs):
 *                     if ojuncs[0] == myjunc:             # <<<<<<<<<<<<<<
 *                         mystart = i
 *                         found   = True
 */
        }

        /* "plastid/genomics/roitools.pyx":1724
 * 
 *                 found = False
 *                 for i, myjunc in enumerate(myjuncs):             # <<<<<<<<<<<<<<
 *                     if ojuncs[0] == myjunc:
 *                         mystart = i
 */
      }
      __pyx_L11_break:;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "plastid/genomics/roitools.pyx":1719
 *             opos    = other.c_get_position_set()
 * 
 *             if opos & selfpos == opos:             # <<<<<<<<<<<<<<
 *                 myjuncs = self.get_junctions()
 *                 ojuncs  = other.get_junctions()
 */
      goto __pyx_L9;
    }

    /* "plastid/genomics/roitools.pyx":1730
 *                         break
 *             else:
 *                 return false             # <<<<<<<<<<<<<<
 * 
 *             if found == True:
 */
    /*else*/ {
      __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
      goto __pyx_L0;
    }
    __pyx_L9:;

    /* "plastid/genomics/roitools.pyx":1732
 *                 return false
 * 
 *             if found == True:             # <<<<<<<<<<<<<<
 *                 return true if ojuncs == myjuncs[mystart:mystart + len(ojuncs)] else false
 *             else:
 */
    __pyx_t_4 = ((__pyx_v_found == 1) != 0);
    if (__pyx_t_4) {

      /* "plastid/genomics/roitools.pyx":1733
 * 
 *             if found == True:
 *                 return true if ojuncs == myjuncs[mystart:mystart + len(ojuncs)] else false             # <<<<<<<<<<<<<<
 *             else:
 *                 return false
 */
      if (unlikely(__pyx_v_myjuncs == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 1733, __pyx_L1_error)
      }
      if (unlikely(__pyx_v_ojuncs == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
        __PYX_ERR(0, 1733, __pyx_L1_error)
      }
      __pyx_t_3 = PyList_GET_SIZE(__pyx_v_ojuncs); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1733, __pyx_L1_error)
      __pyx_t_6 = __Pyx_PyList_GetSlice(__pyx_v_myjuncs, __pyx_v_mystart, (__pyx_v_mystart + __pyx_t_3)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1733, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PyObject_RichCompare(__pyx_v_ojuncs, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1733, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1733, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (__pyx_t_4) {
        __pyx_t_11 = __pyx_e_7plastid_8genomics_8c_common_true;
      } else {
        __pyx_t_11 = __pyx_e_7plastid_8genomics_8c_common_false;
      }
      __pyx_r = __pyx_t_11;
      goto __pyx_L0;

      /* "plastid/genomics/roitools.pyx":1732
 *                 return false
 * 
 *             if found == True:             # <<<<<<<<<<<<<<
 *                 return true if ojuncs == myjuncs[mystart:mystart + len(ojuncs)] else false
 *             else:
 */
    }

    /* "plastid/genomics/roitools.pyx":1735
 *                 return true if ojuncs == myjuncs[mystart:mystart + len(ojuncs)] else false
 *             else:
 *                 return false             # <<<<<<<<<<<<<<
 * 
 *     def shares_segments_with(self, object other):
 */
    /*else*/ {
      __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
      goto __pyx_L0;
    }
  }

  /* "plastid/genomics/roitools.pyx":1690
 *             raise TypeError("The 'in'/containment operator is only defined for GenomicSegments and SegmentChains")
 * 
 *     cdef ExBool c_contains(self, SegmentChain other) except bool_exception:             # <<<<<<<<<<<<<<
 *         cdef:
 *             set selfpos, opos
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_contains", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = __pyx_e_7plastid_8genomics_8c_common_bool_exception;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_selfpos);
  __Pyx_XDECREF(__pyx_v_opos);
  __Pyx_XDECREF(__pyx_v_myjuncs);
  __Pyx_XDECREF(__pyx_v_ojuncs);
  __Pyx_XDECREF((PyObject *)__pyx_v_sspan);
  __Pyx_XDECREF((PyObject *)__pyx_v_ospan);
  __Pyx_XDECREF(__pyx_v_mine);
  __Pyx_XDECREF(__pyx_v_segment);
  __Pyx_XDECREF(__pyx_v_myjunc);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1737
 *                 return false
 * 
 *     def shares_segments_with(self, object other):             # <<<<<<<<<<<<<<
 *         """Returns a list of |GenomicSegment| that are shared between `self` and `other`
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_33shares_segments_with(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_32shares_segments_with[] = "SegmentChain.shares_segments_with(self, other)\nReturns a list of |GenomicSegment| that are shared between `self` and `other`\n\n        Parameters\n        ----------\n        other : |SegmentChain| or |GenomicSegment|\n        \tQuery feature\n\n        Returns\n        -------\n        list\n            List of |GenomicSegments| common to `self` and `other`\n\n        Raises\n        ------\n        TypeError\n            if `other` is not a |GenomicSegment| or |SegmentChain|\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_33shares_segments_with(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("shares_segments_with (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_32shares_segments_with(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((PyObject *)__pyx_v_other));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_32shares_segments_with(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("shares_segments_with", 0);

  /* "plastid/genomics/roitools.pyx":1755
 *             if `other` is not a |GenomicSegment| or |SegmentChain|
 *         """
 *         if isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return self.c_shares_segments_with(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1756
 *         """
 *         if isinstance(other, GenomicSegment):
 *             return self.c_shares_segments_with(SegmentChain(other))             # <<<<<<<<<<<<<<
 *         elif isinstance(other, SegmentChain):
 *             return self.c_shares_segments_with(other)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_v_other); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_shares_segments_with(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1755
 *             if `other` is not a |GenomicSegment| or |SegmentChain|
 *         """
 *         if isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return self.c_shares_segments_with(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):
 */
  }

  /* "plastid/genomics/roitools.pyx":1757
 *         if isinstance(other, GenomicSegment):
 *             return self.c_shares_segments_with(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             return self.c_shares_segments_with(other)
 *         else:
 */
  __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain); 
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (likely(__pyx_t_1)) {

    /* "plastid/genomics/roitools.pyx":1758
 *             return self.c_shares_segments_with(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):
 *             return self.c_shares_segments_with(other)             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError(
 */
    __Pyx_XDECREF(__pyx_r);
    if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 1758, __pyx_L1_error)
    __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_shares_segments_with(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_other)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1758, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1757
 *         if isinstance(other, GenomicSegment):
 *             return self.c_shares_segments_with(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             return self.c_shares_segments_with(other)
 *         else:
 */
  }

  /* "plastid/genomics/roitools.pyx":1760
 *             return self.c_shares_segments_with(other)
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain.shares_segments_with() is defined only for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)
 */
  /*else*/ {

    /* "plastid/genomics/roitools.pyx":1762
 *             raise TypeError(
 *                 "SegmentChain.shares_segments_with() is defined only for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    __pyx_t_4 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_SegmentChain_shares_segments_wit, ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1762, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "plastid/genomics/roitools.pyx":1760
 *             return self.c_shares_segments_with(other)
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain.shares_segments_with() is defined only for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)
 */
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1760, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 1760, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":1737
 *                 return false
 * 
 *     def shares_segments_with(self, object other):             # <<<<<<<<<<<<<<
 *         """Returns a list of |GenomicSegment| that are shared between `self` and `other`
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.shares_segments_with", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1765
 *             )
 * 
 *     cdef list c_shares_segments_with(self, SegmentChain other):             # <<<<<<<<<<<<<<
 *         cdef:
 *             list shared
 */

static PyObject *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_shares_segments_with(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_other) {
  PyObject *__pyx_v_shared = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_segment = 0;
  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;
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_shares_segments_with", 0);

  /* "plastid/genomics/roitools.pyx":1769
 *             list shared
 *             GenomicSegment segment
 *         if self.chrom != other.chrom or self.c_strand != other.c_strand:             # <<<<<<<<<<<<<<
 *             return []
 *         else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_chrom); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1769, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_chrom); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1769, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1769, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1769, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!__pyx_t_5) {
  } else {
    __pyx_t_1 = __pyx_t_5;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_c_strand); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1769, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_c_strand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1769, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1769, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1769, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = __pyx_t_5;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "plastid/genomics/roitools.pyx":1770
 *             GenomicSegment segment
 *         if self.chrom != other.chrom or self.c_strand != other.c_strand:
 *             return []             # <<<<<<<<<<<<<<
 *         else:
 *             shared = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1770, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = ((PyObject*)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1769
 *             list shared
 *             GenomicSegment segment
 *         if self.chrom != other.chrom or self.c_strand != other.c_strand:             # <<<<<<<<<<<<<<
 *             return []
 *         else:
 */
  }

  /* "plastid/genomics/roitools.pyx":1772
 *             return []
 *         else:
 *             shared = []             # <<<<<<<<<<<<<<
 *             for segment in other:
 *                 if segment in self._segments:
 */
  /*else*/ {
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1772, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_shared = ((PyObject*)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "plastid/genomics/roitools.pyx":1773
 *         else:
 *             shared = []
 *             for segment in other:             # <<<<<<<<<<<<<<
 *                 if segment in self._segments:
 *                     shared.append(segment)
 */
    if (likely(PyList_CheckExact(((PyObject *)__pyx_v_other))) || PyTuple_CheckExact(((PyObject *)__pyx_v_other))) {
      __pyx_t_2 = ((PyObject *)__pyx_v_other); __Pyx_INCREF(__pyx_t_2); __pyx_t_6 = 0;
      __pyx_t_7 = NULL;
    } else {
      __pyx_t_6 = -1; __pyx_t_2 = PyObject_GetIter(((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1773, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1773, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_7)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1773, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1773, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        } else {
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1773, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1773, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        }
      } else {
        __pyx_t_3 = __pyx_t_7(__pyx_t_2);
        if (unlikely(!__pyx_t_3)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1773, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_3);
      }
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 1773, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_segment, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "plastid/genomics/roitools.pyx":1774
 *             shared = []
 *             for segment in other:
 *                 if segment in self._segments:             # <<<<<<<<<<<<<<
 *                     shared.append(segment)
 * 
 */
      __pyx_t_1 = (__Pyx_PySequence_ContainsTF(((PyObject *)__pyx_v_segment), __pyx_v_self->_segments, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1774, __pyx_L1_error)
      __pyx_t_5 = (__pyx_t_1 != 0);
      if (__pyx_t_5) {

        /* "plastid/genomics/roitools.pyx":1775
 *             for segment in other:
 *                 if segment in self._segments:
 *                     shared.append(segment)             # <<<<<<<<<<<<<<
 * 
 *             return shared
 */
        __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_shared, ((PyObject *)__pyx_v_segment)); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1775, __pyx_L1_error)

        /* "plastid/genomics/roitools.pyx":1774
 *             shared = []
 *             for segment in other:
 *                 if segment in self._segments:             # <<<<<<<<<<<<<<
 *                     shared.append(segment)
 * 
 */
      }

      /* "plastid/genomics/roitools.pyx":1773
 *         else:
 *             shared = []
 *             for segment in other:             # <<<<<<<<<<<<<<
 *                 if segment in self._segments:
 *                     shared.append(segment)
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "plastid/genomics/roitools.pyx":1777
 *                     shared.append(segment)
 * 
 *             return shared             # <<<<<<<<<<<<<<
 * 
 *     def  unstranded_overlaps(self, object other):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_shared);
    __pyx_r = __pyx_v_shared;
    goto __pyx_L0;
  }

  /* "plastid/genomics/roitools.pyx":1765
 *             )
 * 
 *     cdef list c_shares_segments_with(self, SegmentChain other):             # <<<<<<<<<<<<<<
 *         cdef:
 *             list shared
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_shares_segments_with", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_shared);
  __Pyx_XDECREF((PyObject *)__pyx_v_segment);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1779
 *             return shared
 * 
 *     def  unstranded_overlaps(self, object other):             # <<<<<<<<<<<<<<
 *         """Return `True` if `self` and `other` share genomic positions on the
 *         same chromosome, regardless of their strands
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_35unstranded_overlaps(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_34unstranded_overlaps[] = "SegmentChain.unstranded_overlaps(self, other)\nReturn `True` if `self` and `other` share genomic positions on the\n        same chromosome, regardless of their strands\n\n        Parameters\n        ----------\n        other : |SegmentChain| or |GenomicSegment|\n        \tQuery feature\n\n        Returns\n        -------\n        bool\n            `True` if `self` and `other` share genomic positions on the same\n            chromosome, False otherwise. Strands of `self` and `other` need\n            not match\n\n        Raises\n        ------\n        TypeError\n            if `other` is not a |GenomicSegment| or |SegmentChain|\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_35unstranded_overlaps(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("unstranded_overlaps (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_34unstranded_overlaps(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((PyObject *)__pyx_v_other));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_34unstranded_overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("unstranded_overlaps", 0);

  /* "plastid/genomics/roitools.pyx":1801
 *         """
 *         cdef ExBool retval
 *         if isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             return self.c_unstranded_overlaps(other) == true
 *         elif isinstance(other, GenomicSegment):
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1802
 *         cdef ExBool retval
 *         if isinstance(other, SegmentChain):
 *             return self.c_unstranded_overlaps(other) == true             # <<<<<<<<<<<<<<
 *         elif isinstance(other, GenomicSegment):
 *             return self.c_unstranded_overlaps(SegmentChain(other)) == true
 */
    __Pyx_XDECREF(__pyx_r);
    if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 1802, __pyx_L1_error)
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_unstranded_overlaps(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_other)); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1802, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyBool_FromLong((__pyx_t_3 == __pyx_e_7plastid_8genomics_8c_common_true)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1802, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1801
 *         """
 *         cdef ExBool retval
 *         if isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             return self.c_unstranded_overlaps(other) == true
 *         elif isinstance(other, GenomicSegment):
 */
  }

  /* "plastid/genomics/roitools.pyx":1803
 *         if isinstance(other, SegmentChain):
 *             return self.c_unstranded_overlaps(other) == true
 *         elif isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return self.c_unstranded_overlaps(SegmentChain(other)) == true
 *         else:
 */
  __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment); 
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (likely(__pyx_t_1)) {

    /* "plastid/genomics/roitools.pyx":1804
 *             return self.c_unstranded_overlaps(other) == true
 *         elif isinstance(other, GenomicSegment):
 *             return self.c_unstranded_overlaps(SegmentChain(other)) == true             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError(
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_v_other); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1804, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_unstranded_overlaps(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_4)); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1804, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyBool_FromLong((__pyx_t_3 == __pyx_e_7plastid_8genomics_8c_common_true)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1804, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1803
 *         if isinstance(other, SegmentChain):
 *             return self.c_unstranded_overlaps(other) == true
 *         elif isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return self.c_unstranded_overlaps(SegmentChain(other)) == true
 *         else:
 */
  }

  /* "plastid/genomics/roitools.pyx":1806
 *             return self.c_unstranded_overlaps(SegmentChain(other)) == true
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain.unstranded_overlaps() is only defined for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)
 */
  /*else*/ {

    /* "plastid/genomics/roitools.pyx":1808
 *             raise TypeError(
 *                 "SegmentChain.unstranded_overlaps() is only defined for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    __pyx_t_4 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_SegmentChain_unstranded_overlaps_2, ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1808, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "plastid/genomics/roitools.pyx":1806
 *             return self.c_unstranded_overlaps(SegmentChain(other)) == true
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain.unstranded_overlaps() is only defined for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)
 */
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1806, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 1806, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":1779
 *             return shared
 * 
 *     def  unstranded_overlaps(self, object other):             # <<<<<<<<<<<<<<
 *         """Return `True` if `self` and `other` share genomic positions on the
 *         same chromosome, regardless of their strands
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.unstranded_overlaps", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1811
 *             )
 * 
 *     cdef ExBool c_unstranded_overlaps(self, SegmentChain other) except bool_exception:             # <<<<<<<<<<<<<<
 *         cdef:
 *             GenomicSegment left
 */

static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_unstranded_overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_other) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_left = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_right = 0;
  CYTHON_UNUSED PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_segments = 0;
  int __pyx_v_i;
  int __pyx_v_length;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  long __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_unstranded_overlaps", 0);

  /* "plastid/genomics/roitools.pyx":1815
 *             GenomicSegment left
 *             GenomicSegment right
 *             str chrom = self.chrom             # <<<<<<<<<<<<<<
 *             list segments
 *             int i = 0
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_chrom); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1815, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 1815, __pyx_L1_error)
  __pyx_v_chrom = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1817
 *             str chrom = self.chrom
 *             list segments
 *             int i = 0             # <<<<<<<<<<<<<<
 *             int length
 * 
 */
  __pyx_v_i = 0;

  /* "plastid/genomics/roitools.pyx":1820
 *             int length
 * 
 *         if self.chrom != other.chrom:             # <<<<<<<<<<<<<<
 *             return false
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_chrom); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1820, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_chrom); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1820, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1820, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1820, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":1821
 * 
 *         if self.chrom != other.chrom:
 *             return false             # <<<<<<<<<<<<<<
 * 
 *         segments = sorted(self._segments + other._segments)
 */
    __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1820
 *             int length
 * 
 *         if self.chrom != other.chrom:             # <<<<<<<<<<<<<<
 *             return false
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":1823
 *             return false
 * 
 *         segments = sorted(self._segments + other._segments)             # <<<<<<<<<<<<<<
 *         length = len(segments)
 *         if len(segments) > 0:
 */
  __pyx_t_2 = PyNumber_Add(__pyx_v_self->_segments, __pyx_v_other->_segments); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1823, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PySequence_List(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1823, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_5 = PyList_Sort(__pyx_t_3); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 1823, __pyx_L1_error)
  __pyx_v_segments = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":1824
 * 
 *         segments = sorted(self._segments + other._segments)
 *         length = len(segments)             # <<<<<<<<<<<<<<
 *         if len(segments) > 0:
 *             left = segments[0]
 */
  if (unlikely(__pyx_v_segments == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 1824, __pyx_L1_error)
  }
  __pyx_t_6 = PyList_GET_SIZE(__pyx_v_segments); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1824, __pyx_L1_error)
  __pyx_v_length = __pyx_t_6;

  /* "plastid/genomics/roitools.pyx":1825
 *         segments = sorted(self._segments + other._segments)
 *         length = len(segments)
 *         if len(segments) > 0:             # <<<<<<<<<<<<<<
 *             left = segments[0]
 * 
 */
  if (unlikely(__pyx_v_segments == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 1825, __pyx_L1_error)
  }
  __pyx_t_6 = PyList_GET_SIZE(__pyx_v_segments); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1825, __pyx_L1_error)
  __pyx_t_4 = ((__pyx_t_6 > 0) != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":1826
 *         length = len(segments)
 *         if len(segments) > 0:
 *             left = segments[0]             # <<<<<<<<<<<<<<
 * 
 *             while i < length - 1:
 */
    if (unlikely(__pyx_v_segments == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 1826, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_segments, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1826, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 1826, __pyx_L1_error)
    __pyx_v_left = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":1828
 *             left = segments[0]
 * 
 *             while i < length - 1:             # <<<<<<<<<<<<<<
 *                 right = segments[i+1]
 *                 if right.start < left.end:
 */
    while (1) {
      __pyx_t_4 = ((__pyx_v_i < (__pyx_v_length - 1)) != 0);
      if (!__pyx_t_4) break;

      /* "plastid/genomics/roitools.pyx":1829
 * 
 *             while i < length - 1:
 *                 right = segments[i+1]             # <<<<<<<<<<<<<<
 *                 if right.start < left.end:
 *                     return true
 */
      if (unlikely(__pyx_v_segments == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 1829, __pyx_L1_error)
      }
      __pyx_t_7 = (__pyx_v_i + 1);
      __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_segments, __pyx_t_7, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1829, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 1829, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_right, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "plastid/genomics/roitools.pyx":1830
 *             while i < length - 1:
 *                 right = segments[i+1]
 *                 if right.start < left.end:             # <<<<<<<<<<<<<<
 *                     return true
 * 
 */
      __pyx_t_4 = ((__pyx_v_right->start < __pyx_v_left->end) != 0);
      if (__pyx_t_4) {

        /* "plastid/genomics/roitools.pyx":1831
 *                 right = segments[i+1]
 *                 if right.start < left.end:
 *                     return true             # <<<<<<<<<<<<<<
 * 
 *                 left = right
 */
        __pyx_r = __pyx_e_7plastid_8genomics_8c_common_true;
        goto __pyx_L0;

        /* "plastid/genomics/roitools.pyx":1830
 *             while i < length - 1:
 *                 right = segments[i+1]
 *                 if right.start < left.end:             # <<<<<<<<<<<<<<
 *                     return true
 * 
 */
      }

      /* "plastid/genomics/roitools.pyx":1833
 *                     return true
 * 
 *                 left = right             # <<<<<<<<<<<<<<
 *                 i += 1
 * 
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_right));
      __Pyx_DECREF_SET(__pyx_v_left, __pyx_v_right);

      /* "plastid/genomics/roitools.pyx":1834
 * 
 *                 left = right
 *                 i += 1             # <<<<<<<<<<<<<<
 * 
 *         return false
 */
      __pyx_v_i = (__pyx_v_i + 1);
    }

    /* "plastid/genomics/roitools.pyx":1825
 *         segments = sorted(self._segments + other._segments)
 *         length = len(segments)
 *         if len(segments) > 0:             # <<<<<<<<<<<<<<
 *             left = segments[0]
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":1836
 *                 i += 1
 * 
 *         return false             # <<<<<<<<<<<<<<
 * 
 *     def overlaps(self, object other):
 */
  __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1811
 *             )
 * 
 *     cdef ExBool c_unstranded_overlaps(self, SegmentChain other) except bool_exception:             # <<<<<<<<<<<<<<
 *         cdef:
 *             GenomicSegment left
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_unstranded_overlaps", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = __pyx_e_7plastid_8genomics_8c_common_bool_exception;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_left);
  __Pyx_XDECREF((PyObject *)__pyx_v_right);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_segments);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1838
 *         return false
 * 
 *     def overlaps(self, object other):             # <<<<<<<<<<<<<<
 *         """Return `True` if `self` and `other` share genomic positions on the same strand
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_37overlaps(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_36overlaps[] = "SegmentChain.overlaps(self, other)\nReturn `True` if `self` and `other` share genomic positions on the same strand\n\n        Parameters\n        ----------\n        other : |SegmentChain| or |GenomicSegment|\n        \tQuery feature\n\n        Returns\n        -------\n        bool\n            `True` if `self` and `other` share genomic positions on the same\n            chromosome and strand; False otherwise.\n\n        Raises\n        ------\n        TypeError\n            if `other` is not a |GenomicSegment| or |SegmentChain|\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_37overlaps(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("overlaps (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_36overlaps(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((PyObject *)__pyx_v_other));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_36overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("overlaps", 0);

  /* "plastid/genomics/roitools.pyx":1858
 *         """
 *         cdef ExBool retval
 *         if isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return self.c_overlaps(SegmentChain(other)) == true
 *         elif isinstance(other, SegmentChain):
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1859
 *         cdef ExBool retval
 *         if isinstance(other, GenomicSegment):
 *             return self.c_overlaps(SegmentChain(other)) == true             # <<<<<<<<<<<<<<
 *         elif isinstance(other, SegmentChain):
 *             return self.c_overlaps(other) == true
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_v_other); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1859, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_overlaps(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_3)); if (unlikely(__pyx_t_4 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1859, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyBool_FromLong((__pyx_t_4 == __pyx_e_7plastid_8genomics_8c_common_true)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1859, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1858
 *         """
 *         cdef ExBool retval
 *         if isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return self.c_overlaps(SegmentChain(other)) == true
 *         elif isinstance(other, SegmentChain):
 */
  }

  /* "plastid/genomics/roitools.pyx":1860
 *         if isinstance(other, GenomicSegment):
 *             return self.c_overlaps(SegmentChain(other)) == true
 *         elif isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             return self.c_overlaps(other) == true
 *         else:
 */
  __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain); 
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (likely(__pyx_t_1)) {

    /* "plastid/genomics/roitools.pyx":1861
 *             return self.c_overlaps(SegmentChain(other)) == true
 *         elif isinstance(other, SegmentChain):
 *             return self.c_overlaps(other) == true             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError(
 */
    __Pyx_XDECREF(__pyx_r);
    if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 1861, __pyx_L1_error)
    __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_overlaps(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_other)); if (unlikely(__pyx_t_4 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1861, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyBool_FromLong((__pyx_t_4 == __pyx_e_7plastid_8genomics_8c_common_true)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1861, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1860
 *         if isinstance(other, GenomicSegment):
 *             return self.c_overlaps(SegmentChain(other)) == true
 *         elif isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             return self.c_overlaps(other) == true
 *         else:
 */
  }

  /* "plastid/genomics/roitools.pyx":1863
 *             return self.c_overlaps(other) == true
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain.overlaps() is defined only for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)
 */
  /*else*/ {

    /* "plastid/genomics/roitools.pyx":1865
 *             raise TypeError(
 *                 "SegmentChain.overlaps() is defined only for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    __pyx_t_3 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_SegmentChain_overlaps_is_defined, ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1865, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "plastid/genomics/roitools.pyx":1863
 *             return self.c_overlaps(other) == true
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain.overlaps() is defined only for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)
 */
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1863, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 1863, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":1838
 *         return false
 * 
 *     def overlaps(self, object other):             # <<<<<<<<<<<<<<
 *         """Return `True` if `self` and `other` share genomic positions on the same strand
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.overlaps", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1868
 *             )
 * 
 *     cdef ExBool c_overlaps(self, SegmentChain other) except bool_exception:             # <<<<<<<<<<<<<<
 *         cdef:
 *             Strand sstrand = self.c_strand
 */

static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_other) {
  CYTHON_UNUSED enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_v_sstrand;
  CYTHON_UNUSED enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_v_ostrand;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_t_2;
  int __pyx_t_3;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_overlaps", 0);

  /* "plastid/genomics/roitools.pyx":1870
 *     cdef ExBool c_overlaps(self, SegmentChain other) except bool_exception:
 *         cdef:
 *             Strand sstrand = self.c_strand             # <<<<<<<<<<<<<<
 *             Strand ostrand = other.c_strand
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_c_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1870, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = ((enum __pyx_t_7plastid_8genomics_8c_common_Strand)__Pyx_PyInt_As_enum____pyx_t_7plastid_8genomics_8c_common_Strand(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1870, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_sstrand = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":1871
 *         cdef:
 *             Strand sstrand = self.c_strand
 *             Strand ostrand = other.c_strand             # <<<<<<<<<<<<<<
 * 
 *         if self.c_unstranded_overlaps(other) == true and self.c_strand & other.c_strand > 0:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_c_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1871, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = ((enum __pyx_t_7plastid_8genomics_8c_common_Strand)__Pyx_PyInt_As_enum____pyx_t_7plastid_8genomics_8c_common_Strand(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1871, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ostrand = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":1873
 *             Strand ostrand = other.c_strand
 * 
 *         if self.c_unstranded_overlaps(other) == true and self.c_strand & other.c_strand > 0:             # <<<<<<<<<<<<<<
 *             return true
 * 
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_unstranded_overlaps(__pyx_v_self, __pyx_v_other); if (unlikely(__pyx_t_4 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1873, __pyx_L1_error)
  __pyx_t_5 = ((__pyx_t_4 == __pyx_e_7plastid_8genomics_8c_common_true) != 0);
  if (__pyx_t_5) {
  } else {
    __pyx_t_3 = __pyx_t_5;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_c_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1873, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_c_strand); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1873, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_And(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1873, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_7, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1873, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1873, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_3 = __pyx_t_5;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":1874
 * 
 *         if self.c_unstranded_overlaps(other) == true and self.c_strand & other.c_strand > 0:
 *             return true             # <<<<<<<<<<<<<<
 * 
 *         return false
 */
    __pyx_r = __pyx_e_7plastid_8genomics_8c_common_true;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1873
 *             Strand ostrand = other.c_strand
 * 
 *         if self.c_unstranded_overlaps(other) == true and self.c_strand & other.c_strand > 0:             # <<<<<<<<<<<<<<
 *             return true
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":1876
 *             return true
 * 
 *         return false             # <<<<<<<<<<<<<<
 * 
 *     def antisense_overlaps(self, object other):
 */
  __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1868
 *             )
 * 
 *     cdef ExBool c_overlaps(self, SegmentChain other) except bool_exception:             # <<<<<<<<<<<<<<
 *         cdef:
 *             Strand sstrand = self.c_strand
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_overlaps", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = __pyx_e_7plastid_8genomics_8c_common_bool_exception;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1878
 *         return false
 * 
 *     def antisense_overlaps(self, object other):             # <<<<<<<<<<<<<<
 *         """Returns `True` if `self` and `other` share genomic positions on opposite strands
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_39antisense_overlaps(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_38antisense_overlaps[] = "SegmentChain.antisense_overlaps(self, other)\nReturns `True` if `self` and `other` share genomic positions on opposite strands\n\n        Parameters\n        ----------\n        other : |SegmentChain| or |GenomicSegment|\n        \tQuery feature\n\n        Returns\n        -------\n        bool\n            `True` if `self` and `other` share genomic positions on the same\n            chromosome but opposite strand; False otherwise.\n\n        Raises\n        ------\n        TypeError\n            if `other` is not a |GenomicSegment| or |SegmentChain|\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_39antisense_overlaps(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("antisense_overlaps (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_38antisense_overlaps(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((PyObject *)__pyx_v_other));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_38antisense_overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other) {
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_v_retval;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  Py_UCS4 __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("antisense_overlaps", 0);

  /* "plastid/genomics/roitools.pyx":1898
 *         """
 *         cdef ExBool retval
 *         if isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return self.c_antisense_overlaps(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1899
 *         cdef ExBool retval
 *         if isinstance(other, GenomicSegment):
 *             return self.c_antisense_overlaps(SegmentChain(other))             # <<<<<<<<<<<<<<
 *         elif isinstance(other, SegmentChain):
 *             retval = self.c_antisense_overlaps(other)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_v_other); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1899, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_antisense_overlaps(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_3)); if (unlikely(__pyx_t_4 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1899, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_7plastid_8genomics_8c_common_ExBool(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1899, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1898
 *         """
 *         cdef ExBool retval
 *         if isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return self.c_antisense_overlaps(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):
 */
  }

  /* "plastid/genomics/roitools.pyx":1900
 *         if isinstance(other, GenomicSegment):
 *             return self.c_antisense_overlaps(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             retval = self.c_antisense_overlaps(other)
 *             if retval == bool_exception:
 */
  __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain); 
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (likely(__pyx_t_1)) {

    /* "plastid/genomics/roitools.pyx":1901
 *             return self.c_antisense_overlaps(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):
 *             retval = self.c_antisense_overlaps(other)             # <<<<<<<<<<<<<<
 *             if retval == bool_exception:
 *                 raise RuntimeError(
 */
    if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 1901, __pyx_L1_error)
    __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_antisense_overlaps(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_other)); if (unlikely(__pyx_t_4 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1901, __pyx_L1_error)
    __pyx_v_retval = __pyx_t_4;

    /* "plastid/genomics/roitools.pyx":1902
 *         elif isinstance(other, SegmentChain):
 *             retval = self.c_antisense_overlaps(other)
 *             if retval == bool_exception:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(
 *                     "SegmentChain.antisense_overlaps() errored on chain '%s' and object '%s'"
 */
    __pyx_t_1 = ((__pyx_v_retval == __pyx_e_7plastid_8genomics_8c_common_bool_exception) != 0);
    if (unlikely(__pyx_t_1)) {

      /* "plastid/genomics/roitools.pyx":1904
 *             if retval == bool_exception:
 *                 raise RuntimeError(
 *                     "SegmentChain.antisense_overlaps() errored on chain '%s' and object '%s'"             # <<<<<<<<<<<<<<
 *                     % (self, other)
 *                 )
 */
      __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1904, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = 0;
      __pyx_t_6 = 127;
      __Pyx_INCREF(__pyx_kp_u_SegmentChain_antisense_overlaps);
      __pyx_t_5 += 52;
      __Pyx_GIVEREF(__pyx_kp_u_SegmentChain_antisense_overlaps);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_SegmentChain_antisense_overlaps);

      /* "plastid/genomics/roitools.pyx":1905
 *                 raise RuntimeError(
 *                     "SegmentChain.antisense_overlaps() errored on chain '%s' and object '%s'"
 *                     % (self, other)             # <<<<<<<<<<<<<<
 *                 )
 *             return retval == true
 */
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1905, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u_and_object);
      __pyx_t_5 += 14;
      __Pyx_GIVEREF(__pyx_kp_u_and_object);
      PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_and_object);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_other), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1905, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u__2);
      __pyx_t_5 += 1;
      __Pyx_GIVEREF(__pyx_kp_u__2);
      PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_kp_u__2);

      /* "plastid/genomics/roitools.pyx":1904
 *             if retval == bool_exception:
 *                 raise RuntimeError(
 *                     "SegmentChain.antisense_overlaps() errored on chain '%s' and object '%s'"             # <<<<<<<<<<<<<<
 *                     % (self, other)
 *                 )
 */
      __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_3, 5, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1904, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "plastid/genomics/roitools.pyx":1903
 *             retval = self.c_antisense_overlaps(other)
 *             if retval == bool_exception:
 *                 raise RuntimeError(             # <<<<<<<<<<<<<<
 *                     "SegmentChain.antisense_overlaps() errored on chain '%s' and object '%s'"
 *                     % (self, other)
 */
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1903, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(0, 1903, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":1902
 *         elif isinstance(other, SegmentChain):
 *             retval = self.c_antisense_overlaps(other)
 *             if retval == bool_exception:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(
 *                     "SegmentChain.antisense_overlaps() errored on chain '%s' and object '%s'"
 */
    }

    /* "plastid/genomics/roitools.pyx":1907
 *                     % (self, other)
 *                 )
 *             return retval == true             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError(
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyBool_FromLong((__pyx_v_retval == __pyx_e_7plastid_8genomics_8c_common_true)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1907, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1900
 *         if isinstance(other, GenomicSegment):
 *             return self.c_antisense_overlaps(SegmentChain(other))
 *         elif isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             retval = self.c_antisense_overlaps(other)
 *             if retval == bool_exception:
 */
  }

  /* "plastid/genomics/roitools.pyx":1909
 *             return retval == true
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain.antisense_overlaps() is only defined for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)
 */
  /*else*/ {

    /* "plastid/genomics/roitools.pyx":1911
 *             raise TypeError(
 *                 "SegmentChain.antisense_overlaps() is only defined for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    __pyx_t_3 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_SegmentChain_antisense_overlaps_2, ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1911, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "plastid/genomics/roitools.pyx":1909
 *             return retval == true
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain.antisense_overlaps() is only defined for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)
 */
    __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_7, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __PYX_ERR(0, 1909, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":1878
 *         return false
 * 
 *     def antisense_overlaps(self, object other):             # <<<<<<<<<<<<<<
 *         """Returns `True` if `self` and `other` share genomic positions on opposite strands
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.antisense_overlaps", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1914
 *             )
 * 
 *     cdef ExBool c_antisense_overlaps(self, SegmentChain other) except bool_exception:             # <<<<<<<<<<<<<<
 *         cdef:
 *             Strand sstrand = self.c_strand
 */

static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_antisense_overlaps(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_other) {
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_v_sstrand;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_v_ostrand;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_t_2;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_antisense_overlaps", 0);

  /* "plastid/genomics/roitools.pyx":1916
 *     cdef ExBool c_antisense_overlaps(self, SegmentChain other) except bool_exception:
 *         cdef:
 *             Strand sstrand = self.c_strand             # <<<<<<<<<<<<<<
 *             Strand ostrand = other.c_strand
 *         if self.c_unstranded_overlaps(other) == true:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_c_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1916, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = ((enum __pyx_t_7plastid_8genomics_8c_common_Strand)__Pyx_PyInt_As_enum____pyx_t_7plastid_8genomics_8c_common_Strand(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1916, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_sstrand = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":1917
 *         cdef:
 *             Strand sstrand = self.c_strand
 *             Strand ostrand = other.c_strand             # <<<<<<<<<<<<<<
 *         if self.c_unstranded_overlaps(other) == true:
 *             if unstranded in (sstrand, ostrand) or sstrand != ostrand:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_c_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1917, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = ((enum __pyx_t_7plastid_8genomics_8c_common_Strand)__Pyx_PyInt_As_enum____pyx_t_7plastid_8genomics_8c_common_Strand(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1917, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ostrand = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":1918
 *             Strand sstrand = self.c_strand
 *             Strand ostrand = other.c_strand
 *         if self.c_unstranded_overlaps(other) == true:             # <<<<<<<<<<<<<<
 *             if unstranded in (sstrand, ostrand) or sstrand != ostrand:
 *                 return true
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_unstranded_overlaps(__pyx_v_self, __pyx_v_other); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1918, __pyx_L1_error)
  __pyx_t_4 = ((__pyx_t_3 == __pyx_e_7plastid_8genomics_8c_common_true) != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":1919
 *             Strand ostrand = other.c_strand
 *         if self.c_unstranded_overlaps(other) == true:
 *             if unstranded in (sstrand, ostrand) or sstrand != ostrand:             # <<<<<<<<<<<<<<
 *                 return true
 * 
 */
    __pyx_t_2 = __pyx_e_7plastid_8genomics_8c_common_unstranded;
    __pyx_t_6 = ((__pyx_t_2 == __pyx_v_sstrand) != 0);
    if (!__pyx_t_6) {
    } else {
      __pyx_t_5 = __pyx_t_6;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_6 = ((__pyx_t_2 == __pyx_v_ostrand) != 0);
    __pyx_t_5 = __pyx_t_6;
    __pyx_L7_bool_binop_done:;
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (!__pyx_t_6) {
    } else {
      __pyx_t_4 = __pyx_t_6;
      goto __pyx_L5_bool_binop_done;
    }
    __pyx_t_6 = ((__pyx_v_sstrand != __pyx_v_ostrand) != 0);
    __pyx_t_4 = __pyx_t_6;
    __pyx_L5_bool_binop_done:;
    if (__pyx_t_4) {

      /* "plastid/genomics/roitools.pyx":1920
 *         if self.c_unstranded_overlaps(other) == true:
 *             if unstranded in (sstrand, ostrand) or sstrand != ostrand:
 *                 return true             # <<<<<<<<<<<<<<
 * 
 *         return false
 */
      __pyx_r = __pyx_e_7plastid_8genomics_8c_common_true;
      goto __pyx_L0;

      /* "plastid/genomics/roitools.pyx":1919
 *             Strand ostrand = other.c_strand
 *         if self.c_unstranded_overlaps(other) == true:
 *             if unstranded in (sstrand, ostrand) or sstrand != ostrand:             # <<<<<<<<<<<<<<
 *                 return true
 * 
 */
    }

    /* "plastid/genomics/roitools.pyx":1918
 *             Strand sstrand = self.c_strand
 *             Strand ostrand = other.c_strand
 *         if self.c_unstranded_overlaps(other) == true:             # <<<<<<<<<<<<<<
 *             if unstranded in (sstrand, ostrand) or sstrand != ostrand:
 *                 return true
 */
  }

  /* "plastid/genomics/roitools.pyx":1922
 *                 return true
 * 
 *         return false             # <<<<<<<<<<<<<<
 * 
 *     def covers(self, object other):
 */
  __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1914
 *             )
 * 
 *     cdef ExBool c_antisense_overlaps(self, SegmentChain other) except bool_exception:             # <<<<<<<<<<<<<<
 *         cdef:
 *             Strand sstrand = self.c_strand
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_antisense_overlaps", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = __pyx_e_7plastid_8genomics_8c_common_bool_exception;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1924
 *         return false
 * 
 *     def covers(self, object other):             # <<<<<<<<<<<<<<
 *         """Return `True` if `self` and `other` share a chromosome and strand,
 *         and all genomic positions in `other` are present in `self`.
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_41covers(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_40covers[] = "SegmentChain.covers(self, other)\nReturn `True` if `self` and `other` share a chromosome and strand,\n        and all genomic positions in `other` are present in `self`.\n        By convention, zero-length |SegmentChains| are not covered by other\n        chains.\n\n\n        Parameters\n        ----------\n        other : |SegmentChain| or |GenomicSegment|\n        \tQuery feature\n\n\n        Returns\n        -------\n        bool\n            `True` if `self` and `other` share a chromosome and strand, and all\n            genomic positions in `other` are present in `self`. Otherwise `False`\n\n\n        Raises\n        ------\n        TypeError\n            if `other` is not a |GenomicSegment| or |SegmentChain|\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_41covers(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("covers (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_40covers(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((PyObject *)__pyx_v_other));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_40covers(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("covers", 0);

  /* "plastid/genomics/roitools.pyx":1950
 *         """
 *         cdef ExBool retval
 *         if isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             return self.c_covers(other) == true
 *         elif isinstance(other, GenomicSegment):
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1951
 *         cdef ExBool retval
 *         if isinstance(other, SegmentChain):
 *             return self.c_covers(other) == true             # <<<<<<<<<<<<<<
 *         elif isinstance(other, GenomicSegment):
 *             return self.c_covers(SegmentChain(other)) == true
 */
    __Pyx_XDECREF(__pyx_r);
    if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 1951, __pyx_L1_error)
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_covers(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_other)); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1951, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyBool_FromLong((__pyx_t_3 == __pyx_e_7plastid_8genomics_8c_common_true)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1951, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1950
 *         """
 *         cdef ExBool retval
 *         if isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             return self.c_covers(other) == true
 *         elif isinstance(other, GenomicSegment):
 */
  }

  /* "plastid/genomics/roitools.pyx":1952
 *         if isinstance(other, SegmentChain):
 *             return self.c_covers(other) == true
 *         elif isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return self.c_covers(SegmentChain(other)) == true
 *         else:
 */
  __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment); 
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (likely(__pyx_t_1)) {

    /* "plastid/genomics/roitools.pyx":1953
 *             return self.c_covers(other) == true
 *         elif isinstance(other, GenomicSegment):
 *             return self.c_covers(SegmentChain(other)) == true             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError(
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_v_other); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1953, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_covers(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_4)); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 1953, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyBool_FromLong((__pyx_t_3 == __pyx_e_7plastid_8genomics_8c_common_true)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1953, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1952
 *         if isinstance(other, SegmentChain):
 *             return self.c_covers(other) == true
 *         elif isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return self.c_covers(SegmentChain(other)) == true
 *         else:
 */
  }

  /* "plastid/genomics/roitools.pyx":1955
 *             return self.c_covers(SegmentChain(other)) == true
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain.covers() is only defined for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)
 */
  /*else*/ {

    /* "plastid/genomics/roitools.pyx":1957
 *             raise TypeError(
 *                 "SegmentChain.covers() is only defined for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    __pyx_t_4 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_SegmentChain_covers_is_only_defi, ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1957, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "plastid/genomics/roitools.pyx":1955
 *             return self.c_covers(SegmentChain(other)) == true
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain.covers() is only defined for GenomicSegments and SegmentChains. Found %s."
 *                 % type(other)
 */
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1955, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 1955, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":1924
 *         return false
 * 
 *     def covers(self, object other):             # <<<<<<<<<<<<<<
 *         """Return `True` if `self` and `other` share a chromosome and strand,
 *         and all genomic positions in `other` are present in `self`.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.covers", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":1960
 *             )
 * 
 *     cdef ExBool c_covers(self, SegmentChain other) except bool_exception:             # <<<<<<<<<<<<<<
 *         """Return `True` if `self` and `other` share a chromosome and strand,
 *         and all genomic positions in `other` are present in `self`.
 */

static enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_covers(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_other) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_sspan = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_ospan = 0;
  PyObject *__pyx_v_mine = 0;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_covers", 0);

  /* "plastid/genomics/roitools.pyx":1984
 *         """
 *         cdef:
 *             GenomicSegment sspan = self.spanning_segment             # <<<<<<<<<<<<<<
 *             GenomicSegment ospan = other.spanning_segment
 *             list mine = self._segments
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_sspan = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1985
 *         cdef:
 *             GenomicSegment sspan = self.spanning_segment
 *             GenomicSegment ospan = other.spanning_segment             # <<<<<<<<<<<<<<
 *             list mine = self._segments
 * 
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_other->spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_ospan = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1986
 *             GenomicSegment sspan = self.spanning_segment
 *             GenomicSegment ospan = other.spanning_segment
 *             list mine = self._segments             # <<<<<<<<<<<<<<
 * 
 *         if len(self) == 0 or len(other) == 0:
 */
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_mine = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1988
 *             list mine = self._segments
 * 
 *         if len(self) == 0 or len(other) == 0:             # <<<<<<<<<<<<<<
 *             return false
 *         elif sspan.chrom  == ospan.chrom and\
 */
  __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1988, __pyx_L1_error)
  __pyx_t_4 = ((__pyx_t_3 == 0) != 0);
  if (!__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_other)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1988, __pyx_L1_error)
  __pyx_t_4 = ((__pyx_t_3 == 0) != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1989
 * 
 *         if len(self) == 0 or len(other) == 0:
 *             return false             # <<<<<<<<<<<<<<
 *         elif sspan.chrom  == ospan.chrom and\
 *              sspan.c_strand == ospan.c_strand and\
 */
    __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1988
 *             list mine = self._segments
 * 
 *         if len(self) == 0 or len(other) == 0:             # <<<<<<<<<<<<<<
 *             return false
 *         elif sspan.chrom  == ospan.chrom and\
 */
  }

  /* "plastid/genomics/roitools.pyx":1990
 *         if len(self) == 0 or len(other) == 0:
 *             return false
 *         elif sspan.chrom  == ospan.chrom and\             # <<<<<<<<<<<<<<
 *              sspan.c_strand == ospan.c_strand and\
 *              mine == merge_segments(mine + other._segments):
 */
  __pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_v_sspan->chrom, __pyx_v_ospan->chrom, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1990, __pyx_L1_error)
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {
  } else {
    __pyx_t_2 = __pyx_t_5;
    goto __pyx_L6_bool_binop_done;
  }

  /* "plastid/genomics/roitools.pyx":1991
 *             return false
 *         elif sspan.chrom  == ospan.chrom and\
 *              sspan.c_strand == ospan.c_strand and\             # <<<<<<<<<<<<<<
 *              mine == merge_segments(mine + other._segments):
 *             return true
 */
  __pyx_t_5 = ((__pyx_v_sspan->c_strand == __pyx_v_ospan->c_strand) != 0);
  if (__pyx_t_5) {
  } else {
    __pyx_t_2 = __pyx_t_5;
    goto __pyx_L6_bool_binop_done;
  }

  /* "plastid/genomics/roitools.pyx":1992
 *         elif sspan.chrom  == ospan.chrom and\
 *              sspan.c_strand == ospan.c_strand and\
 *              mine == merge_segments(mine + other._segments):             # <<<<<<<<<<<<<<
 *             return true
 * 
 */
  __pyx_t_1 = PyNumber_Add(__pyx_v_mine, __pyx_v_other->_segments); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1992, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __pyx_f_7plastid_8genomics_8roitools_merge_segments(((PyObject*)__pyx_t_1), 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1992, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_mine, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1992, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1992, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_2 = __pyx_t_5;
  __pyx_L6_bool_binop_done:;

  /* "plastid/genomics/roitools.pyx":1990
 *         if len(self) == 0 or len(other) == 0:
 *             return false
 *         elif sspan.chrom  == ospan.chrom and\             # <<<<<<<<<<<<<<
 *              sspan.c_strand == ospan.c_strand and\
 *              mine == merge_segments(mine + other._segments):
 */
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":1993
 *              sspan.c_strand == ospan.c_strand and\
 *              mine == merge_segments(mine + other._segments):
 *             return true             # <<<<<<<<<<<<<<
 * 
 *         return false
 */
    __pyx_r = __pyx_e_7plastid_8genomics_8c_common_true;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":1990
 *         if len(self) == 0 or len(other) == 0:
 *             return false
 *         elif sspan.chrom  == ospan.chrom and\             # <<<<<<<<<<<<<<
 *              sspan.c_strand == ospan.c_strand and\
 *              mine == merge_segments(mine + other._segments):
 */
  }

  /* "plastid/genomics/roitools.pyx":1995
 *             return true
 * 
 *         return false             # <<<<<<<<<<<<<<
 * 
 * #         extra_attr : keyword arguments
 */
  __pyx_r = __pyx_e_7plastid_8genomics_8c_common_false;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":1960
 *             )
 * 
 *     cdef ExBool c_covers(self, SegmentChain other) except bool_exception:             # <<<<<<<<<<<<<<
 *         """Return `True` if `self` and `other` share a chromosome and strand,
 *         and all genomic positions in `other` are present in `self`.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_covers", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = __pyx_e_7plastid_8genomics_8c_common_bool_exception;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_sspan);
  __Pyx_XDECREF((PyObject *)__pyx_v_ospan);
  __Pyx_XDECREF(__pyx_v_mine);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2000
 * #             Values that will be included in the new chain's `attr` dict.
 * #             These can be used to overwrite values already present.
 *     cdef SegmentChain _restrand(self, Strand strand):#, **extra_attr):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| on strand `strand` using coordinates from `self`.
 * 
 */

static struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain__restrand(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_v_strand) {
  PyObject *__pyx_v_s_strand = 0;
  PyObject *__pyx_v_chrom = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_new_chain = 0;
  PyObject *__pyx_v_new_segments = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_seg = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_restrand", 0);

  /* "plastid/genomics/roitools.pyx":2015
 *         """
 *         cdef:
 *             str            s_strand     = strand_to_str(strand)             # <<<<<<<<<<<<<<
 *             str            chrom        = self.spanning_segment.chrom
 *             SegmentChain   new_chain    = SegmentChain()#**extra_attr)
 */
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8c_common_strand_to_str(__pyx_v_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2015, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_s_strand = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2016
 *         cdef:
 *             str            s_strand     = strand_to_str(strand)
 *             str            chrom        = self.spanning_segment.chrom             # <<<<<<<<<<<<<<
 *             SegmentChain   new_chain    = SegmentChain()#**extra_attr)
 *             list           new_segments = []
 */
  __pyx_t_1 = __pyx_v_self->spanning_segment->chrom;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_chrom = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2017
 *             str            s_strand     = strand_to_str(strand)
 *             str            chrom        = self.spanning_segment.chrom
 *             SegmentChain   new_chain    = SegmentChain()#**extra_attr)             # <<<<<<<<<<<<<<
 *             list           new_segments = []
 *             GenomicSegment seg
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2017, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_new_chain = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2018
 *             str            chrom        = self.spanning_segment.chrom
 *             SegmentChain   new_chain    = SegmentChain()#**extra_attr)
 *             list           new_segments = []             # <<<<<<<<<<<<<<
 *             GenomicSegment seg
 * 
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2018, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_new_segments = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2021
 *             GenomicSegment seg
 * 
 *         for seg in self._segments:             # <<<<<<<<<<<<<<
 *             new_segments.append(GenomicSegment(chrom, seg.start, seg.end, s_strand))
 * 
 */
  if (unlikely(__pyx_v_self->_segments == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 2021, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_v_self->_segments; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2021, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2021, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 2021, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_seg, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":2022
 * 
 *         for seg in self._segments:
 *             new_segments.append(GenomicSegment(chrom, seg.start, seg.end, s_strand))             # <<<<<<<<<<<<<<
 * 
 *         new_chain._set_segments(new_segments)
 */
    __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_seg->start); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2022, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_seg->end); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2022, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2022, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_chrom);
    __Pyx_GIVEREF(__pyx_v_chrom);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_chrom);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
    __Pyx_INCREF(__pyx_v_s_strand);
    __Pyx_GIVEREF(__pyx_v_s_strand);
    PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_s_strand);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2022, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_new_segments, __pyx_t_4); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 2022, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":2021
 *             GenomicSegment seg
 * 
 *         for seg in self._segments:             # <<<<<<<<<<<<<<
 *             new_segments.append(GenomicSegment(chrom, seg.start, seg.end, s_strand))
 * 
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2024
 *             new_segments.append(GenomicSegment(chrom, seg.start, seg.end, s_strand))
 * 
 *         new_chain._set_segments(new_segments)             # <<<<<<<<<<<<<<
 *         return new_chain
 * 
 */
  __pyx_t_7 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_new_chain->__pyx_vtab)->_set_segments(__pyx_v_new_chain, __pyx_v_new_segments); if (unlikely(__pyx_t_7 == ((int)0))) __PYX_ERR(0, 2024, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":2025
 * 
 *         new_chain._set_segments(new_segments)
 *         return new_chain             # <<<<<<<<<<<<<<
 * 
 *     cpdef SegmentChain get_unstranded(self):#,**extra_attr):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_new_chain));
  __pyx_r = __pyx_v_new_chain;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2000
 * #             Values that will be included in the new chain's `attr` dict.
 * #             These can be used to overwrite values already present.
 *     cdef SegmentChain _restrand(self, Strand strand):#, **extra_attr):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| on strand `strand` using coordinates from `self`.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain._restrand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_s_strand);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF((PyObject *)__pyx_v_new_chain);
  __Pyx_XDECREF(__pyx_v_new_segments);
  __Pyx_XDECREF((PyObject *)__pyx_v_seg);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2027
 *         return new_chain
 * 
 *     cpdef SegmentChain get_unstranded(self):#,**extra_attr):             # <<<<<<<<<<<<<<
 *         """Returns an |SegmentChain| antisense to `self`, with empty `attr` dict.
 * 
 */

static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_43get_unstranded(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_get_unstranded(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, int __pyx_skip_dispatch) {
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_unstranded", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_unstranded); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2027, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_43get_unstranded)) {
        __Pyx_XDECREF(((PyObject *)__pyx_r));
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2027, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 2027, __pyx_L1_error)
        __pyx_r = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "plastid/genomics/roitools.pyx":2035
 *             |SegmentChain| antisense to `self`
 *         """
 *         return self._restrand(unstranded)#,**extra_attr)             # <<<<<<<<<<<<<<
 * 
 *     cpdef SegmentChain get_antisense(self):#,**extra_attr):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_restrand(__pyx_v_self, __pyx_e_7plastid_8genomics_8c_common_unstranded)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2035, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2027
 *         return new_chain
 * 
 *     cpdef SegmentChain get_unstranded(self):#,**extra_attr):             # <<<<<<<<<<<<<<
 *         """Returns an |SegmentChain| antisense to `self`, with empty `attr` dict.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_unstranded", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_43get_unstranded(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_42get_unstranded[] = "SegmentChain.get_unstranded(self) -> SegmentChain\nReturns an |SegmentChain| antisense to `self`, with empty `attr` dict.\n\n        Returns\n        -------\n        SegmentChain\n            |SegmentChain| antisense to `self`\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_43get_unstranded(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_unstranded (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_42get_unstranded(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_42get_unstranded(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__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_RefNannySetupContext("get_unstranded", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_get_unstranded(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_unstranded", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2037
 *         return self._restrand(unstranded)#,**extra_attr)
 * 
 *     cpdef SegmentChain get_antisense(self):#,**extra_attr):             # <<<<<<<<<<<<<<
 *         """Returns an |SegmentChain| antisense to `self`, with empty `attr` dict.
 * 
 */

static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_45get_antisense(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_get_antisense(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, int __pyx_skip_dispatch) {
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_v_strand;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_v_new_strand;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__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;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_antisense", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_antisense); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2037, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_45get_antisense)) {
        __Pyx_XDECREF(((PyObject *)__pyx_r));
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2037, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 2037, __pyx_L1_error)
        __pyx_r = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "plastid/genomics/roitools.pyx":2046
 *         """
 *         cdef:
 *             Strand strand = self.spanning_segment.c_strand             # <<<<<<<<<<<<<<
 * 
 *         if strand == forward_strand:
 */
  __pyx_t_5 = __pyx_v_self->spanning_segment->c_strand;
  __pyx_v_strand = __pyx_t_5;

  /* "plastid/genomics/roitools.pyx":2048
 *             Strand strand = self.spanning_segment.c_strand
 * 
 *         if strand == forward_strand:             # <<<<<<<<<<<<<<
 *             new_strand = reverse_strand
 *         elif strand == reverse_strand:
 */
  switch (__pyx_v_strand) {
    case __pyx_e_7plastid_8genomics_8c_common_forward_strand:

    /* "plastid/genomics/roitools.pyx":2049
 * 
 *         if strand == forward_strand:
 *             new_strand = reverse_strand             # <<<<<<<<<<<<<<
 *         elif strand == reverse_strand:
 *             new_strand = forward_strand
 */
    __pyx_v_new_strand = __pyx_e_7plastid_8genomics_8c_common_reverse_strand;

    /* "plastid/genomics/roitools.pyx":2048
 *             Strand strand = self.spanning_segment.c_strand
 * 
 *         if strand == forward_strand:             # <<<<<<<<<<<<<<
 *             new_strand = reverse_strand
 *         elif strand == reverse_strand:
 */
    break;
    case __pyx_e_7plastid_8genomics_8c_common_reverse_strand:

    /* "plastid/genomics/roitools.pyx":2051
 *             new_strand = reverse_strand
 *         elif strand == reverse_strand:
 *             new_strand = forward_strand             # <<<<<<<<<<<<<<
 *         elif strand == unstranded:
 *             new_strand = unstranded
 */
    __pyx_v_new_strand = __pyx_e_7plastid_8genomics_8c_common_forward_strand;

    /* "plastid/genomics/roitools.pyx":2050
 *         if strand == forward_strand:
 *             new_strand = reverse_strand
 *         elif strand == reverse_strand:             # <<<<<<<<<<<<<<
 *             new_strand = forward_strand
 *         elif strand == unstranded:
 */
    break;
    case __pyx_e_7plastid_8genomics_8c_common_unstranded:

    /* "plastid/genomics/roitools.pyx":2053
 *             new_strand = forward_strand
 *         elif strand == unstranded:
 *             new_strand = unstranded             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError("Strand for SegmentChain '%s' is undefined and has no anti-sense." % self)
 */
    __pyx_v_new_strand = __pyx_e_7plastid_8genomics_8c_common_unstranded;

    /* "plastid/genomics/roitools.pyx":2052
 *         elif strand == reverse_strand:
 *             new_strand = forward_strand
 *         elif strand == unstranded:             # <<<<<<<<<<<<<<
 *             new_strand = unstranded
 *         else:
 */
    break;
    default:

    /* "plastid/genomics/roitools.pyx":2055
 *             new_strand = unstranded
 *         else:
 *             raise ValueError("Strand for SegmentChain '%s' is undefined and has no anti-sense." % self)             # <<<<<<<<<<<<<<
 * 
 *         return self._restrand(new_strand)#,**extra_attr)
 */
    __pyx_t_1 = PyUnicode_Format(__pyx_kp_u_Strand_for_SegmentChain_s_is_und, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2055, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2055, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 2055, __pyx_L1_error)
    break;
  }

  /* "plastid/genomics/roitools.pyx":2057
 *             raise ValueError("Strand for SegmentChain '%s' is undefined and has no anti-sense." % self)
 * 
 *         return self._restrand(new_strand)#,**extra_attr)             # <<<<<<<<<<<<<<
 * 
 *     cdef list c_get_position_list(self):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_restrand(__pyx_v_self, __pyx_v_new_strand)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2037
 *         return self._restrand(unstranded)#,**extra_attr)
 * 
 *     cpdef SegmentChain get_antisense(self):#,**extra_attr):             # <<<<<<<<<<<<<<
 *         """Returns an |SegmentChain| antisense to `self`, with empty `attr` dict.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_antisense", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_45get_antisense(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_44get_antisense[] = "SegmentChain.get_antisense(self) -> SegmentChain\nReturns an |SegmentChain| antisense to `self`, with empty `attr` dict.\n\n        Returns\n        -------\n        SegmentChain\n            |SegmentChain| antisense to `self`\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_45get_antisense(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_antisense (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_44get_antisense(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_44get_antisense(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__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_RefNannySetupContext("get_antisense", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_get_antisense(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2037, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_antisense", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2059
 *         return self._restrand(new_strand)#,**extra_attr)
 * 
 *     cdef list c_get_position_list(self):             # <<<<<<<<<<<<<<
 *         """Retrieve a sorted **end-inclusive** numpy array of genomic
 *         coordinates in this |SegmentChain|
 */

static PyObject *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_position_list(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_get_position_list", 0);

  /* "plastid/genomics/roitools.pyx":2068
 *             Genomic coordinates in `self`, as integers, in genomic order
 *         """
 *         return self._get_position_hash().tolist()             # <<<<<<<<<<<<<<
 * 
 *     def get_position_list(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_get_position_hash(__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2068, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_tolist); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2068, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2068, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 2068, __pyx_L1_error)
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2059
 *         return self._restrand(new_strand)#,**extra_attr)
 * 
 *     cdef list c_get_position_list(self):             # <<<<<<<<<<<<<<
 *         """Retrieve a sorted **end-inclusive** numpy array of genomic
 *         coordinates in this |SegmentChain|
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_get_position_list", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2070
 *         return self._get_position_hash().tolist()
 * 
 *     def get_position_list(self):             # <<<<<<<<<<<<<<
 *         """Retrieve a sorted **end-inclusive** numpy array of genomic
 *         coordinates in this |SegmentChain|
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_47get_position_list(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_46get_position_list[] = "SegmentChain.get_position_list(self)\nRetrieve a sorted **end-inclusive** numpy array of genomic\n        coordinates in this |SegmentChain|\n\n\n        Returns\n        -------\n        list\n            Genomic coordinates in `self`, as integers, in genomic order\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_47get_position_list(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_position_list (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_46get_position_list(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_46get_position_list(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_position_list", 0);

  /* "plastid/genomics/roitools.pyx":2080
 *             Genomic coordinates in `self`, as integers, in genomic order
 *         """
 *         return self._get_position_hash().tolist()             # <<<<<<<<<<<<<<
 * 
 *     cdef numpy.ndarray c_get_position_array(self, bint copy):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_get_position_hash(__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2080, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_tolist); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2080, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2080, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2070
 *         return self._get_position_hash().tolist()
 * 
 *     def get_position_list(self):             # <<<<<<<<<<<<<<
 *         """Retrieve a sorted **end-inclusive** numpy array of genomic
 *         coordinates in this |SegmentChain|
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_position_list", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2082
 *         return self._get_position_hash().tolist()
 * 
 *     cdef numpy.ndarray c_get_position_array(self, bint copy):             # <<<<<<<<<<<<<<
 *         """Retrieve a sorted end-inclusive list of genomic coordinates in this
 *         |SegmentChain|
 */

static PyArrayObject *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_position_array(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, int __pyx_v_copy) {
  PyArrayObject *__pyx_v_positions = 0;
  PyArrayObject *__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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_get_position_array", 0);

  /* "plastid/genomics/roitools.pyx":2097
 *             Ggenomic coordinates in `self`, as integers, in genomic order
 *         """
 *         cdef numpy.ndarray positions = numpy.asarray(self._get_position_hash(), dtype=long)             # <<<<<<<<<<<<<<
 *         if copy == False:
 *             return positions
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2097, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_asarray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2097, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_get_position_hash(__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2097, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2097, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2097, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, ((PyObject *)(&PyLong_Type))) < 0) __PYX_ERR(0, 2097, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2097, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2097, __pyx_L1_error)
  __pyx_v_positions = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "plastid/genomics/roitools.pyx":2098
 *         """
 *         cdef numpy.ndarray positions = numpy.asarray(self._get_position_hash(), dtype=long)
 *         if copy == False:             # <<<<<<<<<<<<<<
 *             return positions
 *         else:
 */
  __pyx_t_5 = ((__pyx_v_copy == 0) != 0);
  if (__pyx_t_5) {

    /* "plastid/genomics/roitools.pyx":2099
 *         cdef numpy.ndarray positions = numpy.asarray(self._get_position_hash(), dtype=long)
 *         if copy == False:
 *             return positions             # <<<<<<<<<<<<<<
 *         else:
 *             return copy.deepcopy(positions)
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_positions));
    __pyx_r = __pyx_v_positions;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":2098
 *         """
 *         cdef numpy.ndarray positions = numpy.asarray(self._get_position_hash(), dtype=long)
 *         if copy == False:             # <<<<<<<<<<<<<<
 *             return positions
 *         else:
 */
  }

  /* "plastid/genomics/roitools.pyx":2101
 *             return positions
 *         else:
 *             return copy.deepcopy(positions)             # <<<<<<<<<<<<<<
 * 
 *     def get_position_set(self):
 */
  /*else*/ {
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_copy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2101, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2101, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, ((PyObject *)__pyx_v_positions)) : __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_positions));
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2101, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2101, __pyx_L1_error)
    __pyx_r = ((PyArrayObject *)__pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "plastid/genomics/roitools.pyx":2082
 *         return self._get_position_hash().tolist()
 * 
 *     cdef numpy.ndarray c_get_position_array(self, bint copy):             # <<<<<<<<<<<<<<
 *         """Retrieve a sorted end-inclusive list of genomic coordinates in this
 *         |SegmentChain|
 */

  /* 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("plastid.genomics.roitools.SegmentChain.c_get_position_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_positions);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2103
 *             return copy.deepcopy(positions)
 * 
 *     def get_position_set(self):             # <<<<<<<<<<<<<<
 *         """Retrieve an end-inclusive set of genomic coordinates included in
 *         this |SegmentChain|
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_49get_position_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_48get_position_set[] = "SegmentChain.get_position_set(self)\nRetrieve an end-inclusive set of genomic coordinates included in\n        this |SegmentChain|\n\n        Returns\n        -------\n        set\n            Set of genomic coordinates, as integers\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_49get_position_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_position_set (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_48get_position_set(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_48get_position_set(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_position_set", 0);

  /* "plastid/genomics/roitools.pyx":2112
 *             Set of genomic coordinates, as integers
 *         """
 *         return set(self.c_get_position_list())             # <<<<<<<<<<<<<<
 * 
 *     cdef set c_get_position_set(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_get_position_list(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PySet_New(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2103
 *             return copy.deepcopy(positions)
 * 
 *     def get_position_set(self):             # <<<<<<<<<<<<<<
 *         """Retrieve an end-inclusive set of genomic coordinates included in
 *         this |SegmentChain|
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_position_set", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2114
 *         return set(self.c_get_position_list())
 * 
 *     cdef set c_get_position_set(self):             # <<<<<<<<<<<<<<
 *         return set(self._get_position_hash().tolist())
 * 
 */

static PyObject *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_position_set(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_get_position_set", 0);

  /* "plastid/genomics/roitools.pyx":2115
 * 
 *     cdef set c_get_position_set(self):
 *         return set(self._get_position_hash().tolist())             # <<<<<<<<<<<<<<
 * 
 *     cpdef set get_masked_position_set(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_get_position_hash(__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_tolist); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PySet_New(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2114
 *         return set(self.c_get_position_list())
 * 
 *     cdef set c_get_position_set(self):             # <<<<<<<<<<<<<<
 *         return set(self._get_position_hash().tolist())
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_get_position_set", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2117
 *         return set(self._get_position_hash().tolist())
 * 
 *     cpdef set get_masked_position_set(self):             # <<<<<<<<<<<<<<
 *         """Returns a set of genomic coordinates corresponding to positions in
 *         `self` that **HAVE NOT** been masked using :meth:`SegmentChain.add_masks`
 */

static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_51get_masked_position_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_get_masked_position_set(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, int __pyx_skip_dispatch) {
  PyArrayObject *__pyx_v_mask = 0;
  PyArrayObject *__pyx_v_positions = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_mask;
  __Pyx_Buffer __pyx_pybuffer_mask;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_positions;
  __Pyx_Buffer __pyx_pybuffer_positions;
  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;
  PyObject *__pyx_t_7 = NULL;
  PyArrayObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyArrayObject *__pyx_t_13 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_masked_position_set", 0);
  __pyx_pybuffer_mask.pybuffer.buf = NULL;
  __pyx_pybuffer_mask.refcount = 0;
  __pyx_pybuffernd_mask.data = NULL;
  __pyx_pybuffernd_mask.rcbuffer = &__pyx_pybuffer_mask;
  __pyx_pybuffer_positions.pybuffer.buf = NULL;
  __pyx_pybuffer_positions.refcount = 0;
  __pyx_pybuffernd_positions.data = NULL;
  __pyx_pybuffernd_positions.rcbuffer = &__pyx_pybuffer_positions;
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_masked_position_set); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2117, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_51get_masked_position_set)) {
        __Pyx_XDECREF(__pyx_r);
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2117, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (!(likely(PySet_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "set", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 2117, __pyx_L1_error)
        __pyx_r = ((PyObject*)__pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "plastid/genomics/roitools.pyx":2130
 *             numpy.ndarray[LONG_t, ndim=1] positions
 * 
 *         if self._position_mask is None:             # <<<<<<<<<<<<<<
 *             return self.c_get_position_set()
 *         else:
 */
  __pyx_t_5 = (((PyObject *)__pyx_v_self->_position_mask) == Py_None);
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "plastid/genomics/roitools.pyx":2131
 * 
 *         if self._position_mask is None:
 *             return self.c_get_position_set()             # <<<<<<<<<<<<<<
 *         else:
 *             mask = numpy.frombuffer(self._position_mask, dtype=numpy.intc)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_get_position_set(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2131, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":2130
 *             numpy.ndarray[LONG_t, ndim=1] positions
 * 
 *         if self._position_mask is None:             # <<<<<<<<<<<<<<
 *             return self.c_get_position_set()
 *         else:
 */
  }

  /* "plastid/genomics/roitools.pyx":2133
 *             return self.c_get_position_set()
 *         else:
 *             mask = numpy.frombuffer(self._position_mask, dtype=numpy.intc)             # <<<<<<<<<<<<<<
 *             positions = numpy.frombuffer(self._get_position_hash(), dtype=LONG)
 *             return set(positions[mask == 0])
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_frombuffer); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)__pyx_v_self->_position_mask));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self->_position_mask));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->_position_mask));
    __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_intc); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 2133, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2133, __pyx_L1_error)
    __pyx_t_8 = ((PyArrayObject *)__pyx_t_7);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask.rcbuffer->pybuffer);
      __pyx_t_9 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_9 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mask.rcbuffer->pybuffer, (PyObject*)__pyx_v_mask, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
        }
        __pyx_t_10 = __pyx_t_11 = __pyx_t_12 = 0;
      }
      __pyx_pybuffernd_mask.diminfo[0].strides = __pyx_pybuffernd_mask.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_mask.diminfo[0].shape = __pyx_pybuffernd_mask.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 2133, __pyx_L1_error)
    }
    __pyx_t_8 = 0;
    __pyx_v_mask = ((PyArrayObject *)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":2134
 *         else:
 *             mask = numpy.frombuffer(self._position_mask, dtype=numpy.intc)
 *             positions = numpy.frombuffer(self._get_position_hash(), dtype=LONG)             # <<<<<<<<<<<<<<
 *             return set(positions[mask == 0])
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_numpy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2134, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_frombuffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2134, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_get_position_hash(__pyx_v_self)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2134, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2134, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2134, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_LONG); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2134, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 2134, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2134, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2134, __pyx_L1_error)
    __pyx_t_13 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_positions.rcbuffer->pybuffer);
      __pyx_t_9 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_positions.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_7plastid_8genomics_8roitools_LONG_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_9 < 0)) {
        PyErr_Fetch(&__pyx_t_12, &__pyx_t_11, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_positions.rcbuffer->pybuffer, (PyObject*)__pyx_v_positions, &__Pyx_TypeInfo_nn___pyx_t_7plastid_8genomics_8roitools_LONG_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_12, __pyx_t_11, __pyx_t_10);
        }
        __pyx_t_12 = __pyx_t_11 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_positions.diminfo[0].strides = __pyx_pybuffernd_positions.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_positions.diminfo[0].shape = __pyx_pybuffernd_positions.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 2134, __pyx_L1_error)
    }
    __pyx_t_13 = 0;
    __pyx_v_positions = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "plastid/genomics/roitools.pyx":2135
 *             mask = numpy.frombuffer(self._position_mask, dtype=numpy.intc)
 *             positions = numpy.frombuffer(self._get_position_hash(), dtype=LONG)
 *             return set(positions[mask == 0])             # <<<<<<<<<<<<<<
 * 
 *     def get_name(self):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_mask), __pyx_int_0, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2135, __pyx_L1_error)
    __pyx_t_7 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_positions), __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2135, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PySet_New(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2135, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_r = ((PyObject*)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "plastid/genomics/roitools.pyx":2117
 *         return set(self._get_position_hash().tolist())
 * 
 *     cpdef set get_masked_position_set(self):             # <<<<<<<<<<<<<<
 *         """Returns a set of genomic coordinates corresponding to positions in
 *         `self` that **HAVE NOT** been masked using :meth:`SegmentChain.add_masks`
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_positions.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_masked_position_set", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mask.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_positions.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_mask);
  __Pyx_XDECREF((PyObject *)__pyx_v_positions);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_51get_masked_position_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_50get_masked_position_set[] = "SegmentChain.get_masked_position_set(self) -> set\nReturns a set of genomic coordinates corresponding to positions in\n        `self` that **HAVE NOT** been masked using :meth:`SegmentChain.add_masks`\n\n        Returns\n        -------\n        set\n            Set of genomic coordinates, as integers\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_51get_masked_position_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_masked_position_set (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_50get_masked_position_set(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_50get_masked_position_set(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__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_RefNannySetupContext("get_masked_position_set", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_get_masked_position_set(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_masked_position_set", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2137
 *             return set(positions[mask == 0])
 * 
 *     def get_name(self):             # <<<<<<<<<<<<<<
 *         """Returns the name of this |SegmentChain|, first searching through
 *         `self.attr` for the keys `ID`, `Name`, and `name`. If no value is found
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_53get_name(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_52get_name[] = "SegmentChain.get_name(self)\nReturns the name of this |SegmentChain|, first searching through\n        `self.attr` for the keys `ID`, `Name`, and `name`. If no value is found\n        for any of those keys, a name is generated using :meth:`SegmentChain.__str__`\n\n        Returns\n        -------\n        str\n            In order of preference, `ID` from `self.attr`, `Name` from\n            `self.attr`, `name` from `self.attr` or ``str(self)``\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_53get_name(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_name (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_52get_name(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_52get_name(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_v_name = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_name", 0);

  /* "plastid/genomics/roitools.pyx":2148
 *             `self.attr`, `name` from `self.attr` or ``str(self)``
 *         """
 *         name = self.attr.get("ID",             # <<<<<<<<<<<<<<
 *                self.attr.get("Name",
 *                self.attr.get("name",
 */
  if (unlikely(__pyx_v_self->attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 2148, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":2149
 *         """
 *         name = self.attr.get("ID",
 *                self.attr.get("Name",             # <<<<<<<<<<<<<<
 *                self.attr.get("name",
 *                              str(self))))
 */
  if (unlikely(__pyx_v_self->attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 2149, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":2150
 *         name = self.attr.get("ID",
 *                self.attr.get("Name",
 *                self.attr.get("name",             # <<<<<<<<<<<<<<
 *                              str(self))))
 *         return name
 */
  if (unlikely(__pyx_v_self->attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 2150, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":2151
 *                self.attr.get("Name",
 *                self.attr.get("name",
 *                              str(self))))             # <<<<<<<<<<<<<<
 *         return name
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2151, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "plastid/genomics/roitools.pyx":2150
 *         name = self.attr.get("ID",
 *                self.attr.get("Name",
 *                self.attr.get("name",             # <<<<<<<<<<<<<<
 *                              str(self))))
 *         return name
 */
  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_name_2, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2150, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2149
 *         """
 *         name = self.attr.get("ID",
 *                self.attr.get("Name",             # <<<<<<<<<<<<<<
 *                self.attr.get("name",
 *                              str(self))))
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_Name, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2149, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":2148
 *             `self.attr`, `name` from `self.attr` or ``str(self)``
 *         """
 *         name = self.attr.get("ID",             # <<<<<<<<<<<<<<
 *                self.attr.get("Name",
 *                self.attr.get("name",
 */
  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_ID_2, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_name = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":2152
 *                self.attr.get("name",
 *                              str(self))))
 *         return name             # <<<<<<<<<<<<<<
 * 
 *     def get_gene(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_name);
  __pyx_r = __pyx_v_name;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2137
 *             return set(positions[mask == 0])
 * 
 *     def get_name(self):             # <<<<<<<<<<<<<<
 *         """Returns the name of this |SegmentChain|, first searching through
 *         `self.attr` for the keys `ID`, `Name`, and `name`. If no value is found
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_name", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2154
 *         return name
 * 
 *     def get_gene(self):             # <<<<<<<<<<<<<<
 *         """Return name of gene associated with |SegmentChain|, if any,
 *         by searching through `self.attr` for the keys `gene_id` and `Parent`.
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_55get_gene(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_54get_gene[] = "SegmentChain.get_gene(self)\nReturn name of gene associated with |SegmentChain|, if any,\n        by searching through `self.attr` for the keys `gene_id` and `Parent`.\n        If one is not found, a generated gene name for the SegmentChain is\n        made from :py:meth:`get_name`.\n\n        Returns\n        -------\n        str\n            Returns in order of preference, `gene_id` from `self.attr`,\n            `Parent` from `self.attr` or ``'gene_%s' % self.get_name()``\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_55get_gene(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_gene (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_54get_gene(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_54get_gene(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_v_gene = 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;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_gene", 0);

  /* "plastid/genomics/roitools.pyx":2166
 *             `Parent` from `self.attr` or ``'gene_%s' % self.get_name()``
 *         """
 *         gene = self.attr.get("gene_id",             # <<<<<<<<<<<<<<
 *                self.attr.get("Parent",
 *                "gene_%s" % self.get_name()))
 */
  if (unlikely(__pyx_v_self->attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 2166, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":2167
 *         """
 *         gene = self.attr.get("gene_id",
 *                self.attr.get("Parent",             # <<<<<<<<<<<<<<
 *                "gene_%s" % self.get_name()))
 * 
 */
  if (unlikely(__pyx_v_self->attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 2167, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":2168
 *         gene = self.attr.get("gene_id",
 *                self.attr.get("Parent",
 *                "gene_%s" % self.get_name()))             # <<<<<<<<<<<<<<
 * 
 *         if isinstance(gene, list):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_gene__s, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2167
 *         """
 *         gene = self.attr.get("gene_id",
 *                self.attr.get("Parent",             # <<<<<<<<<<<<<<
 *                "gene_%s" % self.get_name()))
 * 
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_Parent, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":2166
 *             `Parent` from `self.attr` or ``'gene_%s' % self.get_name()``
 *         """
 *         gene = self.attr.get("gene_id",             # <<<<<<<<<<<<<<
 *                self.attr.get("Parent",
 *                "gene_%s" % self.get_name()))
 */
  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_gene_id, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_gene = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":2170
 *                "gene_%s" % self.get_name()))
 * 
 *         if isinstance(gene, list):             # <<<<<<<<<<<<<<
 *             gene = ",".join(sorted(gene))
 * 
 */
  __pyx_t_4 = PyList_Check(__pyx_v_gene); 
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "plastid/genomics/roitools.pyx":2171
 * 
 *         if isinstance(gene, list):
 *             gene = ",".join(sorted(gene))             # <<<<<<<<<<<<<<
 * 
 *         return gene
 */
    __pyx_t_1 = PySequence_List(__pyx_v_gene); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2171, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_6 = PyList_Sort(__pyx_t_2); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 2171, __pyx_L1_error)
    __pyx_t_1 = PyUnicode_Join(__pyx_kp_u__3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2171, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_gene, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":2170
 *                "gene_%s" % self.get_name()))
 * 
 *         if isinstance(gene, list):             # <<<<<<<<<<<<<<
 *             gene = ",".join(sorted(gene))
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":2173
 *             gene = ",".join(sorted(gene))
 * 
 *         return gene             # <<<<<<<<<<<<<<
 * 
 *     cdef bint c_add_segments(self, tuple segments) except False:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_gene);
  __pyx_r = __pyx_v_gene;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2154
 *         return name
 * 
 *     def get_gene(self):             # <<<<<<<<<<<<<<
 *         """Return name of gene associated with |SegmentChain|, if any,
 *         by searching through `self.attr` for the keys `gene_id` and `Parent`.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_gene", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_gene);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2175
 *         return gene
 * 
 *     cdef bint c_add_segments(self, tuple segments) except False:             # <<<<<<<<<<<<<<
 *         """Add |GenomicSegments| to `self`. If there are
 *         already segments in the chain, the incoming segments must be
 */

static int __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_add_segments(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_segments) {
  int __pyx_v_length;
  PyObject *__pyx_v_new_segments = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_add_segments", 0);

  /* "plastid/genomics/roitools.pyx":2186
 *         """
 *         cdef:
 *             int length = len(segments)             # <<<<<<<<<<<<<<
 *             list new_segments
 * 
 */
  if (unlikely(__pyx_v_segments == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 2186, __pyx_L1_error)
  }
  __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_segments); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2186, __pyx_L1_error)
  __pyx_v_length = __pyx_t_1;

  /* "plastid/genomics/roitools.pyx":2189
 *             list new_segments
 * 
 *         if length > 0:             # <<<<<<<<<<<<<<
 *             check_segments(self, segments)
 *             new_segments = list(segments)
 */
  __pyx_t_2 = ((__pyx_v_length > 0) != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":2190
 * 
 *         if length > 0:
 *             check_segments(self, segments)             # <<<<<<<<<<<<<<
 *             new_segments = list(segments)
 *             new_segments = merge_segments(new_segments + self._segments)
 */
    __pyx_t_2 = __pyx_f_7plastid_8genomics_8roitools_check_segments(__pyx_v_self, __pyx_v_segments); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(0, 2190, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":2191
 *         if length > 0:
 *             check_segments(self, segments)
 *             new_segments = list(segments)             # <<<<<<<<<<<<<<
 *             new_segments = merge_segments(new_segments + self._segments)
 *             self._set_segments(new_segments)
 */
    __pyx_t_3 = PySequence_List(__pyx_v_segments); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2191, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_new_segments = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":2192
 *             check_segments(self, segments)
 *             new_segments = list(segments)
 *             new_segments = merge_segments(new_segments + self._segments)             # <<<<<<<<<<<<<<
 *             self._set_segments(new_segments)
 * 
 */
    __pyx_t_3 = PyNumber_Add(__pyx_v_new_segments, __pyx_v_self->_segments); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2192, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __pyx_f_7plastid_8genomics_8roitools_merge_segments(((PyObject*)__pyx_t_3), 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2192, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_new_segments, ((PyObject*)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":2193
 *             new_segments = list(segments)
 *             new_segments = merge_segments(new_segments + self._segments)
 *             self._set_segments(new_segments)             # <<<<<<<<<<<<<<
 * 
 *         return True
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_set_segments(__pyx_v_self, __pyx_v_new_segments); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(0, 2193, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":2189
 *             list new_segments
 * 
 *         if length > 0:             # <<<<<<<<<<<<<<
 *             check_segments(self, segments)
 *             new_segments = list(segments)
 */
  }

  /* "plastid/genomics/roitools.pyx":2195
 *             self._set_segments(new_segments)
 * 
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     def add_segments(self, *segments):
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2175
 *         return gene
 * 
 *     cdef bint c_add_segments(self, tuple segments) except False:             # <<<<<<<<<<<<<<
 *         """Add |GenomicSegments| to `self`. If there are
 *         already segments in the chain, the incoming segments must be
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_add_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_new_segments);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2197
 *         return True
 * 
 *     def add_segments(self, *segments):             # <<<<<<<<<<<<<<
 *         """Add 1 or more |GenomicSegments| to the |SegmentChain|. If there are
 *         already segments in the chain, the incoming segments must be
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_57add_segments(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_56add_segments[] = "SegmentChain.add_segments(self, *segments)\nAdd 1 or more |GenomicSegments| to the |SegmentChain|. If there are\n        already segments in the chain, the incoming segments must be\n        on the same strand and chromosome as all others present.\n\n        Parameters\n        ----------\n        segments : |GenomicSegment|\n            One or more |GenomicSegment| to add to |SegmentChain|\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_57add_segments(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_segments = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("add_segments (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "add_segments", 0))) return NULL;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_segments = __pyx_args;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_56add_segments(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_segments);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_56add_segments(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_segments) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add_segments", 0);

  /* "plastid/genomics/roitools.pyx":2207
 *             One or more |GenomicSegment| to add to |SegmentChain|
 *         """
 *         if len(segments) > 0:             # <<<<<<<<<<<<<<
 *             if self._mask_segments is not None and len(self._mask_segments) > 0:
 *                 warn("Segmentchain: adding segments to %s will reset its masks!" % (self),UserWarning)
 */
  __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_segments); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2207, __pyx_L1_error)
  __pyx_t_2 = ((__pyx_t_1 > 0) != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":2208
 *         """
 *         if len(segments) > 0:
 *             if self._mask_segments is not None and len(self._mask_segments) > 0:             # <<<<<<<<<<<<<<
 *                 warn("Segmentchain: adding segments to %s will reset its masks!" % (self),UserWarning)
 * 
 */
    __pyx_t_3 = (__pyx_v_self->_mask_segments != ((PyObject*)Py_None));
    __pyx_t_4 = (__pyx_t_3 != 0);
    if (__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L5_bool_binop_done;
    }
    __pyx_t_5 = __pyx_v_self->_mask_segments;
    __Pyx_INCREF(__pyx_t_5);
    if (unlikely(__pyx_t_5 == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 2208, __pyx_L1_error)
    }
    __pyx_t_1 = PyList_GET_SIZE(__pyx_t_5); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2208, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_4 = ((__pyx_t_1 > 0) != 0);
    __pyx_t_2 = __pyx_t_4;
    __pyx_L5_bool_binop_done:;
    if (__pyx_t_2) {

      /* "plastid/genomics/roitools.pyx":2209
 *         if len(segments) > 0:
 *             if self._mask_segments is not None and len(self._mask_segments) > 0:
 *                 warn("Segmentchain: adding segments to %s will reset its masks!" % (self),UserWarning)             # <<<<<<<<<<<<<<
 * 
 *             self.c_add_segments(segments)
 */
      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_warn); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2209, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PyUnicode_Format(__pyx_kp_u_Segmentchain_adding_segments_to, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2209, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
          __pyx_t_9 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_7, __pyx_builtin_UserWarning};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2209, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_7, __pyx_builtin_UserWarning};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2209, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else
      #endif
      {
        __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2209, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        if (__pyx_t_8) {
          __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_7);
        __Pyx_INCREF(__pyx_builtin_UserWarning);
        __Pyx_GIVEREF(__pyx_builtin_UserWarning);
        PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_builtin_UserWarning);
        __pyx_t_7 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_10, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2209, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "plastid/genomics/roitools.pyx":2208
 *         """
 *         if len(segments) > 0:
 *             if self._mask_segments is not None and len(self._mask_segments) > 0:             # <<<<<<<<<<<<<<
 *                 warn("Segmentchain: adding segments to %s will reset its masks!" % (self),UserWarning)
 * 
 */
    }

    /* "plastid/genomics/roitools.pyx":2211
 *                 warn("Segmentchain: adding segments to %s will reset its masks!" % (self),UserWarning)
 * 
 *             self.c_add_segments(segments)             # <<<<<<<<<<<<<<
 * 
 *     def add_masks(self, *mask_segments):
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_add_segments(__pyx_v_self, __pyx_v_segments); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(0, 2211, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":2207
 *             One or more |GenomicSegment| to add to |SegmentChain|
 *         """
 *         if len(segments) > 0:             # <<<<<<<<<<<<<<
 *             if self._mask_segments is not None and len(self._mask_segments) > 0:
 *                 warn("Segmentchain: adding segments to %s will reset its masks!" % (self),UserWarning)
 */
  }

  /* "plastid/genomics/roitools.pyx":2197
 *         return True
 * 
 *     def add_segments(self, *segments):             # <<<<<<<<<<<<<<
 *         """Add 1 or more |GenomicSegments| to the |SegmentChain|. If there are
 *         already segments in the chain, the incoming segments must be
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.add_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2213
 *             self.c_add_segments(segments)
 * 
 *     def add_masks(self, *mask_segments):             # <<<<<<<<<<<<<<
 *         """Adds one or more |GenomicSegment| to the collection of masks.  Masks
 *         will be trimmed to the positions of the |SegmentChain| during addition.
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_59add_masks(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_58add_masks[] = "SegmentChain.add_masks(self, *mask_segments)\nAdds one or more |GenomicSegment| to the collection of masks.  Masks\n        will be trimmed to the positions of the |SegmentChain| during addition.\n\n        Parameters\n        ----------\n        mask_segments : |GenomicSegment|\n            One or more segments, in genomic coordinates, covering positions to\n            exclude from return values of :meth:`get_masked_position_set`,\n            :meth:`get_masked_counts`, or :meth:`get_masked_length`\n\t\t\n        See also\n        --------\n        SegmentChain.get_masks\n        SegmentChain.get_masks_as_segmentchain\n        SegmentChain.reset_masks\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_59add_masks(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_mask_segments = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("add_masks (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "add_masks", 0))) return NULL;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_mask_segments = __pyx_args;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_58add_masks(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_mask_segments);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_58add_masks(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_mask_segments) {
  PyObject *__pyx_v_my_chrom = 0;
  PyObject *__pyx_v_my_strand = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_segment = 0;
  PyObject *__pyx_v_positions = 0;
  PyObject *__pyx_v_new_segments = 0;
  PyObject *__pyx_v_segs = 0;
  PyObject *__pyx_v_seg = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add_masks", 0);

  /* "plastid/genomics/roitools.pyx":2233
 *             str my_chrom, my_strand
 *             GenomicSegment segment
 *             set positions = set()             # <<<<<<<<<<<<<<
 *             list new_segments, segs
 * 
 */
  __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2233, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_positions = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2236
 *             list new_segments, segs
 * 
 *         if len(mask_segments) > 0:             # <<<<<<<<<<<<<<
 *             check_segments(self, mask_segments)
 *             seg  = mask_segments[0]
 */
  __pyx_t_2 = PyTuple_GET_SIZE(__pyx_v_mask_segments); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2236, __pyx_L1_error)
  __pyx_t_3 = ((__pyx_t_2 > 0) != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":2237
 * 
 *         if len(mask_segments) > 0:
 *             check_segments(self, mask_segments)             # <<<<<<<<<<<<<<
 *             seg  = mask_segments[0]
 *             my_chrom  = seg.chrom
 */
    __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_check_segments(__pyx_v_self, __pyx_v_mask_segments); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 2237, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":2238
 *         if len(mask_segments) > 0:
 *             check_segments(self, mask_segments)
 *             seg  = mask_segments[0]             # <<<<<<<<<<<<<<
 *             my_chrom  = seg.chrom
 *             my_strand = seg.strand
 */
    __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_mask_segments, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2238, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_seg = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":2239
 *             check_segments(self, mask_segments)
 *             seg  = mask_segments[0]
 *             my_chrom  = seg.chrom             # <<<<<<<<<<<<<<
 *             my_strand = seg.strand
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_seg, __pyx_n_s_chrom); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2239, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 2239, __pyx_L1_error)
    __pyx_v_my_chrom = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":2240
 *             seg  = mask_segments[0]
 *             my_chrom  = seg.chrom
 *             my_strand = seg.strand             # <<<<<<<<<<<<<<
 * 
 *             segs = list(mask_segments)
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_seg, __pyx_n_s_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 2240, __pyx_L1_error)
    __pyx_v_my_strand = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":2242
 *             my_strand = seg.strand
 * 
 *             segs = list(mask_segments)             # <<<<<<<<<<<<<<
 *             if self._mask_segments is not None:
 *                 segs += self._mask_segments
 */
    __pyx_t_1 = PySequence_List(__pyx_v_mask_segments); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2242, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_segs = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":2243
 * 
 *             segs = list(mask_segments)
 *             if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *                 segs += self._mask_segments
 * 
 */
    __pyx_t_3 = (__pyx_v_self->_mask_segments != ((PyObject*)Py_None));
    __pyx_t_4 = (__pyx_t_3 != 0);
    if (__pyx_t_4) {

      /* "plastid/genomics/roitools.pyx":2244
 *             segs = list(mask_segments)
 *             if self._mask_segments is not None:
 *                 segs += self._mask_segments             # <<<<<<<<<<<<<<
 * 
 *             # TODO: optimize this- could be way faster
 */
      __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_segs, __pyx_v_self->_mask_segments); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2244, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF_SET(__pyx_v_segs, ((PyObject*)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":2243
 * 
 *             segs = list(mask_segments)
 *             if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *                 segs += self._mask_segments
 * 
 */
    }

    /* "plastid/genomics/roitools.pyx":2248
 *             # TODO: optimize this- could be way faster
 *             # add new positions to any existing masks
 *             for segment in segs:             # <<<<<<<<<<<<<<
 *                 positions |= set(range(segment.start, segment.end))
 * 
 */
    __pyx_t_1 = __pyx_v_segs; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    for (;;) {
      if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2248, __pyx_L1_error)
      #else
      __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2248, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 2248, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_segment, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "plastid/genomics/roitools.pyx":2249
 *             # add new positions to any existing masks
 *             for segment in segs:
 *                 positions |= set(range(segment.start, segment.end))             # <<<<<<<<<<<<<<
 * 
 *             # trim away non-overlapping masks
 */
      __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_segment->start); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2249, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_segment->end); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2249, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2249, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
      __pyx_t_5 = 0;
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2249, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PySet_New(__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2249, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyNumber_InPlaceOr(__pyx_v_positions, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2249, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF_SET(__pyx_v_positions, ((PyObject*)__pyx_t_6));
      __pyx_t_6 = 0;

      /* "plastid/genomics/roitools.pyx":2248
 *             # TODO: optimize this- could be way faster
 *             # add new positions to any existing masks
 *             for segment in segs:             # <<<<<<<<<<<<<<
 *                 positions |= set(range(segment.start, segment.end))
 * 
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":2252
 * 
 *             # trim away non-overlapping masks
 *             positions &= self.c_get_position_set()             # <<<<<<<<<<<<<<
 * 
 *             # regenerate list of segments from positions, in case some were doubly-listed
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_get_position_set(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = PyNumber_InPlaceAnd(__pyx_v_positions, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_positions, ((PyObject*)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":2255
 * 
 *             # regenerate list of segments from positions, in case some were doubly-listed
 *             new_segments = positions_to_segments(my_chrom, my_strand, positions)             # <<<<<<<<<<<<<<
 *             self._set_masks(new_segments)
 * 
 */
    __pyx_t_6 = __pyx_f_7plastid_8genomics_8roitools_positions_to_segments(__pyx_v_my_chrom, __pyx_v_my_strand, __pyx_v_positions, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2255, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_v_new_segments = ((PyObject*)__pyx_t_6);
    __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":2256
 *             # regenerate list of segments from positions, in case some were doubly-listed
 *             new_segments = positions_to_segments(my_chrom, my_strand, positions)
 *             self._set_masks(new_segments)             # <<<<<<<<<<<<<<
 * 
 *     cdef bint _set_masks(self, list segments) except False:
 */
    __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_set_masks(__pyx_v_self, __pyx_v_new_segments); if (unlikely(__pyx_t_4 == ((int)0))) __PYX_ERR(0, 2256, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":2236
 *             list new_segments, segs
 * 
 *         if len(mask_segments) > 0:             # <<<<<<<<<<<<<<
 *             check_segments(self, mask_segments)
 *             seg  = mask_segments[0]
 */
  }

  /* "plastid/genomics/roitools.pyx":2213
 *             self.c_add_segments(segments)
 * 
 *     def add_masks(self, *mask_segments):             # <<<<<<<<<<<<<<
 *         """Adds one or more |GenomicSegment| to the collection of masks.  Masks
 *         will be trimmed to the positions of the |SegmentChain| during addition.
 */

  /* 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_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.add_masks", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_my_chrom);
  __Pyx_XDECREF(__pyx_v_my_strand);
  __Pyx_XDECREF((PyObject *)__pyx_v_segment);
  __Pyx_XDECREF(__pyx_v_positions);
  __Pyx_XDECREF(__pyx_v_new_segments);
  __Pyx_XDECREF(__pyx_v_segs);
  __Pyx_XDECREF(__pyx_v_seg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2258
 *             self._set_masks(new_segments)
 * 
 *     cdef bint _set_masks(self, list segments) except False:             # <<<<<<<<<<<<<<
 *         """Set `self._mask_segments` and update mask hashes, assuming `segments`
 *         have passed the following criteria:
 */

static int __pyx_f_7plastid_8genomics_8roitools_12SegmentChain__set_masks(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_segments) {
  arrayobject *__pyx_v_pmask = 0;
  __Pyx_memviewslice __pyx_v_pview = { 0, 0, { 0 }, { 0 }, { 0 } };
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_seg = 0;
  long __pyx_v_i;
  long __pyx_v_coord;
  int __pyx_v_tmpsum;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_memviewslice __pyx_t_3 = { 0, 0, { 0 }, { 0 }, { 0 } };
  Py_ssize_t __pyx_t_4;
  long __pyx_t_5;
  long __pyx_t_6;
  long __pyx_t_7;
  long __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_set_masks", 0);

  /* "plastid/genomics/roitools.pyx":2283
 *         """
 *         cdef:
 *             array.array pmask = array.clone(mask_template, self.length, True)             # <<<<<<<<<<<<<<
 *             int [:] pview = pmask
 *             list new_segments
 */
  if (!(likely(((__pyx_v_7plastid_8genomics_8roitools_mask_template) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_7plastid_8genomics_8roitools_mask_template, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 2283, __pyx_L1_error)
  __pyx_t_1 = __pyx_v_7plastid_8genomics_8roitools_mask_template;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_5array_clone(((arrayobject *)__pyx_t_1), __pyx_v_self->length, 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2283, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_pmask = ((arrayobject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":2284
 *         cdef:
 *             array.array pmask = array.clone(mask_template, self.length, True)
 *             int [:] pview = pmask             # <<<<<<<<<<<<<<
 *             list new_segments
 *             GenomicSegment seg
 */
  __pyx_t_3 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(((PyObject *)__pyx_v_pmask), PyBUF_WRITABLE); if (unlikely(!__pyx_t_3.memview)) __PYX_ERR(0, 2284, __pyx_L1_error)
  __pyx_v_pview = __pyx_t_3;
  __pyx_t_3.memview = NULL;
  __pyx_t_3.data = NULL;

  /* "plastid/genomics/roitools.pyx":2288
 *             GenomicSegment seg
 *             long i, coord
 *             int tmpsum = 0             # <<<<<<<<<<<<<<
 * 
 *         pview [:] = 0
 */
  __pyx_v_tmpsum = 0;

  /* "plastid/genomics/roitools.pyx":2290
 *             int tmpsum = 0
 * 
 *         pview [:] = 0             # <<<<<<<<<<<<<<
 *         for seg in segments:
 *             for i in range(seg.start, seg.end):
 */
  {
      int __pyx_temp_scalar = 0;
      {
          Py_ssize_t __pyx_temp_extent_0 = __pyx_v_pview.shape[0];
          Py_ssize_t __pyx_temp_stride_0 = __pyx_v_pview.strides[0];
          char *__pyx_temp_pointer_0;
          Py_ssize_t __pyx_temp_idx_0;
          __pyx_temp_pointer_0 = __pyx_v_pview.data;
          for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
            *((int *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
            __pyx_temp_pointer_0 += __pyx_temp_stride_0;
          }
      }
  }

  /* "plastid/genomics/roitools.pyx":2291
 * 
 *         pview [:] = 0
 *         for seg in segments:             # <<<<<<<<<<<<<<
 *             for i in range(seg.start, seg.end):
 *                 coord = self.c_get_segmentchain_coordinate(i, False)
 */
  if (unlikely(__pyx_v_segments == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 2291, __pyx_L1_error)
  }
  __pyx_t_2 = __pyx_v_segments; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
  for (;;) {
    if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2291, __pyx_L1_error)
    #else
    __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2291, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    #endif
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 2291, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_seg, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":2292
 *         pview [:] = 0
 *         for seg in segments:
 *             for i in range(seg.start, seg.end):             # <<<<<<<<<<<<<<
 *                 coord = self.c_get_segmentchain_coordinate(i, False)
 *                 pview[coord] = 1
 */
    __pyx_t_5 = __pyx_v_seg->end;
    __pyx_t_6 = __pyx_t_5;
    for (__pyx_t_7 = __pyx_v_seg->start; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
      __pyx_v_i = __pyx_t_7;

      /* "plastid/genomics/roitools.pyx":2293
 *         for seg in segments:
 *             for i in range(seg.start, seg.end):
 *                 coord = self.c_get_segmentchain_coordinate(i, False)             # <<<<<<<<<<<<<<
 *                 pview[coord] = 1
 *                 tmpsum += 1
 */
      __pyx_t_8 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_get_segmentchain_coordinate(__pyx_v_self, __pyx_v_i, 0); if (unlikely(__pyx_t_8 == ((long)-1L))) __PYX_ERR(0, 2293, __pyx_L1_error)
      __pyx_v_coord = __pyx_t_8;

      /* "plastid/genomics/roitools.pyx":2294
 *             for i in range(seg.start, seg.end):
 *                 coord = self.c_get_segmentchain_coordinate(i, False)
 *                 pview[coord] = 1             # <<<<<<<<<<<<<<
 *                 tmpsum += 1
 * 
 */
      __pyx_t_9 = __pyx_v_coord;
      __pyx_t_10 = -1;
      if (__pyx_t_9 < 0) {
        __pyx_t_9 += __pyx_v_pview.shape[0];
        if (unlikely(__pyx_t_9 < 0)) __pyx_t_10 = 0;
      } else if (unlikely(__pyx_t_9 >= __pyx_v_pview.shape[0])) __pyx_t_10 = 0;
      if (unlikely(__pyx_t_10 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_10);
        __PYX_ERR(0, 2294, __pyx_L1_error)
      }
      *((int *) ( /* dim=0 */ (__pyx_v_pview.data + __pyx_t_9 * __pyx_v_pview.strides[0]) )) = 1;

      /* "plastid/genomics/roitools.pyx":2295
 *                 coord = self.c_get_segmentchain_coordinate(i, False)
 *                 pview[coord] = 1
 *                 tmpsum += 1             # <<<<<<<<<<<<<<
 * 
 *         self._mask_segments = segments
 */
      __pyx_v_tmpsum = (__pyx_v_tmpsum + 1);
    }

    /* "plastid/genomics/roitools.pyx":2291
 * 
 *         pview [:] = 0
 *         for seg in segments:             # <<<<<<<<<<<<<<
 *             for i in range(seg.start, seg.end):
 *                 coord = self.c_get_segmentchain_coordinate(i, False)
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":2297
 *                 tmpsum += 1
 * 
 *         self._mask_segments = segments             # <<<<<<<<<<<<<<
 *         self.masked_length = self.length - tmpsum
 *         self._position_mask = pmask
 */
  __Pyx_INCREF(__pyx_v_segments);
  __Pyx_GIVEREF(__pyx_v_segments);
  __Pyx_GOTREF(__pyx_v_self->_mask_segments);
  __Pyx_DECREF(__pyx_v_self->_mask_segments);
  __pyx_v_self->_mask_segments = __pyx_v_segments;

  /* "plastid/genomics/roitools.pyx":2298
 * 
 *         self._mask_segments = segments
 *         self.masked_length = self.length - tmpsum             # <<<<<<<<<<<<<<
 *         self._position_mask = pmask
 * 
 */
  __pyx_v_self->masked_length = (__pyx_v_self->length - __pyx_v_tmpsum);

  /* "plastid/genomics/roitools.pyx":2299
 *         self._mask_segments = segments
 *         self.masked_length = self.length - tmpsum
 *         self._position_mask = pmask             # <<<<<<<<<<<<<<
 * 
 *         return True
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_pmask));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_pmask));
  __Pyx_GOTREF(__pyx_v_self->_position_mask);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->_position_mask));
  __pyx_v_self->_position_mask = __pyx_v_pmask;

  /* "plastid/genomics/roitools.pyx":2301
 *         self._position_mask = pmask
 * 
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     def get_masks(self):
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2258
 *             self._set_masks(new_segments)
 * 
 *     cdef bint _set_masks(self, list segments) except False:             # <<<<<<<<<<<<<<
 *         """Set `self._mask_segments` and update mask hashes, assuming `segments`
 *         have passed the following criteria:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __PYX_XDEC_MEMVIEW(&__pyx_t_3, 1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain._set_masks", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_pmask);
  __PYX_XDEC_MEMVIEW(&__pyx_v_pview, 1);
  __Pyx_XDECREF((PyObject *)__pyx_v_seg);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2303
 *         return True
 * 
 *     def get_masks(self):             # <<<<<<<<<<<<<<
 *         """Return masked positions as a list of |GenomicSegments|
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_61get_masks(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_60get_masks[] = "SegmentChain.get_masks(self)\nReturn masked positions as a list of |GenomicSegments|\n\n        Returns\n        -------\n        list\n            list of |GenomicSegments| representing masked positions\n\n        See also\n        --------\n        SegmentChain.get_masks_as_segmentchain\n\n        SegmentChain.add_masks\n\n        SegmentChain.reset_masks\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_61get_masks(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_masks (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_60get_masks(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_60get_masks(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__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_RefNannySetupContext("get_masks", 0);

  /* "plastid/genomics/roitools.pyx":2319
 *         SegmentChain.reset_masks
 *         """
 *         warn(             # <<<<<<<<<<<<<<
 *             "SegmentChain.get_masks() is deprecated and will soon be removed "
 *             "from `plastid`. Use SegmentChain.mask_segments instead"
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_warn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2319, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_kp_u_SegmentChain_get_masks_is_deprec) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_u_SegmentChain_get_masks_is_deprec);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2319, __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;

  /* "plastid/genomics/roitools.pyx":2323
 *             "from `plastid`. Use SegmentChain.mask_segments instead"
 *         )
 *         if self._mask_segments is None:             # <<<<<<<<<<<<<<
 *             return []
 * 
 */
  __pyx_t_4 = (__pyx_v_self->_mask_segments == ((PyObject*)Py_None));
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "plastid/genomics/roitools.pyx":2324
 *         )
 *         if self._mask_segments is None:
 *             return []             # <<<<<<<<<<<<<<
 * 
 *         return self._mask_segments
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":2323
 *             "from `plastid`. Use SegmentChain.mask_segments instead"
 *         )
 *         if self._mask_segments is None:             # <<<<<<<<<<<<<<
 *             return []
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":2326
 *             return []
 * 
 *         return self._mask_segments             # <<<<<<<<<<<<<<
 * 
 *     def get_masks_as_segmentchain(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_mask_segments);
  __pyx_r = __pyx_v_self->_mask_segments;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2303
 *         return True
 * 
 *     def get_masks(self):             # <<<<<<<<<<<<<<
 *         """Return masked positions as a list of |GenomicSegments|
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_masks", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2328
 *         return self._mask_segments
 * 
 *     def get_masks_as_segmentchain(self):             # <<<<<<<<<<<<<<
 *         """Return masked positions as a |SegmentChain|
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_63get_masks_as_segmentchain(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_62get_masks_as_segmentchain[] = "SegmentChain.get_masks_as_segmentchain(self)\nReturn masked positions as a |SegmentChain|\n\n        Returns\n        -------\n        |SegmentChain|\n            Masked positions\n\n        See also\n        --------\n        SegmentChain.get_masks\n\n        SegmentChain.add_masks\n\n        SegmentChain.reset_masks\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_63get_masks_as_segmentchain(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_masks_as_segmentchain (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_62get_masks_as_segmentchain(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_62get_masks_as_segmentchain(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_masks_as_segmentchain", 0);

  /* "plastid/genomics/roitools.pyx":2344
 *         SegmentChain.reset_masks
 *         """
 *         if self._mask_segments is None:             # <<<<<<<<<<<<<<
 *             return SegmentChain()
 * 
 */
  __pyx_t_1 = (__pyx_v_self->_mask_segments == ((PyObject*)Py_None));
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":2345
 *         """
 *         if self._mask_segments is None:
 *             return SegmentChain()             # <<<<<<<<<<<<<<
 * 
 *         return SegmentChain(*self._mask_segments)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2345, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":2344
 *         SegmentChain.reset_masks
 *         """
 *         if self._mask_segments is None:             # <<<<<<<<<<<<<<
 *             return SegmentChain()
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":2347
 *             return SegmentChain()
 * 
 *         return SegmentChain(*self._mask_segments)             # <<<<<<<<<<<<<<
 * 
 *     cdef void c_reset_masks(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PySequence_Tuple(__pyx_v_self->_mask_segments); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2347, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2347, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2328
 *         return self._mask_segments
 * 
 *     def get_masks_as_segmentchain(self):             # <<<<<<<<<<<<<<
 *         """Return masked positions as a |SegmentChain|
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_masks_as_segmentchain", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2349
 *         return SegmentChain(*self._mask_segments)
 * 
 *     cdef void c_reset_masks(self):             # <<<<<<<<<<<<<<
 *         """Resets all masks and hashes that depend on them to empty values
 *         """
 */

static void __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_reset_masks(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  long __pyx_t_3;
  __Pyx_RefNannySetupContext("c_reset_masks", 0);

  /* "plastid/genomics/roitools.pyx":2352
 *         """Resets all masks and hashes that depend on them to empty values
 *         """
 *         if self._mask_segments is None:             # <<<<<<<<<<<<<<
 *             pass
 * 
 */
  __pyx_t_1 = (__pyx_v_self->_mask_segments == ((PyObject*)Py_None));
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {
  }

  /* "plastid/genomics/roitools.pyx":2355
 *             pass
 * 
 *         self._position_mask = None             # <<<<<<<<<<<<<<
 *         self._mask_segments = None
 *         self.masked_length = self.length
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_position_mask);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->_position_mask));
  __pyx_v_self->_position_mask = ((arrayobject *)Py_None);

  /* "plastid/genomics/roitools.pyx":2356
 * 
 *         self._position_mask = None
 *         self._mask_segments = None             # <<<<<<<<<<<<<<
 *         self.masked_length = self.length
 * 
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_mask_segments);
  __Pyx_DECREF(__pyx_v_self->_mask_segments);
  __pyx_v_self->_mask_segments = ((PyObject*)Py_None);

  /* "plastid/genomics/roitools.pyx":2357
 *         self._position_mask = None
 *         self._mask_segments = None
 *         self.masked_length = self.length             # <<<<<<<<<<<<<<
 * 
 *     def reset_masks(self):
 */
  __pyx_t_3 = __pyx_v_self->length;
  __pyx_v_self->masked_length = __pyx_t_3;

  /* "plastid/genomics/roitools.pyx":2349
 *         return SegmentChain(*self._mask_segments)
 * 
 *     cdef void c_reset_masks(self):             # <<<<<<<<<<<<<<
 *         """Resets all masks and hashes that depend on them to empty values
 *         """
 */

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

/* "plastid/genomics/roitools.pyx":2359
 *         self.masked_length = self.length
 * 
 *     def reset_masks(self):             # <<<<<<<<<<<<<<
 *         """Removes masks added by :py:meth:`add_masks`
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_65reset_masks(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_64reset_masks[] = "SegmentChain.reset_masks(self)\nRemoves masks added by :py:meth:`add_masks`\n\n        See also\n        --------\n        SegmentChain.add_masks\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_65reset_masks(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("reset_masks (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_64reset_masks(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_64reset_masks(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("reset_masks", 0);

  /* "plastid/genomics/roitools.pyx":2366
 *         SegmentChain.add_masks
 *         """
 *         self.c_reset_masks()             # <<<<<<<<<<<<<<
 * 
 *     def get_junctions(self):
 */
  ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_reset_masks(__pyx_v_self);

  /* "plastid/genomics/roitools.pyx":2359
 *         self.masked_length = self.length
 * 
 *     def reset_masks(self):             # <<<<<<<<<<<<<<
 *         """Removes masks added by :py:meth:`add_masks`
 * 
 */

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

/* "plastid/genomics/roitools.pyx":2368
 *         self.c_reset_masks()
 * 
 *     def get_junctions(self):             # <<<<<<<<<<<<<<
 *         """Returns a list of |GenomicSegments| representing spaces between the
 *         |GenomicSegments| in `self` In the case of a transcript, these would
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_67get_junctions(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_66get_junctions[] = "SegmentChain.get_junctions(self)\nReturns a list of |GenomicSegments| representing spaces between the\n        |GenomicSegments| in `self` In the case of a transcript, these would\n        represent introns. In the case of an alignment, these would represent\n        gaps in the query compared to the reference.\n\n        Returns\n        -------\n        list\n            List of |GenomicSegments| covering spaces between the intervals in\n            `self` (e.g. introns in the case of a transcript, or gaps in the\n            case of an alignment)\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_67get_junctions(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_junctions (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_66get_junctions(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_66get_junctions(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_seg1 = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_seg2 = 0;
  PyObject *__pyx_v_juncs = 0;
  CYTHON_UNUSED struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_span = 0;
  PyObject *__pyx_v_strand = 0;
  PyObject *__pyx_v_chrom = 0;
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  long __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_junctions", 0);

  /* "plastid/genomics/roitools.pyx":2383
 *         cdef:
 *             GenomicSegment seg1, seg2
 *             list juncs = []             # <<<<<<<<<<<<<<
 *             GenomicSegment span = self.spanning_segment
 *             str strand = self.strand
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2383, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_juncs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2384
 *             GenomicSegment seg1, seg2
 *             list juncs = []
 *             GenomicSegment span = self.spanning_segment             # <<<<<<<<<<<<<<
 *             str strand = self.strand
 *             str chrom = self.chrom
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_span = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2385
 *             list juncs = []
 *             GenomicSegment span = self.spanning_segment
 *             str strand = self.strand             # <<<<<<<<<<<<<<
 *             str chrom = self.chrom
 *             int i
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 2385, __pyx_L1_error)
  __pyx_v_strand = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2386
 *             GenomicSegment span = self.spanning_segment
 *             str strand = self.strand
 *             str chrom = self.chrom             # <<<<<<<<<<<<<<
 *             int i
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_chrom); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 2386, __pyx_L1_error)
  __pyx_v_chrom = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2389
 *             int i
 * 
 *         for i in range(len(self._segments) - 1):             # <<<<<<<<<<<<<<
 *             seg1, seg2 = self._segments[i], self._segments[i+1]
 *             juncs.append(
 */
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  if (unlikely(__pyx_t_1 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 2389, __pyx_L1_error)
  }
  __pyx_t_2 = PyList_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2389, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 - 1);
  __pyx_t_2 = __pyx_t_3;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_2; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;

    /* "plastid/genomics/roitools.pyx":2390
 * 
 *         for i in range(len(self._segments) - 1):
 *             seg1, seg2 = self._segments[i], self._segments[i+1]             # <<<<<<<<<<<<<<
 *             juncs.append(
 *                 GenomicSegment(chrom, seg1.end, seg2.start, strand)
 */
    if (unlikely(__pyx_v_self->_segments == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 2390, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_self->_segments, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2390, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 2390, __pyx_L1_error)
    if (unlikely(__pyx_v_self->_segments == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 2390, __pyx_L1_error)
    }
    __pyx_t_5 = (__pyx_v_i + 1);
    __pyx_t_6 = __Pyx_GetItemInt_List(__pyx_v_self->_segments, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2390, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 2390, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_seg1, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1));
    __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_seg2, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":2392
 *             seg1, seg2 = self._segments[i], self._segments[i+1]
 *             juncs.append(
 *                 GenomicSegment(chrom, seg1.end, seg2.start, strand)             # <<<<<<<<<<<<<<
 *             )
 *         return juncs
 */
    __pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_seg1->end); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2392, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_seg2->start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2392, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2392, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_v_chrom);
    __Pyx_GIVEREF(__pyx_v_chrom);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_chrom);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_1);
    __Pyx_INCREF(__pyx_v_strand);
    __Pyx_GIVEREF(__pyx_v_strand);
    PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_v_strand);
    __pyx_t_6 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2392, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":2391
 *         for i in range(len(self._segments) - 1):
 *             seg1, seg2 = self._segments[i], self._segments[i+1]
 *             juncs.append(             # <<<<<<<<<<<<<<
 *                 GenomicSegment(chrom, seg1.end, seg2.start, strand)
 *             )
 */
    __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_juncs, __pyx_t_1); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 2391, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "plastid/genomics/roitools.pyx":2394
 *                 GenomicSegment(chrom, seg1.end, seg2.start, strand)
 *             )
 *         return juncs             # <<<<<<<<<<<<<<
 * 
 *     # TODO: test optimality
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_juncs);
  __pyx_r = __pyx_v_juncs;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2368
 *         self.c_reset_masks()
 * 
 *     def get_junctions(self):             # <<<<<<<<<<<<<<
 *         """Returns a list of |GenomicSegments| representing spaces between the
 *         |GenomicSegments| in `self` In the case of a transcript, these would
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_junctions", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_seg1);
  __Pyx_XDECREF((PyObject *)__pyx_v_seg2);
  __Pyx_XDECREF(__pyx_v_juncs);
  __Pyx_XDECREF((PyObject *)__pyx_v_span);
  __Pyx_XDECREF(__pyx_v_strand);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2397
 * 
 *     # TODO: test optimality
 *     def as_gff3(self, str feature_type=None, bint escape=True, list excludes=None):             # <<<<<<<<<<<<<<
 *         """Format `self` as a line of `GFF3`_ output.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_69as_gff3(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_68as_gff3[] = "SegmentChain.as_gff3(self, unicode feature_type=None, bool escape=True, list excludes=None)\nFormat `self` as a line of `GFF3`_ output.\n\n        Because `GFF3`_ files permit many schemas of parent-child hierarchy,\n        and in order to reduce confusion and overhead, attempts to export\n        a multi-interval |SegmentChain| will raise an AttributeError.\n\n        Instead, users may export the individual features from which the\n        multi-interval |SegmentChain| was constructed, or construct features\n        for them, setting *ID*, *Parent*, and *type* attributes following\n        their own conventions.\n\n\n        Parameters\n        ----------\n        feature_type : str\n            If not None, overrides the `type` attribute of `self.attr`\n\n        escape : bool, optional\n            Escape tokens in column 9 of `GFF3`_ output (Default: `True`)\n\n        excludes : list, optional\n            List of attribute key names to exclude from column 9\n            (Default: `[]`)\n\n\n        Returns\n        -------\n        str\n            Line of `GFF3`_-formatted text\n\n\n        Raises\n        ------\n        AttributeError\n            if the |SegmentChain| has multiple intervals\n\n        Notes\n        -----\n        Columns of `GFF3`_ are as follows\n            ======== =========\n            Column   Contains\n            ======== =========\n                1     Contig or chromosome\n                2     Source of annotation\n                3     Type of feature (\"exon\", \"CDS\", \"start_codon\", \"stop_codon\")\n                4     Start (1-indexed)\n                5     End (fully-closed)\n                6     Score\n                7     Strand\n                8     Frame. Number of bases within feature before first in-frame codon (if coding)\n                9     Attributes\n            ======== =========\n\n        For further information, see\n            - `GFF3 file format specification <http://www.sequenceontology.org""/gff3.shtml>`_\n            - `Sequence Ontology (SO) v2.53 <http://www.sequenceontology.org/browser/>`_\n            - `SO releases <http://sourceforge.net/projects/song/files/SO_Feature_Annotation/>`_\n            - `UCSC file format FAQ <http://genome.ucsc.edu/FAQ/FAQformat.html>`_\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_69as_gff3(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_feature_type = 0;
  CYTHON_UNUSED int __pyx_v_escape;
  PyObject *__pyx_v_excludes = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("as_gff3 (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_feature_type,&__pyx_n_s_escape,&__pyx_n_s_excludes,0};
    PyObject* values[3] = {0,0,0};
    values[0] = ((PyObject*)Py_None);
    values[2] = ((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  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_feature_type);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_escape);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_excludes);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "as_gff3") < 0)) __PYX_ERR(0, 2397, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_feature_type = ((PyObject*)values[0]);
    if (values[1]) {
      __pyx_v_escape = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_escape == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2397, __pyx_L3_error)
    } else {
      __pyx_v_escape = ((int)1);
    }
    __pyx_v_excludes = ((PyObject*)values[2]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("as_gff3", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2397, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_gff3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_feature_type), (&PyUnicode_Type), 1, "feature_type", 1))) __PYX_ERR(0, 2397, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_excludes), (&PyList_Type), 1, "excludes", 1))) __PYX_ERR(0, 2397, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_68as_gff3(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_feature_type, __pyx_v_escape, __pyx_v_excludes);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_68as_gff3(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_feature_type, CYTHON_UNUSED int __pyx_v_escape, PyObject *__pyx_v_excludes) {
  int __pyx_v_length;
  PyObject *__pyx_v_gff_attr = 0;
  PyObject *__pyx_v_always_excluded = 0;
  PyObject *__pyx_v_ltmp = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_segment = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("as_gff3", 0);
  __Pyx_INCREF(__pyx_v_feature_type);
  __Pyx_INCREF(__pyx_v_excludes);

  /* "plastid/genomics/roitools.pyx":2457
 *             - `UCSC file format FAQ <http://genome.ucsc.edu/FAQ/FAQformat.html>`_
 *         """
 *         cdef int length = len(self._segments)             # <<<<<<<<<<<<<<
 * 
 *         if length == 0: # empty SegmentChain
 */
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  if (unlikely(__pyx_t_1 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 2457, __pyx_L1_error)
  }
  __pyx_t_2 = PyList_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2457, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_length = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":2459
 *         cdef int length = len(self._segments)
 * 
 *         if length == 0: # empty SegmentChain             # <<<<<<<<<<<<<<
 *             return ""
 *         elif length > 1:
 */
  __pyx_t_3 = ((__pyx_v_length == 0) != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":2460
 * 
 *         if length == 0: # empty SegmentChain
 *             return ""             # <<<<<<<<<<<<<<
 *         elif length > 1:
 *             raise AttributeError("Attempted export of multi-interval %s" % self.__class__)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_kp_u__33);
    __pyx_r = __pyx_kp_u__33;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":2459
 *         cdef int length = len(self._segments)
 * 
 *         if length == 0: # empty SegmentChain             # <<<<<<<<<<<<<<
 *             return ""
 *         elif length > 1:
 */
  }

  /* "plastid/genomics/roitools.pyx":2461
 *         if length == 0: # empty SegmentChain
 *             return ""
 *         elif length > 1:             # <<<<<<<<<<<<<<
 *             raise AttributeError("Attempted export of multi-interval %s" % self.__class__)
 * 
 */
  __pyx_t_3 = ((__pyx_v_length > 1) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "plastid/genomics/roitools.pyx":2462
 *             return ""
 *         elif length > 1:
 *             raise AttributeError("Attempted export of multi-interval %s" % self.__class__)             # <<<<<<<<<<<<<<
 * 
 *         cdef:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2462, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_Attempted_export_of_multi_interv, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2462, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_AttributeError, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2462, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 2462, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":2461
 *         if length == 0: # empty SegmentChain
 *             return ""
 *         elif length > 1:             # <<<<<<<<<<<<<<
 *             raise AttributeError("Attempted export of multi-interval %s" % self.__class__)
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":2469
 *             GenomicSegment segment
 * 
 *         excludes = [] if excludes is None else excludes             # <<<<<<<<<<<<<<
 *         gff_attr = copy.deepcopy(self.attr)
 *         feature_type = self.attr["type"] if feature_type is None else feature_type
 */
  __pyx_t_3 = (__pyx_v_excludes == ((PyObject*)Py_None));
  if ((__pyx_t_3 != 0)) {
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2469, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __pyx_t_4;
    __pyx_t_4 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_excludes);
    __pyx_t_1 = __pyx_v_excludes;
  }
  __Pyx_DECREF_SET(__pyx_v_excludes, ((PyObject*)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2470
 * 
 *         excludes = [] if excludes is None else excludes
 *         gff_attr = copy.deepcopy(self.attr)             # <<<<<<<<<<<<<<
 *         feature_type = self.attr["type"] if feature_type is None else feature_type
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2470, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2470, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_v_self->attr) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_self->attr);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2470, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 2470, __pyx_L1_error)
  __pyx_v_gff_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2471
 *         excludes = [] if excludes is None else excludes
 *         gff_attr = copy.deepcopy(self.attr)
 *         feature_type = self.attr["type"] if feature_type is None else feature_type             # <<<<<<<<<<<<<<
 * 
 *         always_excluded = [
 */
  __pyx_t_3 = (__pyx_v_feature_type == ((PyObject*)Py_None));
  if ((__pyx_t_3 != 0)) {
    if (unlikely(__pyx_v_self->attr == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 2471, __pyx_L1_error)
    }
    __pyx_t_5 = __Pyx_PyDict_GetItem(__pyx_v_self->attr, __pyx_n_u_type); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2471, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (!(likely(PyUnicode_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 2471, __pyx_L1_error)
    __pyx_t_1 = __pyx_t_5;
    __pyx_t_5 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_feature_type);
    __pyx_t_1 = __pyx_v_feature_type;
  }
  __Pyx_DECREF_SET(__pyx_v_feature_type, ((PyObject*)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2473
 *         feature_type = self.attr["type"] if feature_type is None else feature_type
 * 
 *         always_excluded = [             # <<<<<<<<<<<<<<
 *             "source",
 *             "score",
 */
  __pyx_t_1 = PyList_New(9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2473, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_u_source);
  __Pyx_GIVEREF(__pyx_n_u_source);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_u_source);
  __Pyx_INCREF(__pyx_n_u_score);
  __Pyx_GIVEREF(__pyx_n_u_score);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_u_score);
  __Pyx_INCREF(__pyx_n_u_phase);
  __Pyx_GIVEREF(__pyx_n_u_phase);
  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_u_phase);
  __Pyx_INCREF(__pyx_n_u_cds_genome_start_2);
  __Pyx_GIVEREF(__pyx_n_u_cds_genome_start_2);
  PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_u_cds_genome_start_2);
  __Pyx_INCREF(__pyx_n_u_cds_genome_end_2);
  __Pyx_GIVEREF(__pyx_n_u_cds_genome_end_2);
  PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_u_cds_genome_end_2);
  __Pyx_INCREF(__pyx_n_u_thickstart);
  __Pyx_GIVEREF(__pyx_n_u_thickstart);
  PyList_SET_ITEM(__pyx_t_1, 5, __pyx_n_u_thickstart);
  __Pyx_INCREF(__pyx_n_u_thickend);
  __Pyx_GIVEREF(__pyx_n_u_thickend);
  PyList_SET_ITEM(__pyx_t_1, 6, __pyx_n_u_thickend);
  __Pyx_INCREF(__pyx_n_u_type);
  __Pyx_GIVEREF(__pyx_n_u_type);
  PyList_SET_ITEM(__pyx_t_1, 7, __pyx_n_u_type);
  __Pyx_INCREF(__pyx_n_u_bedx_column_order);
  __Pyx_GIVEREF(__pyx_n_u_bedx_column_order);
  PyList_SET_ITEM(__pyx_t_1, 8, __pyx_n_u_bedx_column_order);
  __pyx_v_always_excluded = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2485
 *         ]
 * 
 *         for segment in self._segments:             # <<<<<<<<<<<<<<
 *             ltmp = self._get_8_gff_columns(segment, feature_type) +\
 *                    [make_GFF3_tokens(
 */
  if (unlikely(__pyx_v_self->_segments == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 2485, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_v_self->_segments; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2485, __pyx_L1_error)
    #else
    __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2485, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    #endif
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 2485, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_segment, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_5));
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":2486
 * 
 *         for segment in self._segments:
 *             ltmp = self._get_8_gff_columns(segment, feature_type) +\             # <<<<<<<<<<<<<<
 *                    [make_GFF3_tokens(
 *                        gff_attr,
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_8_gff_columns); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2486, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = NULL;
    __pyx_t_7 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_7 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_segment), __pyx_v_feature_type};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2486, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_segment), __pyx_v_feature_type};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2486, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    {
      __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2486, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (__pyx_t_6) {
        __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_segment));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_segment));
      PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, ((PyObject *)__pyx_v_segment));
      __Pyx_INCREF(__pyx_v_feature_type);
      __Pyx_GIVEREF(__pyx_v_feature_type);
      PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_v_feature_type);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2486, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":2487
 *         for segment in self._segments:
 *             ltmp = self._get_8_gff_columns(segment, feature_type) +\
 *                    [make_GFF3_tokens(             # <<<<<<<<<<<<<<
 *                        gff_attr,
 *                        excludes=always_excluded + excludes,
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_make_GFF3_tokens); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2487, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "plastid/genomics/roitools.pyx":2488
 *             ltmp = self._get_8_gff_columns(segment, feature_type) +\
 *                    [make_GFF3_tokens(
 *                        gff_attr,             # <<<<<<<<<<<<<<
 *                        excludes=always_excluded + excludes,
 *                        escape=True
 */
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2487, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_INCREF(__pyx_v_gff_attr);
    __Pyx_GIVEREF(__pyx_v_gff_attr);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_gff_attr);

    /* "plastid/genomics/roitools.pyx":2489
 *                    [make_GFF3_tokens(
 *                        gff_attr,
 *                        excludes=always_excluded + excludes,             # <<<<<<<<<<<<<<
 *                        escape=True
 *                    )
 */
    __pyx_t_6 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2489, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = PyNumber_Add(__pyx_v_always_excluded, __pyx_v_excludes); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2489, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_excludes, __pyx_t_9) < 0) __PYX_ERR(0, 2489, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "plastid/genomics/roitools.pyx":2490
 *                        gff_attr,
 *                        excludes=always_excluded + excludes,
 *                        escape=True             # <<<<<<<<<<<<<<
 *                    )
 *                    ]
 */
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_escape, Py_True) < 0) __PYX_ERR(0, 2489, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":2487
 *         for segment in self._segments:
 *             ltmp = self._get_8_gff_columns(segment, feature_type) +\
 *                    [make_GFF3_tokens(             # <<<<<<<<<<<<<<
 *                        gff_attr,
 *                        excludes=always_excluded + excludes,
 */
    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, __pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2487, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyList_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2487, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_9);
    PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "plastid/genomics/roitools.pyx":2486
 * 
 *         for segment in self._segments:
 *             ltmp = self._get_8_gff_columns(segment, feature_type) +\             # <<<<<<<<<<<<<<
 *                    [make_GFF3_tokens(
 *                        gff_attr,
 */
    __pyx_t_9 = PyNumber_Add(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2486, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(PyList_CheckExact(__pyx_t_9))||((__pyx_t_9) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_9)->tp_name), 0))) __PYX_ERR(0, 2486, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_ltmp, ((PyObject*)__pyx_t_9));
    __pyx_t_9 = 0;

    /* "plastid/genomics/roitools.pyx":2485
 *         ]
 * 
 *         for segment in self._segments:             # <<<<<<<<<<<<<<
 *             ltmp = self._get_8_gff_columns(segment, feature_type) +\
 *                    [make_GFF3_tokens(
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2494
 *                    ]
 * 
 *         return "\t".join(ltmp) + "\n"             # <<<<<<<<<<<<<<
 * 
 *     # TODO: optimize
 */
  __Pyx_XDECREF(__pyx_r);
  if (unlikely(!__pyx_v_ltmp)) { __Pyx_RaiseUnboundLocalError("ltmp"); __PYX_ERR(0, 2494, __pyx_L1_error) }
  __pyx_t_1 = PyUnicode_Join(__pyx_kp_u__19, __pyx_v_ltmp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = __Pyx_PyUnicode_Concat(__pyx_t_1, __pyx_kp_u__18); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_9;
  __pyx_t_9 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2397
 * 
 *     # TODO: test optimality
 *     def as_gff3(self, str feature_type=None, bint escape=True, list excludes=None):             # <<<<<<<<<<<<<<
 *         """Format `self` as a line of `GFF3`_ output.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_gff3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_gff_attr);
  __Pyx_XDECREF(__pyx_v_always_excluded);
  __Pyx_XDECREF(__pyx_v_ltmp);
  __Pyx_XDECREF((PyObject *)__pyx_v_segment);
  __Pyx_XDECREF(__pyx_v_feature_type);
  __Pyx_XDECREF(__pyx_v_excludes);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2497
 * 
 *     # TODO: optimize
 *     def as_gtf(self, str feature_type=None, bint escape=True, list excludes=None):             # <<<<<<<<<<<<<<
 *         """Format |SegmentChain| as a block of `GTF2`_ output.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_71as_gtf(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_70as_gtf[] = "SegmentChain.as_gtf(self, unicode feature_type=None, bool escape=True, list excludes=None)\nFormat |SegmentChain| as a block of `GTF2`_ output.\n\n        The `frame` or `phase` attribute (`GTF2`_ column 8) is valid only for `'CDS'`\n        features, and, if not present in `self.attr`, is calculated assuming\n        the |SegmentChain| contains the entire coding region. If the |SegmentChain|\n        contains multiple intervals, the `frame` or `phase` attribute will\n        *always* be recalculated.\n\n        All attributes in `self.attr`, except those created upon import,\n        will be propagated to all of the features that are generated.\n\n        Parameters\n        ----------\n        feature_type : str\n            If not None, overrides the \"type\" attribute of ``self.attr``\n\n        escape : bool, optional\n            Escape tokens in column 9 of GTF output (Default: True)\n\n        excludes : list, optional\n            List of attribute key names to exclude from column 8\n            (Default: *[]*)\n\n        Returns\n        -------\n        str\n            Block of GTF2-formatted text\n\n\n        Notes\n        -----\n        `gene_id` and `transcript_id` are required\n            The `GTF2 specification <http://mblab.wustl.edu/GTF22.html>`_ requires\n            that attributes `gene_id` and `transcript_id` be defined. If these\n            are not present in `self.attr`, their values will be guessed\n            following the rules in :py:meth:`SegmentChain.get_gene` and\n            :py:meth:`SegmentChain.get_name`, respectively.\n\n        Beware of attribute loss\n            To save memory, only the attributes shared by all of the individual\n            sub-features (e.g. exons) that were used to assemble this |Transcript|\n            have been stored in `self.attr`. This means that upon re-export to `GTF2`_,\n            these sub-features will be lacking any attributes that were specific\n            to them individually. Formally"", this is compliant with the\n            `GTF2 specification <http://mblab.wustl.edu/GTF22.html>`_, which states\n            explicitly that only the attributes `gene_id` and `transcript_id`\n            are supported.\n\n        Columns of `GTF2`_ are as follows\n            ======== =========\n            Column   Contains\n            ======== =========\n                1     Contig or chromosome\n                2     Source of annotation\n                3     Type of feature (\"exon\", \"CDS\", \"start_codon\", \"stop_codon\")\n                4     Start (1-indexed)\n                5     End (fully-closed)\n                6     Score\n                7     Strand\n                8     Frame. Number of bases within feature before first in-frame codon (if coding)\n                9     Attributes. \"gene_id\" and \"transcript_id\" are required\n            ======== =========\n\n        For more info\n            - `GTF2 file format specification <http://mblab.wustl.edu/GTF22.html>`_\n            - `UCSC file format FAQ <http://genome.ucsc.edu/FAQ/FAQformat.html>`_\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_71as_gtf(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_feature_type = 0;
  int __pyx_v_escape;
  PyObject *__pyx_v_excludes = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("as_gtf (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_feature_type,&__pyx_n_s_escape,&__pyx_n_s_excludes,0};
    PyObject* values[3] = {0,0,0};
    values[0] = ((PyObject*)Py_None);
    values[2] = ((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  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_feature_type);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_escape);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_excludes);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "as_gtf") < 0)) __PYX_ERR(0, 2497, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_feature_type = ((PyObject*)values[0]);
    if (values[1]) {
      __pyx_v_escape = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_escape == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2497, __pyx_L3_error)
    } else {
      __pyx_v_escape = ((int)1);
    }
    __pyx_v_excludes = ((PyObject*)values[2]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("as_gtf", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2497, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_gtf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_feature_type), (&PyUnicode_Type), 1, "feature_type", 1))) __PYX_ERR(0, 2497, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_excludes), (&PyList_Type), 1, "excludes", 1))) __PYX_ERR(0, 2497, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_70as_gtf(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_feature_type, __pyx_v_escape, __pyx_v_excludes);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_70as_gtf(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_feature_type, int __pyx_v_escape, PyObject *__pyx_v_excludes) {
  PyObject *__pyx_v_gtf_attr = 0;
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_v_ltmp1 = 0;
  PyObject *__pyx_v_ltmp2 = 0;
  PyObject *__pyx_v_always_excluded = 0;
  PyObject *__pyx_v_segment = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("as_gtf", 0);
  __Pyx_INCREF(__pyx_v_feature_type);
  __Pyx_INCREF(__pyx_v_excludes);

  /* "plastid/genomics/roitools.pyx":2565
 *             - `UCSC file format FAQ <http://genome.ucsc.edu/FAQ/FAQformat.html>`_
 *         """
 *         if len(self) == 0:             # <<<<<<<<<<<<<<
 *             return ""
 * 
 */
  __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2565, __pyx_L1_error)
  __pyx_t_2 = ((__pyx_t_1 == 0) != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":2566
 *         """
 *         if len(self) == 0:
 *             return ""             # <<<<<<<<<<<<<<
 * 
 *         cdef:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_kp_u__33);
    __pyx_r = __pyx_kp_u__33;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":2565
 *             - `UCSC file format FAQ <http://genome.ucsc.edu/FAQ/FAQformat.html>`_
 *         """
 *         if len(self) == 0:             # <<<<<<<<<<<<<<
 *             return ""
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":2570
 *         cdef:
 *             dict gtf_attr
 *             dict attr = self.attr             # <<<<<<<<<<<<<<
 *             list ltmp1, ltmp2, always_excluded
 * 
 */
  __pyx_t_3 = __pyx_v_self->attr;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_v_attr = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":2573
 *             list ltmp1, ltmp2, always_excluded
 * 
 *         excludes = [] if excludes is None else excludes             # <<<<<<<<<<<<<<
 *         gtf_attr = copy.deepcopy(attr)
 *         gtf_attr["transcript_id"] = attr.get("transcript_id", self.get_name())
 */
  __pyx_t_2 = (__pyx_v_excludes == ((PyObject*)Py_None));
  if ((__pyx_t_2 != 0)) {
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2573, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __pyx_t_4;
    __pyx_t_4 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_excludes);
    __pyx_t_3 = __pyx_v_excludes;
  }
  __Pyx_DECREF_SET(__pyx_v_excludes, ((PyObject*)__pyx_t_3));
  __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":2574
 * 
 *         excludes = [] if excludes is None else excludes
 *         gtf_attr = copy.deepcopy(attr)             # <<<<<<<<<<<<<<
 *         gtf_attr["transcript_id"] = attr.get("transcript_id", self.get_name())
 *         gtf_attr["gene_id"]       = attr.get("gene_id", self.get_gene())
 */
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_v_attr) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_attr);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!(likely(PyDict_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 2574, __pyx_L1_error)
  __pyx_v_gtf_attr = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":2575
 *         excludes = [] if excludes is None else excludes
 *         gtf_attr = copy.deepcopy(attr)
 *         gtf_attr["transcript_id"] = attr.get("transcript_id", self.get_name())             # <<<<<<<<<<<<<<
 *         gtf_attr["gene_id"]       = attr.get("gene_id", self.get_gene())
 *         feature_type = attr["type"] if feature_type is None else feature_type
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 2575, __pyx_L1_error)
  }
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2575, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2575, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_attr, __pyx_n_u_transcript_id, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2575, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(__pyx_v_gtf_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 2575, __pyx_L1_error)
  }
  if (unlikely(PyDict_SetItem(__pyx_v_gtf_attr, __pyx_n_u_transcript_id, __pyx_t_5) < 0)) __PYX_ERR(0, 2575, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "plastid/genomics/roitools.pyx":2576
 *         gtf_attr = copy.deepcopy(attr)
 *         gtf_attr["transcript_id"] = attr.get("transcript_id", self.get_name())
 *         gtf_attr["gene_id"]       = attr.get("gene_id", self.get_gene())             # <<<<<<<<<<<<<<
 *         feature_type = attr["type"] if feature_type is None else feature_type
 * 
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 2576, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_gene); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_GetItemDefault(__pyx_v_attr, __pyx_n_u_gene_id, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(__pyx_v_gtf_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 2576, __pyx_L1_error)
  }
  if (unlikely(PyDict_SetItem(__pyx_v_gtf_attr, __pyx_n_u_gene_id, __pyx_t_3) < 0)) __PYX_ERR(0, 2576, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":2577
 *         gtf_attr["transcript_id"] = attr.get("transcript_id", self.get_name())
 *         gtf_attr["gene_id"]       = attr.get("gene_id", self.get_gene())
 *         feature_type = attr["type"] if feature_type is None else feature_type             # <<<<<<<<<<<<<<
 * 
 *         ltmp1 = []
 */
  __pyx_t_2 = (__pyx_v_feature_type == ((PyObject*)Py_None));
  if ((__pyx_t_2 != 0)) {
    if (unlikely(__pyx_v_attr == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 2577, __pyx_L1_error)
    }
    __pyx_t_5 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_type); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2577, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (!(likely(PyUnicode_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 2577, __pyx_L1_error)
    __pyx_t_3 = __pyx_t_5;
    __pyx_t_5 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_feature_type);
    __pyx_t_3 = __pyx_v_feature_type;
  }
  __Pyx_DECREF_SET(__pyx_v_feature_type, ((PyObject*)__pyx_t_3));
  __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":2579
 *         feature_type = attr["type"] if feature_type is None else feature_type
 * 
 *         ltmp1 = []             # <<<<<<<<<<<<<<
 * 
 *         always_excluded = ["source",
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_ltmp1 = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":2581
 *         ltmp1 = []
 * 
 *         always_excluded = ["source",             # <<<<<<<<<<<<<<
 *                            "Parent",
 *                            "score",
 */
  __pyx_t_3 = PyList_New(11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_n_u_source);
  __Pyx_GIVEREF(__pyx_n_u_source);
  PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_u_source);
  __Pyx_INCREF(__pyx_n_u_Parent);
  __Pyx_GIVEREF(__pyx_n_u_Parent);
  PyList_SET_ITEM(__pyx_t_3, 1, __pyx_n_u_Parent);
  __Pyx_INCREF(__pyx_n_u_score);
  __Pyx_GIVEREF(__pyx_n_u_score);
  PyList_SET_ITEM(__pyx_t_3, 2, __pyx_n_u_score);
  __Pyx_INCREF(__pyx_n_u_phase);
  __Pyx_GIVEREF(__pyx_n_u_phase);
  PyList_SET_ITEM(__pyx_t_3, 3, __pyx_n_u_phase);
  __Pyx_INCREF(__pyx_n_u_cds_genome_start_2);
  __Pyx_GIVEREF(__pyx_n_u_cds_genome_start_2);
  PyList_SET_ITEM(__pyx_t_3, 4, __pyx_n_u_cds_genome_start_2);
  __Pyx_INCREF(__pyx_n_u_cds_genome_end_2);
  __Pyx_GIVEREF(__pyx_n_u_cds_genome_end_2);
  PyList_SET_ITEM(__pyx_t_3, 5, __pyx_n_u_cds_genome_end_2);
  __Pyx_INCREF(__pyx_n_u_thickstart);
  __Pyx_GIVEREF(__pyx_n_u_thickstart);
  PyList_SET_ITEM(__pyx_t_3, 6, __pyx_n_u_thickstart);
  __Pyx_INCREF(__pyx_n_u_thickend);
  __Pyx_GIVEREF(__pyx_n_u_thickend);
  PyList_SET_ITEM(__pyx_t_3, 7, __pyx_n_u_thickend);
  __Pyx_INCREF(__pyx_n_u_type);
  __Pyx_GIVEREF(__pyx_n_u_type);
  PyList_SET_ITEM(__pyx_t_3, 8, __pyx_n_u_type);
  __Pyx_INCREF(__pyx_n_u_color);
  __Pyx_GIVEREF(__pyx_n_u_color);
  PyList_SET_ITEM(__pyx_t_3, 9, __pyx_n_u_color);
  __Pyx_INCREF(__pyx_n_u_bedx_column_order);
  __Pyx_GIVEREF(__pyx_n_u_bedx_column_order);
  PyList_SET_ITEM(__pyx_t_3, 10, __pyx_n_u_bedx_column_order);
  __pyx_v_always_excluded = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":2593
 *                            "_bedx_column_order"]
 * 
 *         for segment in self:             # <<<<<<<<<<<<<<
 *             ltmp2 = self._get_8_gff_columns(segment, feature_type) +\
 *                    [make_GTF2_tokens(gtf_attr,
 */
  if (likely(PyList_CheckExact(((PyObject *)__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_v_self))) {
    __pyx_t_3 = ((PyObject *)__pyx_v_self); __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2593, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2593, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 2593, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2593, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 2593, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2593, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_6(__pyx_t_3);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2593, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XDECREF_SET(__pyx_v_segment, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":2594
 * 
 *         for segment in self:
 *             ltmp2 = self._get_8_gff_columns(segment, feature_type) +\             # <<<<<<<<<<<<<<
 *                    [make_GTF2_tokens(gtf_attr,
 *                                      excludes=always_excluded + excludes,
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_8_gff_columns); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2594, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_8 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_segment, __pyx_v_feature_type};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2594, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_segment, __pyx_v_feature_type};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2594, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2594, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (__pyx_t_7) {
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
      }
      __Pyx_INCREF(__pyx_v_segment);
      __Pyx_GIVEREF(__pyx_v_segment);
      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_v_segment);
      __Pyx_INCREF(__pyx_v_feature_type);
      __Pyx_GIVEREF(__pyx_v_feature_type);
      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_feature_type);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2594, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":2595
 *         for segment in self:
 *             ltmp2 = self._get_8_gff_columns(segment, feature_type) +\
 *                    [make_GTF2_tokens(gtf_attr,             # <<<<<<<<<<<<<<
 *                                      excludes=always_excluded + excludes,
 *                                      escape=escape)]
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_make_GTF2_tokens); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2595, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2595, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(__pyx_v_gtf_attr);
    __Pyx_GIVEREF(__pyx_v_gtf_attr);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_gtf_attr);

    /* "plastid/genomics/roitools.pyx":2596
 *             ltmp2 = self._get_8_gff_columns(segment, feature_type) +\
 *                    [make_GTF2_tokens(gtf_attr,
 *                                      excludes=always_excluded + excludes,             # <<<<<<<<<<<<<<
 *                                      escape=escape)]
 * 
 */
    __pyx_t_7 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2596, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_10 = PyNumber_Add(__pyx_v_always_excluded, __pyx_v_excludes); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2596, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_excludes, __pyx_t_10) < 0) __PYX_ERR(0, 2596, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

    /* "plastid/genomics/roitools.pyx":2597
 *                    [make_GTF2_tokens(gtf_attr,
 *                                      excludes=always_excluded + excludes,
 *                                      escape=escape)]             # <<<<<<<<<<<<<<
 * 
 *             ltmp1.append("\t".join(ltmp2))
 */
    __pyx_t_10 = __Pyx_PyBool_FromLong(__pyx_v_escape); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2597, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_escape, __pyx_t_10) < 0) __PYX_ERR(0, 2596, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

    /* "plastid/genomics/roitools.pyx":2595
 *         for segment in self:
 *             ltmp2 = self._get_8_gff_columns(segment, feature_type) +\
 *                    [make_GTF2_tokens(gtf_attr,             # <<<<<<<<<<<<<<
 *                                      excludes=always_excluded + excludes,
 *                                      escape=escape)]
 */
    __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, __pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2595, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2595, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_10);
    PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_10);
    __pyx_t_10 = 0;

    /* "plastid/genomics/roitools.pyx":2594
 * 
 *         for segment in self:
 *             ltmp2 = self._get_8_gff_columns(segment, feature_type) +\             # <<<<<<<<<<<<<<
 *                    [make_GTF2_tokens(gtf_attr,
 *                                      excludes=always_excluded + excludes,
 */
    __pyx_t_10 = PyNumber_Add(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2594, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (!(likely(PyList_CheckExact(__pyx_t_10))||((__pyx_t_10) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_10)->tp_name), 0))) __PYX_ERR(0, 2594, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_ltmp2, ((PyObject*)__pyx_t_10));
    __pyx_t_10 = 0;

    /* "plastid/genomics/roitools.pyx":2599
 *                                      escape=escape)]
 * 
 *             ltmp1.append("\t".join(ltmp2))             # <<<<<<<<<<<<<<
 * 
 *         return "\n".join(ltmp1) + "\n"
 */
    __pyx_t_10 = PyUnicode_Join(__pyx_kp_u__19, __pyx_v_ltmp2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2599, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_ltmp1, __pyx_t_10); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 2599, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

    /* "plastid/genomics/roitools.pyx":2593
 *                            "_bedx_column_order"]
 * 
 *         for segment in self:             # <<<<<<<<<<<<<<
 *             ltmp2 = self._get_8_gff_columns(segment, feature_type) +\
 *                    [make_GTF2_tokens(gtf_attr,
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":2601
 *             ltmp1.append("\t".join(ltmp2))
 * 
 *         return "\n".join(ltmp1) + "\n"             # <<<<<<<<<<<<<<
 * 
 *     # TODO: test optimality
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyUnicode_Join(__pyx_kp_u__18, __pyx_v_ltmp1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2601, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_10 = __Pyx_PyUnicode_Concat(__pyx_t_3, __pyx_kp_u__18); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2601, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_10;
  __pyx_t_10 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2497
 * 
 *     # TODO: optimize
 *     def as_gtf(self, str feature_type=None, bint escape=True, list excludes=None):             # <<<<<<<<<<<<<<
 *         """Format |SegmentChain| as a block of `GTF2`_ output.
 * 
 */

  /* 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_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_gtf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_gtf_attr);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_v_ltmp1);
  __Pyx_XDECREF(__pyx_v_ltmp2);
  __Pyx_XDECREF(__pyx_v_always_excluded);
  __Pyx_XDECREF(__pyx_v_segment);
  __Pyx_XDECREF(__pyx_v_feature_type);
  __Pyx_XDECREF(__pyx_v_excludes);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2604
 * 
 *     # TODO: test optimality
 *     def _get_8_gff_columns(self, GenomicSegment segment, str feature_type):             # <<<<<<<<<<<<<<
 *         """Format columns 1-8 of GFF/GTF2/GFF3 files.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_73_get_8_gff_columns(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_72_get_8_gff_columns[] = "SegmentChain._get_8_gff_columns(self, GenomicSegment segment, unicode feature_type)\nFormat columns 1-8 of GFF/GTF2/GFF3 files.\n\n        Parameters\n        ----------\n        segment : |GenomicSegment|\n            Segment to export\n\n        feature_type : str\n            Type of feature (for column 3 of output)\n\n\n        Notes\n        ------\n        Columns of GFF files are as follows:\n            ======== =========\n            Column   Contains\n            ======== =========\n                1     Contig or chromosome\n                2     Source of annotation\n                3     Type of feature (\"exon\", \"CDS\", \"start_codon\", \"stop_codon\")\n                4     Start (1-indexed)\n                5     End (fully-closed)\n                6     Score\n                7     Strand\n                8     Frame. Number of bases within feature before first in-frame codon (if CDS)\n                9     Attributes. Formatting depends on flavor of GFF\n            ======== =========\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_73_get_8_gff_columns(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_segment = 0;
  PyObject *__pyx_v_feature_type = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_8_gff_columns (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_segment,&__pyx_n_s_feature_type,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_segment)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_feature_type)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_get_8_gff_columns", 1, 2, 2, 1); __PYX_ERR(0, 2604, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_get_8_gff_columns") < 0)) __PYX_ERR(0, 2604, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_segment = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)values[0]);
    __pyx_v_feature_type = ((PyObject*)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_get_8_gff_columns", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2604, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain._get_8_gff_columns", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_segment), __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment, 1, "segment", 0))) __PYX_ERR(0, 2604, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_feature_type), (&PyUnicode_Type), 1, "feature_type", 1))) __PYX_ERR(0, 2604, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_72_get_8_gff_columns(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_segment, __pyx_v_feature_type);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_72_get_8_gff_columns(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_segment, PyObject *__pyx_v_feature_type) {
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_strand = 0;
  PyObject *__pyx_v_phase = 0;
  long __pyx_v_segment_start;
  long __pyx_v_segment_end;
  long __pyx_v_new_segment_start;
  PyObject *__pyx_v_ltmp = 0;
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  long __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_get_8_gff_columns", 0);

  /* "plastid/genomics/roitools.pyx":2634
 *         """
 *         cdef:
 *             str chrom  = segment.chrom             # <<<<<<<<<<<<<<
 *             str strand = segment.strand
 *             str phase  = "."
 */
  __pyx_t_1 = __pyx_v_segment->chrom;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_chrom = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2635
 *         cdef:
 *             str chrom  = segment.chrom
 *             str strand = segment.strand             # <<<<<<<<<<<<<<
 *             str phase  = "."
 *             long segment_start = segment.start
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_segment), __pyx_n_s_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2635, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 2635, __pyx_L1_error)
  __pyx_v_strand = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2636
 *             str chrom  = segment.chrom
 *             str strand = segment.strand
 *             str phase  = "."             # <<<<<<<<<<<<<<
 *             long segment_start = segment.start
 *             long segment_end   = segment.end
 */
  __Pyx_INCREF(__pyx_kp_u__11);
  __pyx_v_phase = __pyx_kp_u__11;

  /* "plastid/genomics/roitools.pyx":2637
 *             str strand = segment.strand
 *             str phase  = "."
 *             long segment_start = segment.start             # <<<<<<<<<<<<<<
 *             long segment_end   = segment.end
 *             long new_segment_start
 */
  __pyx_t_2 = __pyx_v_segment->start;
  __pyx_v_segment_start = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":2638
 *             str phase  = "."
 *             long segment_start = segment.start
 *             long segment_end   = segment.end             # <<<<<<<<<<<<<<
 *             long new_segment_start
 *             list ltmp
 */
  __pyx_t_2 = __pyx_v_segment->end;
  __pyx_v_segment_end = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":2641
 *             long new_segment_start
 *             list ltmp
 *             dict attr = self.attr             # <<<<<<<<<<<<<<
 * 
 *         if feature_type == "CDS":
 */
  __pyx_t_1 = __pyx_v_self->attr;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2643
 *             dict attr = self.attr
 * 
 *         if feature_type == "CDS":             # <<<<<<<<<<<<<<
 *             # use phase/frame if known for length-1 features
 *             # called "phase" in GFF3 conventions; "frame" in GTF2
 */
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_feature_type, __pyx_n_u_CDS, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2643, __pyx_L1_error)
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":2646
 *             # use phase/frame if known for length-1 features
 *             # called "phase" in GFF3 conventions; "frame" in GTF2
 *             if len(self._segments) == 1 and ("phase" in attr or "frame" in attr):             # <<<<<<<<<<<<<<
 *                 phase = str(attr.get("phase", attr.get("frame")))
 *             # otherwise calculate
 */
    __pyx_t_1 = __pyx_v_self->_segments;
    __Pyx_INCREF(__pyx_t_1);
    if (unlikely(__pyx_t_1 == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 2646, __pyx_L1_error)
    }
    __pyx_t_5 = PyList_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2646, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_3 = ((__pyx_t_5 == 1) != 0);
    if (__pyx_t_3) {
    } else {
      __pyx_t_4 = __pyx_t_3;
      goto __pyx_L5_bool_binop_done;
    }
    if (unlikely(__pyx_v_attr == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 2646, __pyx_L1_error)
    }
    __pyx_t_3 = (__Pyx_PyDict_ContainsTF(__pyx_n_u_phase, __pyx_v_attr, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2646, __pyx_L1_error)
    __pyx_t_6 = (__pyx_t_3 != 0);
    if (!__pyx_t_6) {
    } else {
      __pyx_t_4 = __pyx_t_6;
      goto __pyx_L5_bool_binop_done;
    }
    if (unlikely(__pyx_v_attr == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 2646, __pyx_L1_error)
    }
    __pyx_t_6 = (__Pyx_PyDict_ContainsTF(__pyx_n_u_frame, __pyx_v_attr, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2646, __pyx_L1_error)
    __pyx_t_3 = (__pyx_t_6 != 0);
    __pyx_t_4 = __pyx_t_3;
    __pyx_L5_bool_binop_done:;
    if (__pyx_t_4) {

      /* "plastid/genomics/roitools.pyx":2647
 *             # called "phase" in GFF3 conventions; "frame" in GTF2
 *             if len(self._segments) == 1 and ("phase" in attr or "frame" in attr):
 *                 phase = str(attr.get("phase", attr.get("frame")))             # <<<<<<<<<<<<<<
 *             # otherwise calculate
 *             else:
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
        __PYX_ERR(0, 2647, __pyx_L1_error)
      }
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
        __PYX_ERR(0, 2647, __pyx_L1_error)
      }
      __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_attr, __pyx_n_u_frame, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2647, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyDict_GetItemDefault(__pyx_v_attr, __pyx_n_u_phase, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2647, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2647, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF_SET(__pyx_v_phase, ((PyObject*)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":2646
 *             # use phase/frame if known for length-1 features
 *             # called "phase" in GFF3 conventions; "frame" in GTF2
 *             if len(self._segments) == 1 and ("phase" in attr or "frame" in attr):             # <<<<<<<<<<<<<<
 *                 phase = str(attr.get("phase", attr.get("frame")))
 *             # otherwise calculate
 */
      goto __pyx_L4;
    }

    /* "plastid/genomics/roitools.pyx":2650
 *             # otherwise calculate
 *             else:
 *                 new_segment_start = self.get_segmentchain_coordinate(             # <<<<<<<<<<<<<<
 *                     chrom, segment_start, strand, stranded=False
 *                 )
 */
    /*else*/ {
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_segmentchain_coordinate); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2650, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);

      /* "plastid/genomics/roitools.pyx":2651
 *             else:
 *                 new_segment_start = self.get_segmentchain_coordinate(
 *                     chrom, segment_start, strand, stranded=False             # <<<<<<<<<<<<<<
 *                 )
 *                 phase = str((3 - (new_segment_start % 3)) % 3)
 */
      __pyx_t_7 = __Pyx_PyInt_From_long(__pyx_v_segment_start); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2651, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);

      /* "plastid/genomics/roitools.pyx":2650
 *             # otherwise calculate
 *             else:
 *                 new_segment_start = self.get_segmentchain_coordinate(             # <<<<<<<<<<<<<<
 *                     chrom, segment_start, strand, stranded=False
 *                 )
 */
      __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2650, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_v_chrom);
      __Pyx_GIVEREF(__pyx_v_chrom);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_chrom);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
      __Pyx_INCREF(__pyx_v_strand);
      __Pyx_GIVEREF(__pyx_v_strand);
      PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_strand);
      __pyx_t_7 = 0;

      /* "plastid/genomics/roitools.pyx":2651
 *             else:
 *                 new_segment_start = self.get_segmentchain_coordinate(
 *                     chrom, segment_start, strand, stranded=False             # <<<<<<<<<<<<<<
 *                 )
 *                 phase = str((3 - (new_segment_start % 3)) % 3)
 */
      __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2651, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_stranded, Py_False) < 0) __PYX_ERR(0, 2651, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":2650
 *             # otherwise calculate
 *             else:
 *                 new_segment_start = self.get_segmentchain_coordinate(             # <<<<<<<<<<<<<<
 *                     chrom, segment_start, strand, stranded=False
 *                 )
 */
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2650, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_2 = __Pyx_PyInt_As_long(__pyx_t_9); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 2650, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_new_segment_start = __pyx_t_2;

      /* "plastid/genomics/roitools.pyx":2653
 *                     chrom, segment_start, strand, stranded=False
 *                 )
 *                 phase = str((3 - (new_segment_start % 3)) % 3)             # <<<<<<<<<<<<<<
 * 
 *         ltmp = [
 */
      __pyx_t_9 = __Pyx_PyInt_From_long(__Pyx_mod_long((3 - __Pyx_mod_long(__pyx_v_new_segment_start, 3)), 3)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2653, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_7 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2653, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF_SET(__pyx_v_phase, ((PyObject*)__pyx_t_7));
      __pyx_t_7 = 0;
    }
    __pyx_L4:;

    /* "plastid/genomics/roitools.pyx":2643
 *             dict attr = self.attr
 * 
 *         if feature_type == "CDS":             # <<<<<<<<<<<<<<
 *             # use phase/frame if known for length-1 features
 *             # called "phase" in GFF3 conventions; "frame" in GTF2
 */
  }

  /* "plastid/genomics/roitools.pyx":2657
 *         ltmp = [
 *             chrom,
 *             self.attr.get("source","."),             # <<<<<<<<<<<<<<
 *             feature_type,
 *             str(segment_start + 1),
 */
  if (unlikely(__pyx_v_self->attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 2657, __pyx_L1_error)
  }
  __pyx_t_7 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_source, __pyx_kp_u__11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2657, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);

  /* "plastid/genomics/roitools.pyx":2659
 *             self.attr.get("source","."),
 *             feature_type,
 *             str(segment_start + 1),             # <<<<<<<<<<<<<<
 *             str(segment_end),
 *             str(self.attr.get("score",".")),
 */
  __pyx_t_9 = __Pyx_PyInt_From_long((__pyx_v_segment_start + 1)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "plastid/genomics/roitools.pyx":2660
 *             feature_type,
 *             str(segment_start + 1),
 *             str(segment_end),             # <<<<<<<<<<<<<<
 *             str(self.attr.get("score",".")),
 *             strand,
 */
  __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_v_segment_end); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2660, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2660, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "plastid/genomics/roitools.pyx":2661
 *             str(segment_start + 1),
 *             str(segment_end),
 *             str(self.attr.get("score",".")),             # <<<<<<<<<<<<<<
 *             strand,
 *             phase,
 */
  if (unlikely(__pyx_v_self->attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 2661, __pyx_L1_error)
  }
  __pyx_t_9 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_score, __pyx_kp_u__11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_10 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "plastid/genomics/roitools.pyx":2655
 *                 phase = str((3 - (new_segment_start % 3)) % 3)
 * 
 *         ltmp = [             # <<<<<<<<<<<<<<
 *             chrom,
 *             self.attr.get("source","."),
 */
  __pyx_t_9 = PyList_New(8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_INCREF(__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_v_chrom);
  PyList_SET_ITEM(__pyx_t_9, 0, __pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_t_7);
  PyList_SET_ITEM(__pyx_t_9, 1, __pyx_t_7);
  __Pyx_INCREF(__pyx_v_feature_type);
  __Pyx_GIVEREF(__pyx_v_feature_type);
  PyList_SET_ITEM(__pyx_t_9, 2, __pyx_v_feature_type);
  __Pyx_GIVEREF(__pyx_t_8);
  PyList_SET_ITEM(__pyx_t_9, 3, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_1);
  PyList_SET_ITEM(__pyx_t_9, 4, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_10);
  PyList_SET_ITEM(__pyx_t_9, 5, __pyx_t_10);
  __Pyx_INCREF(__pyx_v_strand);
  __Pyx_GIVEREF(__pyx_v_strand);
  PyList_SET_ITEM(__pyx_t_9, 6, __pyx_v_strand);
  __Pyx_INCREF(__pyx_v_phase);
  __Pyx_GIVEREF(__pyx_v_phase);
  PyList_SET_ITEM(__pyx_t_9, 7, __pyx_v_phase);
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;
  __pyx_t_1 = 0;
  __pyx_t_10 = 0;
  __pyx_v_ltmp = ((PyObject*)__pyx_t_9);
  __pyx_t_9 = 0;

  /* "plastid/genomics/roitools.pyx":2666
 *         ]
 * 
 *         return ltmp             # <<<<<<<<<<<<<<
 * 
 *     # TODO: optimize
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ltmp);
  __pyx_r = __pyx_v_ltmp;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2604
 * 
 *     # TODO: test optimality
 *     def _get_8_gff_columns(self, GenomicSegment segment, str feature_type):             # <<<<<<<<<<<<<<
 *         """Format columns 1-8 of GFF/GTF2/GFF3 files.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain._get_8_gff_columns", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_strand);
  __Pyx_XDECREF(__pyx_v_phase);
  __Pyx_XDECREF(__pyx_v_ltmp);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2669
 * 
 *     # TODO: optimize
 *     def as_bed(             # <<<<<<<<<<<<<<
 *         self,
 *         thickstart    = None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_75as_bed(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_74as_bed[] = "SegmentChain.as_bed(self, thickstart=None, thickend=None, as_int=True, color=None, extra_columns=None, empty_value=u'')\nFormat |SegmentChain| as a string of BED12[+X] output.\n\n        If the |SegmentChain| was imported as a `BED`_ file with extra columns,\n        these will be output in the same order, after the `BED`_ columns.\n\n        Parameters\n        ----------\n        thickstart : int or `None`, optional\n            If not `None`, overrides the genome coordinate that starts thick\n            plotting in genome browser found in `self.attr['thickstart']`\n\n        thickend : int or None, optional\n            If not None, overrides the genome coordinate that stops\n            thick plotting in genome browser found in `self.attr['thickend']`\n\n        as_int : bool, optional\n            Force `score` to integer (Default: `True`)\n\n        color : str or None, optional\n            Color represented as RGB hex string.\n            If not none, overrides the color in `self.attr['color']`\n\n        extra_columns : None or list-like, optional\n            If `None`, and the |SegmentChain| was imported using the `extra_columns`\n            keyword of :meth:`~plastid.genomics.roitools.SegmentChain.from_bed`,\n            the |SegmentChain| will be exported in BED 12+X format, in which\n            extra columns are in the same order as they were upon import. If no extra columns\n            were present, the |SegmentChain| will be exported as a BED12 line.\n\n            If a list of attribute names, these attributes will be exported as\n            extra columns in order, overriding whatever happened upon import.\n            If an attribute name is not in the `attr` dict of the |SegmentChain|,\n            it will be exported with the value of `empty_value`\n\n            If an empty list, no extra columns will be exported; the |SegmentChain|\n            will be formatted as a BED12 line.\n\n        empty_value : str, optional\n            Value to ""export for `extra_columns` that are not defined (Default: \"\")\n\n\n        Returns\n        -------\n        str\n            Line of BED12[+X]-formatted text\n\n\n        Notes\n        -----\n        BED12 columns are as follows:\n            ======== =========\n            Column   Contains\n            ======== =========\n               1     Contig or chromosome\n               2     Start of first block in feature (0-indexed)\n               3     End of last block in feature (half-open)\n               4     Feature name\n               5     Feature score\n               6     Strand\n               7     thickstart (in chromosomal coordinates)\n               8     thickend (in chromosomal coordinates)\n               9     Feature color as RGB tuple\n               10    Number of blocks in feature\n               11    Block lengths\n               12    Block starts, relative to start of first block\n            ======== =========\n\n        For more details\n            See the `UCSC file format faq <http://genome.ucsc.edu/FAQ/FAQformat.html>`_\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_75as_bed(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_thickstart = 0;
  PyObject *__pyx_v_thickend = 0;
  PyObject *__pyx_v_as_int = 0;
  PyObject *__pyx_v_color = 0;
  PyObject *__pyx_v_extra_columns = 0;
  PyObject *__pyx_v_empty_value = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("as_bed (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_thickstart,&__pyx_n_s_thickend,&__pyx_n_s_as_int,&__pyx_n_s_color,&__pyx_n_s_extra_columns,&__pyx_n_s_empty_value,0};
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "plastid/genomics/roitools.pyx":2671
 *     def as_bed(
 *         self,
 *         thickstart    = None,             # <<<<<<<<<<<<<<
 *         thickend      = None,
 *         as_int        = True,
 */
    values[0] = ((PyObject *)Py_None);

    /* "plastid/genomics/roitools.pyx":2672
 *         self,
 *         thickstart    = None,
 *         thickend      = None,             # <<<<<<<<<<<<<<
 *         as_int        = True,
 *         color         = None,
 */
    values[1] = ((PyObject *)Py_None);

    /* "plastid/genomics/roitools.pyx":2673
 *         thickstart    = None,
 *         thickend      = None,
 *         as_int        = True,             # <<<<<<<<<<<<<<
 *         color         = None,
 *         extra_columns = None,
 */
    values[2] = ((PyObject *)Py_True);

    /* "plastid/genomics/roitools.pyx":2674
 *         thickend      = None,
 *         as_int        = True,
 *         color         = None,             # <<<<<<<<<<<<<<
 *         extra_columns = None,
 *         empty_value   = ""
 */
    values[3] = ((PyObject *)Py_None);

    /* "plastid/genomics/roitools.pyx":2675
 *         as_int        = True,
 *         color         = None,
 *         extra_columns = None,             # <<<<<<<<<<<<<<
 *         empty_value   = ""
 *         ):
 */
    values[4] = ((PyObject *)Py_None);
    values[5] = ((PyObject *)__pyx_kp_u__33);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_thickstart);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_thickend);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_as_int);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_color);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_extra_columns);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_empty_value);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "as_bed") < 0)) __PYX_ERR(0, 2669, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_thickstart = values[0];
    __pyx_v_thickend = values[1];
    __pyx_v_as_int = values[2];
    __pyx_v_color = values[3];
    __pyx_v_extra_columns = values[4];
    __pyx_v_empty_value = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("as_bed", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2669, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_74as_bed(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_thickstart, __pyx_v_thickend, __pyx_v_as_int, __pyx_v_color, __pyx_v_extra_columns, __pyx_v_empty_value);

  /* "plastid/genomics/roitools.pyx":2669
 * 
 *     # TODO: optimize
 *     def as_bed(             # <<<<<<<<<<<<<<
 *         self,
 *         thickstart    = None,
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_2generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "plastid/genomics/roitools.pyx":2770
 *                 else:
 *                     # is a tuple or sequence
 *                     if all(isinstance(X, float) for X in color) and \             # <<<<<<<<<<<<<<
 *                        all(X < 1 for X in color) and \
 *                        all(X > 0 for X in color):
 */

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_7plastid_8genomics_8roitools___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_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr *)__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr(__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2770, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_2generator, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_as_bed_locals_genexpr, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!gen)) __PYX_ERR(0, 2770, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_bed.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_2generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr *__pyx_cur_scope = ((struct __pyx_obj_7plastid_8genomics_8roitools___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)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("genexpr", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2770, __pyx_L1_error)
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color)) { __Pyx_RaiseClosureNameError("color"); __PYX_ERR(0, 2770, __pyx_L1_error) }
  if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color)) {
    __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_color; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2770, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2770, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2770, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2770, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2770, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2770, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2770, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_X);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_X, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_5 = PyFloat_Check(__pyx_cur_scope->__pyx_v_X); 
    __pyx_t_6 = ((!(__pyx_t_5 != 0)) != 0);
    if (__pyx_t_6) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_False);
      __pyx_r = Py_False;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
  }
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_True);
    __pyx_r = Py_True;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_5generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "plastid/genomics/roitools.pyx":2771
 *                     # is a tuple or sequence
 *                     if all(isinstance(X, float) for X in color) and \
 *                        all(X < 1 for X in color) and \             # <<<<<<<<<<<<<<
 *                        all(X > 0 for X in color):
 *                         color = "%s,%s,%s" % (int(round(255*X)) for X in color)
 */

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_3genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_7plastid_8genomics_8roitools___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_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr *)__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr(__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2771, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_5generator1, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_as_bed_locals_genexpr, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!gen)) __PYX_ERR(0, 2771, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_bed.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_5generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr *__pyx_cur_scope = ((struct __pyx_obj_7plastid_8genomics_8roitools___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)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("genexpr", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2771, __pyx_L1_error)
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color)) { __Pyx_RaiseClosureNameError("color"); __PYX_ERR(0, 2771, __pyx_L1_error) }
  if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color)) {
    __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_color; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2771, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2771, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2771, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2771, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2771, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2771, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2771, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_X);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_X, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_X, __pyx_int_1, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2771, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2771, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_6 = ((!__pyx_t_5) != 0);
    if (__pyx_t_6) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_False);
      __pyx_r = Py_False;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
  }
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_True);
    __pyx_r = Py_True;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_8generator2(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "plastid/genomics/roitools.pyx":2772
 *                     if all(isinstance(X, float) for X in color) and \
 *                        all(X < 1 for X in color) and \
 *                        all(X > 0 for X in color):             # <<<<<<<<<<<<<<
 *                         color = "%s,%s,%s" % (int(round(255*X)) for X in color)
 *                     else:
 */

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_6genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr *)__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr(__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2772, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_8generator2, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_as_bed_locals_genexpr, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!gen)) __PYX_ERR(0, 2772, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_bed.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_8generator2(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr *__pyx_cur_scope = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *(*__pyx_t_3)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("genexpr", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2772, __pyx_L1_error)
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color)) { __Pyx_RaiseClosureNameError("color"); __PYX_ERR(0, 2772, __pyx_L1_error) }
  if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color)) {
    __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_color; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2772, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2772, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2772, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2772, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2772, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2772, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2772, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_X);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_X, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_X, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2772, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2772, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_6 = ((!__pyx_t_5) != 0);
    if (__pyx_t_6) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_False);
      __pyx_r = Py_False;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
  }
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_True);
    __pyx_r = Py_True;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_11generator3(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "plastid/genomics/roitools.pyx":2773
 *                        all(X < 1 for X in color) and \
 *                        all(X > 0 for X in color):
 *                         color = "%s,%s,%s" % (int(round(255*X)) for X in color)             # <<<<<<<<<<<<<<
 *                     else:
 *                         color = "%s,%s,%s" % tuple(color)
 */

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_9genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr *)__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr(__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2773, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_11generator3, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_as_bed_locals_genexpr, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!gen)) __PYX_ERR(0, 2773, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_bed.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_11generator3(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr *__pyx_cur_scope = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *(*__pyx_t_3)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("genexpr", 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_ERR(0, 2773, __pyx_L1_error)
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color)) { __Pyx_RaiseClosureNameError("color"); __PYX_ERR(0, 2773, __pyx_L1_error) }
  if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color)) {
    __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_color; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_color); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2773, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2773, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2773, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2773, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2773, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2773, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2773, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_X);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_X, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Multiply(__pyx_int_255, __pyx_cur_scope->__pyx_v_X); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2773, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_round, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2773, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2773, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_3;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L6_resume_from_yield:;
    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
    __pyx_cur_scope->__pyx_t_0 = 0;
    __Pyx_XGOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_3 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2773, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2669
 * 
 *     # TODO: optimize
 *     def as_bed(             # <<<<<<<<<<<<<<
 *         self,
 *         thickstart    = None,
 */

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_74as_bed(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_thickstart, PyObject *__pyx_v_thickend, PyObject *__pyx_v_as_int, PyObject *__pyx_v_color, PyObject *__pyx_v_extra_columns, PyObject *__pyx_v_empty_value) {
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *__pyx_cur_scope;
  PyObject *__pyx_v_ltmp = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_span = 0;
  long __pyx_v_spanstart;
  PyObject *__pyx_v_score = NULL;
  PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_2generator = 0;
  PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_5generator1 = 0;
  PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_8generator2 = 0;
  PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_11generator3 = 0;
  PyObject *__pyx_9genexpr15__pyx_v_X = NULL;
  PyObject *__pyx_9genexpr16__pyx_v_X = NULL;
  PyObject *__pyx_9genexpr17__pyx_v_X = NULL;
  PyObject *__pyx_9genexpr18__pyx_v_X = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  long __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  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;
  PyObject *(*__pyx_t_16)(PyObject *);
  PyObject *__pyx_t_17 = NULL;
  Py_ssize_t __pyx_t_18;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  int __pyx_t_22;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("as_bed", 0);
  __pyx_cur_scope = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *)__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed(__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2669, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_v_color = __pyx_v_color;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_color);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_color);
  __Pyx_INCREF(__pyx_v_thickstart);
  __Pyx_INCREF(__pyx_v_thickend);
  __Pyx_INCREF(__pyx_v_extra_columns);

  /* "plastid/genomics/roitools.pyx":2750
 *         cdef:
 *             list ltmp
 *             GenomicSegment span = self.spanning_segment             # <<<<<<<<<<<<<<
 *             long spanstart = span.start
 * 
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_span = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2751
 *             list ltmp
 *             GenomicSegment span = self.spanning_segment
 *             long spanstart = span.start             # <<<<<<<<<<<<<<
 * 
 *         if len(self) > 0:
 */
  __pyx_t_2 = __pyx_v_span->start;
  __pyx_v_spanstart = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":2753
 *             long spanstart = span.start
 * 
 *         if len(self) > 0:             # <<<<<<<<<<<<<<
 *             score = self.attr.get("score", 0)
 *             try:
 */
  __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2753, __pyx_L1_error)
  __pyx_t_4 = ((__pyx_t_3 > 0) != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":2754
 * 
 *         if len(self) > 0:
 *             score = self.attr.get("score", 0)             # <<<<<<<<<<<<<<
 *             try:
 *                 score = float(score)
 */
    if (unlikely(__pyx_v_self->attr == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
      __PYX_ERR(0, 2754, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_score, __pyx_int_0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2754, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_score = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":2755
 *         if len(self) > 0:
 *             score = self.attr.get("score", 0)
 *             try:             # <<<<<<<<<<<<<<
 *                 score = float(score)
 *                 if as_int is True:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_7);
      /*try:*/ {

        /* "plastid/genomics/roitools.pyx":2756
 *             score = self.attr.get("score", 0)
 *             try:
 *                 score = float(score)             # <<<<<<<<<<<<<<
 *                 if as_int is True:
 *                     score = int(round(score))
 */
        __pyx_t_1 = __Pyx_PyNumber_Float(__pyx_v_score); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2756, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF_SET(__pyx_v_score, __pyx_t_1);
        __pyx_t_1 = 0;

        /* "plastid/genomics/roitools.pyx":2757
 *             try:
 *                 score = float(score)
 *                 if as_int is True:             # <<<<<<<<<<<<<<
 *                     score = int(round(score))
 *             except ValueError:
 */
        __pyx_t_4 = (__pyx_v_as_int == Py_True);
        __pyx_t_8 = (__pyx_t_4 != 0);
        if (__pyx_t_8) {

          /* "plastid/genomics/roitools.pyx":2758
 *                 score = float(score)
 *                 if as_int is True:
 *                     score = int(round(score))             # <<<<<<<<<<<<<<
 *             except ValueError:
 *                 score = 0
 */
          __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_round, __pyx_v_score); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2758, __pyx_L4_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_9 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2758, __pyx_L4_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF_SET(__pyx_v_score, __pyx_t_9);
          __pyx_t_9 = 0;

          /* "plastid/genomics/roitools.pyx":2757
 *             try:
 *                 score = float(score)
 *                 if as_int is True:             # <<<<<<<<<<<<<<
 *                     score = int(round(score))
 *             except ValueError:
 */
        }

        /* "plastid/genomics/roitools.pyx":2755
 *         if len(self) > 0:
 *             score = self.attr.get("score", 0)
 *             try:             # <<<<<<<<<<<<<<
 *                 score = float(score)
 *                 if as_int is True:
 */
      }
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L9_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "plastid/genomics/roitools.pyx":2759
 *                 if as_int is True:
 *                     score = int(round(score))
 *             except ValueError:             # <<<<<<<<<<<<<<
 *                 score = 0
 *             except TypeError:
 */
      __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
      if (__pyx_t_10) {
        __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_1, &__pyx_t_11) < 0) __PYX_ERR(0, 2759, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GOTREF(__pyx_t_11);

        /* "plastid/genomics/roitools.pyx":2760
 *                     score = int(round(score))
 *             except ValueError:
 *                 score = 0             # <<<<<<<<<<<<<<
 *             except TypeError:
 *                 score = 0
 */
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_DECREF_SET(__pyx_v_score, __pyx_int_0);
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L5_exception_handled;
      }

      /* "plastid/genomics/roitools.pyx":2761
 *             except ValueError:
 *                 score = 0
 *             except TypeError:             # <<<<<<<<<<<<<<
 *                 score = 0
 * 
 */
      __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError);
      if (__pyx_t_10) {
        __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_11, &__pyx_t_1, &__pyx_t_9) < 0) __PYX_ERR(0, 2761, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GOTREF(__pyx_t_9);

        /* "plastid/genomics/roitools.pyx":2762
 *                 score = 0
 *             except TypeError:
 *                 score = 0             # <<<<<<<<<<<<<<
 * 
 *             try:
 */
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_DECREF_SET(__pyx_v_score, __pyx_int_0);
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L5_exception_handled;
      }
      goto __pyx_L6_except_error;
      __pyx_L6_except_error:;

      /* "plastid/genomics/roitools.pyx":2755
 *         if len(self) > 0:
 *             score = self.attr.get("score", 0)
 *             try:             # <<<<<<<<<<<<<<
 *                 score = float(score)
 *                 if as_int is True:
 */
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      goto __pyx_L1_error;
      __pyx_L5_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      __pyx_L9_try_end:;
    }

    /* "plastid/genomics/roitools.pyx":2764
 *                 score = 0
 * 
 *             try:             # <<<<<<<<<<<<<<
 *                 color = self.attr.get("color", "#000000")
 *                 if isinstance(color, str):
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_6, &__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_5);
      /*try:*/ {

        /* "plastid/genomics/roitools.pyx":2765
 * 
 *             try:
 *                 color = self.attr.get("color", "#000000")             # <<<<<<<<<<<<<<
 *                 if isinstance(color, str):
 *                     color = "%s,%s,%s" % tuple(get_rgb255(color))
 */
        if (unlikely(__pyx_v_self->attr == Py_None)) {
          PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
          __PYX_ERR(0, 2765, __pyx_L15_error)
        }
        __pyx_t_9 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_color, __pyx_kp_u_000000); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2765, __pyx_L15_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_color);
        __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_color, __pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_9);
        __pyx_t_9 = 0;

        /* "plastid/genomics/roitools.pyx":2766
 *             try:
 *                 color = self.attr.get("color", "#000000")
 *                 if isinstance(color, str):             # <<<<<<<<<<<<<<
 *                     color = "%s,%s,%s" % tuple(get_rgb255(color))
 *                 else:
 */
        __pyx_t_9 = __pyx_cur_scope->__pyx_v_color;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_t_8 = PyUnicode_Check(__pyx_t_9); 
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_4 = (__pyx_t_8 != 0);
        if (__pyx_t_4) {

          /* "plastid/genomics/roitools.pyx":2767
 *                 color = self.attr.get("color", "#000000")
 *                 if isinstance(color, str):
 *                     color = "%s,%s,%s" % tuple(get_rgb255(color))             # <<<<<<<<<<<<<<
 *                 else:
 *                     # is a tuple or sequence
 */
          __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_get_rgb255); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2767, __pyx_L15_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_11 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_11)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_11);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
            }
          }
          __pyx_t_9 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_11, __pyx_cur_scope->__pyx_v_color) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_cur_scope->__pyx_v_color);
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2767, __pyx_L15_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PySequence_Tuple(__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2767, __pyx_L15_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = PyUnicode_Format(__pyx_kp_u_s_s_s, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2767, __pyx_L15_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_color);
          __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_color, __pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_9);
          __pyx_t_9 = 0;

          /* "plastid/genomics/roitools.pyx":2766
 *             try:
 *                 color = self.attr.get("color", "#000000")
 *                 if isinstance(color, str):             # <<<<<<<<<<<<<<
 *                     color = "%s,%s,%s" % tuple(get_rgb255(color))
 *                 else:
 */
          goto __pyx_L21;
        }

        /* "plastid/genomics/roitools.pyx":2770
 *                 else:
 *                     # is a tuple or sequence
 *                     if all(isinstance(X, float) for X in color) and \             # <<<<<<<<<<<<<<
 *                        all(X < 1 for X in color) and \
 *                        all(X > 0 for X in color):
 */
        /*else*/ {
          __pyx_t_9 = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2770, __pyx_L15_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_1 = __Pyx_Generator_Next(__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2770, __pyx_L15_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2770, __pyx_L15_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (__pyx_t_8) {
          } else {
            __pyx_t_4 = __pyx_t_8;
            goto __pyx_L23_bool_binop_done;
          }

          /* "plastid/genomics/roitools.pyx":2771
 *                     # is a tuple or sequence
 *                     if all(isinstance(X, float) for X in color) and \
 *                        all(X < 1 for X in color) and \             # <<<<<<<<<<<<<<
 *                        all(X > 0 for X in color):
 *                         color = "%s,%s,%s" % (int(round(255*X)) for X in color)
 */
          __pyx_t_1 = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_3genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2771, __pyx_L15_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_9 = __Pyx_Generator_Next(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2771, __pyx_L15_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2771, __pyx_L15_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (__pyx_t_8) {
          } else {
            __pyx_t_4 = __pyx_t_8;
            goto __pyx_L23_bool_binop_done;
          }

          /* "plastid/genomics/roitools.pyx":2772
 *                     if all(isinstance(X, float) for X in color) and \
 *                        all(X < 1 for X in color) and \
 *                        all(X > 0 for X in color):             # <<<<<<<<<<<<<<
 *                         color = "%s,%s,%s" % (int(round(255*X)) for X in color)
 *                     else:
 */
          __pyx_t_9 = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_6genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2772, __pyx_L15_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_1 = __Pyx_Generator_Next(__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2772, __pyx_L15_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2772, __pyx_L15_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_4 = __pyx_t_8;
          __pyx_L23_bool_binop_done:;

          /* "plastid/genomics/roitools.pyx":2770
 *                 else:
 *                     # is a tuple or sequence
 *                     if all(isinstance(X, float) for X in color) and \             # <<<<<<<<<<<<<<
 *                        all(X < 1 for X in color) and \
 *                        all(X > 0 for X in color):
 */
          if (__pyx_t_4) {

            /* "plastid/genomics/roitools.pyx":2773
 *                        all(X < 1 for X in color) and \
 *                        all(X > 0 for X in color):
 *                         color = "%s,%s,%s" % (int(round(255*X)) for X in color)             # <<<<<<<<<<<<<<
 *                     else:
 *                         color = "%s,%s,%s" % tuple(color)
 */
            __pyx_t_1 = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_9genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2773, __pyx_L15_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_9 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_s_s_s, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2773, __pyx_L15_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_color);
            __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_color, __pyx_t_9);
            __Pyx_GIVEREF(__pyx_t_9);
            __pyx_t_9 = 0;

            /* "plastid/genomics/roitools.pyx":2770
 *                 else:
 *                     # is a tuple or sequence
 *                     if all(isinstance(X, float) for X in color) and \             # <<<<<<<<<<<<<<
 *                        all(X < 1 for X in color) and \
 *                        all(X > 0 for X in color):
 */
            goto __pyx_L22;
          }

          /* "plastid/genomics/roitools.pyx":2775
 *                         color = "%s,%s,%s" % (int(round(255*X)) for X in color)
 *                     else:
 *                         color = "%s,%s,%s" % tuple(color)             # <<<<<<<<<<<<<<
 * 
 *             except ValueError:
 */
          /*else*/ {
            __pyx_t_9 = __Pyx_PySequence_Tuple(__pyx_cur_scope->__pyx_v_color); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2775, __pyx_L15_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_1 = PyUnicode_Format(__pyx_kp_u_s_s_s, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2775, __pyx_L15_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_color);
            __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_color, __pyx_t_1);
            __Pyx_GIVEREF(__pyx_t_1);
            __pyx_t_1 = 0;
          }
          __pyx_L22:;
        }
        __pyx_L21:;

        /* "plastid/genomics/roitools.pyx":2764
 *                 score = 0
 * 
 *             try:             # <<<<<<<<<<<<<<
 *                 color = self.attr.get("color", "#000000")
 *                 if isinstance(color, str):
 */
      }
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L20_try_end;
      __pyx_L15_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "plastid/genomics/roitools.pyx":2777
 *                         color = "%s,%s,%s" % tuple(color)
 * 
 *             except ValueError:             # <<<<<<<<<<<<<<
 *                 color = self.attr.get("color", "0,0,0") if color is None else color
 * 
 */
      __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
      if (__pyx_t_10) {
        __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_9, &__pyx_t_11) < 0) __PYX_ERR(0, 2777, __pyx_L17_except_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GOTREF(__pyx_t_11);

        /* "plastid/genomics/roitools.pyx":2778
 * 
 *             except ValueError:
 *                 color = self.attr.get("color", "0,0,0") if color is None else color             # <<<<<<<<<<<<<<
 * 
 *             thickstart = self.attr.get("thickstart", spanstart) if thickstart is None else thickstart
 */
        __pyx_t_4 = (__pyx_cur_scope->__pyx_v_color == Py_None);
        if ((__pyx_t_4 != 0)) {
          if (unlikely(__pyx_v_self->attr == Py_None)) {
            PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
            __PYX_ERR(0, 2778, __pyx_L17_except_error)
          }
          __pyx_t_13 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_color, __pyx_kp_u_0_0_0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2778, __pyx_L17_except_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_12 = __pyx_t_13;
          __pyx_t_13 = 0;
        } else {
          __Pyx_INCREF(__pyx_cur_scope->__pyx_v_color);
          __pyx_t_12 = __pyx_cur_scope->__pyx_v_color;
        }
        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_color);
        __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_color, __pyx_t_12);
        __Pyx_GIVEREF(__pyx_t_12);
        __pyx_t_12 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L16_exception_handled;
      }
      goto __pyx_L17_except_error;
      __pyx_L17_except_error:;

      /* "plastid/genomics/roitools.pyx":2764
 *                 score = 0
 * 
 *             try:             # <<<<<<<<<<<<<<
 *                 color = self.attr.get("color", "#000000")
 *                 if isinstance(color, str):
 */
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_6, __pyx_t_5);
      goto __pyx_L1_error;
      __pyx_L16_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_6, __pyx_t_5);
      __pyx_L20_try_end:;
    }

    /* "plastid/genomics/roitools.pyx":2780
 *                 color = self.attr.get("color", "0,0,0") if color is None else color
 * 
 *             thickstart = self.attr.get("thickstart", spanstart) if thickstart is None else thickstart             # <<<<<<<<<<<<<<
 *             thickend   = self.attr.get("thickend", spanstart)   if thickend   is None else thickend
 * 
 */
    __pyx_t_4 = (__pyx_v_thickstart == Py_None);
    if ((__pyx_t_4 != 0)) {
      if (unlikely(__pyx_v_self->attr == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
        __PYX_ERR(0, 2780, __pyx_L1_error)
      }
      __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_v_spanstart); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2780, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_thickstart, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2780, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_11 = __pyx_t_1;
      __pyx_t_1 = 0;
    } else {
      __Pyx_INCREF(__pyx_v_thickstart);
      __pyx_t_11 = __pyx_v_thickstart;
    }
    __Pyx_DECREF_SET(__pyx_v_thickstart, __pyx_t_11);
    __pyx_t_11 = 0;

    /* "plastid/genomics/roitools.pyx":2781
 * 
 *             thickstart = self.attr.get("thickstart", spanstart) if thickstart is None else thickstart
 *             thickend   = self.attr.get("thickend", spanstart)   if thickend   is None else thickend             # <<<<<<<<<<<<<<
 * 
 *             ltmp = [
 */
    __pyx_t_4 = (__pyx_v_thickend == Py_None);
    if ((__pyx_t_4 != 0)) {
      if (unlikely(__pyx_v_self->attr == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
        __PYX_ERR(0, 2781, __pyx_L1_error)
      }
      __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_spanstart); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2781, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_9 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_thickend, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2781, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_11 = __pyx_t_9;
      __pyx_t_9 = 0;
    } else {
      __Pyx_INCREF(__pyx_v_thickend);
      __pyx_t_11 = __pyx_v_thickend;
    }
    __Pyx_DECREF_SET(__pyx_v_thickend, __pyx_t_11);
    __pyx_t_11 = 0;

    /* "plastid/genomics/roitools.pyx":2785
 *             ltmp = [
 *                 span.chrom,
 *                 spanstart,             # <<<<<<<<<<<<<<
 *                 span.end,
 *                 self.get_name(),
 */
    __pyx_t_11 = __Pyx_PyInt_From_long(__pyx_v_spanstart); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2785, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);

    /* "plastid/genomics/roitools.pyx":2786
 *                 span.chrom,
 *                 spanstart,
 *                 span.end,             # <<<<<<<<<<<<<<
 *                 self.get_name(),
 *                 score,
 */
    __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_v_span->end); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2786, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);

    /* "plastid/genomics/roitools.pyx":2787
 *                 spanstart,
 *                 span.end,
 *                 self.get_name(),             # <<<<<<<<<<<<<<
 *                 score,
 *                 span.strand,
 */
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2787, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_13 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12);
      if (likely(__pyx_t_13)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
        __Pyx_INCREF(__pyx_t_13);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_12, function);
      }
    }
    __pyx_t_1 = (__pyx_t_13) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_13) : __Pyx_PyObject_CallNoArg(__pyx_t_12);
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2787, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

    /* "plastid/genomics/roitools.pyx":2789
 *                 self.get_name(),
 *                 score,
 *                 span.strand,             # <<<<<<<<<<<<<<
 *                 thickstart,
 *                 thickend,
 */
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_span), __pyx_n_s_strand); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2789, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);

    /* "plastid/genomics/roitools.pyx":2793
 *                 thickend,
 *                 color,
 *                 len(self),             # <<<<<<<<<<<<<<
 *                 ",".join([str(len(X)) for X in self]) + ",",
 *                 ",".join([str(X.start - self[0].start) for X in self]) + ",",
 */
    __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2793, __pyx_L1_error)
    __pyx_t_13 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2793, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);

    /* "plastid/genomics/roitools.pyx":2794
 *                 color,
 *                 len(self),
 *                 ",".join([str(len(X)) for X in self]) + ",",             # <<<<<<<<<<<<<<
 *                 ",".join([str(X.start - self[0].start) for X in self]) + ",",
 *             ]
 */
    { /* enter inner scope */
      __pyx_t_14 = PyList_New(0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2794, __pyx_L30_error)
      __Pyx_GOTREF(__pyx_t_14);
      if (likely(PyList_CheckExact(((PyObject *)__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_v_self))) {
        __pyx_t_15 = ((PyObject *)__pyx_v_self); __Pyx_INCREF(__pyx_t_15); __pyx_t_3 = 0;
        __pyx_t_16 = NULL;
      } else {
        __pyx_t_3 = -1; __pyx_t_15 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2794, __pyx_L30_error)
        __Pyx_GOTREF(__pyx_t_15);
        __pyx_t_16 = Py_TYPE(__pyx_t_15)->tp_iternext; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 2794, __pyx_L30_error)
      }
      for (;;) {
        if (likely(!__pyx_t_16)) {
          if (likely(PyList_CheckExact(__pyx_t_15))) {
            if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_15)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_17 = PyList_GET_ITEM(__pyx_t_15, __pyx_t_3); __Pyx_INCREF(__pyx_t_17); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2794, __pyx_L30_error)
            #else
            __pyx_t_17 = PySequence_ITEM(__pyx_t_15, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2794, __pyx_L30_error)
            __Pyx_GOTREF(__pyx_t_17);
            #endif
          } else {
            if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_15)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_17 = PyTuple_GET_ITEM(__pyx_t_15, __pyx_t_3); __Pyx_INCREF(__pyx_t_17); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2794, __pyx_L30_error)
            #else
            __pyx_t_17 = PySequence_ITEM(__pyx_t_15, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2794, __pyx_L30_error)
            __Pyx_GOTREF(__pyx_t_17);
            #endif
          }
        } else {
          __pyx_t_17 = __pyx_t_16(__pyx_t_15);
          if (unlikely(!__pyx_t_17)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 2794, __pyx_L30_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_17);
        }
        __Pyx_XDECREF_SET(__pyx_9genexpr15__pyx_v_X, __pyx_t_17);
        __pyx_t_17 = 0;
        __pyx_t_18 = PyObject_Length(__pyx_9genexpr15__pyx_v_X); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2794, __pyx_L30_error)
        __pyx_t_17 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2794, __pyx_L30_error)
        __Pyx_GOTREF(__pyx_t_17);
        __pyx_t_19 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_17); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2794, __pyx_L30_error)
        __Pyx_GOTREF(__pyx_t_19);
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_14, (PyObject*)__pyx_t_19))) __PYX_ERR(0, 2794, __pyx_L30_error)
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      }
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_XDECREF(__pyx_9genexpr15__pyx_v_X); __pyx_9genexpr15__pyx_v_X = 0;
      goto __pyx_L33_exit_scope;
      __pyx_L30_error:;
      __Pyx_XDECREF(__pyx_9genexpr15__pyx_v_X); __pyx_9genexpr15__pyx_v_X = 0;
      goto __pyx_L1_error;
      __pyx_L33_exit_scope:;
    } /* exit inner scope */
    __pyx_t_15 = PyUnicode_Join(__pyx_kp_u__3, __pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2794, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __pyx_t_14 = __Pyx_PyUnicode_Concat(__pyx_t_15, __pyx_kp_u__3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2794, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "plastid/genomics/roitools.pyx":2795
 *                 len(self),
 *                 ",".join([str(len(X)) for X in self]) + ",",
 *                 ",".join([str(X.start - self[0].start) for X in self]) + ",",             # <<<<<<<<<<<<<<
 *             ]
 * 
 */
    { /* enter inner scope */
      __pyx_t_15 = PyList_New(0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2795, __pyx_L36_error)
      __Pyx_GOTREF(__pyx_t_15);
      if (likely(PyList_CheckExact(((PyObject *)__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_v_self))) {
        __pyx_t_19 = ((PyObject *)__pyx_v_self); __Pyx_INCREF(__pyx_t_19); __pyx_t_3 = 0;
        __pyx_t_16 = NULL;
      } else {
        __pyx_t_3 = -1; __pyx_t_19 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2795, __pyx_L36_error)
        __Pyx_GOTREF(__pyx_t_19);
        __pyx_t_16 = Py_TYPE(__pyx_t_19)->tp_iternext; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 2795, __pyx_L36_error)
      }
      for (;;) {
        if (likely(!__pyx_t_16)) {
          if (likely(PyList_CheckExact(__pyx_t_19))) {
            if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_19)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_17 = PyList_GET_ITEM(__pyx_t_19, __pyx_t_3); __Pyx_INCREF(__pyx_t_17); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2795, __pyx_L36_error)
            #else
            __pyx_t_17 = PySequence_ITEM(__pyx_t_19, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2795, __pyx_L36_error)
            __Pyx_GOTREF(__pyx_t_17);
            #endif
          } else {
            if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_19)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_17 = PyTuple_GET_ITEM(__pyx_t_19, __pyx_t_3); __Pyx_INCREF(__pyx_t_17); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2795, __pyx_L36_error)
            #else
            __pyx_t_17 = PySequence_ITEM(__pyx_t_19, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2795, __pyx_L36_error)
            __Pyx_GOTREF(__pyx_t_17);
            #endif
          }
        } else {
          __pyx_t_17 = __pyx_t_16(__pyx_t_19);
          if (unlikely(!__pyx_t_17)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 2795, __pyx_L36_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_17);
        }
        __Pyx_XDECREF_SET(__pyx_9genexpr16__pyx_v_X, __pyx_t_17);
        __pyx_t_17 = 0;
        __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr16__pyx_v_X, __pyx_n_s_start); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2795, __pyx_L36_error)
        __Pyx_GOTREF(__pyx_t_17);
        __pyx_t_20 = __Pyx_GetItemInt(((PyObject *)__pyx_v_self), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2795, __pyx_L36_error)
        __Pyx_GOTREF(__pyx_t_20);
        __pyx_t_21 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_n_s_start); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2795, __pyx_L36_error)
        __Pyx_GOTREF(__pyx_t_21);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        __pyx_t_20 = PyNumber_Subtract(__pyx_t_17, __pyx_t_21); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2795, __pyx_L36_error)
        __Pyx_GOTREF(__pyx_t_20);
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
        __pyx_t_21 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_20); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2795, __pyx_L36_error)
        __Pyx_GOTREF(__pyx_t_21);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_15, (PyObject*)__pyx_t_21))) __PYX_ERR(0, 2795, __pyx_L36_error)
        __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      }
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_XDECREF(__pyx_9genexpr16__pyx_v_X); __pyx_9genexpr16__pyx_v_X = 0;
      goto __pyx_L39_exit_scope;
      __pyx_L36_error:;
      __Pyx_XDECREF(__pyx_9genexpr16__pyx_v_X); __pyx_9genexpr16__pyx_v_X = 0;
      goto __pyx_L1_error;
      __pyx_L39_exit_scope:;
    } /* exit inner scope */
    __pyx_t_19 = PyUnicode_Join(__pyx_kp_u__3, __pyx_t_15); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2795, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = __Pyx_PyUnicode_Concat(__pyx_t_19, __pyx_kp_u__3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2795, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;

    /* "plastid/genomics/roitools.pyx":2783
 *             thickend   = self.attr.get("thickend", spanstart)   if thickend   is None else thickend
 * 
 *             ltmp = [             # <<<<<<<<<<<<<<
 *                 span.chrom,
 *                 spanstart,
 */
    __pyx_t_19 = PyList_New(12); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2783, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_INCREF(__pyx_v_span->chrom);
    __Pyx_GIVEREF(__pyx_v_span->chrom);
    PyList_SET_ITEM(__pyx_t_19, 0, __pyx_v_span->chrom);
    __Pyx_GIVEREF(__pyx_t_11);
    PyList_SET_ITEM(__pyx_t_19, 1, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_9);
    PyList_SET_ITEM(__pyx_t_19, 2, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_1);
    PyList_SET_ITEM(__pyx_t_19, 3, __pyx_t_1);
    __Pyx_INCREF(__pyx_v_score);
    __Pyx_GIVEREF(__pyx_v_score);
    PyList_SET_ITEM(__pyx_t_19, 4, __pyx_v_score);
    __Pyx_GIVEREF(__pyx_t_12);
    PyList_SET_ITEM(__pyx_t_19, 5, __pyx_t_12);
    __Pyx_INCREF(__pyx_v_thickstart);
    __Pyx_GIVEREF(__pyx_v_thickstart);
    PyList_SET_ITEM(__pyx_t_19, 6, __pyx_v_thickstart);
    __Pyx_INCREF(__pyx_v_thickend);
    __Pyx_GIVEREF(__pyx_v_thickend);
    PyList_SET_ITEM(__pyx_t_19, 7, __pyx_v_thickend);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_color);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_color);
    PyList_SET_ITEM(__pyx_t_19, 8, __pyx_cur_scope->__pyx_v_color);
    __Pyx_GIVEREF(__pyx_t_13);
    PyList_SET_ITEM(__pyx_t_19, 9, __pyx_t_13);
    __Pyx_GIVEREF(__pyx_t_14);
    PyList_SET_ITEM(__pyx_t_19, 10, __pyx_t_14);
    __Pyx_GIVEREF(__pyx_t_15);
    PyList_SET_ITEM(__pyx_t_19, 11, __pyx_t_15);
    __pyx_t_11 = 0;
    __pyx_t_9 = 0;
    __pyx_t_1 = 0;
    __pyx_t_12 = 0;
    __pyx_t_13 = 0;
    __pyx_t_14 = 0;
    __pyx_t_15 = 0;
    __pyx_v_ltmp = ((PyObject*)__pyx_t_19);
    __pyx_t_19 = 0;

    /* "plastid/genomics/roitools.pyx":2798
 *             ]
 * 
 *             if extra_columns is None:             # <<<<<<<<<<<<<<
 *                 extra_columns = self.attr.get("_bedx_column_order", [])
 * 
 */
    __pyx_t_4 = (__pyx_v_extra_columns == Py_None);
    __pyx_t_8 = (__pyx_t_4 != 0);
    if (__pyx_t_8) {

      /* "plastid/genomics/roitools.pyx":2799
 * 
 *             if extra_columns is None:
 *                 extra_columns = self.attr.get("_bedx_column_order", [])             # <<<<<<<<<<<<<<
 * 
 *             if len(extra_columns) > 0:
 */
      if (unlikely(__pyx_v_self->attr == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
        __PYX_ERR(0, 2799, __pyx_L1_error)
      }
      __pyx_t_19 = PyList_New(0); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2799, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
      __pyx_t_15 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_n_u_bedx_column_order, __pyx_t_19); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2799, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_DECREF_SET(__pyx_v_extra_columns, __pyx_t_15);
      __pyx_t_15 = 0;

      /* "plastid/genomics/roitools.pyx":2798
 *             ]
 * 
 *             if extra_columns is None:             # <<<<<<<<<<<<<<
 *                 extra_columns = self.attr.get("_bedx_column_order", [])
 * 
 */
    }

    /* "plastid/genomics/roitools.pyx":2801
 *                 extra_columns = self.attr.get("_bedx_column_order", [])
 * 
 *             if len(extra_columns) > 0:             # <<<<<<<<<<<<<<
 *                 ltmp.extend([self.attr.get(X, empty_value) for X in extra_columns])
 * 
 */
    __pyx_t_3 = PyObject_Length(__pyx_v_extra_columns); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2801, __pyx_L1_error)
    __pyx_t_8 = ((__pyx_t_3 > 0) != 0);
    if (__pyx_t_8) {

      /* "plastid/genomics/roitools.pyx":2802
 * 
 *             if len(extra_columns) > 0:
 *                 ltmp.extend([self.attr.get(X, empty_value) for X in extra_columns])             # <<<<<<<<<<<<<<
 * 
 *             return "\t".join([str(X) for X in ltmp]) + "\n"
 */
      { /* enter inner scope */
        __pyx_t_15 = PyList_New(0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2802, __pyx_L44_error)
        __Pyx_GOTREF(__pyx_t_15);
        if (likely(PyList_CheckExact(__pyx_v_extra_columns)) || PyTuple_CheckExact(__pyx_v_extra_columns)) {
          __pyx_t_19 = __pyx_v_extra_columns; __Pyx_INCREF(__pyx_t_19); __pyx_t_3 = 0;
          __pyx_t_16 = NULL;
        } else {
          __pyx_t_3 = -1; __pyx_t_19 = PyObject_GetIter(__pyx_v_extra_columns); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2802, __pyx_L44_error)
          __Pyx_GOTREF(__pyx_t_19);
          __pyx_t_16 = Py_TYPE(__pyx_t_19)->tp_iternext; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 2802, __pyx_L44_error)
        }
        for (;;) {
          if (likely(!__pyx_t_16)) {
            if (likely(PyList_CheckExact(__pyx_t_19))) {
              if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_19)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_14 = PyList_GET_ITEM(__pyx_t_19, __pyx_t_3); __Pyx_INCREF(__pyx_t_14); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2802, __pyx_L44_error)
              #else
              __pyx_t_14 = PySequence_ITEM(__pyx_t_19, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2802, __pyx_L44_error)
              __Pyx_GOTREF(__pyx_t_14);
              #endif
            } else {
              if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_19)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_19, __pyx_t_3); __Pyx_INCREF(__pyx_t_14); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2802, __pyx_L44_error)
              #else
              __pyx_t_14 = PySequence_ITEM(__pyx_t_19, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2802, __pyx_L44_error)
              __Pyx_GOTREF(__pyx_t_14);
              #endif
            }
          } else {
            __pyx_t_14 = __pyx_t_16(__pyx_t_19);
            if (unlikely(!__pyx_t_14)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 2802, __pyx_L44_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_14);
          }
          __Pyx_XDECREF_SET(__pyx_9genexpr17__pyx_v_X, __pyx_t_14);
          __pyx_t_14 = 0;
          if (unlikely(__pyx_v_self->attr == Py_None)) {
            PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
            __PYX_ERR(0, 2802, __pyx_L44_error)
          }
          __pyx_t_14 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->attr, __pyx_9genexpr17__pyx_v_X, __pyx_v_empty_value); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2802, __pyx_L44_error)
          __Pyx_GOTREF(__pyx_t_14);
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_15, (PyObject*)__pyx_t_14))) __PYX_ERR(0, 2802, __pyx_L44_error)
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        }
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_XDECREF(__pyx_9genexpr17__pyx_v_X); __pyx_9genexpr17__pyx_v_X = 0;
        goto __pyx_L47_exit_scope;
        __pyx_L44_error:;
        __Pyx_XDECREF(__pyx_9genexpr17__pyx_v_X); __pyx_9genexpr17__pyx_v_X = 0;
        goto __pyx_L1_error;
        __pyx_L47_exit_scope:;
      } /* exit inner scope */
      __pyx_t_22 = __Pyx_PyList_Extend(__pyx_v_ltmp, __pyx_t_15); if (unlikely(__pyx_t_22 == ((int)-1))) __PYX_ERR(0, 2802, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

      /* "plastid/genomics/roitools.pyx":2801
 *                 extra_columns = self.attr.get("_bedx_column_order", [])
 * 
 *             if len(extra_columns) > 0:             # <<<<<<<<<<<<<<
 *                 ltmp.extend([self.attr.get(X, empty_value) for X in extra_columns])
 * 
 */
    }

    /* "plastid/genomics/roitools.pyx":2804
 *                 ltmp.extend([self.attr.get(X, empty_value) for X in extra_columns])
 * 
 *             return "\t".join([str(X) for X in ltmp]) + "\n"             # <<<<<<<<<<<<<<
 *         else:
 *             # SegmentChain with no intervals
 */
    __Pyx_XDECREF(__pyx_r);
    { /* enter inner scope */
      __pyx_t_15 = PyList_New(0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2804, __pyx_L50_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_19 = __pyx_v_ltmp; __Pyx_INCREF(__pyx_t_19); __pyx_t_3 = 0;
      for (;;) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_19)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_14 = PyList_GET_ITEM(__pyx_t_19, __pyx_t_3); __Pyx_INCREF(__pyx_t_14); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2804, __pyx_L50_error)
        #else
        __pyx_t_14 = PySequence_ITEM(__pyx_t_19, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2804, __pyx_L50_error)
        __Pyx_GOTREF(__pyx_t_14);
        #endif
        __Pyx_XDECREF_SET(__pyx_9genexpr18__pyx_v_X, __pyx_t_14);
        __pyx_t_14 = 0;
        __pyx_t_14 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_9genexpr18__pyx_v_X); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2804, __pyx_L50_error)
        __Pyx_GOTREF(__pyx_t_14);
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_15, (PyObject*)__pyx_t_14))) __PYX_ERR(0, 2804, __pyx_L50_error)
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      }
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_XDECREF(__pyx_9genexpr18__pyx_v_X); __pyx_9genexpr18__pyx_v_X = 0;
      goto __pyx_L53_exit_scope;
      __pyx_L50_error:;
      __Pyx_XDECREF(__pyx_9genexpr18__pyx_v_X); __pyx_9genexpr18__pyx_v_X = 0;
      goto __pyx_L1_error;
      __pyx_L53_exit_scope:;
    } /* exit inner scope */
    __pyx_t_19 = PyUnicode_Join(__pyx_kp_u__19, __pyx_t_15); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2804, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = __Pyx_PyUnicode_Concat(__pyx_t_19, __pyx_kp_u__18); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2804, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
    __pyx_r = __pyx_t_15;
    __pyx_t_15 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":2753
 *             long spanstart = span.start
 * 
 *         if len(self) > 0:             # <<<<<<<<<<<<<<
 *             score = self.attr.get("score", 0)
 *             try:
 */
  }

  /* "plastid/genomics/roitools.pyx":2807
 *         else:
 *             # SegmentChain with no intervals
 *             return ""             # <<<<<<<<<<<<<<
 * 
 *     def as_psl(self):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_kp_u__33);
    __pyx_r = __pyx_kp_u__33;
    goto __pyx_L0;
  }

  /* "plastid/genomics/roitools.pyx":2669
 * 
 *     # TODO: optimize
 *     def as_bed(             # <<<<<<<<<<<<<<
 *         self,
 *         thickstart    = None,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ltmp);
  __Pyx_XDECREF((PyObject *)__pyx_v_span);
  __Pyx_XDECREF(__pyx_v_score);
  __Pyx_XDECREF(__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_2generator);
  __Pyx_XDECREF(__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_5generator1);
  __Pyx_XDECREF(__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_8generator2);
  __Pyx_XDECREF(__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_bed_11generator3);
  __Pyx_XDECREF(__pyx_9genexpr15__pyx_v_X);
  __Pyx_XDECREF(__pyx_9genexpr16__pyx_v_X);
  __Pyx_XDECREF(__pyx_9genexpr17__pyx_v_X);
  __Pyx_XDECREF(__pyx_9genexpr18__pyx_v_X);
  __Pyx_XDECREF(__pyx_v_thickstart);
  __Pyx_XDECREF(__pyx_v_thickend);
  __Pyx_XDECREF(__pyx_v_extra_columns);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2809
 *             return ""
 * 
 *     def as_psl(self):             # <<<<<<<<<<<<<<
 *         """Formats |SegmentChain| as `PSL`_ (blat) output.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_77as_psl(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_76as_psl[] = "SegmentChain.as_psl(self)\nFormats |SegmentChain| as `PSL`_ (blat) output.\n\n        Notes\n        -----\n        This will raise an :py:class:`AttributeError` unless the following\n        keys are present and defined in `self.attr`, corresponding to the\n        columns of a `PSL`_ file:\n\n            ======  ===================================\n            Column  Key\n            ======  ===================================\n                1   ``match_length``\n                2   ``mismatches``\n                3   ``rep_matches``\n                4   ``N``\n                5   ``query_gap_count``\n                6   ``query_gap_bases``\n                7   ``target_gap_count``\n                8   ``target_gap_bases``\n                9   ``strand``\n                10  ``query_name``\n                11  ``query_length``\n                12  ``query_start``\n                13  ``query_end``\n                14  ``target_name``\n                15  ``target_length``\n                16  ``target_start``\n                17  ``target_end``\n                19  ``q_starts`` : list of integers\n                20  ``l_starts`` : list of integers\n            ======  ===================================\n\n        These keys are defined only if the |SegmentChain| was created by\n        :py:meth:`SegmentChain.from_psl`, or if the user has defined them.\n\n        See the `PSL spec <http://pombe.nci.nih.gov/genome/goldenPath/help/blatSpec.html>`_\n        for more information.\n\n\n        Returns\n        -------\n        str\n            PSL-representation of BLAT alignment\n\n\n        Raises\n        ------\n        AttributeError\n            If not all of the attributes listed above are defined\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_77as_psl(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("as_psl (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_76as_psl(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_psl_2generator4(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "plastid/genomics/roitools.pyx":2893
 *             ltmp.append(q_starts)
 *             ltmp.append(t_starts)
 *             return "\t".join(str(X) for X in ltmp) + "\n"             # <<<<<<<<<<<<<<
 *         except KeyError:
 *             raise AttributeError(
 */

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_psl_genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr *)__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr(__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2893, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_psl_2generator4, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_as_psl_locals_genexpr, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!gen)) __PYX_ERR(0, 2893, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_psl.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_psl_2generator4(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr *__pyx_cur_scope = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_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("genexpr", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2893, __pyx_L1_error)
  __pyx_r = PyList_New(0); if (unlikely(!__pyx_r)) __PYX_ERR(0, 2893, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_r);
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_ltmp)) { __Pyx_RaiseClosureNameError("ltmp"); __PYX_ERR(0, 2893, __pyx_L1_error) }
  if (unlikely(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_ltmp == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 2893, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_ltmp; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2893, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2893, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #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_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_cur_scope->__pyx_v_X); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2893, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (unlikely(__Pyx_ListComp_Append(__pyx_r, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 2893, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2809
 *             return ""
 * 
 *     def as_psl(self):             # <<<<<<<<<<<<<<
 *         """Formats |SegmentChain| as `PSL`_ (blat) output.
 * 
 */

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_76as_psl(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl *__pyx_cur_scope;
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_v_block_sizes = 0;
  PyObject *__pyx_v_q_starts = 0;
  PyObject *__pyx_v_t_starts = 0;
  PyObject *__pyx_9genexpr19__pyx_v_X = NULL;
  PyObject *__pyx_9genexpr20__pyx_v_X = NULL;
  PyObject *__pyx_9genexpr21__pyx_v_X = NULL;
  PyObject *__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_psl_2generator4 = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  Py_ssize_t __pyx_t_21;
  PyObject *__pyx_t_22 = NULL;
  PyObject *__pyx_t_23 = NULL;
  PyObject *(*__pyx_t_24)(PyObject *);
  Py_ssize_t __pyx_t_25;
  int __pyx_t_26;
  int __pyx_t_27;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("as_psl", 0);
  __pyx_cur_scope = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl *)__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl(__pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2809, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }

  /* "plastid/genomics/roitools.pyx":2861
 *         """
 *         cdef:
 *             dict attr = self.attr             # <<<<<<<<<<<<<<
 *             list ltmp
 *             str block_sizes, q_starts, t_starts
 */
  __pyx_t_1 = __pyx_v_self->attr;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2864
 *             list ltmp
 *             str block_sizes, q_starts, t_starts
 *         try:             # <<<<<<<<<<<<<<
 *             ltmp = [
 *                 attr["match_length"],
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_4);
    /*try:*/ {

      /* "plastid/genomics/roitools.pyx":2866
 *         try:
 *             ltmp = [
 *                 attr["match_length"],             # <<<<<<<<<<<<<<
 *                 attr["mismatches"],
 *                 attr["rep_matches"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2866, __pyx_L3_error)
      }
      __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_match_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2866, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_1);

      /* "plastid/genomics/roitools.pyx":2867
 *             ltmp = [
 *                 attr["match_length"],
 *                 attr["mismatches"],             # <<<<<<<<<<<<<<
 *                 attr["rep_matches"],
 *                 attr["N"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2867, __pyx_L3_error)
      }
      __pyx_t_5 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_mismatches); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2867, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);

      /* "plastid/genomics/roitools.pyx":2868
 *                 attr["match_length"],
 *                 attr["mismatches"],
 *                 attr["rep_matches"],             # <<<<<<<<<<<<<<
 *                 attr["N"],
 *                 attr["query_gap_count"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2868, __pyx_L3_error)
      }
      __pyx_t_6 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_rep_matches); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2868, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);

      /* "plastid/genomics/roitools.pyx":2869
 *                 attr["mismatches"],
 *                 attr["rep_matches"],
 *                 attr["N"],             # <<<<<<<<<<<<<<
 *                 attr["query_gap_count"],
 *                 attr["query_gap_bases"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2869, __pyx_L3_error)
      }
      __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_N); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2869, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);

      /* "plastid/genomics/roitools.pyx":2870
 *                 attr["rep_matches"],
 *                 attr["N"],
 *                 attr["query_gap_count"],             # <<<<<<<<<<<<<<
 *                 attr["query_gap_bases"],
 *                 attr["target_gap_count"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2870, __pyx_L3_error)
      }
      __pyx_t_8 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_query_gap_count); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2870, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);

      /* "plastid/genomics/roitools.pyx":2871
 *                 attr["N"],
 *                 attr["query_gap_count"],
 *                 attr["query_gap_bases"],             # <<<<<<<<<<<<<<
 *                 attr["target_gap_count"],
 *                 attr["target_gap_bases"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2871, __pyx_L3_error)
      }
      __pyx_t_9 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_query_gap_bases); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2871, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);

      /* "plastid/genomics/roitools.pyx":2872
 *                 attr["query_gap_count"],
 *                 attr["query_gap_bases"],
 *                 attr["target_gap_count"],             # <<<<<<<<<<<<<<
 *                 attr["target_gap_bases"],
 *                 attr["strand"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2872, __pyx_L3_error)
      }
      __pyx_t_10 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_target_gap_count); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2872, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_10);

      /* "plastid/genomics/roitools.pyx":2873
 *                 attr["query_gap_bases"],
 *                 attr["target_gap_count"],
 *                 attr["target_gap_bases"],             # <<<<<<<<<<<<<<
 *                 attr["strand"],
 *                 attr["query_name"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2873, __pyx_L3_error)
      }
      __pyx_t_11 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_target_gap_bases); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2873, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_11);

      /* "plastid/genomics/roitools.pyx":2874
 *                 attr["target_gap_count"],
 *                 attr["target_gap_bases"],
 *                 attr["strand"],             # <<<<<<<<<<<<<<
 *                 attr["query_name"],
 *                 attr["query_length"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2874, __pyx_L3_error)
      }
      __pyx_t_12 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_strand); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2874, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_12);

      /* "plastid/genomics/roitools.pyx":2875
 *                 attr["target_gap_bases"],
 *                 attr["strand"],
 *                 attr["query_name"],             # <<<<<<<<<<<<<<
 *                 attr["query_length"],
 *                 attr["query_start"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2875, __pyx_L3_error)
      }
      __pyx_t_13 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_query_name); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2875, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_13);

      /* "plastid/genomics/roitools.pyx":2876
 *                 attr["strand"],
 *                 attr["query_name"],
 *                 attr["query_length"],             # <<<<<<<<<<<<<<
 *                 attr["query_start"],
 *                 attr["query_end"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2876, __pyx_L3_error)
      }
      __pyx_t_14 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_query_length); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2876, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_14);

      /* "plastid/genomics/roitools.pyx":2877
 *                 attr["query_name"],
 *                 attr["query_length"],
 *                 attr["query_start"],             # <<<<<<<<<<<<<<
 *                 attr["query_end"],
 *                 attr["target_name"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2877, __pyx_L3_error)
      }
      __pyx_t_15 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_query_start); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2877, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_15);

      /* "plastid/genomics/roitools.pyx":2878
 *                 attr["query_length"],
 *                 attr["query_start"],
 *                 attr["query_end"],             # <<<<<<<<<<<<<<
 *                 attr["target_name"],
 *                 attr["target_length"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2878, __pyx_L3_error)
      }
      __pyx_t_16 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_query_end); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 2878, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_16);

      /* "plastid/genomics/roitools.pyx":2879
 *                 attr["query_start"],
 *                 attr["query_end"],
 *                 attr["target_name"],             # <<<<<<<<<<<<<<
 *                 attr["target_length"],
 *                 attr["target_start"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2879, __pyx_L3_error)
      }
      __pyx_t_17 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_target_name); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2879, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_17);

      /* "plastid/genomics/roitools.pyx":2880
 *                 attr["query_end"],
 *                 attr["target_name"],
 *                 attr["target_length"],             # <<<<<<<<<<<<<<
 *                 attr["target_start"],
 *                 attr["target_end"],
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2880, __pyx_L3_error)
      }
      __pyx_t_18 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_target_length); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 2880, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_18);

      /* "plastid/genomics/roitools.pyx":2881
 *                 attr["target_name"],
 *                 attr["target_length"],
 *                 attr["target_start"],             # <<<<<<<<<<<<<<
 *                 attr["target_end"],
 *                 len(self),
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2881, __pyx_L3_error)
      }
      __pyx_t_19 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_target_start); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2881, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_19);

      /* "plastid/genomics/roitools.pyx":2882
 *                 attr["target_length"],
 *                 attr["target_start"],
 *                 attr["target_end"],             # <<<<<<<<<<<<<<
 *                 len(self),
 *             ]
 */
      if (unlikely(__pyx_v_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 2882, __pyx_L3_error)
      }
      __pyx_t_20 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_target_end); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2882, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_20);

      /* "plastid/genomics/roitools.pyx":2883
 *                 attr["target_start"],
 *                 attr["target_end"],
 *                 len(self),             # <<<<<<<<<<<<<<
 *             ]
 * 
 */
      __pyx_t_21 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_21 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2883, __pyx_L3_error)
      __pyx_t_22 = PyInt_FromSsize_t(__pyx_t_21); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2883, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_22);

      /* "plastid/genomics/roitools.pyx":2865
 *             str block_sizes, q_starts, t_starts
 *         try:
 *             ltmp = [             # <<<<<<<<<<<<<<
 *                 attr["match_length"],
 *                 attr["mismatches"],
 */
      __pyx_t_23 = PyList_New(18); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 2865, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_23);
      __Pyx_GIVEREF(__pyx_t_1);
      PyList_SET_ITEM(__pyx_t_23, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_5);
      PyList_SET_ITEM(__pyx_t_23, 1, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_6);
      PyList_SET_ITEM(__pyx_t_23, 2, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_7);
      PyList_SET_ITEM(__pyx_t_23, 3, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_8);
      PyList_SET_ITEM(__pyx_t_23, 4, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_9);
      PyList_SET_ITEM(__pyx_t_23, 5, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_10);
      PyList_SET_ITEM(__pyx_t_23, 6, __pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_11);
      PyList_SET_ITEM(__pyx_t_23, 7, __pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_12);
      PyList_SET_ITEM(__pyx_t_23, 8, __pyx_t_12);
      __Pyx_GIVEREF(__pyx_t_13);
      PyList_SET_ITEM(__pyx_t_23, 9, __pyx_t_13);
      __Pyx_GIVEREF(__pyx_t_14);
      PyList_SET_ITEM(__pyx_t_23, 10, __pyx_t_14);
      __Pyx_GIVEREF(__pyx_t_15);
      PyList_SET_ITEM(__pyx_t_23, 11, __pyx_t_15);
      __Pyx_GIVEREF(__pyx_t_16);
      PyList_SET_ITEM(__pyx_t_23, 12, __pyx_t_16);
      __Pyx_GIVEREF(__pyx_t_17);
      PyList_SET_ITEM(__pyx_t_23, 13, __pyx_t_17);
      __Pyx_GIVEREF(__pyx_t_18);
      PyList_SET_ITEM(__pyx_t_23, 14, __pyx_t_18);
      __Pyx_GIVEREF(__pyx_t_19);
      PyList_SET_ITEM(__pyx_t_23, 15, __pyx_t_19);
      __Pyx_GIVEREF(__pyx_t_20);
      PyList_SET_ITEM(__pyx_t_23, 16, __pyx_t_20);
      __Pyx_GIVEREF(__pyx_t_22);
      PyList_SET_ITEM(__pyx_t_23, 17, __pyx_t_22);
      __pyx_t_1 = 0;
      __pyx_t_5 = 0;
      __pyx_t_6 = 0;
      __pyx_t_7 = 0;
      __pyx_t_8 = 0;
      __pyx_t_9 = 0;
      __pyx_t_10 = 0;
      __pyx_t_11 = 0;
      __pyx_t_12 = 0;
      __pyx_t_13 = 0;
      __pyx_t_14 = 0;
      __pyx_t_15 = 0;
      __pyx_t_16 = 0;
      __pyx_t_17 = 0;
      __pyx_t_18 = 0;
      __pyx_t_19 = 0;
      __pyx_t_20 = 0;
      __pyx_t_22 = 0;
      __Pyx_GIVEREF(__pyx_t_23);
      __pyx_cur_scope->__pyx_v_ltmp = ((PyObject*)__pyx_t_23);
      __pyx_t_23 = 0;

      /* "plastid/genomics/roitools.pyx":2886
 *             ]
 * 
 *             block_sizes = ",".join([str(len(X)) for X in self]) + ","             # <<<<<<<<<<<<<<
 *             q_starts = ",".join([str(X) for X in self.attr["q_starts"]]) + ","
 *             t_starts = ",".join([str(X) for X in self.attr["t_starts"]]) + ","
 */
      { /* enter inner scope */
        __pyx_t_23 = PyList_New(0); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 2886, __pyx_L11_error)
        __Pyx_GOTREF(__pyx_t_23);
        if (likely(PyList_CheckExact(((PyObject *)__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_v_self))) {
          __pyx_t_22 = ((PyObject *)__pyx_v_self); __Pyx_INCREF(__pyx_t_22); __pyx_t_21 = 0;
          __pyx_t_24 = NULL;
        } else {
          __pyx_t_21 = -1; __pyx_t_22 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2886, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_22);
          __pyx_t_24 = Py_TYPE(__pyx_t_22)->tp_iternext; if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 2886, __pyx_L11_error)
        }
        for (;;) {
          if (likely(!__pyx_t_24)) {
            if (likely(PyList_CheckExact(__pyx_t_22))) {
              if (__pyx_t_21 >= PyList_GET_SIZE(__pyx_t_22)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_20 = PyList_GET_ITEM(__pyx_t_22, __pyx_t_21); __Pyx_INCREF(__pyx_t_20); __pyx_t_21++; if (unlikely(0 < 0)) __PYX_ERR(0, 2886, __pyx_L11_error)
              #else
              __pyx_t_20 = PySequence_ITEM(__pyx_t_22, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2886, __pyx_L11_error)
              __Pyx_GOTREF(__pyx_t_20);
              #endif
            } else {
              if (__pyx_t_21 >= PyTuple_GET_SIZE(__pyx_t_22)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_20 = PyTuple_GET_ITEM(__pyx_t_22, __pyx_t_21); __Pyx_INCREF(__pyx_t_20); __pyx_t_21++; if (unlikely(0 < 0)) __PYX_ERR(0, 2886, __pyx_L11_error)
              #else
              __pyx_t_20 = PySequence_ITEM(__pyx_t_22, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2886, __pyx_L11_error)
              __Pyx_GOTREF(__pyx_t_20);
              #endif
            }
          } else {
            __pyx_t_20 = __pyx_t_24(__pyx_t_22);
            if (unlikely(!__pyx_t_20)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 2886, __pyx_L11_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_20);
          }
          __Pyx_XDECREF_SET(__pyx_9genexpr19__pyx_v_X, __pyx_t_20);
          __pyx_t_20 = 0;
          __pyx_t_25 = PyObject_Length(__pyx_9genexpr19__pyx_v_X); if (unlikely(__pyx_t_25 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2886, __pyx_L11_error)
          __pyx_t_20 = PyInt_FromSsize_t(__pyx_t_25); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2886, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_20);
          __pyx_t_19 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_20); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2886, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_19);
          __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_23, (PyObject*)__pyx_t_19))) __PYX_ERR(0, 2886, __pyx_L11_error)
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        }
        __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
        __Pyx_XDECREF(__pyx_9genexpr19__pyx_v_X); __pyx_9genexpr19__pyx_v_X = 0;
        goto __pyx_L14_exit_scope;
        __pyx_L11_error:;
        __Pyx_XDECREF(__pyx_9genexpr19__pyx_v_X); __pyx_9genexpr19__pyx_v_X = 0;
        goto __pyx_L3_error;
        __pyx_L14_exit_scope:;
      } /* exit inner scope */
      __pyx_t_22 = PyUnicode_Join(__pyx_kp_u__3, __pyx_t_23); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2886, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_22);
      __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
      __pyx_t_23 = __Pyx_PyUnicode_Concat(__pyx_t_22, __pyx_kp_u__3); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 2886, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_23);
      __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      __pyx_v_block_sizes = ((PyObject*)__pyx_t_23);
      __pyx_t_23 = 0;

      /* "plastid/genomics/roitools.pyx":2887
 * 
 *             block_sizes = ",".join([str(len(X)) for X in self]) + ","
 *             q_starts = ",".join([str(X) for X in self.attr["q_starts"]]) + ","             # <<<<<<<<<<<<<<
 *             t_starts = ",".join([str(X) for X in self.attr["t_starts"]]) + ","
 * 
 */
      { /* enter inner scope */
        __pyx_t_23 = PyList_New(0); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 2887, __pyx_L17_error)
        __Pyx_GOTREF(__pyx_t_23);
        if (unlikely(__pyx_v_self->attr == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 2887, __pyx_L17_error)
        }
        __pyx_t_22 = __Pyx_PyDict_GetItem(__pyx_v_self->attr, __pyx_n_u_q_starts); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2887, __pyx_L17_error)
        __Pyx_GOTREF(__pyx_t_22);
        if (likely(PyList_CheckExact(__pyx_t_22)) || PyTuple_CheckExact(__pyx_t_22)) {
          __pyx_t_19 = __pyx_t_22; __Pyx_INCREF(__pyx_t_19); __pyx_t_21 = 0;
          __pyx_t_24 = NULL;
        } else {
          __pyx_t_21 = -1; __pyx_t_19 = PyObject_GetIter(__pyx_t_22); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2887, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_19);
          __pyx_t_24 = Py_TYPE(__pyx_t_19)->tp_iternext; if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 2887, __pyx_L17_error)
        }
        __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
        for (;;) {
          if (likely(!__pyx_t_24)) {
            if (likely(PyList_CheckExact(__pyx_t_19))) {
              if (__pyx_t_21 >= PyList_GET_SIZE(__pyx_t_19)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_22 = PyList_GET_ITEM(__pyx_t_19, __pyx_t_21); __Pyx_INCREF(__pyx_t_22); __pyx_t_21++; if (unlikely(0 < 0)) __PYX_ERR(0, 2887, __pyx_L17_error)
              #else
              __pyx_t_22 = PySequence_ITEM(__pyx_t_19, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2887, __pyx_L17_error)
              __Pyx_GOTREF(__pyx_t_22);
              #endif
            } else {
              if (__pyx_t_21 >= PyTuple_GET_SIZE(__pyx_t_19)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_22 = PyTuple_GET_ITEM(__pyx_t_19, __pyx_t_21); __Pyx_INCREF(__pyx_t_22); __pyx_t_21++; if (unlikely(0 < 0)) __PYX_ERR(0, 2887, __pyx_L17_error)
              #else
              __pyx_t_22 = PySequence_ITEM(__pyx_t_19, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2887, __pyx_L17_error)
              __Pyx_GOTREF(__pyx_t_22);
              #endif
            }
          } else {
            __pyx_t_22 = __pyx_t_24(__pyx_t_19);
            if (unlikely(!__pyx_t_22)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 2887, __pyx_L17_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_22);
          }
          __Pyx_XDECREF_SET(__pyx_9genexpr20__pyx_v_X, __pyx_t_22);
          __pyx_t_22 = 0;
          __pyx_t_22 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_9genexpr20__pyx_v_X); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2887, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_22);
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_23, (PyObject*)__pyx_t_22))) __PYX_ERR(0, 2887, __pyx_L17_error)
          __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
        }
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_XDECREF(__pyx_9genexpr20__pyx_v_X); __pyx_9genexpr20__pyx_v_X = 0;
        goto __pyx_L20_exit_scope;
        __pyx_L17_error:;
        __Pyx_XDECREF(__pyx_9genexpr20__pyx_v_X); __pyx_9genexpr20__pyx_v_X = 0;
        goto __pyx_L3_error;
        __pyx_L20_exit_scope:;
      } /* exit inner scope */
      __pyx_t_19 = PyUnicode_Join(__pyx_kp_u__3, __pyx_t_23); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2887, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_19);
      __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
      __pyx_t_23 = __Pyx_PyUnicode_Concat(__pyx_t_19, __pyx_kp_u__3); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 2887, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_23);
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __pyx_v_q_starts = ((PyObject*)__pyx_t_23);
      __pyx_t_23 = 0;

      /* "plastid/genomics/roitools.pyx":2888
 *             block_sizes = ",".join([str(len(X)) for X in self]) + ","
 *             q_starts = ",".join([str(X) for X in self.attr["q_starts"]]) + ","
 *             t_starts = ",".join([str(X) for X in self.attr["t_starts"]]) + ","             # <<<<<<<<<<<<<<
 * 
 *             ltmp.append(block_sizes)
 */
      { /* enter inner scope */
        __pyx_t_23 = PyList_New(0); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 2888, __pyx_L23_error)
        __Pyx_GOTREF(__pyx_t_23);
        if (unlikely(__pyx_v_self->attr == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 2888, __pyx_L23_error)
        }
        __pyx_t_19 = __Pyx_PyDict_GetItem(__pyx_v_self->attr, __pyx_n_u_t_starts); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2888, __pyx_L23_error)
        __Pyx_GOTREF(__pyx_t_19);
        if (likely(PyList_CheckExact(__pyx_t_19)) || PyTuple_CheckExact(__pyx_t_19)) {
          __pyx_t_22 = __pyx_t_19; __Pyx_INCREF(__pyx_t_22); __pyx_t_21 = 0;
          __pyx_t_24 = NULL;
        } else {
          __pyx_t_21 = -1; __pyx_t_22 = PyObject_GetIter(__pyx_t_19); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2888, __pyx_L23_error)
          __Pyx_GOTREF(__pyx_t_22);
          __pyx_t_24 = Py_TYPE(__pyx_t_22)->tp_iternext; if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 2888, __pyx_L23_error)
        }
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        for (;;) {
          if (likely(!__pyx_t_24)) {
            if (likely(PyList_CheckExact(__pyx_t_22))) {
              if (__pyx_t_21 >= PyList_GET_SIZE(__pyx_t_22)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_19 = PyList_GET_ITEM(__pyx_t_22, __pyx_t_21); __Pyx_INCREF(__pyx_t_19); __pyx_t_21++; if (unlikely(0 < 0)) __PYX_ERR(0, 2888, __pyx_L23_error)
              #else
              __pyx_t_19 = PySequence_ITEM(__pyx_t_22, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2888, __pyx_L23_error)
              __Pyx_GOTREF(__pyx_t_19);
              #endif
            } else {
              if (__pyx_t_21 >= PyTuple_GET_SIZE(__pyx_t_22)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_19 = PyTuple_GET_ITEM(__pyx_t_22, __pyx_t_21); __Pyx_INCREF(__pyx_t_19); __pyx_t_21++; if (unlikely(0 < 0)) __PYX_ERR(0, 2888, __pyx_L23_error)
              #else
              __pyx_t_19 = PySequence_ITEM(__pyx_t_22, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2888, __pyx_L23_error)
              __Pyx_GOTREF(__pyx_t_19);
              #endif
            }
          } else {
            __pyx_t_19 = __pyx_t_24(__pyx_t_22);
            if (unlikely(!__pyx_t_19)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 2888, __pyx_L23_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_19);
          }
          __Pyx_XDECREF_SET(__pyx_9genexpr21__pyx_v_X, __pyx_t_19);
          __pyx_t_19 = 0;
          __pyx_t_19 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_9genexpr21__pyx_v_X); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2888, __pyx_L23_error)
          __Pyx_GOTREF(__pyx_t_19);
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_23, (PyObject*)__pyx_t_19))) __PYX_ERR(0, 2888, __pyx_L23_error)
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        }
        __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
        __Pyx_XDECREF(__pyx_9genexpr21__pyx_v_X); __pyx_9genexpr21__pyx_v_X = 0;
        goto __pyx_L26_exit_scope;
        __pyx_L23_error:;
        __Pyx_XDECREF(__pyx_9genexpr21__pyx_v_X); __pyx_9genexpr21__pyx_v_X = 0;
        goto __pyx_L3_error;
        __pyx_L26_exit_scope:;
      } /* exit inner scope */
      __pyx_t_22 = PyUnicode_Join(__pyx_kp_u__3, __pyx_t_23); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2888, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_22);
      __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
      __pyx_t_23 = __Pyx_PyUnicode_Concat(__pyx_t_22, __pyx_kp_u__3); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 2888, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_23);
      __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      __pyx_v_t_starts = ((PyObject*)__pyx_t_23);
      __pyx_t_23 = 0;

      /* "plastid/genomics/roitools.pyx":2890
 *             t_starts = ",".join([str(X) for X in self.attr["t_starts"]]) + ","
 * 
 *             ltmp.append(block_sizes)             # <<<<<<<<<<<<<<
 *             ltmp.append(q_starts)
 *             ltmp.append(t_starts)
 */
      __pyx_t_26 = __Pyx_PyList_Append(__pyx_cur_scope->__pyx_v_ltmp, __pyx_v_block_sizes); if (unlikely(__pyx_t_26 == ((int)-1))) __PYX_ERR(0, 2890, __pyx_L3_error)

      /* "plastid/genomics/roitools.pyx":2891
 * 
 *             ltmp.append(block_sizes)
 *             ltmp.append(q_starts)             # <<<<<<<<<<<<<<
 *             ltmp.append(t_starts)
 *             return "\t".join(str(X) for X in ltmp) + "\n"
 */
      __pyx_t_26 = __Pyx_PyList_Append(__pyx_cur_scope->__pyx_v_ltmp, __pyx_v_q_starts); if (unlikely(__pyx_t_26 == ((int)-1))) __PYX_ERR(0, 2891, __pyx_L3_error)

      /* "plastid/genomics/roitools.pyx":2892
 *             ltmp.append(block_sizes)
 *             ltmp.append(q_starts)
 *             ltmp.append(t_starts)             # <<<<<<<<<<<<<<
 *             return "\t".join(str(X) for X in ltmp) + "\n"
 *         except KeyError:
 */
      __pyx_t_26 = __Pyx_PyList_Append(__pyx_cur_scope->__pyx_v_ltmp, __pyx_v_t_starts); if (unlikely(__pyx_t_26 == ((int)-1))) __PYX_ERR(0, 2892, __pyx_L3_error)

      /* "plastid/genomics/roitools.pyx":2893
 *             ltmp.append(q_starts)
 *             ltmp.append(t_starts)
 *             return "\t".join(str(X) for X in ltmp) + "\n"             # <<<<<<<<<<<<<<
 *         except KeyError:
 *             raise AttributeError(
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_23 = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6as_psl_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 2893, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_23);
      __pyx_t_22 = __Pyx_Generator_Next(__pyx_t_23); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2893, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_22);
      __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
      __pyx_t_23 = PyUnicode_Join(__pyx_kp_u__19, __pyx_t_22); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 2893, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_23);
      __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      __pyx_t_22 = __Pyx_PyUnicode_Concat(__pyx_t_23, __pyx_kp_u__18); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2893, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_22);
      __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
      __pyx_r = __pyx_t_22;
      __pyx_t_22 = 0;
      goto __pyx_L7_try_return;

      /* "plastid/genomics/roitools.pyx":2864
 *             list ltmp
 *             str block_sizes, q_starts, t_starts
 *         try:             # <<<<<<<<<<<<<<
 *             ltmp = [
 *                 attr["match_length"],
 */
    }
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 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;
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
    __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
    __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
    __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0;
    __Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "plastid/genomics/roitools.pyx":2894
 *             ltmp.append(t_starts)
 *             return "\t".join(str(X) for X in ltmp) + "\n"
 *         except KeyError:             # <<<<<<<<<<<<<<
 *             raise AttributeError(
 *                 "SegmentChains only support PSL output if all PSL attributes are defined in self.attr: match_length, mismatches, rep_matches, N, query_gap_count, query_gap_bases, strand, query_length, query_start, query_end, target_name, target_length, target_start, target_end"
 */
    __pyx_t_27 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
    if (__pyx_t_27) {
      __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_psl", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_22, &__pyx_t_23, &__pyx_t_19) < 0) __PYX_ERR(0, 2894, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_22);
      __Pyx_GOTREF(__pyx_t_23);
      __Pyx_GOTREF(__pyx_t_19);

      /* "plastid/genomics/roitools.pyx":2895
 *             return "\t".join(str(X) for X in ltmp) + "\n"
 *         except KeyError:
 *             raise AttributeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChains only support PSL output if all PSL attributes are defined in self.attr: match_length, mismatches, rep_matches, N, query_gap_count, query_gap_bases, strand, query_length, query_start, query_end, target_name, target_length, target_start, target_end"
 *             )
 */
      __pyx_t_20 = __Pyx_PyObject_Call(__pyx_builtin_AttributeError, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2895, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_20);
      __Pyx_Raise(__pyx_t_20, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __PYX_ERR(0, 2895, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "plastid/genomics/roitools.pyx":2864
 *             list ltmp
 *             str block_sizes, q_starts, t_starts
 *         try:             # <<<<<<<<<<<<<<
 *             ltmp = [
 *                 attr["match_length"],
 */
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
    goto __pyx_L1_error;
    __pyx_L7_try_return:;
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
    goto __pyx_L0;
  }

  /* "plastid/genomics/roitools.pyx":2809
 *             return ""
 * 
 *     def as_psl(self):             # <<<<<<<<<<<<<<
 *         """Formats |SegmentChain| as `PSL`_ (blat) output.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_22);
  __Pyx_XDECREF(__pyx_t_23);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.as_psl", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_v_block_sizes);
  __Pyx_XDECREF(__pyx_v_q_starts);
  __Pyx_XDECREF(__pyx_v_t_starts);
  __Pyx_XDECREF(__pyx_9genexpr19__pyx_v_X);
  __Pyx_XDECREF(__pyx_9genexpr20__pyx_v_X);
  __Pyx_XDECREF(__pyx_9genexpr21__pyx_v_X);
  __Pyx_XDECREF(__pyx_gb_7plastid_8genomics_8roitools_12SegmentChain_6as_psl_2generator4);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2899
 *             )
 * 
 *     def get_segmentchain_coordinate(             # <<<<<<<<<<<<<<
 *         self,
 *         str chrom,
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_79get_segmentchain_coordinate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_78get_segmentchain_coordinate[] = "SegmentChain.get_segmentchain_coordinate(self, unicode chrom, long genomic_x, unicode strand, bool stranded=True)\nFinds the |SegmentChain| coordinate corresponding to a genomic position\n\n        Parameters\n        ----------\n        chrom : str\n            Chromosome name\n\n        genomic_x : int\n            coordinate, in genomic space\n\n        strand : str\n            Chromosome strand (`'+'`, `'-'`, or `'.'`)\n\n        stranded : bool, optional\n            If `True`, coordinates are given in stranded space\n            (i.e. from 5' end of chain, as one might expect for a transcript).\n            If `False`, coordinates are given from the left end of `self`,\n            regardless of strand. (Default: `True`)\n\n\n        Returns\n        -------\n        int\n            Position in |SegmentChain|\n\n        Raises\n        ------\n        KeyError\n            if position outside bounds of |SegmentChain|\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_79get_segmentchain_coordinate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_chrom = 0;
  long __pyx_v_genomic_x;
  PyObject *__pyx_v_strand = 0;
  int __pyx_v_stranded;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_segmentchain_coordinate (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_chrom,&__pyx_n_s_genomic_x,&__pyx_n_s_strand,&__pyx_n_s_stranded,0};
    PyObject* values[4] = {0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_chrom)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_genomic_x)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_segmentchain_coordinate", 0, 3, 4, 1); __PYX_ERR(0, 2899, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_strand)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_segmentchain_coordinate", 0, 3, 4, 2); __PYX_ERR(0, 2899, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stranded);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_segmentchain_coordinate") < 0)) __PYX_ERR(0, 2899, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_chrom = ((PyObject*)values[0]);
    __pyx_v_genomic_x = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v_genomic_x == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 2902, __pyx_L3_error)
    __pyx_v_strand = ((PyObject*)values[2]);
    if (values[3]) {
      __pyx_v_stranded = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_stranded == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2904, __pyx_L3_error)
    } else {

      /* "plastid/genomics/roitools.pyx":2904
 *         long genomic_x,
 *         str strand,
 *         bint stranded = True             # <<<<<<<<<<<<<<
 *         ):
 *         """Finds the |SegmentChain| coordinate corresponding to a genomic position
 */
      __pyx_v_stranded = ((int)1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_segmentchain_coordinate", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2899, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_segmentchain_coordinate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_chrom), (&PyUnicode_Type), 1, "chrom", 1))) __PYX_ERR(0, 2901, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_strand), (&PyUnicode_Type), 1, "strand", 1))) __PYX_ERR(0, 2903, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_78get_segmentchain_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_chrom, __pyx_v_genomic_x, __pyx_v_strand, __pyx_v_stranded);

  /* "plastid/genomics/roitools.pyx":2899
 *             )
 * 
 *     def get_segmentchain_coordinate(             # <<<<<<<<<<<<<<
 *         self,
 *         str chrom,
 */

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_78get_segmentchain_coordinate(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_chrom, long __pyx_v_genomic_x, PyObject *__pyx_v_strand, int __pyx_v_stranded) {
  long __pyx_v_retval;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  Py_UCS4 __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_segmentchain_coordinate", 0);

  /* "plastid/genomics/roitools.pyx":2937
 *         """
 *         cdef long retval
 *         if chrom != self.chrom:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "get_segmentchain_coordinate: query chromosome '%s' does not match chain '%s'"
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_chrom); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2937, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_chrom, __pyx_t_1, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2937, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(__pyx_t_2)) {

    /* "plastid/genomics/roitools.pyx":2939
 *         if chrom != self.chrom:
 *             raise ValueError(
 *                 "get_segmentchain_coordinate: query chromosome '%s' does not match chain '%s'"             # <<<<<<<<<<<<<<
 *                 % (chrom, self)
 *             )
 */
    __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2939, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = 0;
    __pyx_t_4 = 127;
    __Pyx_INCREF(__pyx_kp_u_get_segmentchain_coordinate_quer);
    __pyx_t_3 += 47;
    __Pyx_GIVEREF(__pyx_kp_u_get_segmentchain_coordinate_quer);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_get_segmentchain_coordinate_quer);

    /* "plastid/genomics/roitools.pyx":2940
 *             raise ValueError(
 *                 "get_segmentchain_coordinate: query chromosome '%s' does not match chain '%s'"
 *                 % (chrom, self)             # <<<<<<<<<<<<<<
 *             )
 *         if strand != self.strand:
 */
    __pyx_t_5 = __Pyx_PyUnicode_Unicode(__pyx_v_chrom); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2940, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_4;
    __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u_does_not_match_chain);
    __pyx_t_3 += 24;
    __Pyx_GIVEREF(__pyx_kp_u_does_not_match_chain);
    PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_does_not_match_chain);
    __pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2940, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_4;
    __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u__2);
    __pyx_t_3 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__2);
    PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__2);

    /* "plastid/genomics/roitools.pyx":2939
 *         if chrom != self.chrom:
 *             raise ValueError(
 *                 "get_segmentchain_coordinate: query chromosome '%s' does not match chain '%s'"             # <<<<<<<<<<<<<<
 *                 % (chrom, self)
 *             )
 */
    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2939, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":2938
 *         cdef long retval
 *         if chrom != self.chrom:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "get_segmentchain_coordinate: query chromosome '%s' does not match chain '%s'"
 *                 % (chrom, self)
 */
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2938, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 2938, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":2937
 *         """
 *         cdef long retval
 *         if chrom != self.chrom:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "get_segmentchain_coordinate: query chromosome '%s' does not match chain '%s'"
 */
  }

  /* "plastid/genomics/roitools.pyx":2942
 *                 % (chrom, self)
 *             )
 *         if strand != self.strand:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "get_segmentchain_coordinate: query strand '%s' does not match chain '%s'"
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2942, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_strand, __pyx_t_1, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2942, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(__pyx_t_2)) {

    /* "plastid/genomics/roitools.pyx":2944
 *         if strand != self.strand:
 *             raise ValueError(
 *                 "get_segmentchain_coordinate: query strand '%s' does not match chain '%s'"             # <<<<<<<<<<<<<<
 *                 % (strand, self)
 *             )
 */
    __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2944, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = 0;
    __pyx_t_4 = 127;
    __Pyx_INCREF(__pyx_kp_u_get_segmentchain_coordinate_quer_2);
    __pyx_t_3 += 43;
    __Pyx_GIVEREF(__pyx_kp_u_get_segmentchain_coordinate_quer_2);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_get_segmentchain_coordinate_quer_2);

    /* "plastid/genomics/roitools.pyx":2945
 *             raise ValueError(
 *                 "get_segmentchain_coordinate: query strand '%s' does not match chain '%s'"
 *                 % (strand, self)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    __pyx_t_5 = __Pyx_PyUnicode_Unicode(__pyx_v_strand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2945, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_4;
    __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u_does_not_match_chain);
    __pyx_t_3 += 24;
    __Pyx_GIVEREF(__pyx_kp_u_does_not_match_chain);
    PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_does_not_match_chain);
    __pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2945, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_4;
    __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u__2);
    __pyx_t_3 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__2);
    PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__2);

    /* "plastid/genomics/roitools.pyx":2944
 *         if strand != self.strand:
 *             raise ValueError(
 *                 "get_segmentchain_coordinate: query strand '%s' does not match chain '%s'"             # <<<<<<<<<<<<<<
 *                 % (strand, self)
 *             )
 */
    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2944, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":2943
 *             )
 *         if strand != self.strand:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "get_segmentchain_coordinate: query strand '%s' does not match chain '%s'"
 *                 % (strand, self)
 */
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 2943, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":2942
 *                 % (chrom, self)
 *             )
 *         if strand != self.strand:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "get_segmentchain_coordinate: query strand '%s' does not match chain '%s'"
 */
  }

  /* "plastid/genomics/roitools.pyx":2948
 *             )
 * 
 *         retval = self.c_get_segmentchain_coordinate(genomic_x, stranded)             # <<<<<<<<<<<<<<
 *         if retval == -1:
 *             raise KeyError(
 */
  __pyx_t_6 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_get_segmentchain_coordinate(__pyx_v_self, __pyx_v_genomic_x, __pyx_v_stranded); if (unlikely(__pyx_t_6 == ((long)-1L))) __PYX_ERR(0, 2948, __pyx_L1_error)
  __pyx_v_retval = __pyx_t_6;

  /* "plastid/genomics/roitools.pyx":2949
 * 
 *         retval = self.c_get_segmentchain_coordinate(genomic_x, stranded)
 *         if retval == -1:             # <<<<<<<<<<<<<<
 *             raise KeyError(
 *                 "SegmentChain.get_segmentchain_coordinate: Genomic position %s not in SegmentChain %s."
 */
  __pyx_t_2 = ((__pyx_v_retval == -1L) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "plastid/genomics/roitools.pyx":2951
 *         if retval == -1:
 *             raise KeyError(
 *                 "SegmentChain.get_segmentchain_coordinate: Genomic position %s not in SegmentChain %s."             # <<<<<<<<<<<<<<
 *                 % (genomic_x, self)
 *             )
 */
    __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2951, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = 0;
    __pyx_t_4 = 127;
    __Pyx_INCREF(__pyx_kp_u_SegmentChain_get_segmentchain_co);
    __pyx_t_3 += 59;
    __Pyx_GIVEREF(__pyx_kp_u_SegmentChain_get_segmentchain_co);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_SegmentChain_get_segmentchain_co);

    /* "plastid/genomics/roitools.pyx":2952
 *             raise KeyError(
 *                 "SegmentChain.get_segmentchain_coordinate: Genomic position %s not in SegmentChain %s."
 *                 % (genomic_x, self)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    __pyx_t_5 = __Pyx_PyUnicode_From_long(__pyx_v_genomic_x, 0, ' ', 'd'); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2952, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u_not_in_SegmentChain);
    __pyx_t_3 += 21;
    __Pyx_GIVEREF(__pyx_kp_u_not_in_SegmentChain);
    PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_not_in_SegmentChain);
    __pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2952, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_4;
    __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u__11);
    __pyx_t_3 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__11);
    PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__11);

    /* "plastid/genomics/roitools.pyx":2951
 *         if retval == -1:
 *             raise KeyError(
 *                 "SegmentChain.get_segmentchain_coordinate: Genomic position %s not in SegmentChain %s."             # <<<<<<<<<<<<<<
 *                 % (genomic_x, self)
 *             )
 */
    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2951, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":2950
 *         retval = self.c_get_segmentchain_coordinate(genomic_x, stranded)
 *         if retval == -1:
 *             raise KeyError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain.get_segmentchain_coordinate: Genomic position %s not in SegmentChain %s."
 *                 % (genomic_x, self)
 */
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2950, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 2950, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":2949
 * 
 *         retval = self.c_get_segmentchain_coordinate(genomic_x, stranded)
 *         if retval == -1:             # <<<<<<<<<<<<<<
 *             raise KeyError(
 *                 "SegmentChain.get_segmentchain_coordinate: Genomic position %s not in SegmentChain %s."
 */
  }

  /* "plastid/genomics/roitools.pyx":2955
 *             )
 * 
 *         return retval             # <<<<<<<<<<<<<<
 * 
 *     cdef long c_get_segmentchain_coordinate(self, long genomic_x, bint stranded) except -1:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_retval); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2955, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":2899
 *             )
 * 
 *     def get_segmentchain_coordinate(             # <<<<<<<<<<<<<<
 *         self,
 *         str chrom,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_segmentchain_coordinate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":2957
 *         return retval
 * 
 *     cdef long c_get_segmentchain_coordinate(self, long genomic_x, bint stranded) except -1:             # <<<<<<<<<<<<<<
 *         """Finds the |SegmentChain| coordinate corresponding to a genomic position
 * 
 */

static long __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_segmentchain_coordinate(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, long __pyx_v_genomic_x, int __pyx_v_stranded) {
  int __pyx_v_i;
  int __pyx_v_num_segs;
  long __pyx_v_cumlength;
  long __pyx_v_retval;
  long __pyx_v_chrom_end;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_span = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_seg = 0;
  PyObject *__pyx_v_msg = 0;
  long __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  Py_UCS4 __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  long __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_get_segmentchain_coordinate", 0);

  /* "plastid/genomics/roitools.pyx":2983
 *         """
 *         cdef:
 *             int i = 0             # <<<<<<<<<<<<<<
 *             int num_segs = len(self._segments)
 *             long cumlength = 0
 */
  __pyx_v_i = 0;

  /* "plastid/genomics/roitools.pyx":2984
 *         cdef:
 *             int i = 0
 *             int num_segs = len(self._segments)             # <<<<<<<<<<<<<<
 *             long cumlength = 0
 *             long retval
 */
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  if (unlikely(__pyx_t_1 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 2984, __pyx_L1_error)
  }
  __pyx_t_2 = PyList_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2984, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_num_segs = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":2985
 *             int i = 0
 *             int num_segs = len(self._segments)
 *             long cumlength = 0             # <<<<<<<<<<<<<<
 *             long retval
 *             long chrom_end
 */
  __pyx_v_cumlength = 0;

  /* "plastid/genomics/roitools.pyx":2988
 *             long retval
 *             long chrom_end
 *             GenomicSegment span = self.spanning_segment             # <<<<<<<<<<<<<<
 *             GenomicSegment seg
 *             str msg
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_span = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":2992
 *             str msg
 * 
 *         msg = "SegmentChain.get_segmentchain_coordinate: genomic position '%s' is not in chain '%s'.\n" % (genomic_x, self)             # <<<<<<<<<<<<<<
 * 
 *         if genomic_x < span.start:
 */
  __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2992, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = 0;
  __pyx_t_3 = 127;
  __Pyx_INCREF(__pyx_kp_u_SegmentChain_get_segmentchain_co_2);
  __pyx_t_2 += 60;
  __Pyx_GIVEREF(__pyx_kp_u_SegmentChain_get_segmentchain_co_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_SegmentChain_get_segmentchain_co_2);
  __pyx_t_4 = __Pyx_PyUnicode_From_long(__pyx_v_genomic_x, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2992, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u_is_not_in_chain);
  __pyx_t_2 += 19;
  __Pyx_GIVEREF(__pyx_kp_u_is_not_in_chain);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_is_not_in_chain);
  __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2992, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_INCREF(__pyx_kp_u__35);
  __pyx_t_2 += 3;
  __Pyx_GIVEREF(__pyx_kp_u__35);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__35);
  __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2992, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_msg = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "plastid/genomics/roitools.pyx":2994
 *         msg = "SegmentChain.get_segmentchain_coordinate: genomic position '%s' is not in chain '%s'.\n" % (genomic_x, self)
 * 
 *         if genomic_x < span.start:             # <<<<<<<<<<<<<<
 *             raise KeyError(msg)
 * 
 */
  __pyx_t_5 = ((__pyx_v_genomic_x < __pyx_v_span->start) != 0);
  if (unlikely(__pyx_t_5)) {

    /* "plastid/genomics/roitools.pyx":2995
 * 
 *         if genomic_x < span.start:
 *             raise KeyError(msg)             # <<<<<<<<<<<<<<
 * 
 *         while i < num_segs:
 */
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_v_msg); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2995, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 2995, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":2994
 *         msg = "SegmentChain.get_segmentchain_coordinate: genomic position '%s' is not in chain '%s'.\n" % (genomic_x, self)
 * 
 *         if genomic_x < span.start:             # <<<<<<<<<<<<<<
 *             raise KeyError(msg)
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":2997
 *             raise KeyError(msg)
 * 
 *         while i < num_segs:             # <<<<<<<<<<<<<<
 *             seg = self._segments[i]
 *             chrom_end = seg.end
 */
  while (1) {
    __pyx_t_5 = ((__pyx_v_i < __pyx_v_num_segs) != 0);
    if (!__pyx_t_5) break;

    /* "plastid/genomics/roitools.pyx":2998
 * 
 *         while i < num_segs:
 *             seg = self._segments[i]             # <<<<<<<<<<<<<<
 *             chrom_end = seg.end
 *             cumlength += len(seg)
 */
    if (unlikely(__pyx_v_self->_segments == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 2998, __pyx_L1_error)
    }
    __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_v_self->_segments, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2998, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 2998, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_seg, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":2999
 *         while i < num_segs:
 *             seg = self._segments[i]
 *             chrom_end = seg.end             # <<<<<<<<<<<<<<
 *             cumlength += len(seg)
 *             if genomic_x < chrom_end:
 */
    __pyx_t_6 = __pyx_v_seg->end;
    __pyx_v_chrom_end = __pyx_t_6;

    /* "plastid/genomics/roitools.pyx":3000
 *             seg = self._segments[i]
 *             chrom_end = seg.end
 *             cumlength += len(seg)             # <<<<<<<<<<<<<<
 *             if genomic_x < chrom_end:
 *                 if genomic_x >= self._segments[i].start:
 */
    __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_seg)); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3000, __pyx_L1_error)
    __pyx_v_cumlength = (__pyx_v_cumlength + __pyx_t_2);

    /* "plastid/genomics/roitools.pyx":3001
 *             chrom_end = seg.end
 *             cumlength += len(seg)
 *             if genomic_x < chrom_end:             # <<<<<<<<<<<<<<
 *                 if genomic_x >= self._segments[i].start:
 *                     retval = cumlength  - chrom_end + genomic_x
 */
    __pyx_t_5 = ((__pyx_v_genomic_x < __pyx_v_chrom_end) != 0);
    if (__pyx_t_5) {

      /* "plastid/genomics/roitools.pyx":3002
 *             cumlength += len(seg)
 *             if genomic_x < chrom_end:
 *                 if genomic_x >= self._segments[i].start:             # <<<<<<<<<<<<<<
 *                     retval = cumlength  - chrom_end + genomic_x
 *                     if span.c_strand == reverse_strand and stranded == True:
 */
      __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_genomic_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3002, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely(__pyx_v_self->_segments == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 3002, __pyx_L1_error)
      }
      __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_self->_segments, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3002, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_start); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3002, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_t_7, Py_GE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3002, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3002, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_5) {

        /* "plastid/genomics/roitools.pyx":3003
 *             if genomic_x < chrom_end:
 *                 if genomic_x >= self._segments[i].start:
 *                     retval = cumlength  - chrom_end + genomic_x             # <<<<<<<<<<<<<<
 *                     if span.c_strand == reverse_strand and stranded == True:
 *                         retval = self.length - retval - 1
 */
        __pyx_v_retval = ((__pyx_v_cumlength - __pyx_v_chrom_end) + __pyx_v_genomic_x);

        /* "plastid/genomics/roitools.pyx":3004
 *                 if genomic_x >= self._segments[i].start:
 *                     retval = cumlength  - chrom_end + genomic_x
 *                     if span.c_strand == reverse_strand and stranded == True:             # <<<<<<<<<<<<<<
 *                         retval = self.length - retval - 1
 *                     return retval
 */
        __pyx_t_8 = ((__pyx_v_span->c_strand == __pyx_e_7plastid_8genomics_8c_common_reverse_strand) != 0);
        if (__pyx_t_8) {
        } else {
          __pyx_t_5 = __pyx_t_8;
          goto __pyx_L9_bool_binop_done;
        }
        __pyx_t_8 = ((__pyx_v_stranded == 1) != 0);
        __pyx_t_5 = __pyx_t_8;
        __pyx_L9_bool_binop_done:;
        if (__pyx_t_5) {

          /* "plastid/genomics/roitools.pyx":3005
 *                     retval = cumlength  - chrom_end + genomic_x
 *                     if span.c_strand == reverse_strand and stranded == True:
 *                         retval = self.length - retval - 1             # <<<<<<<<<<<<<<
 *                     return retval
 *                 # because segments are sorted, if < end but not >= start,
 */
          __pyx_v_retval = ((__pyx_v_self->length - __pyx_v_retval) - 1);

          /* "plastid/genomics/roitools.pyx":3004
 *                 if genomic_x >= self._segments[i].start:
 *                     retval = cumlength  - chrom_end + genomic_x
 *                     if span.c_strand == reverse_strand and stranded == True:             # <<<<<<<<<<<<<<
 *                         retval = self.length - retval - 1
 *                     return retval
 */
        }

        /* "plastid/genomics/roitools.pyx":3006
 *                     if span.c_strand == reverse_strand and stranded == True:
 *                         retval = self.length - retval - 1
 *                     return retval             # <<<<<<<<<<<<<<
 *                 # because segments are sorted, if < end but not >= start,
 *                 # key must be outside bounds of chain
 */
        __pyx_r = __pyx_v_retval;
        goto __pyx_L0;

        /* "plastid/genomics/roitools.pyx":3002
 *             cumlength += len(seg)
 *             if genomic_x < chrom_end:
 *                 if genomic_x >= self._segments[i].start:             # <<<<<<<<<<<<<<
 *                     retval = cumlength  - chrom_end + genomic_x
 *                     if span.c_strand == reverse_strand and stranded == True:
 */
      }

      /* "plastid/genomics/roitools.pyx":3009
 *                 # because segments are sorted, if < end but not >= start,
 *                 # key must be outside bounds of chain
 *                 raise KeyError(msg)             # <<<<<<<<<<<<<<
 *             i += 1
 * 
 */
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_v_msg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3009, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 3009, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":3001
 *             chrom_end = seg.end
 *             cumlength += len(seg)
 *             if genomic_x < chrom_end:             # <<<<<<<<<<<<<<
 *                 if genomic_x >= self._segments[i].start:
 *                     retval = cumlength  - chrom_end + genomic_x
 */
    }

    /* "plastid/genomics/roitools.pyx":3010
 *                 # key must be outside bounds of chain
 *                 raise KeyError(msg)
 *             i += 1             # <<<<<<<<<<<<<<
 * 
 *         raise KeyError(msg)
 */
    __pyx_v_i = (__pyx_v_i + 1);
  }

  /* "plastid/genomics/roitools.pyx":3012
 *             i += 1
 * 
 *         raise KeyError(msg)             # <<<<<<<<<<<<<<
 * 
 *     def get_genomic_coordinate(self, x, stranded=True):
 */
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_v_msg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3012, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(0, 3012, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":2957
 *         return retval
 * 
 *     cdef long c_get_segmentchain_coordinate(self, long genomic_x, bint stranded) except -1:             # <<<<<<<<<<<<<<
 *         """Finds the |SegmentChain| coordinate corresponding to a genomic position
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_get_segmentchain_coordinate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_span);
  __Pyx_XDECREF((PyObject *)__pyx_v_seg);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3014
 *         raise KeyError(msg)
 * 
 *     def get_genomic_coordinate(self, x, stranded=True):             # <<<<<<<<<<<<<<
 *         """Finds genomic coordinate corresponding to position `x` in `self`
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_81get_genomic_coordinate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_80get_genomic_coordinate[] = "SegmentChain.get_genomic_coordinate(self, x, stranded=True)\nFinds genomic coordinate corresponding to position `x` in `self`\n\n        Parameters\n        ----------\n        x : int\n            position of interest, relative to |SegmentChain|\n\n        stranded : bool, optional\n            If `True`, `x` is assumed to be in stranded space (i.e. counted from\n            5' end of chain, as one might expect for a transcript). If `False`,\n            coordinates assumed to be counted the left end of the `self`,\n            regardless of the strand of `self`. (Default: `True`)\n\n\n        Returns\n        -------\n        str\n            Chromosome name\n\n        long\n            Genomic cordinate corresponding to position `x`\n\n        str\n            Chromosome strand (`'+'`, `'-'`, or `'.'`)\n\n\n        Raises\n        ------\n        IndexError\n            if `x` is outside the bounds of the |SegmentChain|\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_81get_genomic_coordinate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_x = 0;
  PyObject *__pyx_v_stranded = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_genomic_coordinate (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_x,&__pyx_n_s_stranded,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_x)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stranded);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_genomic_coordinate") < 0)) __PYX_ERR(0, 3014, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_x = values[0];
    __pyx_v_stranded = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_genomic_coordinate", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3014, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_genomic_coordinate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_80get_genomic_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_x, __pyx_v_stranded);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_80get_genomic_coordinate(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_x, PyObject *__pyx_v_stranded) {
  long __pyx_v_new_x;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  long __pyx_t_1;
  int __pyx_t_2;
  long __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  Py_UCS4 __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_genomic_coordinate", 0);

  /* "plastid/genomics/roitools.pyx":3046
 *             if `x` is outside the bounds of the |SegmentChain|
 *         """
 *         cdef long new_x = self.c_get_genomic_coordinate(x, stranded)             # <<<<<<<<<<<<<<
 *         if new_x == -1:
 *             raise RuntimeError(
 */
  __pyx_t_1 = __Pyx_PyInt_As_long(__pyx_v_x); if (unlikely((__pyx_t_1 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3046, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_stranded); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3046, __pyx_L1_error)
  __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_get_genomic_coordinate(__pyx_v_self, __pyx_t_1, __pyx_t_2); if (unlikely(__pyx_t_3 == ((long)-1L))) __PYX_ERR(0, 3046, __pyx_L1_error)
  __pyx_v_new_x = __pyx_t_3;

  /* "plastid/genomics/roitools.pyx":3047
 *         """
 *         cdef long new_x = self.c_get_genomic_coordinate(x, stranded)
 *         if new_x == -1:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(
 *                 "Cannot fetch coordinate %s from SegmentChain %s (length %s)"
 */
  __pyx_t_2 = ((__pyx_v_new_x == -1L) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "plastid/genomics/roitools.pyx":3049
 *         if new_x == -1:
 *             raise RuntimeError(
 *                 "Cannot fetch coordinate %s from SegmentChain %s (length %s)"             # <<<<<<<<<<<<<<
 *                 % (x, self, self.length)
 *             )
 */
    __pyx_t_4 = PyTuple_New(7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3049, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = 0;
    __pyx_t_6 = 127;
    __Pyx_INCREF(__pyx_kp_u_Cannot_fetch_coordinate);
    __pyx_t_5 += 24;
    __Pyx_GIVEREF(__pyx_kp_u_Cannot_fetch_coordinate);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_Cannot_fetch_coordinate);

    /* "plastid/genomics/roitools.pyx":3050
 *             raise RuntimeError(
 *                 "Cannot fetch coordinate %s from SegmentChain %s (length %s)"
 *                 % (x, self, self.length)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_x), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3050, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
    __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_INCREF(__pyx_kp_u_from_SegmentChain);
    __pyx_t_5 += 19;
    __Pyx_GIVEREF(__pyx_kp_u_from_SegmentChain);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u_from_SegmentChain);
    __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3050, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
    __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_INCREF(__pyx_kp_u_length);
    __pyx_t_5 += 9;
    __Pyx_GIVEREF(__pyx_kp_u_length);
    PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_kp_u_length);
    __pyx_t_7 = __Pyx_PyUnicode_From_long(__pyx_v_self->length, 0, ' ', 'd'); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3050, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_INCREF(__pyx_kp_u__15);
    __pyx_t_5 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__15);
    PyTuple_SET_ITEM(__pyx_t_4, 6, __pyx_kp_u__15);

    /* "plastid/genomics/roitools.pyx":3049
 *         if new_x == -1:
 *             raise RuntimeError(
 *                 "Cannot fetch coordinate %s from SegmentChain %s (length %s)"             # <<<<<<<<<<<<<<
 *                 % (x, self, self.length)
 *             )
 */
    __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_4, 7, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3049, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":3048
 *         cdef long new_x = self.c_get_genomic_coordinate(x, stranded)
 *         if new_x == -1:
 *             raise RuntimeError(             # <<<<<<<<<<<<<<
 *                 "Cannot fetch coordinate %s from SegmentChain %s (length %s)"
 *                 % (x, self, self.length)
 */
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3048, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 3048, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3047
 *         """
 *         cdef long new_x = self.c_get_genomic_coordinate(x, stranded)
 *         if new_x == -1:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(
 *                 "Cannot fetch coordinate %s from SegmentChain %s (length %s)"
 */
  }

  /* "plastid/genomics/roitools.pyx":3053
 *             )
 * 
 *         return self.chrom, new_x, self.strand             # <<<<<<<<<<<<<<
 * 
 *     cdef long c_get_genomic_coordinate(self, long x, bint stranded) except -1:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_chrom); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyInt_From_long(__pyx_v_new_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_8);
  __pyx_t_4 = 0;
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;
  __pyx_r = __pyx_t_9;
  __pyx_t_9 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3014
 *         raise KeyError(msg)
 * 
 *     def get_genomic_coordinate(self, x, stranded=True):             # <<<<<<<<<<<<<<
 *         """Finds genomic coordinate corresponding to position `x` in `self`
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_genomic_coordinate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3055
 *         return self.chrom, new_x, self.strand
 * 
 *     cdef long c_get_genomic_coordinate(self, long x, bint stranded) except -1:             # <<<<<<<<<<<<<<
 *         """Finds genomic coordinate corresponding to position `x` in `self`
 * 
 */

static long __pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_genomic_coordinate(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, long __pyx_v_x, int __pyx_v_stranded) {
  int __pyx_v_i;
  int __pyx_v_num_segs;
  long __pyx_v_retval;
  long __pyx_v_lastlength;
  long __pyx_v_cumlength;
  long __pyx_v_length;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_seg = 0;
  PyObject *__pyx_v_msg = 0;
  long __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  long __pyx_t_3;
  Py_UCS4 __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_get_genomic_coordinate", 0);

  /* "plastid/genomics/roitools.pyx":3086
 *         """
 *         cdef:
 *             int i = 0             # <<<<<<<<<<<<<<
 *             int num_segs = len(self._segments)
 *             long retval
 */
  __pyx_v_i = 0;

  /* "plastid/genomics/roitools.pyx":3087
 *         cdef:
 *             int i = 0
 *             int num_segs = len(self._segments)             # <<<<<<<<<<<<<<
 *             long retval
 *             long lastlength = 0
 */
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  if (unlikely(__pyx_t_1 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 3087, __pyx_L1_error)
  }
  __pyx_t_2 = PyList_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3087, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_num_segs = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":3089
 *             int num_segs = len(self._segments)
 *             long retval
 *             long lastlength = 0             # <<<<<<<<<<<<<<
 *             long cumlength = 0
 *             long length = self.length
 */
  __pyx_v_lastlength = 0;

  /* "plastid/genomics/roitools.pyx":3090
 *             long retval
 *             long lastlength = 0
 *             long cumlength = 0             # <<<<<<<<<<<<<<
 *             long length = self.length
 *             GenomicSegment seg
 */
  __pyx_v_cumlength = 0;

  /* "plastid/genomics/roitools.pyx":3091
 *             long lastlength = 0
 *             long cumlength = 0
 *             long length = self.length             # <<<<<<<<<<<<<<
 *             GenomicSegment seg
 *             str msg
 */
  __pyx_t_3 = __pyx_v_self->length;
  __pyx_v_length = __pyx_t_3;

  /* "plastid/genomics/roitools.pyx":3095
 *             str msg
 * 
 *         msg = "Position %s is outside bounds [0,%s) of SegmentChain '%s'" % \             # <<<<<<<<<<<<<<
 *               (x, length, self.get_name())
 *         if x < 0 or x >= length:
 */
  __pyx_t_1 = PyTuple_New(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3095, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = 0;
  __pyx_t_4 = 127;
  __Pyx_INCREF(__pyx_kp_u_Position);
  __pyx_t_2 += 9;
  __Pyx_GIVEREF(__pyx_kp_u_Position);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Position);

  /* "plastid/genomics/roitools.pyx":3096
 * 
 *         msg = "Position %s is outside bounds [0,%s) of SegmentChain '%s'" % \
 *               (x, length, self.get_name())             # <<<<<<<<<<<<<<
 *         if x < 0 or x >= length:
 *             raise IndexError(msg)
 */
  __pyx_t_5 = __Pyx_PyUnicode_From_long(__pyx_v_x, 0, ' ', 'd'); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3096, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
  __pyx_t_5 = 0;
  __Pyx_INCREF(__pyx_kp_u_is_outside_bounds_0);
  __pyx_t_2 += 22;
  __Pyx_GIVEREF(__pyx_kp_u_is_outside_bounds_0);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_is_outside_bounds_0);
  __pyx_t_5 = __Pyx_PyUnicode_From_long(__pyx_v_length, 0, ' ', 'd'); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3096, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_5);
  __pyx_t_5 = 0;
  __Pyx_INCREF(__pyx_kp_u_of_SegmentChain);
  __pyx_t_2 += 19;
  __Pyx_GIVEREF(__pyx_kp_u_of_SegmentChain);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_of_SegmentChain);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3096, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3096, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_5), __pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3096, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_4;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_6);
  __pyx_t_6 = 0;
  __Pyx_INCREF(__pyx_kp_u__2);
  __pyx_t_2 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__2);
  PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u__2);

  /* "plastid/genomics/roitools.pyx":3095
 *             str msg
 * 
 *         msg = "Position %s is outside bounds [0,%s) of SegmentChain '%s'" % \             # <<<<<<<<<<<<<<
 *               (x, length, self.get_name())
 *         if x < 0 or x >= length:
 */
  __pyx_t_6 = __Pyx_PyUnicode_Join(__pyx_t_1, 7, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3095, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_msg = ((PyObject*)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "plastid/genomics/roitools.pyx":3097
 *         msg = "Position %s is outside bounds [0,%s) of SegmentChain '%s'" % \
 *               (x, length, self.get_name())
 *         if x < 0 or x >= length:             # <<<<<<<<<<<<<<
 *             raise IndexError(msg)
 * 
 */
  __pyx_t_9 = ((__pyx_v_x < 0) != 0);
  if (!__pyx_t_9) {
  } else {
    __pyx_t_8 = __pyx_t_9;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_9 = ((__pyx_v_x >= __pyx_v_length) != 0);
  __pyx_t_8 = __pyx_t_9;
  __pyx_L4_bool_binop_done:;
  if (unlikely(__pyx_t_8)) {

    /* "plastid/genomics/roitools.pyx":3098
 *               (x, length, self.get_name())
 *         if x < 0 or x >= length:
 *             raise IndexError(msg)             # <<<<<<<<<<<<<<
 * 
 *         if self.c_strand == reverse_strand and stranded == True:
 */
    __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_v_msg); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3098, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_Raise(__pyx_t_6, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __PYX_ERR(0, 3098, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3097
 *         msg = "Position %s is outside bounds [0,%s) of SegmentChain '%s'" % \
 *               (x, length, self.get_name())
 *         if x < 0 or x >= length:             # <<<<<<<<<<<<<<
 *             raise IndexError(msg)
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3100
 *             raise IndexError(msg)
 * 
 *         if self.c_strand == reverse_strand and stranded == True:             # <<<<<<<<<<<<<<
 *             x = length - x - 1
 * 
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_c_strand); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyInt_From_enum____pyx_t_7plastid_8genomics_8c_common_Strand(__pyx_e_7plastid_8genomics_8c_common_reverse_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_6, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_9) {
  } else {
    __pyx_t_8 = __pyx_t_9;
    goto __pyx_L7_bool_binop_done;
  }
  __pyx_t_9 = ((__pyx_v_stranded == 1) != 0);
  __pyx_t_8 = __pyx_t_9;
  __pyx_L7_bool_binop_done:;
  if (__pyx_t_8) {

    /* "plastid/genomics/roitools.pyx":3101
 * 
 *         if self.c_strand == reverse_strand and stranded == True:
 *             x = length - x - 1             # <<<<<<<<<<<<<<
 * 
 *         if self._position_hash is None:
 */
    __pyx_v_x = ((__pyx_v_length - __pyx_v_x) - 1);

    /* "plastid/genomics/roitools.pyx":3100
 *             raise IndexError(msg)
 * 
 *         if self.c_strand == reverse_strand and stranded == True:             # <<<<<<<<<<<<<<
 *             x = length - x - 1
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3103
 *             x = length - x - 1
 * 
 *         if self._position_hash is None:             # <<<<<<<<<<<<<<
 *             while i < num_segs:
 *                 seg = self._segments[i]
 */
  __pyx_t_8 = (((PyObject *)__pyx_v_self->_position_hash) == Py_None);
  __pyx_t_9 = (__pyx_t_8 != 0);
  if (__pyx_t_9) {

    /* "plastid/genomics/roitools.pyx":3104
 * 
 *         if self._position_hash is None:
 *             while i < num_segs:             # <<<<<<<<<<<<<<
 *                 seg = self._segments[i]
 *                 cumlength += len(seg)
 */
    while (1) {
      __pyx_t_9 = ((__pyx_v_i < __pyx_v_num_segs) != 0);
      if (!__pyx_t_9) break;

      /* "plastid/genomics/roitools.pyx":3105
 *         if self._position_hash is None:
 *             while i < num_segs:
 *                 seg = self._segments[i]             # <<<<<<<<<<<<<<
 *                 cumlength += len(seg)
 *                 if x < cumlength:
 */
      if (unlikely(__pyx_v_self->_segments == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 3105, __pyx_L1_error)
      }
      __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_self->_segments, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3105, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 3105, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_seg, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "plastid/genomics/roitools.pyx":3106
 *             while i < num_segs:
 *                 seg = self._segments[i]
 *                 cumlength += len(seg)             # <<<<<<<<<<<<<<
 *                 if x < cumlength:
 *                     if x >= lastlength:
 */
      __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_seg)); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3106, __pyx_L1_error)
      __pyx_v_cumlength = (__pyx_v_cumlength + __pyx_t_2);

      /* "plastid/genomics/roitools.pyx":3107
 *                 seg = self._segments[i]
 *                 cumlength += len(seg)
 *                 if x < cumlength:             # <<<<<<<<<<<<<<
 *                     if x >= lastlength:
 *                         retval = x - lastlength + seg.start
 */
      __pyx_t_9 = ((__pyx_v_x < __pyx_v_cumlength) != 0);
      if (__pyx_t_9) {

        /* "plastid/genomics/roitools.pyx":3108
 *                 cumlength += len(seg)
 *                 if x < cumlength:
 *                     if x >= lastlength:             # <<<<<<<<<<<<<<
 *                         retval = x - lastlength + seg.start
 * 
 */
        __pyx_t_9 = ((__pyx_v_x >= __pyx_v_lastlength) != 0);
        if (__pyx_t_9) {

          /* "plastid/genomics/roitools.pyx":3109
 *                 if x < cumlength:
 *                     if x >= lastlength:
 *                         retval = x - lastlength + seg.start             # <<<<<<<<<<<<<<
 * 
 *                         return retval
 */
          __pyx_v_retval = ((__pyx_v_x - __pyx_v_lastlength) + __pyx_v_seg->start);

          /* "plastid/genomics/roitools.pyx":3111
 *                         retval = x - lastlength + seg.start
 * 
 *                         return retval             # <<<<<<<<<<<<<<
 *                     raise IndexError(msg)
 * 
 */
          __pyx_r = __pyx_v_retval;
          goto __pyx_L0;

          /* "plastid/genomics/roitools.pyx":3108
 *                 cumlength += len(seg)
 *                 if x < cumlength:
 *                     if x >= lastlength:             # <<<<<<<<<<<<<<
 *                         retval = x - lastlength + seg.start
 * 
 */
        }

        /* "plastid/genomics/roitools.pyx":3112
 * 
 *                         return retval
 *                     raise IndexError(msg)             # <<<<<<<<<<<<<<
 * 
 *                 lastlength = cumlength
 */
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_v_msg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3112, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_Raise(__pyx_t_5, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __PYX_ERR(0, 3112, __pyx_L1_error)

        /* "plastid/genomics/roitools.pyx":3107
 *                 seg = self._segments[i]
 *                 cumlength += len(seg)
 *                 if x < cumlength:             # <<<<<<<<<<<<<<
 *                     if x >= lastlength:
 *                         retval = x - lastlength + seg.start
 */
      }

      /* "plastid/genomics/roitools.pyx":3114
 *                     raise IndexError(msg)
 * 
 *                 lastlength = cumlength             # <<<<<<<<<<<<<<
 *                 i += 1
 *         else:
 */
      __pyx_v_lastlength = __pyx_v_cumlength;

      /* "plastid/genomics/roitools.pyx":3115
 * 
 *                 lastlength = cumlength
 *                 i += 1             # <<<<<<<<<<<<<<
 *         else:
 *             return self._position_hash[x]
 */
      __pyx_v_i = (__pyx_v_i + 1);
    }

    /* "plastid/genomics/roitools.pyx":3103
 *             x = length - x - 1
 * 
 *         if self._position_hash is None:             # <<<<<<<<<<<<<<
 *             while i < num_segs:
 *                 seg = self._segments[i]
 */
    goto __pyx_L9;
  }

  /* "plastid/genomics/roitools.pyx":3117
 *                 i += 1
 *         else:
 *             return self._position_hash[x]             # <<<<<<<<<<<<<<
 * 
 *         raise IndexError(msg)
 */
  /*else*/ {
    __pyx_t_5 = __Pyx_GetItemInt(((PyObject *)__pyx_v_self->_position_hash), __pyx_v_x, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_PyInt_As_long(__pyx_t_5); if (unlikely((__pyx_t_3 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3117, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_3;
    goto __pyx_L0;
  }
  __pyx_L9:;

  /* "plastid/genomics/roitools.pyx":3119
 *             return self._position_hash[x]
 * 
 *         raise IndexError(msg)             # <<<<<<<<<<<<<<
 * 
 *     def get_subchain(self, long start, long end, bint stranded=True, **extra_attr):
 */
  __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_v_msg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3119, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_Raise(__pyx_t_5, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __PYX_ERR(0, 3119, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":3055
 *         return self.chrom, new_x, self.strand
 * 
 *     cdef long c_get_genomic_coordinate(self, long x, bint stranded) except -1:             # <<<<<<<<<<<<<<
 *         """Finds genomic coordinate corresponding to position `x` in `self`
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_get_genomic_coordinate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_seg);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3121
 *         raise IndexError(msg)
 * 
 *     def get_subchain(self, long start, long end, bint stranded=True, **extra_attr):             # <<<<<<<<<<<<<<
 *         """Retrieves a sub-|SegmentChain| corresponding a range of positions
 *         specified in coordinates relative this |SegmentChain|. Attributes in
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_83get_subchain(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_82get_subchain[] = "SegmentChain.get_subchain(self, long start, long end, bool stranded=True, **extra_attr)\nRetrieves a sub-|SegmentChain| corresponding a range of positions\n        specified in coordinates relative this |SegmentChain|. Attributes in\n        `self.attr` are copied to the child SegmentChain, with the exception\n        of `ID`, to which the suffix `'subchain'` is appended.\n\n        Parameters\n        ----------\n        start : int\n            position of interest in SegmentChain coordinates, 0-indexed\n\n        end : int\n            position of interest in SegmentChain coordinates, 0-indexed\n            and half-open\n\n        stranded : bool, optional\n            If `True`, `start` and `end` are assumed to be in stranded space\n            (i.e. counted from 5' end of chain, as one might expect for a\n            transcript). If `False`, they assumed to be counted the left end of\n            the `self`, regardless of the strand of `self`. (Default: `True`)\n\n        extra_attr : keyword arguments\n            Values that will be included in the subchain's `attr` dict.\n            These can be used to overwrite values already present.\n\n        Returns\n        -------\n        |SegmentChain|\n            covering parent chain positions `start` to `end` of `self`\n\n\n        Raises\n        ------\n        IndexError\n            if `start` or `end` is outside the bounds of the |SegmentChain|\n\n        TypeError\n            if `start` or `end` is None\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_83get_subchain(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  long __pyx_v_start;
  long __pyx_v_end;
  int __pyx_v_stranded;
  PyObject *__pyx_v_extra_attr = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_subchain (wrapper)", 0);
  __pyx_v_extra_attr = PyDict_New(); if (unlikely(!__pyx_v_extra_attr)) return NULL;
  __Pyx_GOTREF(__pyx_v_extra_attr);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_stranded,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_subchain", 0, 2, 3, 1); __PYX_ERR(0, 3121, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stranded);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_extra_attr, values, pos_args, "get_subchain") < 0)) __PYX_ERR(0, 3121, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_start = __Pyx_PyInt_As_long(values[0]); if (unlikely((__pyx_v_start == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3121, __pyx_L3_error)
    __pyx_v_end = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v_end == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3121, __pyx_L3_error)
    if (values[2]) {
      __pyx_v_stranded = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_stranded == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3121, __pyx_L3_error)
    } else {
      __pyx_v_stranded = ((int)1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_subchain", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3121, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_extra_attr); __pyx_v_extra_attr = 0;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_subchain", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_82get_subchain(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_start, __pyx_v_end, __pyx_v_stranded, __pyx_v_extra_attr);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_82get_subchain(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, long __pyx_v_start, long __pyx_v_end, int __pyx_v_stranded, PyObject *__pyx_v_extra_attr) {
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_chain = 0;
  PyObject *__pyx_v_old_attr = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_subchain", 0);

  /* "plastid/genomics/roitools.pyx":3161
 *         """
 *         cdef:
 *             SegmentChain chain = self.c_get_subchain(start, end, stranded)             # <<<<<<<<<<<<<<
 *             dict old_attr = copy.deepcopy(self.attr)
 * 
 */
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->c_get_subchain(__pyx_v_self, __pyx_v_start, __pyx_v_end, __pyx_v_stranded)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3161, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_chain = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3162
 *         cdef:
 *             SegmentChain chain = self.c_get_subchain(start, end, stranded)
 *             dict old_attr = copy.deepcopy(self.attr)             # <<<<<<<<<<<<<<
 * 
 *         old_attr.update(extra_attr)
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_self->attr) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->attr);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 3162, __pyx_L1_error)
  __pyx_v_old_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3164
 *             dict old_attr = copy.deepcopy(self.attr)
 * 
 *         old_attr.update(extra_attr)             # <<<<<<<<<<<<<<
 *         chain.attr = old_attr
 *         chain.attr["ID"] = "%s_subchain" % self.get_name()
 */
  __pyx_t_1 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_update, __pyx_v_old_attr, __pyx_v_extra_attr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3164, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3165
 * 
 *         old_attr.update(extra_attr)
 *         chain.attr = old_attr             # <<<<<<<<<<<<<<
 *         chain.attr["ID"] = "%s_subchain" % self.get_name()
 *         return chain
 */
  __Pyx_INCREF(__pyx_v_old_attr);
  __Pyx_GIVEREF(__pyx_v_old_attr);
  __Pyx_GOTREF(__pyx_v_chain->attr);
  __Pyx_DECREF(__pyx_v_chain->attr);
  __pyx_v_chain->attr = __pyx_v_old_attr;

  /* "plastid/genomics/roitools.pyx":3166
 *         old_attr.update(extra_attr)
 *         chain.attr = old_attr
 *         chain.attr["ID"] = "%s_subchain" % self.get_name()             # <<<<<<<<<<<<<<
 *         return chain
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_s_subchain, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(__pyx_v_chain->attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3166, __pyx_L1_error)
  }
  if (unlikely(PyDict_SetItem(__pyx_v_chain->attr, __pyx_n_u_ID_2, __pyx_t_3) < 0)) __PYX_ERR(0, 3166, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":3167
 *         chain.attr = old_attr
 *         chain.attr["ID"] = "%s_subchain" % self.get_name()
 *         return chain             # <<<<<<<<<<<<<<
 * 
 *     cdef SegmentChain c_get_subchain(self, long start, long end, bint stranded):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_chain));
  __pyx_r = ((PyObject *)__pyx_v_chain);
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3121
 *         raise IndexError(msg)
 * 
 *     def get_subchain(self, long start, long end, bint stranded=True, **extra_attr):             # <<<<<<<<<<<<<<
 *         """Retrieves a sub-|SegmentChain| corresponding a range of positions
 *         specified in coordinates relative this |SegmentChain|. Attributes in
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_subchain", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_chain);
  __Pyx_XDECREF(__pyx_v_old_attr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3169
 *         return chain
 * 
 *     cdef SegmentChain c_get_subchain(self, long start, long end, bint stranded):             # <<<<<<<<<<<<<<
 *         """Similar to :meth:`SegmentChain.get_subchain` but does not copy `attr` dict
 * 
 */

static struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_subchain(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, long __pyx_v_start, long __pyx_v_end, int __pyx_v_stranded) {
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_chain = 0;
  long __pyx_v_length;
  long __pyx_v_tmp;
  PyObject *__pyx_v_segs = 0;
  PyObject *__pyx_v_positions = NULL;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  long __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("c_get_subchain", 0);

  /* "plastid/genomics/roitools.pyx":3197
 *         """
 *         cdef:
 *             SegmentChain chain = SegmentChain()             # <<<<<<<<<<<<<<
 *             long length = self.length
 *             long tmp
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_chain = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3198
 *         cdef:
 *             SegmentChain chain = SegmentChain()
 *             long length = self.length             # <<<<<<<<<<<<<<
 *             long tmp
 *             list segs
 */
  __pyx_t_2 = __pyx_v_self->length;
  __pyx_v_length = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":3202
 *             list segs
 * 
 *         if start == end: # this is a special case which we need to account for             # <<<<<<<<<<<<<<
 *             return SegmentChain()
 * 
 */
  __pyx_t_3 = ((__pyx_v_start == __pyx_v_end) != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":3203
 * 
 *         if start == end: # this is a special case which we need to account for
 *             return SegmentChain()             # <<<<<<<<<<<<<<
 * 
 *         if start is None:
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3203, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":3202
 *             list segs
 * 
 *         if start == end: # this is a special case which we need to account for             # <<<<<<<<<<<<<<
 *             return SegmentChain()
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3205
 *             return SegmentChain()
 * 
 *         if start is None:             # <<<<<<<<<<<<<<
 *             raise TypeError('start coordinate supplied is None. Expected int')
 *         elif end is None:
 */
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = (__pyx_t_1 == Py_None);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (unlikely(__pyx_t_4)) {

    /* "plastid/genomics/roitools.pyx":3206
 * 
 *         if start is None:
 *             raise TypeError('start coordinate supplied is None. Expected int')             # <<<<<<<<<<<<<<
 *         elif end is None:
 *             raise TypeError('end coordinate supplied is None. Expected int')
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 3206, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3205
 *             return SegmentChain()
 * 
 *         if start is None:             # <<<<<<<<<<<<<<
 *             raise TypeError('start coordinate supplied is None. Expected int')
 *         elif end is None:
 */
  }

  /* "plastid/genomics/roitools.pyx":3207
 *         if start is None:
 *             raise TypeError('start coordinate supplied is None. Expected int')
 *         elif end is None:             # <<<<<<<<<<<<<<
 *             raise TypeError('end coordinate supplied is None. Expected int')
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3207, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = (__pyx_t_1 == Py_None);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_4 != 0);
  if (unlikely(__pyx_t_3)) {

    /* "plastid/genomics/roitools.pyx":3208
 *             raise TypeError('start coordinate supplied is None. Expected int')
 *         elif end is None:
 *             raise TypeError('end coordinate supplied is None. Expected int')             # <<<<<<<<<<<<<<
 * 
 *         if stranded == True and self.c_strand == reverse_strand:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3208, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 3208, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3207
 *         if start is None:
 *             raise TypeError('start coordinate supplied is None. Expected int')
 *         elif end is None:             # <<<<<<<<<<<<<<
 *             raise TypeError('end coordinate supplied is None. Expected int')
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3210
 *             raise TypeError('end coordinate supplied is None. Expected int')
 * 
 *         if stranded == True and self.c_strand == reverse_strand:             # <<<<<<<<<<<<<<
 *             tmp = end
 *             end   = length - start
 */
  __pyx_t_4 = ((__pyx_v_stranded == 1) != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_3 = __pyx_t_4;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_c_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyInt_From_enum____pyx_t_7plastid_8genomics_8c_common_Strand(__pyx_e_7plastid_8genomics_8c_common_reverse_strand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3210, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 3210, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_3 = __pyx_t_4;
  __pyx_L6_bool_binop_done:;
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":3211
 * 
 *         if stranded == True and self.c_strand == reverse_strand:
 *             tmp = end             # <<<<<<<<<<<<<<
 *             end   = length - start
 *             start = length - tmp
 */
    __pyx_v_tmp = __pyx_v_end;

    /* "plastid/genomics/roitools.pyx":3212
 *         if stranded == True and self.c_strand == reverse_strand:
 *             tmp = end
 *             end   = length - start             # <<<<<<<<<<<<<<
 *             start = length - tmp
 * 
 */
    __pyx_v_end = (__pyx_v_length - __pyx_v_start);

    /* "plastid/genomics/roitools.pyx":3213
 *             tmp = end
 *             end   = length - start
 *             start = length - tmp             # <<<<<<<<<<<<<<
 * 
 *         positions = self._get_position_hash()[start:end].tolist()
 */
    __pyx_v_start = (__pyx_v_length - __pyx_v_tmp);

    /* "plastid/genomics/roitools.pyx":3210
 *             raise TypeError('end coordinate supplied is None. Expected int')
 * 
 *         if stranded == True and self.c_strand == reverse_strand:             # <<<<<<<<<<<<<<
 *             tmp = end
 *             end   = length - start
 */
  }

  /* "plastid/genomics/roitools.pyx":3215
 *             start = length - tmp
 * 
 *         positions = self._get_position_hash()[start:end].tolist()             # <<<<<<<<<<<<<<
 *         segs = positionlist_to_segments(self.chrom, self.strand, positions)
 *         chain._set_segments(segs)
 */
  __pyx_t_5 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self->__pyx_vtab)->_get_position_hash(__pyx_v_self)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3215, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_t_5, __pyx_v_start, __pyx_v_end, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3215, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_tolist); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3215, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3215, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_positions = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "plastid/genomics/roitools.pyx":3216
 * 
 *         positions = self._get_position_hash()[start:end].tolist()
 *         segs = positionlist_to_segments(self.chrom, self.strand, positions)             # <<<<<<<<<<<<<<
 *         chain._set_segments(segs)
 * 
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_chrom); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 3216, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 3216, __pyx_L1_error)
  if (!(likely(PyList_CheckExact(__pyx_v_positions))||((__pyx_v_positions) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_positions)->tp_name), 0))) __PYX_ERR(0, 3216, __pyx_L1_error)
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_positionlist_to_segments(((PyObject*)__pyx_t_6), ((PyObject*)__pyx_t_5), ((PyObject*)__pyx_v_positions), 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_segs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3217
 *         positions = self._get_position_hash()[start:end].tolist()
 *         segs = positionlist_to_segments(self.chrom, self.strand, positions)
 *         chain._set_segments(segs)             # <<<<<<<<<<<<<<
 * 
 *         return chain
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain->__pyx_vtab)->_set_segments(__pyx_v_chain, __pyx_v_segs); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 3217, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":3219
 *         chain._set_segments(segs)
 * 
 *         return chain             # <<<<<<<<<<<<<<
 * 
 *     def get_counts(self,ga,stranded=True):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_chain));
  __pyx_r = __pyx_v_chain;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3169
 *         return chain
 * 
 *     cdef SegmentChain c_get_subchain(self, long start, long end, bint stranded):             # <<<<<<<<<<<<<<
 *         """Similar to :meth:`SegmentChain.get_subchain` but does not copy `attr` dict
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.c_get_subchain", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_chain);
  __Pyx_XDECREF(__pyx_v_segs);
  __Pyx_XDECREF(__pyx_v_positions);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3221
 *         return chain
 * 
 *     def get_counts(self,ga,stranded=True):             # <<<<<<<<<<<<<<
 *         """Return list of counts or values drawn from `ga` at each position in `self`
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_85get_counts(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_84get_counts[] = "SegmentChain.get_counts(self, ga, stranded=True)\nReturn list of counts or values drawn from `ga` at each position in `self`\n\n        Parameters\n        ----------\n        ga : GenomeArray from which to fetch counts\n\n        stranded : bool, optional\n            If `True` and `self` is on the minus strand,\n            count order will be reversed relative to genome so that the\n            array positions march from the 5' to 3' end of the chain.\n            (Default: `True`)\n\n\n        Returns\n        -------\n        numpy.ndarray\n            Array of counts from `ga` covering `self`\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_85get_counts(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_ga = 0;
  PyObject *__pyx_v_stranded = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_counts (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_ga,&__pyx_n_s_stranded,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ga)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stranded);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_counts") < 0)) __PYX_ERR(0, 3221, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_ga = values[0];
    __pyx_v_stranded = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_counts", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3221, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_counts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_84get_counts(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_ga, __pyx_v_stranded);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_84get_counts(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_ga, PyObject *__pyx_v_stranded) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_seg = 0;
  PyObject *__pyx_v_segments = 0;
  PyArrayObject *__pyx_v_count_array = 0;
  PyObject *__pyx_v_count_arrays = 0;
  PyObject *__pyx_v_dims = 0;
  int __pyx_v_i;
  int __pyx_v_j;
  int __pyx_v_n;
  PyObject *__pyx_9genexpr23__pyx_v_X = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  Py_ssize_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_counts", 0);

  /* "plastid/genomics/roitools.pyx":3242
 *         cdef:
 *             GenomicSegment  seg
 *             list segments = self._segments             # <<<<<<<<<<<<<<
 *             numpy.ndarray   count_array
 *             list count_arrays
 */
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_segments = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3248
 *             int i, j, n
 * 
 *         if len(self) == 0:             # <<<<<<<<<<<<<<
 *             warn(
 *                 "%s is a zero-length SegmentChain. Returning 0-length count vector."
 */
  __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3248, __pyx_L1_error)
  __pyx_t_3 = ((__pyx_t_2 == 0) != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":3249
 * 
 *         if len(self) == 0:
 *             warn(             # <<<<<<<<<<<<<<
 *                 "%s is a zero-length SegmentChain. Returning 0-length count vector."
 *                 % self.get_name(), DataWarning
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_warn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3249, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "plastid/genomics/roitools.pyx":3251
 *             warn(
 *                 "%s is a zero-length SegmentChain. Returning 0-length count vector."
 *                 % self.get_name(), DataWarning             # <<<<<<<<<<<<<<
 *             )
 *             return numpy.array([], dtype=float)
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3251, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3251, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_s_is_a_zero_length_SegmentChain, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3251, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_DataWarning); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3251, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_8 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_t_5};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3249, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_t_5};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3249, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3249, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (__pyx_t_7) {
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_5);
      __pyx_t_6 = 0;
      __pyx_t_5 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3249, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":3253
 *                 % self.get_name(), DataWarning
 *             )
 *             return numpy.array([], dtype=float)             # <<<<<<<<<<<<<<
 * 
 * #        count_array = numpy.concatenate([ga.get(X,roi_order=False) for X in self._segments],axis=-1)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, ((PyObject *)(&PyFloat_Type))) < 0) __PYX_ERR(0, 3253, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":3248
 *             int i, j, n
 * 
 *         if len(self) == 0:             # <<<<<<<<<<<<<<
 *             warn(
 *                 "%s is a zero-length SegmentChain. Returning 0-length count vector."
 */
  }

  /* "plastid/genomics/roitools.pyx":3259
 *         # code block below is ugly compared to numpy.concatenate, but this is actually
 *         # faster. must be something weird in implementation
 *         count_arrays = [ga.get(X, roi_order=False) for X in segments]             # <<<<<<<<<<<<<<
 *         dims         = list(count_arrays[0].shape)
 *         dims[-1]     = self.length
 */
  { /* enter inner scope */
    __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3259, __pyx_L6_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(__pyx_v_segments == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 3259, __pyx_L6_error)
    }
    __pyx_t_1 = __pyx_v_segments; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    for (;;) {
      if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_9 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_9); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3259, __pyx_L6_error)
      #else
      __pyx_t_9 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3259, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_XDECREF_SET(__pyx_9genexpr23__pyx_v_X, __pyx_t_9);
      __pyx_t_9 = 0;
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_ga, __pyx_n_s_get); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3259, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3259, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_9genexpr23__pyx_v_X);
      __Pyx_GIVEREF(__pyx_9genexpr23__pyx_v_X);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_9genexpr23__pyx_v_X);
      __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3259, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_6);
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_roi_order, Py_False) < 0) __PYX_ERR(0, 3259, __pyx_L6_error)
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3259, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 3259, __pyx_L6_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_9genexpr23__pyx_v_X); __pyx_9genexpr23__pyx_v_X = 0;
    goto __pyx_L9_exit_scope;
    __pyx_L6_error:;
    __Pyx_XDECREF(__pyx_9genexpr23__pyx_v_X); __pyx_9genexpr23__pyx_v_X = 0;
    goto __pyx_L1_error;
    __pyx_L9_exit_scope:;
  } /* exit inner scope */
  __pyx_v_count_arrays = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "plastid/genomics/roitools.pyx":3260
 *         # faster. must be something weird in implementation
 *         count_arrays = [ga.get(X, roi_order=False) for X in segments]
 *         dims         = list(count_arrays[0].shape)             # <<<<<<<<<<<<<<
 *         dims[-1]     = self.length
 *         count_array  = numpy.empty(dims, dtype=float)
 */
  __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_count_arrays, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3260, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3260, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3260, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_dims = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "plastid/genomics/roitools.pyx":3261
 *         count_arrays = [ga.get(X, roi_order=False) for X in segments]
 *         dims         = list(count_arrays[0].shape)
 *         dims[-1]     = self.length             # <<<<<<<<<<<<<<
 *         count_array  = numpy.empty(dims, dtype=float)
 * 
 */
  __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_self->length); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3261, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (unlikely(__Pyx_SetItemInt(__pyx_v_dims, -1L, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 3261, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "plastid/genomics/roitools.pyx":3262
 *         dims         = list(count_arrays[0].shape)
 *         dims[-1]     = self.length
 *         count_array  = numpy.empty(dims, dtype=float)             # <<<<<<<<<<<<<<
 * 
 *         i = 0
 */
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_numpy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3262, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3262, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3262, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_v_dims);
  __Pyx_GIVEREF(__pyx_v_dims);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_dims);
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3262, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, ((PyObject *)(&PyFloat_Type))) < 0) __PYX_ERR(0, 3262, __pyx_L1_error)
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3262, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 3262, __pyx_L1_error)
  __pyx_v_count_array = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "plastid/genomics/roitools.pyx":3264
 *         count_array  = numpy.empty(dims, dtype=float)
 * 
 *         i = 0             # <<<<<<<<<<<<<<
 *         for n, seg in enumerate(segments):
 *             j = i + len(seg)
 */
  __pyx_v_i = 0;

  /* "plastid/genomics/roitools.pyx":3265
 * 
 *         i = 0
 *         for n, seg in enumerate(segments):             # <<<<<<<<<<<<<<
 *             j = i + len(seg)
 *             count_array[..., i:j] = count_arrays[n]
 */
  __pyx_t_8 = 0;
  __pyx_t_6 = __pyx_v_segments; __Pyx_INCREF(__pyx_t_6); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_6)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_7 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_2); __Pyx_INCREF(__pyx_t_7); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3265, __pyx_L1_error)
    #else
    __pyx_t_7 = PySequence_ITEM(__pyx_t_6, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3265, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    #endif
    if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment))))) __PYX_ERR(0, 3265, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_seg, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_7));
    __pyx_t_7 = 0;
    __pyx_v_n = __pyx_t_8;
    __pyx_t_8 = (__pyx_t_8 + 1);

    /* "plastid/genomics/roitools.pyx":3266
 *         i = 0
 *         for n, seg in enumerate(segments):
 *             j = i + len(seg)             # <<<<<<<<<<<<<<
 *             count_array[..., i:j] = count_arrays[n]
 *             i = j
 */
    __pyx_t_10 = PyObject_Length(((PyObject *)__pyx_v_seg)); if (unlikely(__pyx_t_10 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3266, __pyx_L1_error)
    __pyx_v_j = (__pyx_v_i + __pyx_t_10);

    /* "plastid/genomics/roitools.pyx":3267
 *         for n, seg in enumerate(segments):
 *             j = i + len(seg)
 *             count_array[..., i:j] = count_arrays[n]             # <<<<<<<<<<<<<<
 *             i = j
 * 
 */
    __pyx_t_7 = __Pyx_GetItemInt_List(__pyx_v_count_arrays, __pyx_v_n, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3267, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3267, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_j); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3267, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PySlice_New(__pyx_t_5, __pyx_t_1, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3267, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3267, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(Py_Ellipsis);
    __Pyx_GIVEREF(Py_Ellipsis);
    PyTuple_SET_ITEM(__pyx_t_1, 0, Py_Ellipsis);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4);
    __pyx_t_4 = 0;
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_count_array), __pyx_t_1, __pyx_t_7) < 0)) __PYX_ERR(0, 3267, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":3268
 *             j = i + len(seg)
 *             count_array[..., i:j] = count_arrays[n]
 *             i = j             # <<<<<<<<<<<<<<
 * 
 *         if self.c_strand == reverse_strand and stranded is True:
 */
    __pyx_v_i = __pyx_v_j;

    /* "plastid/genomics/roitools.pyx":3265
 * 
 *         i = 0
 *         for n, seg in enumerate(segments):             # <<<<<<<<<<<<<<
 *             j = i + len(seg)
 *             count_array[..., i:j] = count_arrays[n]
 */
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "plastid/genomics/roitools.pyx":3270
 *             i = j
 * 
 *         if self.c_strand == reverse_strand and stranded is True:             # <<<<<<<<<<<<<<
 *             count_array = count_array[..., ::-1]
 * 
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_c_strand); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3270, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyInt_From_enum____pyx_t_7plastid_8genomics_8c_common_Strand(__pyx_e_7plastid_8genomics_8c_common_reverse_strand); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3270, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_6, __pyx_t_7, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3270, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 3270, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_11) {
  } else {
    __pyx_t_3 = __pyx_t_11;
    goto __pyx_L13_bool_binop_done;
  }
  __pyx_t_11 = (__pyx_v_stranded == Py_True);
  __pyx_t_12 = (__pyx_t_11 != 0);
  __pyx_t_3 = __pyx_t_12;
  __pyx_L13_bool_binop_done:;
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":3271
 * 
 *         if self.c_strand == reverse_strand and stranded is True:
 *             count_array = count_array[..., ::-1]             # <<<<<<<<<<<<<<
 * 
 *         return count_array
 */
    __pyx_t_1 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_count_array), __pyx_tuple__39); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3271, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 3271, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_count_array, ((PyArrayObject *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":3270
 *             i = j
 * 
 *         if self.c_strand == reverse_strand and stranded is True:             # <<<<<<<<<<<<<<
 *             count_array = count_array[..., ::-1]
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3273
 *             count_array = count_array[..., ::-1]
 * 
 *         return count_array             # <<<<<<<<<<<<<<
 * 
 *     def get_masked_counts(self, ga, stranded=True, copy=False):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_count_array));
  __pyx_r = ((PyObject *)__pyx_v_count_array);
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3221
 *         return chain
 * 
 *     def get_counts(self,ga,stranded=True):             # <<<<<<<<<<<<<<
 *         """Return list of counts or values drawn from `ga` at each position in `self`
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_counts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_seg);
  __Pyx_XDECREF(__pyx_v_segments);
  __Pyx_XDECREF((PyObject *)__pyx_v_count_array);
  __Pyx_XDECREF(__pyx_v_count_arrays);
  __Pyx_XDECREF(__pyx_v_dims);
  __Pyx_XDECREF(__pyx_9genexpr23__pyx_v_X);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3275
 *         return count_array
 * 
 *     def get_masked_counts(self, ga, stranded=True, copy=False):             # <<<<<<<<<<<<<<
 *         """Return counts covering `self` in dataset `gnd` as a masked array, in
 *         transcript coordinates. Positions masked by
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_87get_masked_counts(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_86get_masked_counts[] = "SegmentChain.get_masked_counts(self, ga, stranded=True, copy=False)\nReturn counts covering `self` in dataset `gnd` as a masked array, in\n        transcript coordinates. Positions masked by\n        :py:meth:`SegmentChain.add_mask` will be masked in the array\n\n        Parameters\n        ----------\n        gnd : non-abstract subclass of |AbstractGenomeArray|\n            GenomeArray from which to fetch counts\n\n        stranded : bool, optional\n            If true and the |SegmentChain| is on the minus strand, count order\n            will be reversed relative to genome so that the array positions\n            march from the 5' to 3' end of the chain.  (Default: `True`)\n\n        copy : bool, optional\n            If `False` (default) returns a view of the data; so changing values\n            in the view changes the values in the |GenomeArray| if it is\n            mutable. If `True`, a copy is returned instead.\n\n\n        Returns\n        -------\n        :py:class:`numpy.ma.masked_array`\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_87get_masked_counts(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_ga = 0;
  CYTHON_UNUSED PyObject *__pyx_v_stranded = 0;
  PyObject *__pyx_v_copy = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_masked_counts (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_ga,&__pyx_n_s_stranded,&__pyx_n_s_copy,0};
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)Py_True);
    values[2] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ga)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stranded);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_copy);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_masked_counts") < 0)) __PYX_ERR(0, 3275, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_ga = values[0];
    __pyx_v_stranded = values[1];
    __pyx_v_copy = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_masked_counts", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3275, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_masked_counts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_86get_masked_counts(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_ga, __pyx_v_stranded, __pyx_v_copy);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_86get_masked_counts(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_ga, CYTHON_UNUSED PyObject *__pyx_v_stranded, PyObject *__pyx_v_copy) {
  PyArrayObject *__pyx_v_counts = 0;
  PyArrayObject *__pyx_v_mask = 0;
  PyArrayObject *__pyx_v_m = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_masked_counts", 0);

  /* "plastid/genomics/roitools.pyx":3301
 *         """
 *         cdef:
 *             numpy.ndarray counts = self.get_counts(ga)             # <<<<<<<<<<<<<<
 *             numpy.ndarray mask, m
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_counts); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3301, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_ga) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_ga);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3301, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 3301, __pyx_L1_error)
  __pyx_v_counts = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3304
 *             numpy.ndarray mask, m
 * 
 *         if self._position_mask is None:             # <<<<<<<<<<<<<<
 *             mask = numpy.zeros_like(counts)
 *         else:
 */
  __pyx_t_4 = (((PyObject *)__pyx_v_self->_position_mask) == Py_None);
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "plastid/genomics/roitools.pyx":3305
 * 
 *         if self._position_mask is None:
 *             mask = numpy.zeros_like(counts)             # <<<<<<<<<<<<<<
 *         else:
 *             # need to use intc bc self._position_mask is an array.array
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3305, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros_like); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3305, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, ((PyObject *)__pyx_v_counts)) : __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_counts));
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3305, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 3305, __pyx_L1_error)
    __pyx_v_mask = ((PyArrayObject *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":3304
 *             numpy.ndarray mask, m
 * 
 *         if self._position_mask is None:             # <<<<<<<<<<<<<<
 *             mask = numpy.zeros_like(counts)
 *         else:
 */
    goto __pyx_L3;
  }

  /* "plastid/genomics/roitools.pyx":3308
 *         else:
 *             # need to use intc bc self._position_mask is an array.array
 *             m = numpy.frombuffer(self._position_mask, dtype=numpy.intc)             # <<<<<<<<<<<<<<
 *             if self.c_strand == reverse_strand:
 *                 m = m[::-1]
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3308, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_frombuffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3308, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3308, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)__pyx_v_self->_position_mask));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self->_position_mask));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->_position_mask));
    __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3308, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3308, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_intc); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3308, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 3308, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3308, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 3308, __pyx_L1_error)
    __pyx_v_m = ((PyArrayObject *)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":3309
 *             # need to use intc bc self._position_mask is an array.array
 *             m = numpy.frombuffer(self._position_mask, dtype=numpy.intc)
 *             if self.c_strand == reverse_strand:             # <<<<<<<<<<<<<<
 *                 m = m[::-1]
 * 
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_c_strand); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3309, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = __Pyx_PyInt_From_enum____pyx_t_7plastid_8genomics_8c_common_Strand(__pyx_e_7plastid_8genomics_8c_common_reverse_strand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3309, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_7, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3309, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 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_ERR(0, 3309, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_5) {

      /* "plastid/genomics/roitools.pyx":3310
 *             m = numpy.frombuffer(self._position_mask, dtype=numpy.intc)
 *             if self.c_strand == reverse_strand:
 *                 m = m[::-1]             # <<<<<<<<<<<<<<
 * 
 *             mask = numpy.empty_like(counts)
 */
      __pyx_t_1 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_m), __pyx_slice__38); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3310, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 3310, __pyx_L1_error)
      __Pyx_DECREF_SET(__pyx_v_m, ((PyArrayObject *)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":3309
 *             # need to use intc bc self._position_mask is an array.array
 *             m = numpy.frombuffer(self._position_mask, dtype=numpy.intc)
 *             if self.c_strand == reverse_strand:             # <<<<<<<<<<<<<<
 *                 m = m[::-1]
 * 
 */
    }

    /* "plastid/genomics/roitools.pyx":3312
 *                 m = m[::-1]
 * 
 *             mask = numpy.empty_like(counts)             # <<<<<<<<<<<<<<
 *             mask[..., :] = m
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3312, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty_like); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3312, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, ((PyObject *)__pyx_v_counts)) : __Pyx_PyObject_CallOneArg(__pyx_t_7, ((PyObject *)__pyx_v_counts));
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3312, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 3312, __pyx_L1_error)
    __pyx_v_mask = ((PyArrayObject *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":3313
 * 
 *             mask = numpy.empty_like(counts)
 *             mask[..., :] = m             # <<<<<<<<<<<<<<
 * 
 *         return MaskedArray(counts, mask=mask.astype(bool), copy=copy)
 */
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_mask), __pyx_tuple__41, ((PyObject *)__pyx_v_m)) < 0)) __PYX_ERR(0, 3313, __pyx_L1_error)
  }
  __pyx_L3:;

  /* "plastid/genomics/roitools.pyx":3315
 *             mask[..., :] = m
 * 
 *         return MaskedArray(counts, mask=mask.astype(bool), copy=copy)             # <<<<<<<<<<<<<<
 * 
 *     def get_sequence(self, genome, stranded=True):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_MaskedArray); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(((PyObject *)__pyx_v_counts));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_counts));
  PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_counts));
  __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_mask), __pyx_n_s_astype); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_8 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_3 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, ((PyObject*)&PyBool_Type)) : __Pyx_PyObject_CallOneArg(__pyx_t_6, ((PyObject*)&PyBool_Type));
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_mask, __pyx_t_3) < 0) __PYX_ERR(0, 3315, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_copy, __pyx_v_copy) < 0) __PYX_ERR(0, 3315, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3275
 *         return count_array
 * 
 *     def get_masked_counts(self, ga, stranded=True, copy=False):             # <<<<<<<<<<<<<<
 *         """Return counts covering `self` in dataset `gnd` as a masked array, in
 *         transcript coordinates. Positions masked by
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_masked_counts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_counts);
  __Pyx_XDECREF((PyObject *)__pyx_v_mask);
  __Pyx_XDECREF((PyObject *)__pyx_v_m);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3317
 *         return MaskedArray(counts, mask=mask.astype(bool), copy=copy)
 * 
 *     def get_sequence(self, genome, stranded=True):             # <<<<<<<<<<<<<<
 *         """Return spliced genomic sequence of |SegmentChain| as a string
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_89get_sequence(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_88get_sequence[] = "SegmentChain.get_sequence(self, genome, stranded=True)\nReturn spliced genomic sequence of |SegmentChain| as a string\n\n        Parameters\n        ----------\n        genome : dict or :class:`twobitreader.TwoBitFile`\n            Dictionary mapping chromosome names to sequences.  Sequences may be\n            strings, string-like, or :py:class:`Bio.Seq.SeqRecord` objects\n\n        stranded : bool\n            If `True` and the |SegmentChain| is on the minus strand, sequence\n            will be reverse-complemented (Default: True)\n\n\n        Returns\n        -------\n        str\n            Nucleotide sequence of the |SegmentChain| extracted from `genome`\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_89get_sequence(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_genome = 0;
  PyObject *__pyx_v_stranded = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_sequence (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_genome,&__pyx_n_s_stranded,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_genome)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stranded);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_sequence") < 0)) __PYX_ERR(0, 3317, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_genome = values[0];
    __pyx_v_stranded = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_sequence", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3317, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_88get_sequence(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_genome, __pyx_v_stranded);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_88get_sequence(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_genome, PyObject *__pyx_v_stranded) {
  PyObject *__pyx_v_ltmp = 0;
  PyObject *__pyx_v_stmp = 0;
  PyObject *__pyx_v_chromseq = NULL;
  PyObject *__pyx_9genexpr24__pyx_v_X = NULL;
  PyObject *__pyx_9genexpr25__pyx_v_X = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *(*__pyx_t_10)(PyObject *);
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_sequence", 0);

  /* "plastid/genomics/roitools.pyx":3340
 *             str stmp
 * 
 *         if len(self._segments) == 0:             # <<<<<<<<<<<<<<
 *             warn(
 *                 "%s is a zero-length SegmentChain. Returning empty sequence." % self.get_name(),
 */
  __pyx_t_1 = __pyx_v_self->_segments;
  __Pyx_INCREF(__pyx_t_1);
  if (unlikely(__pyx_t_1 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 3340, __pyx_L1_error)
  }
  __pyx_t_2 = PyList_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3340, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((__pyx_t_2 == 0) != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":3341
 * 
 *         if len(self._segments) == 0:
 *             warn(             # <<<<<<<<<<<<<<
 *                 "%s is a zero-length SegmentChain. Returning empty sequence." % self.get_name(),
 *                 DataWarning
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_warn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3341, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "plastid/genomics/roitools.pyx":3342
 *         if len(self._segments) == 0:
 *             warn(
 *                 "%s is a zero-length SegmentChain. Returning empty sequence." % self.get_name(),             # <<<<<<<<<<<<<<
 *                 DataWarning
 *             )
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3342, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3342, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_s_is_a_zero_length_SegmentChain_2, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3342, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":3343
 *             warn(
 *                 "%s is a zero-length SegmentChain. Returning empty sequence." % self.get_name(),
 *                 DataWarning             # <<<<<<<<<<<<<<
 *             )
 *             return ""
 */
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_DataWarning); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3343, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_8 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_t_5};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3341, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_t_5};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3341, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3341, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (__pyx_t_7) {
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_5);
      __pyx_t_6 = 0;
      __pyx_t_5 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3341, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":3345
 *                 DataWarning
 *             )
 *             return ""             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_kp_u__33);
    __pyx_r = __pyx_kp_u__33;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":3340
 *             str stmp
 * 
 *         if len(self._segments) == 0:             # <<<<<<<<<<<<<<
 *             warn(
 *                 "%s is a zero-length SegmentChain. Returning empty sequence." % self.get_name(),
 */
  }

  /* "plastid/genomics/roitools.pyx":3348
 * 
 *         else:
 *             chromseq = genome[self.spanning_segment.chrom]             # <<<<<<<<<<<<<<
 *             ltmp = [chromseq[X.start:X.end] for X in self]
 *             stmp = "".join([str(X.seq) if isinstance(X, SeqRecord) else X for X in ltmp])
 */
  /*else*/ {
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_genome, __pyx_v_self->spanning_segment->chrom); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3348, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_chromseq = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":3349
 *         else:
 *             chromseq = genome[self.spanning_segment.chrom]
 *             ltmp = [chromseq[X.start:X.end] for X in self]             # <<<<<<<<<<<<<<
 *             stmp = "".join([str(X.seq) if isinstance(X, SeqRecord) else X for X in ltmp])
 * 
 */
    { /* enter inner scope */
      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3349, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (likely(PyList_CheckExact(((PyObject *)__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_v_self))) {
        __pyx_t_4 = ((PyObject *)__pyx_v_self); __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0;
        __pyx_t_10 = NULL;
      } else {
        __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3349, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_10 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3349, __pyx_L6_error)
      }
      for (;;) {
        if (likely(!__pyx_t_10)) {
          if (likely(PyList_CheckExact(__pyx_t_4))) {
            if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_9 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_9); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3349, __pyx_L6_error)
            #else
            __pyx_t_9 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3349, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_9);
            #endif
          } else {
            if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_9); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3349, __pyx_L6_error)
            #else
            __pyx_t_9 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3349, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_9);
            #endif
          }
        } else {
          __pyx_t_9 = __pyx_t_10(__pyx_t_4);
          if (unlikely(!__pyx_t_9)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 3349, __pyx_L6_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_9);
        }
        __Pyx_XDECREF_SET(__pyx_9genexpr24__pyx_v_X, __pyx_t_9);
        __pyx_t_9 = 0;
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr24__pyx_v_X, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3349, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr24__pyx_v_X, __pyx_n_s_end); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3349, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = __Pyx_PyObject_GetSlice(__pyx_v_chromseq, 0, 0, &__pyx_t_9, &__pyx_t_5, NULL, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3349, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 3349, __pyx_L6_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_9genexpr24__pyx_v_X); __pyx_9genexpr24__pyx_v_X = 0;
      goto __pyx_L9_exit_scope;
      __pyx_L6_error:;
      __Pyx_XDECREF(__pyx_9genexpr24__pyx_v_X); __pyx_9genexpr24__pyx_v_X = 0;
      goto __pyx_L1_error;
      __pyx_L9_exit_scope:;
    } /* exit inner scope */
    __pyx_v_ltmp = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":3350
 *             chromseq = genome[self.spanning_segment.chrom]
 *             ltmp = [chromseq[X.start:X.end] for X in self]
 *             stmp = "".join([str(X.seq) if isinstance(X, SeqRecord) else X for X in ltmp])             # <<<<<<<<<<<<<<
 * 
 *             if self.strand == "-"  and stranded == True:
 */
    { /* enter inner scope */
      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3350, __pyx_L12_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = __pyx_v_ltmp; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0;
      for (;;) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_6); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3350, __pyx_L12_error)
        #else
        __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3350, __pyx_L12_error)
        __Pyx_GOTREF(__pyx_t_6);
        #endif
        __Pyx_XDECREF_SET(__pyx_9genexpr25__pyx_v_X, __pyx_t_6);
        __pyx_t_6 = 0;
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_SeqRecord); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3350, __pyx_L12_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_3 = PyObject_IsInstance(__pyx_9genexpr25__pyx_v_X, __pyx_t_5); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 3350, __pyx_L12_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if ((__pyx_t_3 != 0)) {
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr25__pyx_v_X, __pyx_n_s_seq); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3350, __pyx_L12_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_9 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3350, __pyx_L12_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_6 = __pyx_t_9;
          __pyx_t_9 = 0;
        } else {
          __Pyx_INCREF(__pyx_9genexpr25__pyx_v_X);
          __pyx_t_6 = __pyx_9genexpr25__pyx_v_X;
        }
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 3350, __pyx_L12_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_9genexpr25__pyx_v_X); __pyx_9genexpr25__pyx_v_X = 0;
      goto __pyx_L15_exit_scope;
      __pyx_L12_error:;
      __Pyx_XDECREF(__pyx_9genexpr25__pyx_v_X); __pyx_9genexpr25__pyx_v_X = 0;
      goto __pyx_L1_error;
      __pyx_L15_exit_scope:;
    } /* exit inner scope */
    __pyx_t_4 = PyUnicode_Join(__pyx_kp_u__33, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3350, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_stmp = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":3352
 *             stmp = "".join([str(X.seq) if isinstance(X, SeqRecord) else X for X in ltmp])
 * 
 *             if self.strand == "-"  and stranded == True:             # <<<<<<<<<<<<<<
 *                 stmp = str(Seq(stmp).reverse_complement())
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3352, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_11 = (__Pyx_PyUnicode_Equals(__pyx_t_4, __pyx_kp_u__13, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 3352, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_11) {
    } else {
      __pyx_t_3 = __pyx_t_11;
      goto __pyx_L17_bool_binop_done;
    }
    __pyx_t_4 = PyObject_RichCompare(__pyx_v_stranded, Py_True, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3352, __pyx_L1_error)
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 3352, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_3 = __pyx_t_11;
    __pyx_L17_bool_binop_done:;
    if (__pyx_t_3) {

      /* "plastid/genomics/roitools.pyx":3353
 * 
 *             if self.strand == "-"  and stranded == True:
 *                 stmp = str(Seq(stmp).reverse_complement())             # <<<<<<<<<<<<<<
 * 
 *         return stmp
 */
      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_Seq); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3353, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_9 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_9, __pyx_v_stmp) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_stmp);
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3353, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_reverse_complement); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3353, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3353, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3353, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF_SET(__pyx_v_stmp, ((PyObject*)__pyx_t_6));
      __pyx_t_6 = 0;

      /* "plastid/genomics/roitools.pyx":3352
 *             stmp = "".join([str(X.seq) if isinstance(X, SeqRecord) else X for X in ltmp])
 * 
 *             if self.strand == "-"  and stranded == True:             # <<<<<<<<<<<<<<
 *                 stmp = str(Seq(stmp).reverse_complement())
 * 
 */
    }
  }

  /* "plastid/genomics/roitools.pyx":3355
 *                 stmp = str(Seq(stmp).reverse_complement())
 * 
 *         return stmp             # <<<<<<<<<<<<<<
 * 
 *     def get_fasta(self, genome, stranded=True):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_stmp);
  __pyx_r = __pyx_v_stmp;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3317
 *         return MaskedArray(counts, mask=mask.astype(bool), copy=copy)
 * 
 *     def get_sequence(self, genome, stranded=True):             # <<<<<<<<<<<<<<
 *         """Return spliced genomic sequence of |SegmentChain| as a string
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ltmp);
  __Pyx_XDECREF(__pyx_v_stmp);
  __Pyx_XDECREF(__pyx_v_chromseq);
  __Pyx_XDECREF(__pyx_9genexpr24__pyx_v_X);
  __Pyx_XDECREF(__pyx_9genexpr25__pyx_v_X);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3357
 *         return stmp
 * 
 *     def get_fasta(self, genome, stranded=True):             # <<<<<<<<<<<<<<
 *         """Formats sequence of SegmentChain as FASTA output
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_91get_fasta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_90get_fasta[] = "SegmentChain.get_fasta(self, genome, stranded=True)\nFormats sequence of SegmentChain as FASTA output\n\n        Parameters\n        ----------\n        genome : dict or :class:`twobitreader.TwoBitFile`\n            Dictionary mapping chromosome names to sequences. Sequences may be\n            strings, string-like, or :py:class:`Bio.Seq.SeqRecord` objects\n\n        stranded : bool\n            If `True` and the |SegmentChain| is on the minus strand, sequence\n            will be reverse-complemented (Default: True)\n\n\n        Returns\n        -------\n        str\n            FASTA-formatted seuqence of |SegmentChain| extracted from `genome`\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_91get_fasta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_genome = 0;
  PyObject *__pyx_v_stranded = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_fasta (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_genome,&__pyx_n_s_stranded,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_genome)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stranded);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_fasta") < 0)) __PYX_ERR(0, 3357, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_genome = values[0];
    __pyx_v_stranded = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_fasta", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3357, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_fasta", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_90get_fasta(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_genome, __pyx_v_stranded);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_90get_fasta(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_genome, PyObject *__pyx_v_stranded) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  Py_UCS4 __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_fasta", 0);

  /* "plastid/genomics/roitools.pyx":3376
 *             FASTA-formatted seuqence of |SegmentChain| extracted from `genome`
 *         """
 *         return ">%s\n%s\n" % (self.get_name(), self.get_sequence(genome, stranded=stranded))             # <<<<<<<<<<<<<<
 * 
 *     @staticmethod
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3376, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = 0;
  __pyx_t_3 = 127;
  __Pyx_INCREF(__pyx_kp_u__30);
  __pyx_t_2 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__30);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u__30);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3376, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3376, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_4), __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3376, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_3;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
  __pyx_t_5 = 0;
  __Pyx_INCREF(__pyx_kp_u__18);
  __pyx_t_2 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__18);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u__18);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_sequence); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3376, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3376, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_genome);
  __Pyx_GIVEREF(__pyx_v_genome);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_genome);
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3376, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_stranded, __pyx_v_stranded) < 0) __PYX_ERR(0, 3376, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3376, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_7), __pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3376, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_3;
  __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_6);
  __pyx_t_6 = 0;
  __Pyx_INCREF(__pyx_kp_u__18);
  __pyx_t_2 += 1;
  __Pyx_GIVEREF(__pyx_kp_u__18);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__18);
  __pyx_t_6 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3376, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3357
 *         return stmp
 * 
 *     def get_fasta(self, genome, stranded=True):             # <<<<<<<<<<<<<<
 *         """Formats sequence of SegmentChain as FASTA output
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.get_fasta", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3379
 * 
 *     @staticmethod
 *     def from_str(str inp):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| from a string formatted by :py:meth:`SegmentChain.__str__`:
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_93from_str(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_92from_str[] = "SegmentChain.from_str(unicode inp)\nCreate a |SegmentChain| from a string formatted by :py:meth:`SegmentChain.__str__`:\n\n            `chrom:start-end^start-end(strand)`\n\n        where '^' indicates a splice junction between regions specified\n        by `start` and `end` and `strand` is '+', '-', or '.'. Coordinates are\n        0-indexed and half-open.\n\n\n        Parameters\n        ----------\n        inp : str\n\t\t\tString formatted in manner of :py:meth:`SegmentChain.__str__`\n\n\n        Returns\n        -------\n        |SegmentChain|\n        ";
static PyMethodDef __pyx_mdef_7plastid_8genomics_8roitools_12SegmentChain_93from_str = {"from_str", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_93from_str, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_92from_str};
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_93from_str(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_inp = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_str (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_inp,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_inp)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "from_str") < 0)) __PYX_ERR(0, 3379, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_inp = ((PyObject*)values[0]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("from_str", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3379, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.from_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_inp), (&PyUnicode_Type), 1, "inp", 1))) __PYX_ERR(0, 3379, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_92from_str(__pyx_v_inp);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_92from_str(PyObject *__pyx_v_inp) {
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_middle = 0;
  PyObject *__pyx_v_strand = 0;
  PyObject *__pyx_v_sstart = 0;
  PyObject *__pyx_v_send = 0;
  PyObject *__pyx_v_piece = 0;
  PyObject *__pyx_v_segs = 0;
  long __pyx_v_start;
  long __pyx_v_end;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  Py_ssize_t __pyx_t_12;
  long __pyx_t_13;
  int __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("from_str", 0);

  /* "plastid/genomics/roitools.pyx":3404
 *             long start, end
 * 
 *         if inp in ("na", "nan", "None:(None)", "None", "none", None) \             # <<<<<<<<<<<<<<
 *             or isinstance(inp, float) \
 *             and numpy.isnan(inp):
 */
  __Pyx_INCREF(__pyx_v_inp);
  __pyx_t_2 = __pyx_v_inp;
  __pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_na, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 3404, __pyx_L1_error)
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (!__pyx_t_5) {
  } else {
    __pyx_t_3 = __pyx_t_5;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_nan, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3404, __pyx_L1_error)
  __pyx_t_4 = (__pyx_t_5 != 0);
  if (!__pyx_t_4) {
  } else {
    __pyx_t_3 = __pyx_t_4;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_kp_u_None_None, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 3404, __pyx_L1_error)
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (!__pyx_t_5) {
  } else {
    __pyx_t_3 = __pyx_t_5;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_kp_u_None, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3404, __pyx_L1_error)
  __pyx_t_4 = (__pyx_t_5 != 0);
  if (!__pyx_t_4) {
  } else {
    __pyx_t_3 = __pyx_t_4;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_none, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 3404, __pyx_L1_error)
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (!__pyx_t_5) {
  } else {
    __pyx_t_3 = __pyx_t_5;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_t_2, Py_None, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3404, __pyx_L1_error)
  __pyx_t_3 = __pyx_t_5;
  __pyx_L6_bool_binop_done:;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = (__pyx_t_3 != 0);
  if (!__pyx_t_5) {
  } else {
    __pyx_t_1 = __pyx_t_5;
    goto __pyx_L4_bool_binop_done;
  }

  /* "plastid/genomics/roitools.pyx":3405
 * 
 *         if inp in ("na", "nan", "None:(None)", "None", "none", None) \
 *             or isinstance(inp, float) \             # <<<<<<<<<<<<<<
 *             and numpy.isnan(inp):
 * 
 */
  __pyx_t_5 = PyFloat_Check(__pyx_v_inp); 
  __pyx_t_3 = (__pyx_t_5 != 0);
  if (__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }

  /* "plastid/genomics/roitools.pyx":3406
 *         if inp in ("na", "nan", "None:(None)", "None", "none", None) \
 *             or isinstance(inp, float) \
 *             and numpy.isnan(inp):             # <<<<<<<<<<<<<<
 * 
 *             return SegmentChain()
 */
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_numpy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3406, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_isnan); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3406, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_v_inp) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_inp);
  __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3406, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 3406, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;

  /* "plastid/genomics/roitools.pyx":3404
 *             long start, end
 * 
 *         if inp in ("na", "nan", "None:(None)", "None", "none", None) \             # <<<<<<<<<<<<<<
 *             or isinstance(inp, float) \
 *             and numpy.isnan(inp):
 */
  if (__pyx_t_1) {

    /* "plastid/genomics/roitools.pyx":3408
 *             and numpy.isnan(inp):
 * 
 *             return SegmentChain()             # <<<<<<<<<<<<<<
 *         else:
 *             chrom, middle, strand = ivcpat.search(inp).groups()
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_6 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3408, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":3404
 *             long start, end
 * 
 *         if inp in ("na", "nan", "None:(None)", "None", "none", None) \             # <<<<<<<<<<<<<<
 *             or isinstance(inp, float) \
 *             and numpy.isnan(inp):
 */
  }

  /* "plastid/genomics/roitools.pyx":3410
 *             return SegmentChain()
 *         else:
 *             chrom, middle, strand = ivcpat.search(inp).groups()             # <<<<<<<<<<<<<<
 *             segs = []
 *             for piece in middle.split("^"):
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_ivcpat); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3410, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_search); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3410, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_7, __pyx_v_inp) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_inp);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3410, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_groups); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3410, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_9);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3410, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
      PyObject* sequence = __pyx_t_6;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 3)) {
        if (size > 3) __Pyx_RaiseTooManyValuesError(3);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 3410, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); 
      } else {
        __pyx_t_9 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_8 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_7 = PyList_GET_ITEM(sequence, 2); 
      }
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_7);
      #else
      __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3410, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3410, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3410, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      #endif
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_10 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3410, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
      index = 0; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L13_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      index = 1; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L13_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_8);
      index = 2; __pyx_t_7 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_7)) goto __pyx_L13_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_7);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 3) < 0) __PYX_ERR(0, 3410, __pyx_L1_error)
      __pyx_t_11 = NULL;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      goto __pyx_L14_unpacking_done;
      __pyx_L13_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_11 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 3410, __pyx_L1_error)
      __pyx_L14_unpacking_done:;
    }
    if (!(likely(PyUnicode_CheckExact(__pyx_t_9))||((__pyx_t_9) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_9)->tp_name), 0))) __PYX_ERR(0, 3410, __pyx_L1_error)
    if (!(likely(PyUnicode_CheckExact(__pyx_t_8))||((__pyx_t_8) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_8)->tp_name), 0))) __PYX_ERR(0, 3410, __pyx_L1_error)
    if (!(likely(PyUnicode_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_7)->tp_name), 0))) __PYX_ERR(0, 3410, __pyx_L1_error)
    __pyx_v_chrom = ((PyObject*)__pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_v_middle = ((PyObject*)__pyx_t_8);
    __pyx_t_8 = 0;
    __pyx_v_strand = ((PyObject*)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":3411
 *         else:
 *             chrom, middle, strand = ivcpat.search(inp).groups()
 *             segs = []             # <<<<<<<<<<<<<<
 *             for piece in middle.split("^"):
 *                 sstart, send = piece.split("-")
 */
    __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3411, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_v_segs = ((PyObject*)__pyx_t_6);
    __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":3412
 *             chrom, middle, strand = ivcpat.search(inp).groups()
 *             segs = []
 *             for piece in middle.split("^"):             # <<<<<<<<<<<<<<
 *                 sstart, send = piece.split("-")
 *                 start = <long>long(sstart)
 */
    if (unlikely(__pyx_v_middle == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "split");
      __PYX_ERR(0, 3412, __pyx_L1_error)
    }
    __pyx_t_6 = PyUnicode_Split(__pyx_v_middle, __pyx_kp_u__31, -1L); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3412, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __pyx_t_6; __Pyx_INCREF(__pyx_t_7); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    for (;;) {
      if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_7)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_6 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_12); __Pyx_INCREF(__pyx_t_6); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 3412, __pyx_L1_error)
      #else
      __pyx_t_6 = PySequence_ITEM(__pyx_t_7, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3412, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      #endif
      if (!(likely(PyUnicode_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 3412, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_piece, ((PyObject*)__pyx_t_6));
      __pyx_t_6 = 0;

      /* "plastid/genomics/roitools.pyx":3413
 *             segs = []
 *             for piece in middle.split("^"):
 *                 sstart, send = piece.split("-")             # <<<<<<<<<<<<<<
 *                 start = <long>long(sstart)
 *                 end = <long>long(send)
 */
      if (unlikely(__pyx_v_piece == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "split");
        __PYX_ERR(0, 3413, __pyx_L1_error)
      }
      __pyx_t_6 = PyUnicode_Split(__pyx_v_piece, __pyx_kp_u__13, -1L); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3413, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      if (1) {
        PyObject* sequence = __pyx_t_6;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 3413, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_9);
        #else
        __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3413, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3413, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      if (!(likely(PyUnicode_CheckExact(__pyx_t_8))||((__pyx_t_8) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_8)->tp_name), 0))) __PYX_ERR(0, 3413, __pyx_L1_error)
      if (!(likely(PyUnicode_CheckExact(__pyx_t_9))||((__pyx_t_9) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_9)->tp_name), 0))) __PYX_ERR(0, 3413, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_sstart, ((PyObject*)__pyx_t_8));
      __pyx_t_8 = 0;
      __Pyx_XDECREF_SET(__pyx_v_send, ((PyObject*)__pyx_t_9));
      __pyx_t_9 = 0;

      /* "plastid/genomics/roitools.pyx":3414
 *             for piece in middle.split("^"):
 *                 sstart, send = piece.split("-")
 *                 start = <long>long(sstart)             # <<<<<<<<<<<<<<
 *                 end = <long>long(send)
 *                 segs.append(GenomicSegment(chrom, start, end, strand))
 */
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_v_sstart); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3414, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_13 = __Pyx_PyInt_As_long(__pyx_t_6); if (unlikely((__pyx_t_13 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3414, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_start = ((long)__pyx_t_13);

      /* "plastid/genomics/roitools.pyx":3415
 *                 sstart, send = piece.split("-")
 *                 start = <long>long(sstart)
 *                 end = <long>long(send)             # <<<<<<<<<<<<<<
 *                 segs.append(GenomicSegment(chrom, start, end, strand))
 *             return SegmentChain(*segs)
 */
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_v_send); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3415, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_13 = __Pyx_PyInt_As_long(__pyx_t_6); if (unlikely((__pyx_t_13 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3415, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_end = ((long)__pyx_t_13);

      /* "plastid/genomics/roitools.pyx":3416
 *                 start = <long>long(sstart)
 *                 end = <long>long(send)
 *                 segs.append(GenomicSegment(chrom, start, end, strand))             # <<<<<<<<<<<<<<
 *             return SegmentChain(*segs)
 * 
 */
      __pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_start); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3416, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_v_end); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3416, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_8 = PyTuple_New(4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3416, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_v_chrom);
      __Pyx_GIVEREF(__pyx_v_chrom);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_chrom);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_9);
      __Pyx_INCREF(__pyx_v_strand);
      __Pyx_GIVEREF(__pyx_v_strand);
      PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_v_strand);
      __pyx_t_6 = 0;
      __pyx_t_9 = 0;
      __pyx_t_9 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3416, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_segs, __pyx_t_9); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 3416, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "plastid/genomics/roitools.pyx":3412
 *             chrom, middle, strand = ivcpat.search(inp).groups()
 *             segs = []
 *             for piece in middle.split("^"):             # <<<<<<<<<<<<<<
 *                 sstart, send = piece.split("-")
 *                 start = <long>long(sstart)
 */
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":3417
 *                 end = <long>long(send)
 *                 segs.append(GenomicSegment(chrom, start, end, strand))
 *             return SegmentChain(*segs)             # <<<<<<<<<<<<<<
 * 
 *     # at each call to from_bed (e.g. from a BigBedReader)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_7 = PySequence_Tuple(__pyx_v_segs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3417, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_t_7, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3417, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_r = __pyx_t_9;
    __pyx_t_9 = 0;
    goto __pyx_L0;
  }

  /* "plastid/genomics/roitools.pyx":3379
 * 
 *     @staticmethod
 *     def from_str(str inp):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| from a string formatted by :py:meth:`SegmentChain.__str__`:
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.from_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_middle);
  __Pyx_XDECREF(__pyx_v_strand);
  __Pyx_XDECREF(__pyx_v_sstart);
  __Pyx_XDECREF(__pyx_v_send);
  __Pyx_XDECREF(__pyx_v_piece);
  __Pyx_XDECREF(__pyx_v_segs);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3421
 *     # at each call to from_bed (e.g. from a BigBedReader)
 *     @staticmethod
 *     def from_bed(str line, object extra_columns=0):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| from a line from a `BED`_ file.  The `BED`_
 *         line may contain 4 to 12 columns, per the specification.  These will be
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_95from_bed(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_94from_bed[] = "SegmentChain.from_bed(unicode line, extra_columns=0)\nCreate a |SegmentChain| from a line from a `BED`_ file.  The `BED`_\n        line may contain 4 to 12 columns, per the specification.  These will be\n        auto-detected and parsed appropriately.\n\n        See the `UCSC file format faq <http://genome.ucsc.edu/FAQ/FAQformat.html>`_\n        for more details.\n\n        Parameters\n        ----------\n        line\n            Line from a `BED`_ file, containing 4 or more columns\n\n        extra_columns: int or list optional\n            Extra, non-BED columns in :term:`Extended BED`_ format file\n            corresponding to feature attributes. This is common in\n            `ENCODE`_-specific `BED`_ variants.\n\n            if `extra-columns` is:\n\n              - an :class:`int`: it is taken to be the number of attribute\n                columns. Attributes will be stored in the `attr` dictionary of\n                the |SegmentChain|, under names like `custom0`, `custom1`, ...\n                , `customN`.\n\n              - a :class:`list` of :class:`str`, it is taken to be the names of\n                the attribute columns, in order, from left to right in the\n                file.  In this case, attributes in extra columns will be stored\n                under their respective names in the `attr` dict.\n\n              - a :class:`list` of :class:`tuple`, each tuple is taken\n                to be a pair of `(attribute_name, formatter_func)`. In this\n                case, the value of `attribute_name` in the `attr` dict of the\n                |SegmentChain| will be set to `formatter_func(column_value)`.\n\n            (Default: 0)\n\n        Returns\n        -------\n        |SegmentChain|\n        ";
static PyMethodDef __pyx_mdef_7plastid_8genomics_8roitools_12SegmentChain_95from_bed = {"from_bed", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_95from_bed, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_94from_bed};
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_95from_bed(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_line = 0;
  PyObject *__pyx_v_extra_columns = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_bed (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_line,&__pyx_n_s_extra_columns,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_int_0);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_line)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_extra_columns);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "from_bed") < 0)) __PYX_ERR(0, 3421, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_line = ((PyObject*)values[0]);
    __pyx_v_extra_columns = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("from_bed", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3421, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.from_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_line), (&PyUnicode_Type), 1, "line", 1))) __PYX_ERR(0, 3421, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_94from_bed(__pyx_v_line, __pyx_v_extra_columns);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_94from_bed(PyObject *__pyx_v_line, PyObject *__pyx_v_extra_columns) {
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_v_segments = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_chain = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_7plastid_8genomics_8roitools_get_attr_from_bed __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("from_bed", 0);

  /* "plastid/genomics/roitools.pyx":3463
 *         """
 *         cdef:
 *             dict         attr     = get_attr_from_bed(line, extra_columns=extra_columns)             # <<<<<<<<<<<<<<
 *             list         segments = get_segments_from_bed(attr)
 *             SegmentChain chain    = SegmentChain()
 */
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.extra_columns = __pyx_v_extra_columns;
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed(__pyx_v_line, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3464
 *         cdef:
 *             dict         attr     = get_attr_from_bed(line, extra_columns=extra_columns)
 *             list         segments = get_segments_from_bed(attr)             # <<<<<<<<<<<<<<
 *             SegmentChain chain    = SegmentChain()
 * 
 */
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_get_segments_from_bed(__pyx_v_attr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3464, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_segments = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3465
 *             dict         attr     = get_attr_from_bed(line, extra_columns=extra_columns)
 *             list         segments = get_segments_from_bed(attr)
 *             SegmentChain chain    = SegmentChain()             # <<<<<<<<<<<<<<
 * 
 *         chain._set_segments(segments)
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3465, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_chain = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3467
 *             SegmentChain chain    = SegmentChain()
 * 
 *         chain._set_segments(segments)             # <<<<<<<<<<<<<<
 *         chain.attr.update(attr)
 *         return chain
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain->__pyx_vtab)->_set_segments(__pyx_v_chain, __pyx_v_segments); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 3467, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":3468
 * 
 *         chain._set_segments(segments)
 *         chain.attr.update(attr)             # <<<<<<<<<<<<<<
 *         return chain
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_chain->attr, __pyx_n_s_update); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3468, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_v_attr) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_attr);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3468, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3469
 *         chain._set_segments(segments)
 *         chain.attr.update(attr)
 *         return chain             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_chain));
  __pyx_r = ((PyObject *)__pyx_v_chain);
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3421
 *     # at each call to from_bed (e.g. from a BigBedReader)
 *     @staticmethod
 *     def from_bed(str line, object extra_columns=0):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| from a line from a `BED`_ file.  The `BED`_
 *         line may contain 4 to 12 columns, per the specification.  These will be
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.from_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_v_segments);
  __Pyx_XDECREF((PyObject *)__pyx_v_chain);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3473
 * 
 *     @staticmethod
 *     def from_psl(psl_line):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| from a line from a `PSL`_ (BLAT) file
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_97from_psl(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_96from_psl[] = "SegmentChain.from_psl(psl_line)\nCreate a |SegmentChain| from a line from a `PSL`_ (BLAT) file\n\n        See the `PSL spec <http://pombe.nci.nih.gov/genome/goldenPath/help/blatSpec.html>`_\n\n        Parameters\n        ----------\n        psl_line : str\n            Line from a `PSL`_ file\n\n        Returns\n        -------\n        |SegmentChain|\n        ";
static PyMethodDef __pyx_mdef_7plastid_8genomics_8roitools_12SegmentChain_97from_psl = {"from_psl", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_97from_psl, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_96from_psl};
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_97from_psl(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_psl_line = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_psl (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_psl_line,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_psl_line)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "from_psl") < 0)) __PYX_ERR(0, 3473, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_psl_line = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("from_psl", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3473, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.from_psl", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_96from_psl(__pyx_v_psl_line);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_96from_psl(PyObject *__pyx_v_psl_line) {
  PyObject *__pyx_v_items = 0;
  PyObject *__pyx_v_segs = 0;
  PyObject *__pyx_v_attr = 0;
  long __pyx_v_t_start;
  long __pyx_v_block_size;
  PyObject *__pyx_v_st = 0;
  PyObject *__pyx_v_sb = 0;
  PyObject *__pyx_v_strand = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_seg = 0;
  PyObject *__pyx_v_block_sizes = 0;
  PyObject *__pyx_v_sq_starts = 0;
  PyObject *__pyx_v_st_starts = 0;
  PyObject *__pyx_v_t_starts = 0;
  PyObject *__pyx_v_q_starts = 0;
  PyObject *__pyx_v_sq = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  Py_UCS4 __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  long __pyx_t_12;
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("from_psl", 0);

  /* "plastid/genomics/roitools.pyx":3488
 *         """
 *         cdef:
 *             list items = psl_line.strip().split("\t")             # <<<<<<<<<<<<<<
 *             list segs = []
 *             dict attr = {}
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_psl_line, __pyx_n_s_strip); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3488, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3488, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3488, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u__19) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u__19);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3488, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 3488, __pyx_L1_error)
  __pyx_v_items = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3489
 *         cdef:
 *             list items = psl_line.strip().split("\t")
 *             list segs = []             # <<<<<<<<<<<<<<
 *             dict attr = {}
 *             long t_start, block_size
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3489, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_segs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3490
 *             list items = psl_line.strip().split("\t")
 *             list segs = []
 *             dict attr = {}             # <<<<<<<<<<<<<<
 *             long t_start, block_size
 *             str st, sb
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3496
 *             GenomicSegment seg
 *             list block_sizes, sq_starts, st_starts
 *             list t_starts = []             # <<<<<<<<<<<<<<
 *             list q_starts = []
 * 
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3496, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_t_starts = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3497
 *             list block_sizes, sq_starts, st_starts
 *             list t_starts = []
 *             list q_starts = []             # <<<<<<<<<<<<<<
 * 
 *         attr["type"]             = "alignment"
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3497, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_q_starts = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3499
 *             list q_starts = []
 * 
 *         attr["type"]             = "alignment"             # <<<<<<<<<<<<<<
 *         attr["query_name"]       = items[9]
 *         attr["match_length"]     = int(items[0])
 */
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_type, __pyx_n_u_alignment) < 0)) __PYX_ERR(0, 3499, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":3500
 * 
 *         attr["type"]             = "alignment"
 *         attr["query_name"]       = items[9]             # <<<<<<<<<<<<<<
 *         attr["match_length"]     = int(items[0])
 *         attr["mismatches"]       = int(items[1])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3500, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_items, 9, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3500, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_query_name, __pyx_t_1) < 0)) __PYX_ERR(0, 3500, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3501
 *         attr["type"]             = "alignment"
 *         attr["query_name"]       = items[9]
 *         attr["match_length"]     = int(items[0])             # <<<<<<<<<<<<<<
 *         attr["mismatches"]       = int(items[1])
 *         attr["rep_matches"]      = int(items[2])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3501, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_items, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3501, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3501, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_match_length, __pyx_t_3) < 0)) __PYX_ERR(0, 3501, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":3502
 *         attr["query_name"]       = items[9]
 *         attr["match_length"]     = int(items[0])
 *         attr["mismatches"]       = int(items[1])             # <<<<<<<<<<<<<<
 *         attr["rep_matches"]      = int(items[2])
 *         attr["N"]                = int(items[3])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3502, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_items, 1, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3502, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3502, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_mismatches, __pyx_t_1) < 0)) __PYX_ERR(0, 3502, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3503
 *         attr["match_length"]     = int(items[0])
 *         attr["mismatches"]       = int(items[1])
 *         attr["rep_matches"]      = int(items[2])             # <<<<<<<<<<<<<<
 *         attr["N"]                = int(items[3])
 *         attr["query_gap_count"]  = int(items[4])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3503, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_items, 2, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_rep_matches, __pyx_t_3) < 0)) __PYX_ERR(0, 3503, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":3504
 *         attr["mismatches"]       = int(items[1])
 *         attr["rep_matches"]      = int(items[2])
 *         attr["N"]                = int(items[3])             # <<<<<<<<<<<<<<
 *         attr["query_gap_count"]  = int(items[4])
 *         attr["query_gap_bases"]  = int(items[5])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3504, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_items, 3, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3504, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3504, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_N, __pyx_t_1) < 0)) __PYX_ERR(0, 3504, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3505
 *         attr["rep_matches"]      = int(items[2])
 *         attr["N"]                = int(items[3])
 *         attr["query_gap_count"]  = int(items[4])             # <<<<<<<<<<<<<<
 *         attr["query_gap_bases"]  = int(items[5])
 *         attr["target_gap_count"] = int(items[6])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3505, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_items, 4, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_query_gap_count, __pyx_t_3) < 0)) __PYX_ERR(0, 3505, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":3506
 *         attr["N"]                = int(items[3])
 *         attr["query_gap_count"]  = int(items[4])
 *         attr["query_gap_bases"]  = int(items[5])             # <<<<<<<<<<<<<<
 *         attr["target_gap_count"] = int(items[6])
 *         attr["target_gap_bases"] = int(items[7])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3506, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_items, 5, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_query_gap_bases, __pyx_t_1) < 0)) __PYX_ERR(0, 3506, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3507
 *         attr["query_gap_count"]  = int(items[4])
 *         attr["query_gap_bases"]  = int(items[5])
 *         attr["target_gap_count"] = int(items[6])             # <<<<<<<<<<<<<<
 *         attr["target_gap_bases"] = int(items[7])
 * 
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3507, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_items, 6, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_target_gap_count, __pyx_t_3) < 0)) __PYX_ERR(0, 3507, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":3508
 *         attr["query_gap_bases"]  = int(items[5])
 *         attr["target_gap_count"] = int(items[6])
 *         attr["target_gap_bases"] = int(items[7])             # <<<<<<<<<<<<<<
 * 
 *         attr["query_length"]     = int(items[10])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3508, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_items, 7, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3508, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3508, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_target_gap_bases, __pyx_t_1) < 0)) __PYX_ERR(0, 3508, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3510
 *         attr["target_gap_bases"] = int(items[7])
 * 
 *         attr["query_length"]     = int(items[10])             # <<<<<<<<<<<<<<
 *         attr["query_start"]      = int(items[11])
 *         attr["query_end"]        = int(items[12])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3510, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_items, 10, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3510, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3510, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_query_length, __pyx_t_3) < 0)) __PYX_ERR(0, 3510, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":3511
 * 
 *         attr["query_length"]     = int(items[10])
 *         attr["query_start"]      = int(items[11])             # <<<<<<<<<<<<<<
 *         attr["query_end"]        = int(items[12])
 *         attr["target_name"]      = items[13]
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3511, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_items, 11, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_query_start, __pyx_t_1) < 0)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3512
 *         attr["query_length"]     = int(items[10])
 *         attr["query_start"]      = int(items[11])
 *         attr["query_end"]        = int(items[12])             # <<<<<<<<<<<<<<
 *         attr["target_name"]      = items[13]
 *         attr["target_length"]    = int(items[14])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3512, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_items, 12, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3512, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3512, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_query_end, __pyx_t_3) < 0)) __PYX_ERR(0, 3512, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":3513
 *         attr["query_start"]      = int(items[11])
 *         attr["query_end"]        = int(items[12])
 *         attr["target_name"]      = items[13]             # <<<<<<<<<<<<<<
 *         attr["target_length"]    = int(items[14])
 *         attr["target_start"]     = int(items[15])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3513, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_items, 13, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3513, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_target_name, __pyx_t_3) < 0)) __PYX_ERR(0, 3513, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":3514
 *         attr["query_end"]        = int(items[12])
 *         attr["target_name"]      = items[13]
 *         attr["target_length"]    = int(items[14])             # <<<<<<<<<<<<<<
 *         attr["target_start"]     = int(items[15])
 *         attr["target_end"]       = int(items[16])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3514, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_items, 14, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3514, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3514, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_target_length, __pyx_t_1) < 0)) __PYX_ERR(0, 3514, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3515
 *         attr["target_name"]      = items[13]
 *         attr["target_length"]    = int(items[14])
 *         attr["target_start"]     = int(items[15])             # <<<<<<<<<<<<<<
 *         attr["target_end"]       = int(items[16])
 *         attr["ID"]               = attr["query_name"]
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3515, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_items, 15, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_target_start, __pyx_t_3) < 0)) __PYX_ERR(0, 3515, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "plastid/genomics/roitools.pyx":3516
 *         attr["target_length"]    = int(items[14])
 *         attr["target_start"]     = int(items[15])
 *         attr["target_end"]       = int(items[16])             # <<<<<<<<<<<<<<
 *         attr["ID"]               = attr["query_name"]
 *         #block_count           = int(items[17])
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3516, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_items, 16, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3516, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3516, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_target_end, __pyx_t_1) < 0)) __PYX_ERR(0, 3516, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3517
 *         attr["target_start"]     = int(items[15])
 *         attr["target_end"]       = int(items[16])
 *         attr["ID"]               = attr["query_name"]             # <<<<<<<<<<<<<<
 *         #block_count           = int(items[17])
 * 
 */
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_query_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3517, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_ID_2, __pyx_t_1) < 0)) __PYX_ERR(0, 3517, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3522
 *         # for translated alignments, "++" or "+-" are results,
 *         # the second result indicating the genomic strand
 *         strand = items[8]             # <<<<<<<<<<<<<<
 *         if len(strand) == 2:
 *             if strand[0] == "+":
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3522, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_items, 8, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 3522, __pyx_L1_error)
  __pyx_v_strand = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3523
 *         # the second result indicating the genomic strand
 *         strand = items[8]
 *         if len(strand) == 2:             # <<<<<<<<<<<<<<
 *             if strand[0] == "+":
 *                 strand = strand[:-1]
 */
  if (unlikely(__pyx_v_strand == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 3523, __pyx_L1_error)
  }
  __pyx_t_5 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_strand); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3523, __pyx_L1_error)
  __pyx_t_6 = ((__pyx_t_5 == 2) != 0);
  if (__pyx_t_6) {

    /* "plastid/genomics/roitools.pyx":3524
 *         strand = items[8]
 *         if len(strand) == 2:
 *             if strand[0] == "+":             # <<<<<<<<<<<<<<
 *                 strand = strand[:-1]
 *             elif strand[0] == "-":
 */
    __pyx_t_7 = __Pyx_GetItemInt_Unicode(__pyx_v_strand, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_7 == (Py_UCS4)-1)) __PYX_ERR(0, 3524, __pyx_L1_error)
    __pyx_t_6 = ((__pyx_t_7 == 43) != 0);
    if (__pyx_t_6) {

      /* "plastid/genomics/roitools.pyx":3525
 *         if len(strand) == 2:
 *             if strand[0] == "+":
 *                 strand = strand[:-1]             # <<<<<<<<<<<<<<
 *             elif strand[0] == "-":
 *                 strand = "+" if strand[:-1] == "-" else "+"
 */
      if (unlikely(__pyx_v_strand == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 3525, __pyx_L1_error)
      }
      __pyx_t_1 = __Pyx_PyUnicode_Substring(__pyx_v_strand, 0, -1L); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3525, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF_SET(__pyx_v_strand, ((PyObject*)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":3524
 *         strand = items[8]
 *         if len(strand) == 2:
 *             if strand[0] == "+":             # <<<<<<<<<<<<<<
 *                 strand = strand[:-1]
 *             elif strand[0] == "-":
 */
      goto __pyx_L4;
    }

    /* "plastid/genomics/roitools.pyx":3526
 *             if strand[0] == "+":
 *                 strand = strand[:-1]
 *             elif strand[0] == "-":             # <<<<<<<<<<<<<<
 *                 strand = "+" if strand[:-1] == "-" else "+"
 * 
 */
    __pyx_t_7 = __Pyx_GetItemInt_Unicode(__pyx_v_strand, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_7 == (Py_UCS4)-1)) __PYX_ERR(0, 3526, __pyx_L1_error)
    __pyx_t_6 = ((__pyx_t_7 == 45) != 0);
    if (__pyx_t_6) {

      /* "plastid/genomics/roitools.pyx":3527
 *                 strand = strand[:-1]
 *             elif strand[0] == "-":
 *                 strand = "+" if strand[:-1] == "-" else "+"             # <<<<<<<<<<<<<<
 * 
 *         attr["strand"] = strand
 */
      if (unlikely(__pyx_v_strand == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 3527, __pyx_L1_error)
      }
      __pyx_t_3 = __Pyx_PyUnicode_Substring(__pyx_v_strand, 0, -1L); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = (__Pyx_PyUnicode_Equals(__pyx_t_3, __pyx_kp_u__13, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 3527, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if ((__pyx_t_6 != 0)) {
        __Pyx_INCREF(__pyx_kp_u__42);
        __pyx_t_1 = __pyx_kp_u__42;
      } else {
        __Pyx_INCREF(__pyx_kp_u__42);
        __pyx_t_1 = __pyx_kp_u__42;
      }
      __Pyx_DECREF_SET(__pyx_v_strand, ((PyObject*)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":3526
 *             if strand[0] == "+":
 *                 strand = strand[:-1]
 *             elif strand[0] == "-":             # <<<<<<<<<<<<<<
 *                 strand = "+" if strand[:-1] == "-" else "+"
 * 
 */
    }
    __pyx_L4:;

    /* "plastid/genomics/roitools.pyx":3523
 *         # the second result indicating the genomic strand
 *         strand = items[8]
 *         if len(strand) == 2:             # <<<<<<<<<<<<<<
 *             if strand[0] == "+":
 *                 strand = strand[:-1]
 */
  }

  /* "plastid/genomics/roitools.pyx":3529
 *                 strand = "+" if strand[:-1] == "-" else "+"
 * 
 *         attr["strand"] = strand             # <<<<<<<<<<<<<<
 * 
 *         block_sizes  = items[18].strip(",").split(",")
 */
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_strand, __pyx_v_strand) < 0)) __PYX_ERR(0, 3529, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":3531
 *         attr["strand"] = strand
 * 
 *         block_sizes  = items[18].strip(",").split(",")             # <<<<<<<<<<<<<<
 *         sq_starts    = items[19].strip(",").split(",")
 *         st_starts    = items[20].strip(",").split(",")
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3531, __pyx_L1_error)
  }
  __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_items, 18, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_strip); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, __pyx_kp_u__3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u__3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_split); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u__3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u__3);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 3531, __pyx_L1_error)
  __pyx_v_block_sizes = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3532
 * 
 *         block_sizes  = items[18].strip(",").split(",")
 *         sq_starts    = items[19].strip(",").split(",")             # <<<<<<<<<<<<<<
 *         st_starts    = items[20].strip(",").split(",")
 * 
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3532, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_items, 19, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3532, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_strip); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3532, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_kp_u__3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_u__3);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3532, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_split); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3532, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_kp_u__3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_u__3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3532, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 3532, __pyx_L1_error)
  __pyx_v_sq_starts = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3533
 *         block_sizes  = items[18].strip(",").split(",")
 *         sq_starts    = items[19].strip(",").split(",")
 *         st_starts    = items[20].strip(",").split(",")             # <<<<<<<<<<<<<<
 * 
 *         for st, sb, sq in zip(st_starts, block_sizes, sq_starts):
 */
  if (unlikely(__pyx_v_items == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 3533, __pyx_L1_error)
  }
  __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_v_items, 20, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3533, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_strip); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3533, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_u__3) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u__3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3533, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3533, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u__3) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u__3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3533, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 3533, __pyx_L1_error)
  __pyx_v_st_starts = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3535
 *         st_starts    = items[20].strip(",").split(",")
 * 
 *         for st, sb, sq in zip(st_starts, block_sizes, sq_starts):             # <<<<<<<<<<<<<<
 *             t_start = long(st)
 *             block_size = long(sb)
 */
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3535, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_st_starts);
  __Pyx_GIVEREF(__pyx_v_st_starts);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_st_starts);
  __Pyx_INCREF(__pyx_v_block_sizes);
  __Pyx_GIVEREF(__pyx_v_block_sizes);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_block_sizes);
  __Pyx_INCREF(__pyx_v_sq_starts);
  __Pyx_GIVEREF(__pyx_v_sq_starts);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_sq_starts);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3535, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_8 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3535, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3535, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_8)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 3535, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3535, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 3535, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3535, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_8(__pyx_t_1);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 3535, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
      PyObject* sequence = __pyx_t_3;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 3)) {
        if (size > 3) __Pyx_RaiseTooManyValuesError(3);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 3535, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 2); 
      } else {
        __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 2); 
      }
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3535, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3535, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_9 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3535, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_10 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3535, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
      index = 0; __pyx_t_2 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_2)) goto __pyx_L7_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_2);
      index = 1; __pyx_t_4 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_4)) goto __pyx_L7_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_4);
      index = 2; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L7_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 3) < 0) __PYX_ERR(0, 3535, __pyx_L1_error)
      __pyx_t_11 = NULL;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      goto __pyx_L8_unpacking_done;
      __pyx_L7_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_11 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 3535, __pyx_L1_error)
      __pyx_L8_unpacking_done:;
    }
    if (!(likely(PyUnicode_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 3535, __pyx_L1_error)
    if (!(likely(PyUnicode_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 3535, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_st, ((PyObject*)__pyx_t_2));
    __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_sb, ((PyObject*)__pyx_t_4));
    __pyx_t_4 = 0;
    __Pyx_XDECREF_SET(__pyx_v_sq, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "plastid/genomics/roitools.pyx":3536
 * 
 *         for st, sb, sq in zip(st_starts, block_sizes, sq_starts):
 *             t_start = long(st)             # <<<<<<<<<<<<<<
 *             block_size = long(sb)
 *             t_starts.append(t_start)
 */
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_v_st); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3536, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_12 = __Pyx_PyInt_As_long(__pyx_t_3); if (unlikely((__pyx_t_12 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3536, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_t_start = __pyx_t_12;

    /* "plastid/genomics/roitools.pyx":3537
 *         for st, sb, sq in zip(st_starts, block_sizes, sq_starts):
 *             t_start = long(st)
 *             block_size = long(sb)             # <<<<<<<<<<<<<<
 *             t_starts.append(t_start)
 *             q_starts.append(long(sq))
 */
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_v_sb); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3537, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_12 = __Pyx_PyInt_As_long(__pyx_t_3); if (unlikely((__pyx_t_12 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3537, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_block_size = __pyx_t_12;

    /* "plastid/genomics/roitools.pyx":3538
 *             t_start = long(st)
 *             block_size = long(sb)
 *             t_starts.append(t_start)             # <<<<<<<<<<<<<<
 *             q_starts.append(long(sq))
 *             seg = GenomicSegment(
 */
    __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_t_start); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3538, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_13 = __Pyx_PyList_Append(__pyx_v_t_starts, __pyx_t_3); if (unlikely(__pyx_t_13 == ((int)-1))) __PYX_ERR(0, 3538, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":3539
 *             block_size = long(sb)
 *             t_starts.append(t_start)
 *             q_starts.append(long(sq))             # <<<<<<<<<<<<<<
 *             seg = GenomicSegment(
 *                 attr["target_name"],
 */
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_v_sq); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3539, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_13 = __Pyx_PyList_Append(__pyx_v_q_starts, __pyx_t_3); if (unlikely(__pyx_t_13 == ((int)-1))) __PYX_ERR(0, 3539, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":3541
 *             q_starts.append(long(sq))
 *             seg = GenomicSegment(
 *                 attr["target_name"],             # <<<<<<<<<<<<<<
 *                 t_start,
 *                 t_start + block_size,
 */
    __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_target_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3541, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "plastid/genomics/roitools.pyx":3542
 *             seg = GenomicSegment(
 *                 attr["target_name"],
 *                 t_start,             # <<<<<<<<<<<<<<
 *                 t_start + block_size,
 *                 attr["strand"]
 */
    __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_v_t_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3542, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);

    /* "plastid/genomics/roitools.pyx":3543
 *                 attr["target_name"],
 *                 t_start,
 *                 t_start + block_size,             # <<<<<<<<<<<<<<
 *                 attr["strand"]
 *             )
 */
    __pyx_t_4 = __Pyx_PyInt_From_long((__pyx_v_t_start + __pyx_v_block_size)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "plastid/genomics/roitools.pyx":3544
 *                 t_start,
 *                 t_start + block_size,
 *                 attr["strand"]             # <<<<<<<<<<<<<<
 *             )
 *             segs.append(seg)
 */
    __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_attr, __pyx_n_u_strand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3544, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "plastid/genomics/roitools.pyx":3540
 *             t_starts.append(t_start)
 *             q_starts.append(long(sq))
 *             seg = GenomicSegment(             # <<<<<<<<<<<<<<
 *                 attr["target_name"],
 *                 t_start,
 */
    __pyx_t_10 = PyTuple_New(4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3540, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_2);
    __pyx_t_3 = 0;
    __pyx_t_9 = 0;
    __pyx_t_4 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_t_10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3540, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_XDECREF_SET(__pyx_v_seg, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "plastid/genomics/roitools.pyx":3546
 *                 attr["strand"]
 *             )
 *             segs.append(seg)             # <<<<<<<<<<<<<<
 * 
 *         attr["t_starts"] = t_starts
 */
    __pyx_t_13 = __Pyx_PyList_Append(__pyx_v_segs, ((PyObject *)__pyx_v_seg)); if (unlikely(__pyx_t_13 == ((int)-1))) __PYX_ERR(0, 3546, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3535
 *         st_starts    = items[20].strip(",").split(",")
 * 
 *         for st, sb, sq in zip(st_starts, block_sizes, sq_starts):             # <<<<<<<<<<<<<<
 *             t_start = long(st)
 *             block_size = long(sb)
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3548
 *             segs.append(seg)
 * 
 *         attr["t_starts"] = t_starts             # <<<<<<<<<<<<<<
 *         attr["q_starts"] = q_starts
 * 
 */
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_t_starts, __pyx_v_t_starts) < 0)) __PYX_ERR(0, 3548, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":3549
 * 
 *         attr["t_starts"] = t_starts
 *         attr["q_starts"] = q_starts             # <<<<<<<<<<<<<<
 * 
 *         return SegmentChain(*segs, **attr)
 */
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_q_starts, __pyx_v_q_starts) < 0)) __PYX_ERR(0, 3549, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":3551
 *         attr["q_starts"] = q_starts
 * 
 *         return SegmentChain(*segs, **attr)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PySequence_Tuple(__pyx_v_segs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyDict_Copy(__pyx_v_attr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_10 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_10;
  __pyx_t_10 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3473
 * 
 *     @staticmethod
 *     def from_psl(psl_line):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| from a line from a `PSL`_ (BLAT) file
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.from_psl", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_items);
  __Pyx_XDECREF(__pyx_v_segs);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_v_st);
  __Pyx_XDECREF(__pyx_v_sb);
  __Pyx_XDECREF(__pyx_v_strand);
  __Pyx_XDECREF((PyObject *)__pyx_v_seg);
  __Pyx_XDECREF(__pyx_v_block_sizes);
  __Pyx_XDECREF(__pyx_v_sq_starts);
  __Pyx_XDECREF(__pyx_v_st_starts);
  __Pyx_XDECREF(__pyx_v_t_starts);
  __Pyx_XDECREF(__pyx_v_q_starts);
  __Pyx_XDECREF(__pyx_v_sq);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pxd":83
 *     cdef:
 *         list _segments, _mask_segments                 # 72 bytes/each -> 144 + contents
 *         readonly GenomicSegment spanning_segment       # 20 bytes + str             # <<<<<<<<<<<<<<
 *         readonly long length                           # 8 bytes
 *         readonly long masked_length                    # 8 bytes
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_16spanning_segment_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_16spanning_segment_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_16spanning_segment___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_16spanning_segment___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->spanning_segment));
  __pyx_r = ((PyObject *)__pyx_v_self->spanning_segment);
  goto __pyx_L0;

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

/* "plastid/genomics/roitools.pxd":84
 *         list _segments, _mask_segments                 # 72 bytes/each -> 144 + contents
 *         readonly GenomicSegment spanning_segment       # 20 bytes + str
 *         readonly long length                           # 8 bytes             # <<<<<<<<<<<<<<
 *         readonly long masked_length                    # 8 bytes
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_6length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_6length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6length___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_6length___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__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_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->length); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 84, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pxd":85
 *         readonly GenomicSegment spanning_segment       # 20 bytes + str
 *         readonly long length                           # 8 bytes
 *         readonly long masked_length                    # 8 bytes             # <<<<<<<<<<<<<<
 * 
 *         array.array _position_hash                     # 56 + contents
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_13masked_length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_13masked_length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_13masked_length___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_13masked_length___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__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_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->masked_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 85, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.masked_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pxd":90
 *         array.array _position_mask # really should be bint, but we can't use it there
 *         array.array _endmap
 *         public dict attr                               # 280 bytes + contents             # <<<<<<<<<<<<<<
 *         #dict _inverse_hash                             # 280 bytes + contents
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_4attr_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_4attr_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_4attr___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_4attr___get__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->attr);
  __pyx_r = __pyx_v_self->attr;
  goto __pyx_L0;

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

/* Python wrapper */
static int __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_4attr_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_4attr_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_4attr_2__set__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((PyObject *)__pyx_v_value));

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

static int __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_4attr_2__set__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(1, 90, __pyx_L1_error)
  __pyx_t_1 = __pyx_v_value;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->attr);
  __Pyx_DECREF(__pyx_v_self->attr);
  __pyx_v_self->attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.SegmentChain.attr.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_4attr_5__del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_4attr_5__del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__del__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_4attr_4__del__(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self));

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

static int __pyx_pf_7plastid_8genomics_8roitools_12SegmentChain_4attr_4__del__(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__del__", 0);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->attr);
  __Pyx_DECREF(__pyx_v_self->attr);
  __pyx_v_self->attr = ((PyObject*)Py_None);

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

/* "plastid/genomics/roitools.pyx":3629
 *     """
 * 
 *     def __cinit__(self,*segments,type=None,**attr):             # <<<<<<<<<<<<<<
 *         """Create a |Transcript|
 * 
 */

/* Python wrapper */
static int __pyx_pw_7plastid_8genomics_8roitools_10Transcript_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_7plastid_8genomics_8roitools_10Transcript_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_type = 0;
  CYTHON_UNUSED PyObject *__pyx_v_segments = 0;
  PyObject *__pyx_v_attr = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  __pyx_v_attr = PyDict_New(); if (unlikely(!__pyx_v_attr)) return -1;
  __Pyx_GOTREF(__pyx_v_attr);
  if (PyTuple_GET_SIZE(__pyx_args) > 0) {
    __pyx_v_segments = PyTuple_GetSlice(__pyx_args, 0, PyTuple_GET_SIZE(__pyx_args));
    if (unlikely(!__pyx_v_segments)) {
      __Pyx_DECREF(__pyx_v_attr); __pyx_v_attr = 0;
      __Pyx_RefNannyFinishContext();
      return -1;
    }
    __Pyx_GOTREF(__pyx_v_segments);
  } else {
    __pyx_v_segments = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_type,0};
    PyObject* values[1] = {0};
    values[0] = ((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) {
        default:
        case  0: break;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      if (kw_args == 1) {
        const Py_ssize_t index = 0;
        PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, *__pyx_pyargnames[index]);
        if (value) { values[index] = value; kw_args--; }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_attr, values, 0, "__cinit__") < 0)) __PYX_ERR(0, 3629, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) < 0) {
      goto __pyx_L5_argtuple_error;
    } else {
    }
    __pyx_v_type = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 0, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3629, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_segments); __pyx_v_segments = 0;
  __Pyx_DECREF(__pyx_v_attr); __pyx_v_attr = 0;
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript___cinit__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), __pyx_v_type, __pyx_v_segments, __pyx_v_attr);

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

static int __pyx_pf_7plastid_8genomics_8roitools_10Transcript___cinit__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_type, CYTHON_UNUSED PyObject *__pyx_v_segments, PyObject *__pyx_v_attr) {
  PyObject *__pyx_v_gstart = NULL;
  PyObject *__pyx_v_gend = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "plastid/genomics/roitools.pyx":3662
 *             Otherwise, generated from genomic coordinates.
 *         """
 *         if type == None:             # <<<<<<<<<<<<<<
 *             self.attr["type"] = "mRNA"
 * 
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_type, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3662, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3662, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":3663
 *         """
 *         if type == None:
 *             self.attr["type"] = "mRNA"             # <<<<<<<<<<<<<<
 * 
 *         gstart = attr.get("cds_genome_start", None)
 */
    if (unlikely(__pyx_v_self->__pyx_base.attr == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 3663, __pyx_L1_error)
    }
    if (unlikely(PyDict_SetItem(__pyx_v_self->__pyx_base.attr, __pyx_n_u_type, __pyx_n_u_mRNA) < 0)) __PYX_ERR(0, 3663, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3662
 *             Otherwise, generated from genomic coordinates.
 *         """
 *         if type == None:             # <<<<<<<<<<<<<<
 *             self.attr["type"] = "mRNA"
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3665
 *             self.attr["type"] = "mRNA"
 * 
 *         gstart = attr.get("cds_genome_start", None)             # <<<<<<<<<<<<<<
 *         gend   = attr.get("cds_genome_end"  , None)
 *         self.cds_genome_start = gstart
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_attr, __pyx_n_u_cds_genome_start_2, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3665, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_gstart = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3666
 * 
 *         gstart = attr.get("cds_genome_start", None)
 *         gend   = attr.get("cds_genome_end"  , None)             # <<<<<<<<<<<<<<
 *         self.cds_genome_start = gstart
 *         self.cds_genome_end   = gend
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_attr, __pyx_n_u_cds_genome_end_2, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3666, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_gend = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3667
 *         gstart = attr.get("cds_genome_start", None)
 *         gend   = attr.get("cds_genome_end"  , None)
 *         self.cds_genome_start = gstart             # <<<<<<<<<<<<<<
 *         self.cds_genome_end   = gend
 * 
 */
  __Pyx_INCREF(__pyx_v_gstart);
  __Pyx_GIVEREF(__pyx_v_gstart);
  __Pyx_GOTREF(__pyx_v_self->cds_genome_start);
  __Pyx_DECREF(__pyx_v_self->cds_genome_start);
  __pyx_v_self->cds_genome_start = __pyx_v_gstart;

  /* "plastid/genomics/roitools.pyx":3668
 *         gend   = attr.get("cds_genome_end"  , None)
 *         self.cds_genome_start = gstart
 *         self.cds_genome_end   = gend             # <<<<<<<<<<<<<<
 * 
 *         if gstart is not None and gend is not None:
 */
  __Pyx_INCREF(__pyx_v_gend);
  __Pyx_GIVEREF(__pyx_v_gend);
  __Pyx_GOTREF(__pyx_v_self->cds_genome_end);
  __Pyx_DECREF(__pyx_v_self->cds_genome_end);
  __pyx_v_self->cds_genome_end = __pyx_v_gend;

  /* "plastid/genomics/roitools.pyx":3670
 *         self.cds_genome_end   = gend
 * 
 *         if gstart is not None and gend is not None:             # <<<<<<<<<<<<<<
 *             self._update_cds()
 *         else:
 */
  __pyx_t_3 = (__pyx_v_gstart != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_gend != Py_None);
  __pyx_t_3 = (__pyx_t_4 != 0);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L5_bool_binop_done:;
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":3671
 * 
 *         if gstart is not None and gend is not None:
 *             self._update_cds()             # <<<<<<<<<<<<<<
 *         else:
 *             self.cds_genome_start = None
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->_update_cds(__pyx_v_self); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(0, 3671, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3670
 *         self.cds_genome_end   = gend
 * 
 *         if gstart is not None and gend is not None:             # <<<<<<<<<<<<<<
 *             self._update_cds()
 *         else:
 */
    goto __pyx_L4;
  }

  /* "plastid/genomics/roitools.pyx":3673
 *             self._update_cds()
 *         else:
 *             self.cds_genome_start = None             # <<<<<<<<<<<<<<
 *             self.cds_genome_end = None
 *             self.cds_start = None
 */
  /*else*/ {
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_genome_start);
    __Pyx_DECREF(__pyx_v_self->cds_genome_start);
    __pyx_v_self->cds_genome_start = Py_None;

    /* "plastid/genomics/roitools.pyx":3674
 *         else:
 *             self.cds_genome_start = None
 *             self.cds_genome_end = None             # <<<<<<<<<<<<<<
 *             self.cds_start = None
 *             self.cds_end = None
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_genome_end);
    __Pyx_DECREF(__pyx_v_self->cds_genome_end);
    __pyx_v_self->cds_genome_end = Py_None;

    /* "plastid/genomics/roitools.pyx":3675
 *             self.cds_genome_start = None
 *             self.cds_genome_end = None
 *             self.cds_start = None             # <<<<<<<<<<<<<<
 *             self.cds_end = None
 * 
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_start);
    __Pyx_DECREF(__pyx_v_self->cds_start);
    __pyx_v_self->cds_start = Py_None;

    /* "plastid/genomics/roitools.pyx":3676
 *             self.cds_genome_end = None
 *             self.cds_start = None
 *             self.cds_end = None             # <<<<<<<<<<<<<<
 * 
 *     def __copy__(self):  # copy info and segments; shallow copy attr
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_end);
    __Pyx_DECREF(__pyx_v_self->cds_end);
    __pyx_v_self->cds_end = Py_None;
  }
  __pyx_L4:;

  /* "plastid/genomics/roitools.pyx":3629
 *     """
 * 
 *     def __cinit__(self,*segments,type=None,**attr):             # <<<<<<<<<<<<<<
 *         """Create a |Transcript|
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_gstart);
  __Pyx_XDECREF(__pyx_v_gend);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3678
 *             self.cds_end = None
 * 
 *     def __copy__(self):  # copy info and segments; shallow copy attr             # <<<<<<<<<<<<<<
 *         chain2 = Transcript()
 *         chain2._set_segments(self._segments)
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_3__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_2__copy__[] = "Transcript.__copy__(self)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_3__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__copy__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_2__copy__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_2__copy__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_chain2 = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__copy__", 0);

  /* "plastid/genomics/roitools.pyx":3679
 * 
 *     def __copy__(self):  # copy info and segments; shallow copy attr
 *         chain2 = Transcript()             # <<<<<<<<<<<<<<
 *         chain2._set_segments(self._segments)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_chain2 = ((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3680
 *     def __copy__(self):  # copy info and segments; shallow copy attr
 *         chain2 = Transcript()
 *         chain2._set_segments(self._segments)             # <<<<<<<<<<<<<<
 * 
 *         if self._mask_segments is not None:
 */
  __pyx_t_1 = __pyx_v_self->__pyx_base._segments;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_chain2->__pyx_base.__pyx_vtab)->__pyx_base._set_segments(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2), ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(0, 3680, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3682
 *         chain2._set_segments(self._segments)
 * 
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             chain2._set_masks(self._mask_segments)
 * 
 */
  __pyx_t_2 = (__pyx_v_self->__pyx_base._mask_segments != ((PyObject*)Py_None));
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":3683
 * 
 *         if self._mask_segments is not None:
 *             chain2._set_masks(self._mask_segments)             # <<<<<<<<<<<<<<
 * 
 *         chain2.cds_genome_start = self.cds_genome_start
 */
    __pyx_t_1 = __pyx_v_self->__pyx_base._mask_segments;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_chain2->__pyx_base.__pyx_vtab)->__pyx_base._set_masks(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2), ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 3683, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":3682
 *         chain2._set_segments(self._segments)
 * 
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             chain2._set_masks(self._mask_segments)
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3685
 *             chain2._set_masks(self._mask_segments)
 * 
 *         chain2.cds_genome_start = self.cds_genome_start             # <<<<<<<<<<<<<<
 *         chain2.cds_genome_end = self.cds_genome_end
 * 
 */
  __pyx_t_1 = __pyx_v_self->cds_genome_start;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_chain2->cds_genome_start);
  __Pyx_DECREF(__pyx_v_chain2->cds_genome_start);
  __pyx_v_chain2->cds_genome_start = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3686
 * 
 *         chain2.cds_genome_start = self.cds_genome_start
 *         chain2.cds_genome_end = self.cds_genome_end             # <<<<<<<<<<<<<<
 * 
 *         if chain2.cds_genome_start is not None:
 */
  __pyx_t_1 = __pyx_v_self->cds_genome_end;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_chain2->cds_genome_end);
  __Pyx_DECREF(__pyx_v_chain2->cds_genome_end);
  __pyx_v_chain2->cds_genome_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3688
 *         chain2.cds_genome_end = self.cds_genome_end
 * 
 *         if chain2.cds_genome_start is not None:             # <<<<<<<<<<<<<<
 *             chain2._update_from_cds_genome_start()
 * 
 */
  __pyx_t_3 = (__pyx_v_chain2->cds_genome_start != Py_None);
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":3689
 * 
 *         if chain2.cds_genome_start is not None:
 *             chain2._update_from_cds_genome_start()             # <<<<<<<<<<<<<<
 * 
 *         if chain2.cds_genome_end is not None:
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_chain2->__pyx_base.__pyx_vtab)->_update_from_cds_genome_start(__pyx_v_chain2); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(0, 3689, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3688
 *         chain2.cds_genome_end = self.cds_genome_end
 * 
 *         if chain2.cds_genome_start is not None:             # <<<<<<<<<<<<<<
 *             chain2._update_from_cds_genome_start()
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3691
 *             chain2._update_from_cds_genome_start()
 * 
 *         if chain2.cds_genome_end is not None:             # <<<<<<<<<<<<<<
 *             chain2._update_from_cds_genome_end()
 * 
 */
  __pyx_t_2 = (__pyx_v_chain2->cds_genome_end != Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":3692
 * 
 *         if chain2.cds_genome_end is not None:
 *             chain2._update_from_cds_genome_end()             # <<<<<<<<<<<<<<
 * 
 *         chain2.attr = self.attr
 */
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_chain2->__pyx_base.__pyx_vtab)->_update_from_cds_genome_end(__pyx_v_chain2); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 3692, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3691
 *             chain2._update_from_cds_genome_start()
 * 
 *         if chain2.cds_genome_end is not None:             # <<<<<<<<<<<<<<
 *             chain2._update_from_cds_genome_end()
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3694
 *             chain2._update_from_cds_genome_end()
 * 
 *         chain2.attr = self.attr             # <<<<<<<<<<<<<<
 *         return chain2
 * 
 */
  __pyx_t_1 = __pyx_v_self->__pyx_base.attr;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_chain2->__pyx_base.attr);
  __Pyx_DECREF(__pyx_v_chain2->__pyx_base.attr);
  __pyx_v_chain2->__pyx_base.attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3695
 * 
 *         chain2.attr = self.attr
 *         return chain2             # <<<<<<<<<<<<<<
 * 
 *     def __deepcopy__(self, memo): # deep copy everything
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_chain2));
  __pyx_r = ((PyObject *)__pyx_v_chain2);
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3678
 *             self.cds_end = None
 * 
 *     def __copy__(self):  # copy info and segments; shallow copy attr             # <<<<<<<<<<<<<<
 *         chain2 = Transcript()
 *         chain2._set_segments(self._segments)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.__copy__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_chain2);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3697
 *         return chain2
 * 
 *     def __deepcopy__(self, memo): # deep copy everything             # <<<<<<<<<<<<<<
 *         chain2 = Transcript()
 *         chain2._set_segments(copy.deepcopy(self._segments))
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_5__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_4__deepcopy__[] = "Transcript.__deepcopy__(self, memo)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_5__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__deepcopy__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_4__deepcopy__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), ((PyObject *)__pyx_v_memo));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_4__deepcopy__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo) {
  struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_chain2 = 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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__deepcopy__", 0);

  /* "plastid/genomics/roitools.pyx":3698
 * 
 *     def __deepcopy__(self, memo): # deep copy everything
 *         chain2 = Transcript()             # <<<<<<<<<<<<<<
 *         chain2._set_segments(copy.deepcopy(self._segments))
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_chain2 = ((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3699
 *     def __deepcopy__(self, memo): # deep copy everything
 *         chain2 = Transcript()
 *         chain2._set_segments(copy.deepcopy(self._segments))             # <<<<<<<<<<<<<<
 * 
 *         if self._mask_segments is not None:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3699, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3699, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_self->__pyx_base._segments) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->__pyx_base._segments);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3699, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 3699, __pyx_L1_error)
  __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_chain2->__pyx_base.__pyx_vtab)->__pyx_base._set_segments(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2), ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_4 == ((int)0))) __PYX_ERR(0, 3699, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3701
 *         chain2._set_segments(copy.deepcopy(self._segments))
 * 
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             chain2._set_masks(copy.deepcopy(self._mask_segments))
 * 
 */
  __pyx_t_4 = (__pyx_v_self->__pyx_base._mask_segments != ((PyObject*)Py_None));
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "plastid/genomics/roitools.pyx":3702
 * 
 *         if self._mask_segments is not None:
 *             chain2._set_masks(copy.deepcopy(self._mask_segments))             # <<<<<<<<<<<<<<
 * 
 *         chain2.cds_genome_start = self.cds_genome_start
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_copy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3702, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3702, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_self->__pyx_base._mask_segments) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_self->__pyx_base._mask_segments);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3702, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 3702, __pyx_L1_error)
    __pyx_t_5 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_chain2->__pyx_base.__pyx_vtab)->__pyx_base._set_masks(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain2), ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(0, 3702, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":3701
 *         chain2._set_segments(copy.deepcopy(self._segments))
 * 
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             chain2._set_masks(copy.deepcopy(self._mask_segments))
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3704
 *             chain2._set_masks(copy.deepcopy(self._mask_segments))
 * 
 *         chain2.cds_genome_start = self.cds_genome_start             # <<<<<<<<<<<<<<
 *         chain2.cds_genome_end = self.cds_genome_end
 * 
 */
  __pyx_t_1 = __pyx_v_self->cds_genome_start;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_chain2->cds_genome_start);
  __Pyx_DECREF(__pyx_v_chain2->cds_genome_start);
  __pyx_v_chain2->cds_genome_start = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3705
 * 
 *         chain2.cds_genome_start = self.cds_genome_start
 *         chain2.cds_genome_end = self.cds_genome_end             # <<<<<<<<<<<<<<
 * 
 *         if chain2.cds_genome_start is not None:
 */
  __pyx_t_1 = __pyx_v_self->cds_genome_end;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_chain2->cds_genome_end);
  __Pyx_DECREF(__pyx_v_chain2->cds_genome_end);
  __pyx_v_chain2->cds_genome_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3707
 *         chain2.cds_genome_end = self.cds_genome_end
 * 
 *         if chain2.cds_genome_start is not None:             # <<<<<<<<<<<<<<
 *             chain2._update_from_cds_genome_start()
 * 
 */
  __pyx_t_5 = (__pyx_v_chain2->cds_genome_start != Py_None);
  __pyx_t_4 = (__pyx_t_5 != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":3708
 * 
 *         if chain2.cds_genome_start is not None:
 *             chain2._update_from_cds_genome_start()             # <<<<<<<<<<<<<<
 * 
 *         if chain2.cds_genome_end is not None:
 */
    __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_chain2->__pyx_base.__pyx_vtab)->_update_from_cds_genome_start(__pyx_v_chain2); if (unlikely(__pyx_t_4 == ((int)0))) __PYX_ERR(0, 3708, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3707
 *         chain2.cds_genome_end = self.cds_genome_end
 * 
 *         if chain2.cds_genome_start is not None:             # <<<<<<<<<<<<<<
 *             chain2._update_from_cds_genome_start()
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3710
 *             chain2._update_from_cds_genome_start()
 * 
 *         if chain2.cds_genome_end is not None:             # <<<<<<<<<<<<<<
 *             chain2._update_from_cds_genome_end()
 * 
 */
  __pyx_t_4 = (__pyx_v_chain2->cds_genome_end != Py_None);
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "plastid/genomics/roitools.pyx":3711
 * 
 *         if chain2.cds_genome_end is not None:
 *             chain2._update_from_cds_genome_end()             # <<<<<<<<<<<<<<
 * 
 *         chain2.attr = copy.deepcopy(self.attr)
 */
    __pyx_t_5 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_chain2->__pyx_base.__pyx_vtab)->_update_from_cds_genome_end(__pyx_v_chain2); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(0, 3711, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3710
 *             chain2._update_from_cds_genome_start()
 * 
 *         if chain2.cds_genome_end is not None:             # <<<<<<<<<<<<<<
 *             chain2._update_from_cds_genome_end()
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3713
 *             chain2._update_from_cds_genome_end()
 * 
 *         chain2.attr = copy.deepcopy(self.attr)             # <<<<<<<<<<<<<<
 *         return chain2
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3713, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3713, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_self->__pyx_base.attr) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->__pyx_base.attr);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3713, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 3713, __pyx_L1_error)
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_chain2->__pyx_base.attr);
  __Pyx_DECREF(__pyx_v_chain2->__pyx_base.attr);
  __pyx_v_chain2->__pyx_base.attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3714
 * 
 *         chain2.attr = copy.deepcopy(self.attr)
 *         return chain2             # <<<<<<<<<<<<<<
 * 
 *     def __reduce__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_chain2));
  __pyx_r = ((PyObject *)__pyx_v_chain2);
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3697
 *         return chain2
 * 
 *     def __deepcopy__(self, memo): # deep copy everything             # <<<<<<<<<<<<<<
 *         chain2 = Transcript()
 *         chain2._set_segments(copy.deepcopy(self._segments))
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.__deepcopy__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_chain2);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3716
 *         return chain2
 * 
 *     def __reduce__(self):             # <<<<<<<<<<<<<<
 *         return (Transcript, tuple(), self.__getstate__())
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_7__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_6__reduce__[] = "Transcript.__reduce__(self)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_7__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_6__reduce__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_6__reduce__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce__", 0);

  /* "plastid/genomics/roitools.pyx":3717
 * 
 *     def __reduce__(self):
 *         return (Transcript, tuple(), self.__getstate__())             # <<<<<<<<<<<<<<
 * 
 *     def __getstate__(self): # pickle state
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)(&PyTuple_Type))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3717, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getstate); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3717, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3717, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3717, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript));
  __Pyx_GIVEREF(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript));
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3716
 *         return chain2
 * 
 *     def __reduce__(self):             # <<<<<<<<<<<<<<
 *         return (Transcript, tuple(), self.__getstate__())
 * 
 */

  /* 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("plastid.genomics.roitools.Transcript.__reduce__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3719
 *         return (Transcript, tuple(), self.__getstate__())
 * 
 *     def __getstate__(self): # pickle state             # <<<<<<<<<<<<<<
 *         cdef:
 *             list segstrs  = [str(X) for X in self._segments]
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_9__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_8__getstate__[] = "Transcript.__getstate__(self)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_9__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getstate__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_8__getstate__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_8__getstate__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  PyObject *__pyx_v_segstrs = 0;
  PyObject *__pyx_v_maskstrs = 0;
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_9genexpr26__pyx_v_X = NULL;
  PyObject *__pyx_9genexpr27__pyx_v_X = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getstate__", 0);

  /* "plastid/genomics/roitools.pyx":3721
 *     def __getstate__(self): # pickle state
 *         cdef:
 *             list segstrs  = [str(X) for X in self._segments]             # <<<<<<<<<<<<<<
 *             list maskstrs = []
 *             dict attr = self.attr
 */
  { /* enter inner scope */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3721, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (unlikely(__pyx_v_self->__pyx_base._segments == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 3721, __pyx_L5_error)
    }
    __pyx_t_2 = __pyx_v_self->__pyx_base._segments; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
    for (;;) {
      if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 3721, __pyx_L5_error)
      #else
      __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3721, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_4);
      #endif
      __Pyx_XDECREF_SET(__pyx_9genexpr26__pyx_v_X, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_9genexpr26__pyx_v_X); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3721, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 3721, __pyx_L5_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_9genexpr26__pyx_v_X); __pyx_9genexpr26__pyx_v_X = 0;
    goto __pyx_L8_exit_scope;
    __pyx_L5_error:;
    __Pyx_XDECREF(__pyx_9genexpr26__pyx_v_X); __pyx_9genexpr26__pyx_v_X = 0;
    goto __pyx_L1_error;
    __pyx_L8_exit_scope:;
  } /* exit inner scope */
  __pyx_v_segstrs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3722
 *         cdef:
 *             list segstrs  = [str(X) for X in self._segments]
 *             list maskstrs = []             # <<<<<<<<<<<<<<
 *             dict attr = self.attr
 *         if self._mask_segments is not None:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3722, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_maskstrs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3723
 *             list segstrs  = [str(X) for X in self._segments]
 *             list maskstrs = []
 *             dict attr = self.attr             # <<<<<<<<<<<<<<
 *         if self._mask_segments is not None:
 *             maskstrs = [str(X) for X in self._mask_segments]
 */
  __pyx_t_1 = __pyx_v_self->__pyx_base.attr;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3724
 *             list maskstrs = []
 *             dict attr = self.attr
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             maskstrs = [str(X) for X in self._mask_segments]
 * 
 */
  __pyx_t_5 = (__pyx_v_self->__pyx_base._mask_segments != ((PyObject*)Py_None));
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "plastid/genomics/roitools.pyx":3725
 *             dict attr = self.attr
 *         if self._mask_segments is not None:
 *             maskstrs = [str(X) for X in self._mask_segments]             # <<<<<<<<<<<<<<
 * 
 *         return (segstrs, maskstrs, attr, self.cds_genome_start, self.cds_genome_end)
 */
    { /* enter inner scope */
      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3725, __pyx_L12_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (unlikely(__pyx_v_self->__pyx_base._mask_segments == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 3725, __pyx_L12_error)
      }
      __pyx_t_2 = __pyx_v_self->__pyx_base._mask_segments; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
      for (;;) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 3725, __pyx_L12_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3725, __pyx_L12_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
        __Pyx_XDECREF_SET(__pyx_9genexpr27__pyx_v_X, __pyx_t_4);
        __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_9genexpr27__pyx_v_X); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3725, __pyx_L12_error)
        __Pyx_GOTREF(__pyx_t_4);
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 3725, __pyx_L12_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_9genexpr27__pyx_v_X); __pyx_9genexpr27__pyx_v_X = 0;
      goto __pyx_L15_exit_scope;
      __pyx_L12_error:;
      __Pyx_XDECREF(__pyx_9genexpr27__pyx_v_X); __pyx_9genexpr27__pyx_v_X = 0;
      goto __pyx_L1_error;
      __pyx_L15_exit_scope:;
    } /* exit inner scope */
    __Pyx_DECREF_SET(__pyx_v_maskstrs, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":3724
 *             list maskstrs = []
 *             dict attr = self.attr
 *         if self._mask_segments is not None:             # <<<<<<<<<<<<<<
 *             maskstrs = [str(X) for X in self._mask_segments]
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3727
 *             maskstrs = [str(X) for X in self._mask_segments]
 * 
 *         return (segstrs, maskstrs, attr, self.cds_genome_start, self.cds_genome_end)             # <<<<<<<<<<<<<<
 * 
 *     def __setstate__(self, state): # revive state from pickling
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3727, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_segstrs);
  __Pyx_GIVEREF(__pyx_v_segstrs);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_segstrs);
  __Pyx_INCREF(__pyx_v_maskstrs);
  __Pyx_GIVEREF(__pyx_v_maskstrs);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_maskstrs);
  __Pyx_INCREF(__pyx_v_attr);
  __Pyx_GIVEREF(__pyx_v_attr);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_attr);
  __Pyx_INCREF(__pyx_v_self->cds_genome_start);
  __Pyx_GIVEREF(__pyx_v_self->cds_genome_start);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_self->cds_genome_start);
  __Pyx_INCREF(__pyx_v_self->cds_genome_end);
  __Pyx_GIVEREF(__pyx_v_self->cds_genome_end);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_self->cds_genome_end);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3719
 *         return (Transcript, tuple(), self.__getstate__())
 * 
 *     def __getstate__(self): # pickle state             # <<<<<<<<<<<<<<
 *         cdef:
 *             list segstrs  = [str(X) for X in self._segments]
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.__getstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_segstrs);
  __Pyx_XDECREF(__pyx_v_maskstrs);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_9genexpr26__pyx_v_X);
  __Pyx_XDECREF(__pyx_9genexpr27__pyx_v_X);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3729
 *         return (segstrs, maskstrs, attr, self.cds_genome_start, self.cds_genome_end)
 * 
 *     def __setstate__(self, state): # revive state from pickling             # <<<<<<<<<<<<<<
 *         cdef:
 *             list segs  = [GenomicSegment.from_str(X) for X in state[0]]
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_11__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_10__setstate__[] = "Transcript.__setstate__(self, state)";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_11__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_10__setstate__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), ((PyObject *)__pyx_v_state));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_10__setstate__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_state) {
  PyObject *__pyx_v_segs = 0;
  PyObject *__pyx_v_masks = 0;
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_v_gstart = 0;
  PyObject *__pyx_v_gend = 0;
  PyObject *__pyx_9genexpr28__pyx_v_X = NULL;
  PyObject *__pyx_9genexpr29__pyx_v_X = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate__", 0);

  /* "plastid/genomics/roitools.pyx":3731
 *     def __setstate__(self, state): # revive state from pickling
 *         cdef:
 *             list segs  = [GenomicSegment.from_str(X) for X in state[0]]             # <<<<<<<<<<<<<<
 *             list masks = [GenomicSegment.from_str(X) for X in state[1]]
 *             dict attr = state[2]
 */
  { /* enter inner scope */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3731, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3731, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
      __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3731, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3731, __pyx_L5_error)
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_3))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 3731, __pyx_L5_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3731, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 3731, __pyx_L5_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3731, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_5(__pyx_t_3);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 3731, __pyx_L5_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_9genexpr28__pyx_v_X, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_n_s_from_str); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3731, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_2 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_9genexpr28__pyx_v_X) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_9genexpr28__pyx_v_X);
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3731, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 3731, __pyx_L5_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_9genexpr28__pyx_v_X); __pyx_9genexpr28__pyx_v_X = 0;
    goto __pyx_L8_exit_scope;
    __pyx_L5_error:;
    __Pyx_XDECREF(__pyx_9genexpr28__pyx_v_X); __pyx_9genexpr28__pyx_v_X = 0;
    goto __pyx_L1_error;
    __pyx_L8_exit_scope:;
  } /* exit inner scope */
  __pyx_v_segs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3732
 *         cdef:
 *             list segs  = [GenomicSegment.from_str(X) for X in state[0]]
 *             list masks = [GenomicSegment.from_str(X) for X in state[1]]             # <<<<<<<<<<<<<<
 *             dict attr = state[2]
 *             object gstart = state[3]
 */
  { /* enter inner scope */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3732, __pyx_L11_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3732, __pyx_L11_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
      __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3732, __pyx_L11_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3732, __pyx_L11_error)
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 3732, __pyx_L11_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3732, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 3732, __pyx_L11_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3732, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        }
      } else {
        __pyx_t_3 = __pyx_t_5(__pyx_t_2);
        if (unlikely(!__pyx_t_3)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 3732, __pyx_L11_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_XDECREF_SET(__pyx_9genexpr29__pyx_v_X, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_n_s_from_str); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3732, __pyx_L11_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_9genexpr29__pyx_v_X) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_9genexpr29__pyx_v_X);
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3732, __pyx_L11_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 3732, __pyx_L11_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_9genexpr29__pyx_v_X); __pyx_9genexpr29__pyx_v_X = 0;
    goto __pyx_L14_exit_scope;
    __pyx_L11_error:;
    __Pyx_XDECREF(__pyx_9genexpr29__pyx_v_X); __pyx_9genexpr29__pyx_v_X = 0;
    goto __pyx_L1_error;
    __pyx_L14_exit_scope:;
  } /* exit inner scope */
  __pyx_v_masks = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3733
 *             list segs  = [GenomicSegment.from_str(X) for X in state[0]]
 *             list masks = [GenomicSegment.from_str(X) for X in state[1]]
 *             dict attr = state[2]             # <<<<<<<<<<<<<<
 *             object gstart = state[3]
 *             object gend = state[4]
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3733, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 3733, __pyx_L1_error)
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3734
 *             list masks = [GenomicSegment.from_str(X) for X in state[1]]
 *             dict attr = state[2]
 *             object gstart = state[3]             # <<<<<<<<<<<<<<
 *             object gend = state[4]
 * 
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_gstart = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3735
 *             dict attr = state[2]
 *             object gstart = state[3]
 *             object gend = state[4]             # <<<<<<<<<<<<<<
 * 
 *         self.attr = attr
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3735, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_gend = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3737
 *             object gend = state[4]
 * 
 *         self.attr = attr             # <<<<<<<<<<<<<<
 *         self._set_segments(segs)
 * 
 */
  __Pyx_INCREF(__pyx_v_attr);
  __Pyx_GIVEREF(__pyx_v_attr);
  __Pyx_GOTREF(__pyx_v_self->__pyx_base.attr);
  __Pyx_DECREF(__pyx_v_self->__pyx_base.attr);
  __pyx_v_self->__pyx_base.attr = __pyx_v_attr;

  /* "plastid/genomics/roitools.pyx":3738
 * 
 *         self.attr = attr
 *         self._set_segments(segs)             # <<<<<<<<<<<<<<
 * 
 *         if len(masks) > 0:
 */
  __pyx_t_8 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._set_segments(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_segs); if (unlikely(__pyx_t_8 == ((int)0))) __PYX_ERR(0, 3738, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":3740
 *         self._set_segments(segs)
 * 
 *         if len(masks) > 0:             # <<<<<<<<<<<<<<
 *             self._set_masks(masks)
 * 
 */
  __pyx_t_4 = PyList_GET_SIZE(__pyx_v_masks); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3740, __pyx_L1_error)
  __pyx_t_8 = ((__pyx_t_4 > 0) != 0);
  if (__pyx_t_8) {

    /* "plastid/genomics/roitools.pyx":3741
 * 
 *         if len(masks) > 0:
 *             self._set_masks(masks)             # <<<<<<<<<<<<<<
 * 
 *         self.cds_genome_start = gstart
 */
    __pyx_t_8 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._set_masks(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_masks); if (unlikely(__pyx_t_8 == ((int)0))) __PYX_ERR(0, 3741, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3740
 *         self._set_segments(segs)
 * 
 *         if len(masks) > 0:             # <<<<<<<<<<<<<<
 *             self._set_masks(masks)
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":3743
 *             self._set_masks(masks)
 * 
 *         self.cds_genome_start = gstart             # <<<<<<<<<<<<<<
 *         self.cds_genome_end = gend
 * 
 */
  __Pyx_INCREF(__pyx_v_gstart);
  __Pyx_GIVEREF(__pyx_v_gstart);
  __Pyx_GOTREF(__pyx_v_self->cds_genome_start);
  __Pyx_DECREF(__pyx_v_self->cds_genome_start);
  __pyx_v_self->cds_genome_start = __pyx_v_gstart;

  /* "plastid/genomics/roitools.pyx":3744
 * 
 *         self.cds_genome_start = gstart
 *         self.cds_genome_end = gend             # <<<<<<<<<<<<<<
 * 
 *         if gstart is not None and gend is not None:
 */
  __Pyx_INCREF(__pyx_v_gend);
  __Pyx_GIVEREF(__pyx_v_gend);
  __Pyx_GOTREF(__pyx_v_self->cds_genome_end);
  __Pyx_DECREF(__pyx_v_self->cds_genome_end);
  __pyx_v_self->cds_genome_end = __pyx_v_gend;

  /* "plastid/genomics/roitools.pyx":3746
 *         self.cds_genome_end = gend
 * 
 *         if gstart is not None and gend is not None:             # <<<<<<<<<<<<<<
 *             self._update_cds()
 *         else:
 */
  __pyx_t_9 = (__pyx_v_gstart != Py_None);
  __pyx_t_10 = (__pyx_t_9 != 0);
  if (__pyx_t_10) {
  } else {
    __pyx_t_8 = __pyx_t_10;
    goto __pyx_L17_bool_binop_done;
  }
  __pyx_t_10 = (__pyx_v_gend != Py_None);
  __pyx_t_9 = (__pyx_t_10 != 0);
  __pyx_t_8 = __pyx_t_9;
  __pyx_L17_bool_binop_done:;
  if (__pyx_t_8) {

    /* "plastid/genomics/roitools.pyx":3747
 * 
 *         if gstart is not None and gend is not None:
 *             self._update_cds()             # <<<<<<<<<<<<<<
 *         else:
 *             self.cds_start = None
 */
    __pyx_t_8 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->_update_cds(__pyx_v_self); if (unlikely(__pyx_t_8 == ((int)0))) __PYX_ERR(0, 3747, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":3746
 *         self.cds_genome_end = gend
 * 
 *         if gstart is not None and gend is not None:             # <<<<<<<<<<<<<<
 *             self._update_cds()
 *         else:
 */
    goto __pyx_L16;
  }

  /* "plastid/genomics/roitools.pyx":3749
 *             self._update_cds()
 *         else:
 *             self.cds_start = None             # <<<<<<<<<<<<<<
 *             self.cds_end = None
 * 
 */
  /*else*/ {
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_start);
    __Pyx_DECREF(__pyx_v_self->cds_start);
    __pyx_v_self->cds_start = Py_None;

    /* "plastid/genomics/roitools.pyx":3750
 *         else:
 *             self.cds_start = None
 *             self.cds_end = None             # <<<<<<<<<<<<<<
 * 
 *     def __richcmp__(self, object other, int cmpval):
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_end);
    __Pyx_DECREF(__pyx_v_self->cds_end);
    __pyx_v_self->cds_end = Py_None;
  }
  __pyx_L16:;

  /* "plastid/genomics/roitools.pyx":3729
 *         return (segstrs, maskstrs, attr, self.cds_genome_start, self.cds_genome_end)
 * 
 *     def __setstate__(self, state): # revive state from pickling             # <<<<<<<<<<<<<<
 *         cdef:
 *             list segs  = [GenomicSegment.from_str(X) for X in state[0]]
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.__setstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_segs);
  __Pyx_XDECREF(__pyx_v_masks);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_v_gstart);
  __Pyx_XDECREF(__pyx_v_gend);
  __Pyx_XDECREF(__pyx_9genexpr28__pyx_v_X);
  __Pyx_XDECREF(__pyx_9genexpr29__pyx_v_X);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3752
 *             self.cds_end = None
 * 
 *     def __richcmp__(self, object other, int cmpval):             # <<<<<<<<<<<<<<
 *         """Test whether `self` and `other` are equal or unequal. Equality is
 *         defined as identity of positions, chromosomes, and strands. Two
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_13__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_cmpval); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_13__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_cmpval) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_12__richcmp__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), ((PyObject *)__pyx_v_other), ((int)__pyx_v_cmpval));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_12__richcmp__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_cmpval) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  enum __pyx_t_7plastid_8genomics_8c_common_ExBool __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__richcmp__", 0);

  /* "plastid/genomics/roitools.pyx":3766
 *         bool
 *         """
 *         if isinstance(other, Transcript):             # <<<<<<<<<<<<<<
 *             return transcript_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, SegmentChain):
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_Transcript); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":3767
 *         """
 *         if isinstance(other, Transcript):
 *             return transcript_richcmp(self, other, cmpval) == true             # <<<<<<<<<<<<<<
 *         elif isinstance(other, SegmentChain):
 *             return chain_richcmp(self, other, cmpval) == true
 */
    __Pyx_XDECREF(__pyx_r);
    if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_Transcript))))) __PYX_ERR(0, 3767, __pyx_L1_error)
    __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_transcript_richcmp(__pyx_v_self, ((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_other), __pyx_v_cmpval); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 3767, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyBool_FromLong((__pyx_t_3 == __pyx_e_7plastid_8genomics_8c_common_true)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3767, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":3766
 *         bool
 *         """
 *         if isinstance(other, Transcript):             # <<<<<<<<<<<<<<
 *             return transcript_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, SegmentChain):
 */
  }

  /* "plastid/genomics/roitools.pyx":3768
 *         if isinstance(other, Transcript):
 *             return transcript_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             return chain_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, GenomicSegment):
 */
  __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain); 
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "plastid/genomics/roitools.pyx":3769
 *             return transcript_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, SegmentChain):
 *             return chain_richcmp(self, other, cmpval) == true             # <<<<<<<<<<<<<<
 *         elif isinstance(other, GenomicSegment):
 *             return chain_richcmp(self, SegmentChain(other), cmpval) == true
 */
    __Pyx_XDECREF(__pyx_r);
    if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 3769, __pyx_L1_error)
    __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_other), __pyx_v_cmpval); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 3769, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyBool_FromLong((__pyx_t_3 == __pyx_e_7plastid_8genomics_8c_common_true)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3769, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":3768
 *         if isinstance(other, Transcript):
 *             return transcript_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, SegmentChain):             # <<<<<<<<<<<<<<
 *             return chain_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, GenomicSegment):
 */
  }

  /* "plastid/genomics/roitools.pyx":3770
 *         elif isinstance(other, SegmentChain):
 *             return chain_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return chain_richcmp(self, SegmentChain(other), cmpval) == true
 *         else:
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (likely(__pyx_t_2)) {

    /* "plastid/genomics/roitools.pyx":3771
 *             return chain_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, GenomicSegment):
 *             return chain_richcmp(self, SegmentChain(other), cmpval) == true             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError(
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_v_other); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3771, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __pyx_f_7plastid_8genomics_8roitools_chain_richcmp(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_4), __pyx_v_cmpval); if (unlikely(__pyx_t_3 == ((enum __pyx_t_7plastid_8genomics_8c_common_ExBool)__pyx_e_7plastid_8genomics_8c_common_bool_exception))) __PYX_ERR(0, 3771, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyBool_FromLong((__pyx_t_3 == __pyx_e_7plastid_8genomics_8c_common_true)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3771, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":3770
 *         elif isinstance(other, SegmentChain):
 *             return chain_richcmp(self, other, cmpval) == true
 *         elif isinstance(other, GenomicSegment):             # <<<<<<<<<<<<<<
 *             return chain_richcmp(self, SegmentChain(other), cmpval) == true
 *         else:
 */
  }

  /* "plastid/genomics/roitools.pyx":3773
 *             return chain_richcmp(self, SegmentChain(other), cmpval) == true
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain eq/ineq/et c is only defined for other SegmentChains or GenomicSegments."
 *             )
 */
  /*else*/ {
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3773, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 3773, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":3752
 *             self.cds_end = None
 * 
 *     def __richcmp__(self, object other, int cmpval):             # <<<<<<<<<<<<<<
 *         """Test whether `self` and `other` are equal or unequal. Equality is
 *         defined as identity of positions, chromosomes, and strands. Two
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3782
 *         `self.cds_genome_start` and `self.cds_genome_end` to None
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.cds_start
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_9cds_start_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_9cds_start_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_9cds_start___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_9cds_start___get__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":3783
 *         """
 *         def __get__(self):
 *             return self.cds_start             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             cdef object end = self.cds_end
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->cds_start);
  __pyx_r = __pyx_v_self->cds_start;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3782
 *         `self.cds_genome_start` and `self.cds_genome_end` to None
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.cds_start
 *         def __set__(self, val):
 */

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

/* "plastid/genomics/roitools.pyx":3784
 *         def __get__(self):
 *             return self.cds_start
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             cdef object end = self.cds_end
 *             if val is not None and end is not None:
 */

/* Python wrapper */
static int __pyx_pw_7plastid_8genomics_8roitools_10Transcript_9cds_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_7plastid_8genomics_8roitools_10Transcript_9cds_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_9cds_start_2__set__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_7plastid_8genomics_8roitools_10Transcript_9cds_start_2__set__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_val) {
  PyObject *__pyx_v_end = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  Py_UCS4 __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);

  /* "plastid/genomics/roitools.pyx":3785
 *             return self.cds_start
 *         def __set__(self, val):
 *             cdef object end = self.cds_end             # <<<<<<<<<<<<<<
 *             if val is not None and end is not None:
 *                 if val > end:
 */
  __pyx_t_1 = __pyx_v_self->cds_end;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3786
 *         def __set__(self, val):
 *             cdef object end = self.cds_end
 *             if val is not None and end is not None:             # <<<<<<<<<<<<<<
 *                 if val > end:
 *                     raise ValueError(
 */
  __pyx_t_3 = (__pyx_v_val != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_end != Py_None);
  __pyx_t_3 = (__pyx_t_4 != 0);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":3787
 *             cdef object end = self.cds_end
 *             if val is not None and end is not None:
 *                 if val > end:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "Transcript '%s': cds_start (%s) must be <= cds_end (%s)" % (self, val, end)
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_val, __pyx_v_end, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3787, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3787, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__pyx_t_2)) {

      /* "plastid/genomics/roitools.pyx":3789
 *                 if val > end:
 *                     raise ValueError(
 *                         "Transcript '%s': cds_start (%s) must be <= cds_end (%s)" % (self, val, end)             # <<<<<<<<<<<<<<
 *                     )
 *                 if val < 0:
 */
      __pyx_t_1 = PyTuple_New(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3789, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = 0;
      __pyx_t_6 = 127;
      __Pyx_INCREF(__pyx_kp_u_Transcript_2);
      __pyx_t_5 += 12;
      __Pyx_GIVEREF(__pyx_kp_u_Transcript_2);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Transcript_2);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3789, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u_cds_start);
      __pyx_t_5 += 14;
      __Pyx_GIVEREF(__pyx_kp_u_cds_start);
      PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_cds_start);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_val), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3789, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u_must_be_cds_end);
      __pyx_t_5 += 22;
      __Pyx_GIVEREF(__pyx_kp_u_must_be_cds_end);
      PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_must_be_cds_end);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_end), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3789, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u__15);
      __pyx_t_5 += 1;
      __Pyx_GIVEREF(__pyx_kp_u__15);
      PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u__15);
      __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_1, 7, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3789, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":3788
 *             if val is not None and end is not None:
 *                 if val > end:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "Transcript '%s': cds_start (%s) must be <= cds_end (%s)" % (self, val, end)
 *                     )
 */
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3788, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 3788, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":3787
 *             cdef object end = self.cds_end
 *             if val is not None and end is not None:
 *                 if val > end:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "Transcript '%s': cds_start (%s) must be <= cds_end (%s)" % (self, val, end)
 */
    }

    /* "plastid/genomics/roitools.pyx":3791
 *                         "Transcript '%s': cds_start (%s) must be <= cds_end (%s)" % (self, val, end)
 *                     )
 *                 if val < 0:             # <<<<<<<<<<<<<<
 *                     raise ValueError("Transcript '%s': cds_start (%s) must be >= 0" % (self, val))
 * 
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_val, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3791, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3791, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__pyx_t_2)) {

      /* "plastid/genomics/roitools.pyx":3792
 *                     )
 *                 if val < 0:
 *                     raise ValueError("Transcript '%s': cds_start (%s) must be >= 0" % (self, val))             # <<<<<<<<<<<<<<
 * 
 *             self.cds_start = val
 */
      __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3792, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = 0;
      __pyx_t_6 = 127;
      __Pyx_INCREF(__pyx_kp_u_Transcript_2);
      __pyx_t_5 += 12;
      __Pyx_GIVEREF(__pyx_kp_u_Transcript_2);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Transcript_2);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3792, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u_cds_start);
      __pyx_t_5 += 14;
      __Pyx_GIVEREF(__pyx_kp_u_cds_start);
      PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_cds_start);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_val), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3792, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u_must_be_0);
      __pyx_t_5 += 14;
      __Pyx_GIVEREF(__pyx_kp_u_must_be_0);
      PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_must_be_0);
      __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3792, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3792, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 3792, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":3791
 *                         "Transcript '%s': cds_start (%s) must be <= cds_end (%s)" % (self, val, end)
 *                     )
 *                 if val < 0:             # <<<<<<<<<<<<<<
 *                     raise ValueError("Transcript '%s': cds_start (%s) must be >= 0" % (self, val))
 * 
 */
    }

    /* "plastid/genomics/roitools.pyx":3786
 *         def __set__(self, val):
 *             cdef object end = self.cds_end
 *             if val is not None and end is not None:             # <<<<<<<<<<<<<<
 *                 if val > end:
 *                     raise ValueError(
 */
  }

  /* "plastid/genomics/roitools.pyx":3794
 *                     raise ValueError("Transcript '%s': cds_start (%s) must be >= 0" % (self, val))
 * 
 *             self.cds_start = val             # <<<<<<<<<<<<<<
 *             if val is None:
 *                 self.cds_end = None
 */
  __Pyx_INCREF(__pyx_v_val);
  __Pyx_GIVEREF(__pyx_v_val);
  __Pyx_GOTREF(__pyx_v_self->cds_start);
  __Pyx_DECREF(__pyx_v_self->cds_start);
  __pyx_v_self->cds_start = __pyx_v_val;

  /* "plastid/genomics/roitools.pyx":3795
 * 
 *             self.cds_start = val
 *             if val is None:             # <<<<<<<<<<<<<<
 *                 self.cds_end = None
 *                 self.cds_genome_start = None
 */
  __pyx_t_2 = (__pyx_v_val == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":3796
 *             self.cds_start = val
 *             if val is None:
 *                 self.cds_end = None             # <<<<<<<<<<<<<<
 *                 self.cds_genome_start = None
 *                 self.cds_genome_end = None
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_end);
    __Pyx_DECREF(__pyx_v_self->cds_end);
    __pyx_v_self->cds_end = Py_None;

    /* "plastid/genomics/roitools.pyx":3797
 *             if val is None:
 *                 self.cds_end = None
 *                 self.cds_genome_start = None             # <<<<<<<<<<<<<<
 *                 self.cds_genome_end = None
 *             else:
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_genome_start);
    __Pyx_DECREF(__pyx_v_self->cds_genome_start);
    __pyx_v_self->cds_genome_start = Py_None;

    /* "plastid/genomics/roitools.pyx":3798
 *                 self.cds_end = None
 *                 self.cds_genome_start = None
 *                 self.cds_genome_end = None             # <<<<<<<<<<<<<<
 *             else:
 *                 self._update_from_cds_start()
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_genome_end);
    __Pyx_DECREF(__pyx_v_self->cds_genome_end);
    __pyx_v_self->cds_genome_end = Py_None;

    /* "plastid/genomics/roitools.pyx":3795
 * 
 *             self.cds_start = val
 *             if val is None:             # <<<<<<<<<<<<<<
 *                 self.cds_end = None
 *                 self.cds_genome_start = None
 */
    goto __pyx_L8;
  }

  /* "plastid/genomics/roitools.pyx":3800
 *                 self.cds_genome_end = None
 *             else:
 *                 self._update_from_cds_start()             # <<<<<<<<<<<<<<
 * 
 *     property cds_end:
 */
  /*else*/ {
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->_update_from_cds_start(__pyx_v_self); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 3800, __pyx_L1_error)
  }
  __pyx_L8:;

  /* "plastid/genomics/roitools.pyx":3784
 *         def __get__(self):
 *             return self.cds_start
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             cdef object end = self.cds_end
 *             if val is not None and end is not None:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.cds_start.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_end);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3807
 *         `self.cds_genome_start` and `self.cds_genome_end` to None
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.cds_end
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_7cds_end_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_7cds_end_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_7cds_end___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_7cds_end___get__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":3808
 *         """
 *         def __get__(self):
 *             return self.cds_end             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, val):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->cds_end);
  __pyx_r = __pyx_v_self->cds_end;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3807
 *         `self.cds_genome_start` and `self.cds_genome_end` to None
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.cds_end
 * 
 */

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

/* "plastid/genomics/roitools.pyx":3810
 *             return self.cds_end
 * 
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             cdef object start = self.cds_start
 *             if val is not None and start is not None:
 */

/* Python wrapper */
static int __pyx_pw_7plastid_8genomics_8roitools_10Transcript_7cds_end_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_7plastid_8genomics_8roitools_10Transcript_7cds_end_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_7cds_end_2__set__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_7plastid_8genomics_8roitools_10Transcript_7cds_end_2__set__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_val) {
  PyObject *__pyx_v_start = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  Py_UCS4 __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);

  /* "plastid/genomics/roitools.pyx":3811
 * 
 *         def __set__(self, val):
 *             cdef object start = self.cds_start             # <<<<<<<<<<<<<<
 *             if val is not None and start is not None:
 *                 if val < start:
 */
  __pyx_t_1 = __pyx_v_self->cds_start;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_start = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3812
 *         def __set__(self, val):
 *             cdef object start = self.cds_start
 *             if val is not None and start is not None:             # <<<<<<<<<<<<<<
 *                 if val < start:
 *                     raise ValueError(
 */
  __pyx_t_3 = (__pyx_v_val != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_start != Py_None);
  __pyx_t_3 = (__pyx_t_4 != 0);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":3813
 *             cdef object start = self.cds_start
 *             if val is not None and start is not None:
 *                 if val < start:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "Transcript '%s': cds_end (%s) must be >= cds_start (%s)" % (self, val, start)
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_val, __pyx_v_start, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3813, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3813, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__pyx_t_2)) {

      /* "plastid/genomics/roitools.pyx":3815
 *                 if val < start:
 *                     raise ValueError(
 *                         "Transcript '%s': cds_end (%s) must be >= cds_start (%s)" % (self, val, start)             # <<<<<<<<<<<<<<
 *                     )
 *                 if val > self.length:
 */
      __pyx_t_1 = PyTuple_New(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3815, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = 0;
      __pyx_t_6 = 127;
      __Pyx_INCREF(__pyx_kp_u_Transcript_2);
      __pyx_t_5 += 12;
      __Pyx_GIVEREF(__pyx_kp_u_Transcript_2);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Transcript_2);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3815, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u_cds_end);
      __pyx_t_5 += 12;
      __Pyx_GIVEREF(__pyx_kp_u_cds_end);
      PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_cds_end);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_val), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3815, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u_must_be_cds_start);
      __pyx_t_5 += 24;
      __Pyx_GIVEREF(__pyx_kp_u_must_be_cds_start);
      PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_must_be_cds_start);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_start), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3815, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u__15);
      __pyx_t_5 += 1;
      __Pyx_GIVEREF(__pyx_kp_u__15);
      PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u__15);
      __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_1, 7, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3815, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":3814
 *             if val is not None and start is not None:
 *                 if val < start:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "Transcript '%s': cds_end (%s) must be >= cds_start (%s)" % (self, val, start)
 *                     )
 */
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3814, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 3814, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":3813
 *             cdef object start = self.cds_start
 *             if val is not None and start is not None:
 *                 if val < start:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "Transcript '%s': cds_end (%s) must be >= cds_start (%s)" % (self, val, start)
 */
    }

    /* "plastid/genomics/roitools.pyx":3817
 *                         "Transcript '%s': cds_end (%s) must be >= cds_start (%s)" % (self, val, start)
 *                     )
 *                 if val > self.length:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "Transcript '%s': cds_end (%s) must be <= self.length (%s)"
 */
    __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->__pyx_base.length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3817, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = PyObject_RichCompare(__pyx_v_val, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3817, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3817, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__pyx_t_2)) {

      /* "plastid/genomics/roitools.pyx":3819
 *                 if val > self.length:
 *                     raise ValueError(
 *                         "Transcript '%s': cds_end (%s) must be <= self.length (%s)"             # <<<<<<<<<<<<<<
 *                         % (self, val, self.length)
 *                     )
 */
      __pyx_t_7 = PyTuple_New(7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3819, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_5 = 0;
      __pyx_t_6 = 127;
      __Pyx_INCREF(__pyx_kp_u_Transcript_2);
      __pyx_t_5 += 12;
      __Pyx_GIVEREF(__pyx_kp_u_Transcript_2);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_kp_u_Transcript_2);

      /* "plastid/genomics/roitools.pyx":3820
 *                     raise ValueError(
 *                         "Transcript '%s': cds_end (%s) must be <= self.length (%s)"
 *                         % (self, val, self.length)             # <<<<<<<<<<<<<<
 *                     )
 * 
 */
      __pyx_t_1 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3820, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1);
      __pyx_t_1 = 0;
      __Pyx_INCREF(__pyx_kp_u_cds_end);
      __pyx_t_5 += 12;
      __Pyx_GIVEREF(__pyx_kp_u_cds_end);
      PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_kp_u_cds_end);
      __pyx_t_1 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_val), __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3820, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_t_1);
      __pyx_t_1 = 0;
      __Pyx_INCREF(__pyx_kp_u_must_be_self_length);
      __pyx_t_5 += 26;
      __Pyx_GIVEREF(__pyx_kp_u_must_be_self_length);
      PyTuple_SET_ITEM(__pyx_t_7, 4, __pyx_kp_u_must_be_self_length);
      __pyx_t_1 = __Pyx_PyUnicode_From_long(__pyx_v_self->__pyx_base.length, 0, ' ', 'd'); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3820, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_7, 5, __pyx_t_1);
      __pyx_t_1 = 0;
      __Pyx_INCREF(__pyx_kp_u__15);
      __pyx_t_5 += 1;
      __Pyx_GIVEREF(__pyx_kp_u__15);
      PyTuple_SET_ITEM(__pyx_t_7, 6, __pyx_kp_u__15);

      /* "plastid/genomics/roitools.pyx":3819
 *                 if val > self.length:
 *                     raise ValueError(
 *                         "Transcript '%s': cds_end (%s) must be <= self.length (%s)"             # <<<<<<<<<<<<<<
 *                         % (self, val, self.length)
 *                     )
 */
      __pyx_t_1 = __Pyx_PyUnicode_Join(__pyx_t_7, 7, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3819, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "plastid/genomics/roitools.pyx":3818
 *                     )
 *                 if val > self.length:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "Transcript '%s': cds_end (%s) must be <= self.length (%s)"
 *                         % (self, val, self.length)
 */
      __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3818, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __PYX_ERR(0, 3818, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":3817
 *                         "Transcript '%s': cds_end (%s) must be >= cds_start (%s)" % (self, val, start)
 *                     )
 *                 if val > self.length:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "Transcript '%s': cds_end (%s) must be <= self.length (%s)"
 */
    }

    /* "plastid/genomics/roitools.pyx":3812
 *         def __set__(self, val):
 *             cdef object start = self.cds_start
 *             if val is not None and start is not None:             # <<<<<<<<<<<<<<
 *                 if val < start:
 *                     raise ValueError(
 */
  }

  /* "plastid/genomics/roitools.pyx":3823
 *                     )
 * 
 *             self.cds_end = val             # <<<<<<<<<<<<<<
 *             if val is None:
 *                 self.cds_start = None
 */
  __Pyx_INCREF(__pyx_v_val);
  __Pyx_GIVEREF(__pyx_v_val);
  __Pyx_GOTREF(__pyx_v_self->cds_end);
  __Pyx_DECREF(__pyx_v_self->cds_end);
  __pyx_v_self->cds_end = __pyx_v_val;

  /* "plastid/genomics/roitools.pyx":3824
 * 
 *             self.cds_end = val
 *             if val is None:             # <<<<<<<<<<<<<<
 *                 self.cds_start = None
 *                 self.cds_genome_start = None
 */
  __pyx_t_2 = (__pyx_v_val == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":3825
 *             self.cds_end = val
 *             if val is None:
 *                 self.cds_start = None             # <<<<<<<<<<<<<<
 *                 self.cds_genome_start = None
 *                 self.cds_genome_end = None
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_start);
    __Pyx_DECREF(__pyx_v_self->cds_start);
    __pyx_v_self->cds_start = Py_None;

    /* "plastid/genomics/roitools.pyx":3826
 *             if val is None:
 *                 self.cds_start = None
 *                 self.cds_genome_start = None             # <<<<<<<<<<<<<<
 *                 self.cds_genome_end = None
 *             else:
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_genome_start);
    __Pyx_DECREF(__pyx_v_self->cds_genome_start);
    __pyx_v_self->cds_genome_start = Py_None;

    /* "plastid/genomics/roitools.pyx":3827
 *                 self.cds_start = None
 *                 self.cds_genome_start = None
 *                 self.cds_genome_end = None             # <<<<<<<<<<<<<<
 *             else:
 *                 self._update_from_cds_end()
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_genome_end);
    __Pyx_DECREF(__pyx_v_self->cds_genome_end);
    __pyx_v_self->cds_genome_end = Py_None;

    /* "plastid/genomics/roitools.pyx":3824
 * 
 *             self.cds_end = val
 *             if val is None:             # <<<<<<<<<<<<<<
 *                 self.cds_start = None
 *                 self.cds_genome_start = None
 */
    goto __pyx_L8;
  }

  /* "plastid/genomics/roitools.pyx":3829
 *                 self.cds_genome_end = None
 *             else:
 *                 self._update_from_cds_end()             # <<<<<<<<<<<<<<
 * 
 *     property cds_genome_start:
 */
  /*else*/ {
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->_update_from_cds_end(__pyx_v_self); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 3829, __pyx_L1_error)
  }
  __pyx_L8:;

  /* "plastid/genomics/roitools.pyx":3810
 *             return self.cds_end
 * 
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             cdef object start = self.cds_start
 *             if val is not None and start is not None:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.cds_end.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_start);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3837
 *         `self.cds_end`, and `self.cds_genome_end` to None
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.cds_genome_start
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_16cds_genome_start_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_16cds_genome_start_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_16cds_genome_start___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_16cds_genome_start___get__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":3838
 *         """
 *         def __get__(self):
 *             return self.cds_genome_start             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, val):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->cds_genome_start);
  __pyx_r = __pyx_v_self->cds_genome_start;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3837
 *         `self.cds_end`, and `self.cds_genome_end` to None
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.cds_genome_start
 * 
 */

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

/* "plastid/genomics/roitools.pyx":3840
 *             return self.cds_genome_start
 * 
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             cdef object end = self.cds_genome_end
 *             if val is not None and end is not None:
 */

/* Python wrapper */
static int __pyx_pw_7plastid_8genomics_8roitools_10Transcript_16cds_genome_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_7plastid_8genomics_8roitools_10Transcript_16cds_genome_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_16cds_genome_start_2__set__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_7plastid_8genomics_8roitools_10Transcript_16cds_genome_start_2__set__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_val) {
  PyObject *__pyx_v_end = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  Py_UCS4 __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);

  /* "plastid/genomics/roitools.pyx":3841
 * 
 *         def __set__(self, val):
 *             cdef object end = self.cds_genome_end             # <<<<<<<<<<<<<<
 *             if val is not None and end is not None:
 *                 if val > end:
 */
  __pyx_t_1 = __pyx_v_self->cds_genome_end;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3842
 *         def __set__(self, val):
 *             cdef object end = self.cds_genome_end
 *             if val is not None and end is not None:             # <<<<<<<<<<<<<<
 *                 if val > end:
 *                     raise ValueError(
 */
  __pyx_t_3 = (__pyx_v_val != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_end != Py_None);
  __pyx_t_3 = (__pyx_t_4 != 0);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":3843
 *             cdef object end = self.cds_genome_end
 *             if val is not None and end is not None:
 *                 if val > end:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "Transcript '%s': cds_genome_start (%s) must be <= cds_genome_end (%s)"
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_val, __pyx_v_end, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3843, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3843, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__pyx_t_2)) {

      /* "plastid/genomics/roitools.pyx":3845
 *                 if val > end:
 *                     raise ValueError(
 *                         "Transcript '%s': cds_genome_start (%s) must be <= cds_genome_end (%s)"             # <<<<<<<<<<<<<<
 *                         % (self, val, end)
 *                     )
 */
      __pyx_t_1 = PyTuple_New(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3845, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = 0;
      __pyx_t_6 = 127;
      __Pyx_INCREF(__pyx_kp_u_Transcript_2);
      __pyx_t_5 += 12;
      __Pyx_GIVEREF(__pyx_kp_u_Transcript_2);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Transcript_2);

      /* "plastid/genomics/roitools.pyx":3846
 *                     raise ValueError(
 *                         "Transcript '%s': cds_genome_start (%s) must be <= cds_genome_end (%s)"
 *                         % (self, val, end)             # <<<<<<<<<<<<<<
 *                     )
 * 
 */
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3846, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u_cds_genome_start_3);
      __pyx_t_5 += 21;
      __Pyx_GIVEREF(__pyx_kp_u_cds_genome_start_3);
      PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_cds_genome_start_3);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_val), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3846, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u_must_be_cds_genome_end);
      __pyx_t_5 += 29;
      __Pyx_GIVEREF(__pyx_kp_u_must_be_cds_genome_end);
      PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_must_be_cds_genome_end);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_end), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3846, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u__15);
      __pyx_t_5 += 1;
      __Pyx_GIVEREF(__pyx_kp_u__15);
      PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u__15);

      /* "plastid/genomics/roitools.pyx":3845
 *                 if val > end:
 *                     raise ValueError(
 *                         "Transcript '%s': cds_genome_start (%s) must be <= cds_genome_end (%s)"             # <<<<<<<<<<<<<<
 *                         % (self, val, end)
 *                     )
 */
      __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_1, 7, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3845, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":3844
 *             if val is not None and end is not None:
 *                 if val > end:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "Transcript '%s': cds_genome_start (%s) must be <= cds_genome_end (%s)"
 *                         % (self, val, end)
 */
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3844, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 3844, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":3843
 *             cdef object end = self.cds_genome_end
 *             if val is not None and end is not None:
 *                 if val > end:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "Transcript '%s': cds_genome_start (%s) must be <= cds_genome_end (%s)"
 */
    }

    /* "plastid/genomics/roitools.pyx":3842
 *         def __set__(self, val):
 *             cdef object end = self.cds_genome_end
 *             if val is not None and end is not None:             # <<<<<<<<<<<<<<
 *                 if val > end:
 *                     raise ValueError(
 */
  }

  /* "plastid/genomics/roitools.pyx":3849
 *                     )
 * 
 *             self.cds_genome_start = val             # <<<<<<<<<<<<<<
 *             if val is None:
 *                 self.cds_genome_end = None
 */
  __Pyx_INCREF(__pyx_v_val);
  __Pyx_GIVEREF(__pyx_v_val);
  __Pyx_GOTREF(__pyx_v_self->cds_genome_start);
  __Pyx_DECREF(__pyx_v_self->cds_genome_start);
  __pyx_v_self->cds_genome_start = __pyx_v_val;

  /* "plastid/genomics/roitools.pyx":3850
 * 
 *             self.cds_genome_start = val
 *             if val is None:             # <<<<<<<<<<<<<<
 *                 self.cds_genome_end = None
 *                 self.cds_start = None
 */
  __pyx_t_2 = (__pyx_v_val == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":3851
 *             self.cds_genome_start = val
 *             if val is None:
 *                 self.cds_genome_end = None             # <<<<<<<<<<<<<<
 *                 self.cds_start = None
 *                 self.cds_end = None
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_genome_end);
    __Pyx_DECREF(__pyx_v_self->cds_genome_end);
    __pyx_v_self->cds_genome_end = Py_None;

    /* "plastid/genomics/roitools.pyx":3852
 *             if val is None:
 *                 self.cds_genome_end = None
 *                 self.cds_start = None             # <<<<<<<<<<<<<<
 *                 self.cds_end = None
 *             else:
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_start);
    __Pyx_DECREF(__pyx_v_self->cds_start);
    __pyx_v_self->cds_start = Py_None;

    /* "plastid/genomics/roitools.pyx":3853
 *                 self.cds_genome_end = None
 *                 self.cds_start = None
 *                 self.cds_end = None             # <<<<<<<<<<<<<<
 *             else:
 *                 self._update_from_cds_genome_start()
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_end);
    __Pyx_DECREF(__pyx_v_self->cds_end);
    __pyx_v_self->cds_end = Py_None;

    /* "plastid/genomics/roitools.pyx":3850
 * 
 *             self.cds_genome_start = val
 *             if val is None:             # <<<<<<<<<<<<<<
 *                 self.cds_genome_end = None
 *                 self.cds_start = None
 */
    goto __pyx_L7;
  }

  /* "plastid/genomics/roitools.pyx":3855
 *                 self.cds_end = None
 *             else:
 *                 self._update_from_cds_genome_start()             # <<<<<<<<<<<<<<
 * 
 *     property cds_genome_end:
 */
  /*else*/ {
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->_update_from_cds_genome_start(__pyx_v_self); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 3855, __pyx_L1_error)
  }
  __pyx_L7:;

  /* "plastid/genomics/roitools.pyx":3840
 *             return self.cds_genome_start
 * 
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             cdef object end = self.cds_genome_end
 *             if val is not None and end is not None:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.cds_genome_start.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_end);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3863
 *         `self.cds_end`, and `self.cds_genome_start` to None
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.cds_genome_end
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_14cds_genome_end_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_14cds_genome_end_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_14cds_genome_end___get__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_14cds_genome_end___get__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "plastid/genomics/roitools.pyx":3864
 *         """
 *         def __get__(self):
 *             return self.cds_genome_end             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             cdef object start = self.cds_genome_start
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->cds_genome_end);
  __pyx_r = __pyx_v_self->cds_genome_end;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3863
 *         `self.cds_end`, and `self.cds_genome_start` to None
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.cds_genome_end
 *         def __set__(self, val):
 */

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

/* "plastid/genomics/roitools.pyx":3865
 *         def __get__(self):
 *             return self.cds_genome_end
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             cdef object start = self.cds_genome_start
 *             if val is not None and start is not None:
 */

/* Python wrapper */
static int __pyx_pw_7plastid_8genomics_8roitools_10Transcript_14cds_genome_end_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_7plastid_8genomics_8roitools_10Transcript_14cds_genome_end_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_14cds_genome_end_2__set__(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_7plastid_8genomics_8roitools_10Transcript_14cds_genome_end_2__set__(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_val) {
  PyObject *__pyx_v_start = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  Py_UCS4 __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);

  /* "plastid/genomics/roitools.pyx":3866
 *             return self.cds_genome_end
 *         def __set__(self, val):
 *             cdef object start = self.cds_genome_start             # <<<<<<<<<<<<<<
 *             if val is not None and start is not None:
 *                 if val < start:
 */
  __pyx_t_1 = __pyx_v_self->cds_genome_start;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_start = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3867
 *         def __set__(self, val):
 *             cdef object start = self.cds_genome_start
 *             if val is not None and start is not None:             # <<<<<<<<<<<<<<
 *                 if val < start:
 *                     raise ValueError(
 */
  __pyx_t_3 = (__pyx_v_val != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_start != Py_None);
  __pyx_t_3 = (__pyx_t_4 != 0);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":3868
 *             cdef object start = self.cds_genome_start
 *             if val is not None and start is not None:
 *                 if val < start:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "Transcript '%s': cds_genome_end (%s) must be >= cds_genome_start (%s)"
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_val, __pyx_v_start, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3868, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3868, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__pyx_t_2)) {

      /* "plastid/genomics/roitools.pyx":3870
 *                 if val < start:
 *                     raise ValueError(
 *                         "Transcript '%s': cds_genome_end (%s) must be >= cds_genome_start (%s)"             # <<<<<<<<<<<<<<
 *                         % (self, val, start)
 *                     )
 */
      __pyx_t_1 = PyTuple_New(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3870, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = 0;
      __pyx_t_6 = 127;
      __Pyx_INCREF(__pyx_kp_u_Transcript_2);
      __pyx_t_5 += 12;
      __Pyx_GIVEREF(__pyx_kp_u_Transcript_2);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Transcript_2);

      /* "plastid/genomics/roitools.pyx":3871
 *                     raise ValueError(
 *                         "Transcript '%s': cds_genome_end (%s) must be >= cds_genome_start (%s)"
 *                         % (self, val, start)             # <<<<<<<<<<<<<<
 *                     )
 * 
 */
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)__pyx_v_self)), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3871, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u_cds_genome_end_3);
      __pyx_t_5 += 19;
      __Pyx_GIVEREF(__pyx_kp_u_cds_genome_end_3);
      PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_cds_genome_end_3);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_val), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3871, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u_must_be_cds_genome_start);
      __pyx_t_5 += 31;
      __Pyx_GIVEREF(__pyx_kp_u_must_be_cds_genome_start);
      PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_must_be_cds_genome_start);
      __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_start), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3871, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6;
      __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_kp_u__15);
      __pyx_t_5 += 1;
      __Pyx_GIVEREF(__pyx_kp_u__15);
      PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u__15);

      /* "plastid/genomics/roitools.pyx":3870
 *                 if val < start:
 *                     raise ValueError(
 *                         "Transcript '%s': cds_genome_end (%s) must be >= cds_genome_start (%s)"             # <<<<<<<<<<<<<<
 *                         % (self, val, start)
 *                     )
 */
      __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_1, 7, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3870, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":3869
 *             if val is not None and start is not None:
 *                 if val < start:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "Transcript '%s': cds_genome_end (%s) must be >= cds_genome_start (%s)"
 *                         % (self, val, start)
 */
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3869, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 3869, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":3868
 *             cdef object start = self.cds_genome_start
 *             if val is not None and start is not None:
 *                 if val < start:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "Transcript '%s': cds_genome_end (%s) must be >= cds_genome_start (%s)"
 */
    }

    /* "plastid/genomics/roitools.pyx":3867
 *         def __set__(self, val):
 *             cdef object start = self.cds_genome_start
 *             if val is not None and start is not None:             # <<<<<<<<<<<<<<
 *                 if val < start:
 *                     raise ValueError(
 */
  }

  /* "plastid/genomics/roitools.pyx":3874
 *                     )
 * 
 *             self.cds_genome_end = val             # <<<<<<<<<<<<<<
 *             if val is None:
 *                 self.cds_genome_start = None
 */
  __Pyx_INCREF(__pyx_v_val);
  __Pyx_GIVEREF(__pyx_v_val);
  __Pyx_GOTREF(__pyx_v_self->cds_genome_end);
  __Pyx_DECREF(__pyx_v_self->cds_genome_end);
  __pyx_v_self->cds_genome_end = __pyx_v_val;

  /* "plastid/genomics/roitools.pyx":3875
 * 
 *             self.cds_genome_end = val
 *             if val is None:             # <<<<<<<<<<<<<<
 *                 self.cds_genome_start = None
 *                 self.cds_start = None
 */
  __pyx_t_2 = (__pyx_v_val == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":3876
 *             self.cds_genome_end = val
 *             if val is None:
 *                 self.cds_genome_start = None             # <<<<<<<<<<<<<<
 *                 self.cds_start = None
 *                 self.cds_end = None
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_genome_start);
    __Pyx_DECREF(__pyx_v_self->cds_genome_start);
    __pyx_v_self->cds_genome_start = Py_None;

    /* "plastid/genomics/roitools.pyx":3877
 *             if val is None:
 *                 self.cds_genome_start = None
 *                 self.cds_start = None             # <<<<<<<<<<<<<<
 *                 self.cds_end = None
 *             else:
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_start);
    __Pyx_DECREF(__pyx_v_self->cds_start);
    __pyx_v_self->cds_start = Py_None;

    /* "plastid/genomics/roitools.pyx":3878
 *                 self.cds_genome_start = None
 *                 self.cds_start = None
 *                 self.cds_end = None             # <<<<<<<<<<<<<<
 *             else:
 *                 self._update_from_cds_genome_end()
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->cds_end);
    __Pyx_DECREF(__pyx_v_self->cds_end);
    __pyx_v_self->cds_end = Py_None;

    /* "plastid/genomics/roitools.pyx":3875
 * 
 *             self.cds_genome_end = val
 *             if val is None:             # <<<<<<<<<<<<<<
 *                 self.cds_genome_start = None
 *                 self.cds_start = None
 */
    goto __pyx_L7;
  }

  /* "plastid/genomics/roitools.pyx":3880
 *                 self.cds_end = None
 *             else:
 *                 self._update_from_cds_genome_end()             # <<<<<<<<<<<<<<
 * 
 *     # TODO: create explicit unit test
 */
  /*else*/ {
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->_update_from_cds_genome_end(__pyx_v_self); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 3880, __pyx_L1_error)
  }
  __pyx_L7:;

  /* "plastid/genomics/roitools.pyx":3865
 *         def __get__(self):
 *             return self.cds_genome_end
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             cdef object start = self.cds_genome_start
 *             if val is not None and start is not None:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.cds_genome_end.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_start);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3883
 * 
 *     # TODO: create explicit unit test
 *     cdef bint _update_cds(self) except False:             # <<<<<<<<<<<<<<
 *         """Generate `self.cds_start` and `self.cds_end` from `self.cds_genome_start` and `self.cds_genome_end`
 *         AFTER verifying that these values are not None
 */

static int __pyx_f_7plastid_8genomics_8roitools_10Transcript__update_cds(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_span = 0;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_v_strand;
  CYTHON_UNUSED PyObject *__pyx_v_chrom = 0;
  long __pyx_v_cds_genome_start;
  long __pyx_v_cds_genome_end;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_t_2;
  long __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_update_cds", 0);

  /* "plastid/genomics/roitools.pyx":3888
 *         """
 *         cdef:
 *             GenomicSegment span = self.spanning_segment             # <<<<<<<<<<<<<<
 *             Strand strand = span.c_strand
 *             str chrom = span.chrom
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->__pyx_base.spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_span = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3889
 *         cdef:
 *             GenomicSegment span = self.spanning_segment
 *             Strand strand = span.c_strand             # <<<<<<<<<<<<<<
 *             str chrom = span.chrom
 *             long cds_genome_start = self.cds_genome_start
 */
  __pyx_t_2 = __pyx_v_span->c_strand;
  __pyx_v_strand = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":3890
 *             GenomicSegment span = self.spanning_segment
 *             Strand strand = span.c_strand
 *             str chrom = span.chrom             # <<<<<<<<<<<<<<
 *             long cds_genome_start = self.cds_genome_start
 *             long cds_genome_end   = self.cds_genome_end
 */
  __pyx_t_1 = __pyx_v_span->chrom;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_chrom = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3891
 *             Strand strand = span.c_strand
 *             str chrom = span.chrom
 *             long cds_genome_start = self.cds_genome_start             # <<<<<<<<<<<<<<
 *             long cds_genome_end   = self.cds_genome_end
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_As_long(__pyx_v_self->cds_genome_start); if (unlikely((__pyx_t_3 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3891, __pyx_L1_error)
  __pyx_v_cds_genome_start = __pyx_t_3;

  /* "plastid/genomics/roitools.pyx":3892
 *             str chrom = span.chrom
 *             long cds_genome_start = self.cds_genome_start
 *             long cds_genome_end   = self.cds_genome_end             # <<<<<<<<<<<<<<
 * 
 *         if strand == forward_strand:
 */
  __pyx_t_3 = __Pyx_PyInt_As_long(__pyx_v_self->cds_genome_end); if (unlikely((__pyx_t_3 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3892, __pyx_L1_error)
  __pyx_v_cds_genome_end = __pyx_t_3;

  /* "plastid/genomics/roitools.pyx":3894
 *             long cds_genome_end   = self.cds_genome_end
 * 
 *         if strand == forward_strand:             # <<<<<<<<<<<<<<
 *             self.cds_start = self.c_get_segmentchain_coordinate(cds_genome_start, True)
 * 
 */
  __pyx_t_4 = ((__pyx_v_strand == __pyx_e_7plastid_8genomics_8c_common_forward_strand) != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":3895
 * 
 *         if strand == forward_strand:
 *             self.cds_start = self.c_get_segmentchain_coordinate(cds_genome_start, True)             # <<<<<<<<<<<<<<
 * 
 *             # this is in a try-catch because if the half-open cds_end coincides
 */
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_segmentchain_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_cds_genome_start, 1); if (unlikely(__pyx_t_3 == ((long)-1L))) __PYX_ERR(0, 3895, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3895, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __Pyx_GOTREF(__pyx_v_self->cds_start);
    __Pyx_DECREF(__pyx_v_self->cds_start);
    __pyx_v_self->cds_start = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":3899
 *             # this is in a try-catch because if the half-open cds_end coincides
 *             # with the end of an exon, it will not be in the end-inclusive position
 *             try:             # <<<<<<<<<<<<<<
 *                 self.cds_end = self.c_get_segmentchain_coordinate(cds_genome_end, True)
 *             except KeyError:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_7);
      /*try:*/ {

        /* "plastid/genomics/roitools.pyx":3900
 *             # with the end of an exon, it will not be in the end-inclusive position
 *             try:
 *                 self.cds_end = self.c_get_segmentchain_coordinate(cds_genome_end, True)             # <<<<<<<<<<<<<<
 *             except KeyError:
 *                 # minus one, plus one corrections because end-exclusive genome
 */
        __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_segmentchain_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_cds_genome_end, 1); if (unlikely(__pyx_t_3 == ((long)-1L))) __PYX_ERR(0, 3900, __pyx_L4_error)
        __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3900, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_1);
        __Pyx_GOTREF(__pyx_v_self->cds_end);
        __Pyx_DECREF(__pyx_v_self->cds_end);
        __pyx_v_self->cds_end = __pyx_t_1;
        __pyx_t_1 = 0;

        /* "plastid/genomics/roitools.pyx":3899
 *             # this is in a try-catch because if the half-open cds_end coincides
 *             # with the end of an exon, it will not be in the end-inclusive position
 *             try:             # <<<<<<<<<<<<<<
 *                 self.cds_end = self.c_get_segmentchain_coordinate(cds_genome_end, True)
 *             except KeyError:
 */
      }
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L9_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":3901
 *             try:
 *                 self.cds_end = self.c_get_segmentchain_coordinate(cds_genome_end, True)
 *             except KeyError:             # <<<<<<<<<<<<<<
 *                 # minus one, plus one corrections because end-exclusive genome
 *                 # position will not be in position hash if it coincides with
 */
      __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
      if (__pyx_t_8) {
        __Pyx_AddTraceback("plastid.genomics.roitools.Transcript._update_cds", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_9, &__pyx_t_10) < 0) __PYX_ERR(0, 3901, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GOTREF(__pyx_t_10);

        /* "plastid/genomics/roitools.pyx":3905
 *                 # position will not be in position hash if it coincides with
 *                 # the end of any exon
 *                 self.cds_end   = 1 + self.c_get_segmentchain_coordinate(cds_genome_end - 1, True)             # <<<<<<<<<<<<<<
 *         else:
 *             # likewise for minus-strand
 */
        __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_segmentchain_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), (__pyx_v_cds_genome_end - 1), 1); if (unlikely(__pyx_t_3 == ((long)-1L))) __PYX_ERR(0, 3905, __pyx_L6_except_error)
        __pyx_t_11 = __Pyx_PyInt_From_long((1 + __pyx_t_3)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 3905, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_11);
        __Pyx_GOTREF(__pyx_v_self->cds_end);
        __Pyx_DECREF(__pyx_v_self->cds_end);
        __pyx_v_self->cds_end = __pyx_t_11;
        __pyx_t_11 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L5_exception_handled;
      }
      goto __pyx_L6_except_error;
      __pyx_L6_except_error:;

      /* "plastid/genomics/roitools.pyx":3899
 *             # this is in a try-catch because if the half-open cds_end coincides
 *             # with the end of an exon, it will not be in the end-inclusive position
 *             try:             # <<<<<<<<<<<<<<
 *                 self.cds_end = self.c_get_segmentchain_coordinate(cds_genome_end, True)
 *             except KeyError:
 */
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      goto __pyx_L1_error;
      __pyx_L5_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      __pyx_L9_try_end:;
    }

    /* "plastid/genomics/roitools.pyx":3894
 *             long cds_genome_end   = self.cds_genome_end
 * 
 *         if strand == forward_strand:             # <<<<<<<<<<<<<<
 *             self.cds_start = self.c_get_segmentchain_coordinate(cds_genome_start, True)
 * 
 */
    goto __pyx_L3;
  }

  /* "plastid/genomics/roitools.pyx":3911
 *             # have been thoroughly tested by examining BED files exported
 *             # for this purpose
 *             self.cds_start = self.c_get_segmentchain_coordinate(cds_genome_end - 1, True)             # <<<<<<<<<<<<<<
 *             self.cds_end   = 1 + self.c_get_segmentchain_coordinate(cds_genome_start, True)
 * 
 */
  /*else*/ {
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_segmentchain_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), (__pyx_v_cds_genome_end - 1), 1); if (unlikely(__pyx_t_3 == ((long)-1L))) __PYX_ERR(0, 3911, __pyx_L1_error)
    __pyx_t_10 = __Pyx_PyInt_From_long(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3911, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    __Pyx_GOTREF(__pyx_v_self->cds_start);
    __Pyx_DECREF(__pyx_v_self->cds_start);
    __pyx_v_self->cds_start = __pyx_t_10;
    __pyx_t_10 = 0;

    /* "plastid/genomics/roitools.pyx":3912
 *             # for this purpose
 *             self.cds_start = self.c_get_segmentchain_coordinate(cds_genome_end - 1, True)
 *             self.cds_end   = 1 + self.c_get_segmentchain_coordinate(cds_genome_start, True)             # <<<<<<<<<<<<<<
 * 
 *         return True
 */
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_segmentchain_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_cds_genome_start, 1); if (unlikely(__pyx_t_3 == ((long)-1L))) __PYX_ERR(0, 3912, __pyx_L1_error)
    __pyx_t_10 = __Pyx_PyInt_From_long((1 + __pyx_t_3)); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3912, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    __Pyx_GOTREF(__pyx_v_self->cds_end);
    __Pyx_DECREF(__pyx_v_self->cds_end);
    __pyx_v_self->cds_end = __pyx_t_10;
    __pyx_t_10 = 0;
  }
  __pyx_L3:;

  /* "plastid/genomics/roitools.pyx":3914
 *             self.cds_end   = 1 + self.c_get_segmentchain_coordinate(cds_genome_start, True)
 * 
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     cdef bint _update_from_cds_start(self) except False:
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3883
 * 
 *     # TODO: create explicit unit test
 *     cdef bint _update_cds(self) except False:             # <<<<<<<<<<<<<<
 *         """Generate `self.cds_start` and `self.cds_end` from `self.cds_genome_start` and `self.cds_genome_end`
 *         AFTER verifying that these values are not None
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript._update_cds", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_span);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3916
 *         return True
 * 
 *     cdef bint _update_from_cds_start(self) except False:             # <<<<<<<<<<<<<<
 *         cdef:
 *             long cds_start = <long>self.cds_start
 */

static int __pyx_f_7plastid_8genomics_8roitools_10Transcript__update_from_cds_start(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  long __pyx_v_cds_start;
  __Pyx_memviewslice __pyx_v_phash = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  long __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_memviewslice __pyx_t_3 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_update_from_cds_start", 0);

  /* "plastid/genomics/roitools.pyx":3918
 *     cdef bint _update_from_cds_start(self) except False:
 *         cdef:
 *             long cds_start = <long>self.cds_start             # <<<<<<<<<<<<<<
 *             long [:] phash = self._get_position_hash()
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_As_long(__pyx_v_self->cds_start); if (unlikely((__pyx_t_1 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3918, __pyx_L1_error)
  __pyx_v_cds_start = ((long)__pyx_t_1);

  /* "plastid/genomics/roitools.pyx":3919
 *         cdef:
 *             long cds_start = <long>self.cds_start
 *             long [:] phash = self._get_position_hash()             # <<<<<<<<<<<<<<
 * 
 *         if self.spanning_segment.c_strand == forward_strand:
 */
  __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._get_position_hash(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_3.memview)) __PYX_ERR(0, 3919, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_phash = __pyx_t_3;
  __pyx_t_3.memview = NULL;
  __pyx_t_3.data = NULL;

  /* "plastid/genomics/roitools.pyx":3921
 *             long [:] phash = self._get_position_hash()
 * 
 *         if self.spanning_segment.c_strand == forward_strand:             # <<<<<<<<<<<<<<
 *             self.cds_genome_start = phash[cds_start]
 *         else:
 */
  __pyx_t_4 = ((__pyx_v_self->__pyx_base.spanning_segment->c_strand == __pyx_e_7plastid_8genomics_8c_common_forward_strand) != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":3922
 * 
 *         if self.spanning_segment.c_strand == forward_strand:
 *             self.cds_genome_start = phash[cds_start]             # <<<<<<<<<<<<<<
 *         else:
 *             self.cds_genome_end = phash[self.length - cds_start - 1] + 1 # CHECKME
 */
    __pyx_t_5 = __pyx_v_cds_start;
    __pyx_t_6 = -1;
    if (__pyx_t_5 < 0) {
      __pyx_t_5 += __pyx_v_phash.shape[0];
      if (unlikely(__pyx_t_5 < 0)) __pyx_t_6 = 0;
    } else if (unlikely(__pyx_t_5 >= __pyx_v_phash.shape[0])) __pyx_t_6 = 0;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 3922, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_PyInt_From_long((*((long *) ( /* dim=0 */ (__pyx_v_phash.data + __pyx_t_5 * __pyx_v_phash.strides[0]) )))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3922, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __Pyx_GOTREF(__pyx_v_self->cds_genome_start);
    __Pyx_DECREF(__pyx_v_self->cds_genome_start);
    __pyx_v_self->cds_genome_start = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "plastid/genomics/roitools.pyx":3921
 *             long [:] phash = self._get_position_hash()
 * 
 *         if self.spanning_segment.c_strand == forward_strand:             # <<<<<<<<<<<<<<
 *             self.cds_genome_start = phash[cds_start]
 *         else:
 */
    goto __pyx_L3;
  }

  /* "plastid/genomics/roitools.pyx":3924
 *             self.cds_genome_start = phash[cds_start]
 *         else:
 *             self.cds_genome_end = phash[self.length - cds_start - 1] + 1 # CHECKME             # <<<<<<<<<<<<<<
 * 
 *         return True
 */
  /*else*/ {
    __pyx_t_5 = ((__pyx_v_self->__pyx_base.length - __pyx_v_cds_start) - 1);
    __pyx_t_6 = -1;
    if (__pyx_t_5 < 0) {
      __pyx_t_5 += __pyx_v_phash.shape[0];
      if (unlikely(__pyx_t_5 < 0)) __pyx_t_6 = 0;
    } else if (unlikely(__pyx_t_5 >= __pyx_v_phash.shape[0])) __pyx_t_6 = 0;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 3924, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_PyInt_From_long(((*((long *) ( /* dim=0 */ (__pyx_v_phash.data + __pyx_t_5 * __pyx_v_phash.strides[0]) ))) + 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3924, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __Pyx_GOTREF(__pyx_v_self->cds_genome_end);
    __Pyx_DECREF(__pyx_v_self->cds_genome_end);
    __pyx_v_self->cds_genome_end = __pyx_t_2;
    __pyx_t_2 = 0;
  }
  __pyx_L3:;

  /* "plastid/genomics/roitools.pyx":3926
 *             self.cds_genome_end = phash[self.length - cds_start - 1] + 1 # CHECKME
 * 
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     cdef bint _update_from_cds_end(self) except False:
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3916
 *         return True
 * 
 *     cdef bint _update_from_cds_start(self) except False:             # <<<<<<<<<<<<<<
 *         cdef:
 *             long cds_start = <long>self.cds_start
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __PYX_XDEC_MEMVIEW(&__pyx_t_3, 1);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript._update_from_cds_start", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_phash, 1);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3928
 *         return True
 * 
 *     cdef bint _update_from_cds_end(self) except False:             # <<<<<<<<<<<<<<
 *         cdef:
 *             long cds_end = <long>self.cds_end
 */

static int __pyx_f_7plastid_8genomics_8roitools_10Transcript__update_from_cds_end(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  long __pyx_v_cds_end;
  __Pyx_memviewslice __pyx_v_phash = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  long __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_memviewslice __pyx_t_3 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_update_from_cds_end", 0);

  /* "plastid/genomics/roitools.pyx":3930
 *     cdef bint _update_from_cds_end(self) except False:
 *         cdef:
 *             long cds_end = <long>self.cds_end             # <<<<<<<<<<<<<<
 *             long [:] phash = self._get_position_hash()
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_As_long(__pyx_v_self->cds_end); if (unlikely((__pyx_t_1 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3930, __pyx_L1_error)
  __pyx_v_cds_end = ((long)__pyx_t_1);

  /* "plastid/genomics/roitools.pyx":3931
 *         cdef:
 *             long cds_end = <long>self.cds_end
 *             long [:] phash = self._get_position_hash()             # <<<<<<<<<<<<<<
 * 
 *         if self.spanning_segment.c_strand == forward_strand:
 */
  __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._get_position_hash(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3931, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_3.memview)) __PYX_ERR(0, 3931, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_phash = __pyx_t_3;
  __pyx_t_3.memview = NULL;
  __pyx_t_3.data = NULL;

  /* "plastid/genomics/roitools.pyx":3933
 *             long [:] phash = self._get_position_hash()
 * 
 *         if self.spanning_segment.c_strand == forward_strand:             # <<<<<<<<<<<<<<
 *             self.cds_genome_end = phash[cds_end - 1] + 1
 *         else:
 */
  __pyx_t_4 = ((__pyx_v_self->__pyx_base.spanning_segment->c_strand == __pyx_e_7plastid_8genomics_8c_common_forward_strand) != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":3934
 * 
 *         if self.spanning_segment.c_strand == forward_strand:
 *             self.cds_genome_end = phash[cds_end - 1] + 1             # <<<<<<<<<<<<<<
 *         else:
 *             self.cds_genome_start = phash[self.length - cds_end]
 */
    __pyx_t_5 = (__pyx_v_cds_end - 1);
    __pyx_t_6 = -1;
    if (__pyx_t_5 < 0) {
      __pyx_t_5 += __pyx_v_phash.shape[0];
      if (unlikely(__pyx_t_5 < 0)) __pyx_t_6 = 0;
    } else if (unlikely(__pyx_t_5 >= __pyx_v_phash.shape[0])) __pyx_t_6 = 0;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 3934, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_PyInt_From_long(((*((long *) ( /* dim=0 */ (__pyx_v_phash.data + __pyx_t_5 * __pyx_v_phash.strides[0]) ))) + 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3934, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __Pyx_GOTREF(__pyx_v_self->cds_genome_end);
    __Pyx_DECREF(__pyx_v_self->cds_genome_end);
    __pyx_v_self->cds_genome_end = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "plastid/genomics/roitools.pyx":3933
 *             long [:] phash = self._get_position_hash()
 * 
 *         if self.spanning_segment.c_strand == forward_strand:             # <<<<<<<<<<<<<<
 *             self.cds_genome_end = phash[cds_end - 1] + 1
 *         else:
 */
    goto __pyx_L3;
  }

  /* "plastid/genomics/roitools.pyx":3936
 *             self.cds_genome_end = phash[cds_end - 1] + 1
 *         else:
 *             self.cds_genome_start = phash[self.length - cds_end]             # <<<<<<<<<<<<<<
 * 
 *         return True
 */
  /*else*/ {
    __pyx_t_5 = (__pyx_v_self->__pyx_base.length - __pyx_v_cds_end);
    __pyx_t_6 = -1;
    if (__pyx_t_5 < 0) {
      __pyx_t_5 += __pyx_v_phash.shape[0];
      if (unlikely(__pyx_t_5 < 0)) __pyx_t_6 = 0;
    } else if (unlikely(__pyx_t_5 >= __pyx_v_phash.shape[0])) __pyx_t_6 = 0;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 3936, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_PyInt_From_long((*((long *) ( /* dim=0 */ (__pyx_v_phash.data + __pyx_t_5 * __pyx_v_phash.strides[0]) )))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3936, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __Pyx_GOTREF(__pyx_v_self->cds_genome_start);
    __Pyx_DECREF(__pyx_v_self->cds_genome_start);
    __pyx_v_self->cds_genome_start = __pyx_t_2;
    __pyx_t_2 = 0;
  }
  __pyx_L3:;

  /* "plastid/genomics/roitools.pyx":3938
 *             self.cds_genome_start = phash[self.length - cds_end]
 * 
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     cdef bint _update_from_cds_genome_start(self) except False:
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3928
 *         return True
 * 
 *     cdef bint _update_from_cds_end(self) except False:             # <<<<<<<<<<<<<<
 *         cdef:
 *             long cds_end = <long>self.cds_end
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __PYX_XDEC_MEMVIEW(&__pyx_t_3, 1);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript._update_from_cds_end", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_phash, 1);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3940
 *         return True
 * 
 *     cdef bint _update_from_cds_genome_start(self) except False:             # <<<<<<<<<<<<<<
 *         """Generate `self.cds_start` and `self.cds_end` from
 *         `self.cds_genome_start` and `self.cds_genome_end` AFTER verifying that
 */

static int __pyx_f_7plastid_8genomics_8roitools_10Transcript__update_from_cds_genome_start(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  long __pyx_v_cds_genome_start;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  long __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_update_from_cds_genome_start", 0);

  /* "plastid/genomics/roitools.pyx":3946
 *         """
 *         cdef:
 *             long cds_genome_start = <long>self.cds_genome_start             # <<<<<<<<<<<<<<
 * 
 *         if self.spanning_segment.c_strand == forward_strand:
 */
  __pyx_t_1 = __Pyx_PyInt_As_long(__pyx_v_self->cds_genome_start); if (unlikely((__pyx_t_1 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3946, __pyx_L1_error)
  __pyx_v_cds_genome_start = ((long)__pyx_t_1);

  /* "plastid/genomics/roitools.pyx":3948
 *             long cds_genome_start = <long>self.cds_genome_start
 * 
 *         if self.spanning_segment.c_strand == forward_strand:             # <<<<<<<<<<<<<<
 *             self.cds_start = self.c_get_segmentchain_coordinate(cds_genome_start, True)
 *         else:
 */
  __pyx_t_2 = ((__pyx_v_self->__pyx_base.spanning_segment->c_strand == __pyx_e_7plastid_8genomics_8c_common_forward_strand) != 0);
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":3949
 * 
 *         if self.spanning_segment.c_strand == forward_strand:
 *             self.cds_start = self.c_get_segmentchain_coordinate(cds_genome_start, True)             # <<<<<<<<<<<<<<
 *         else:
 *             self.cds_end   = 1 + self.c_get_segmentchain_coordinate(cds_genome_start, True)
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_segmentchain_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_cds_genome_start, 1); if (unlikely(__pyx_t_1 == ((long)-1L))) __PYX_ERR(0, 3949, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3949, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_GOTREF(__pyx_v_self->cds_start);
    __Pyx_DECREF(__pyx_v_self->cds_start);
    __pyx_v_self->cds_start = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":3948
 *             long cds_genome_start = <long>self.cds_genome_start
 * 
 *         if self.spanning_segment.c_strand == forward_strand:             # <<<<<<<<<<<<<<
 *             self.cds_start = self.c_get_segmentchain_coordinate(cds_genome_start, True)
 *         else:
 */
    goto __pyx_L3;
  }

  /* "plastid/genomics/roitools.pyx":3951
 *             self.cds_start = self.c_get_segmentchain_coordinate(cds_genome_start, True)
 *         else:
 *             self.cds_end   = 1 + self.c_get_segmentchain_coordinate(cds_genome_start, True)             # <<<<<<<<<<<<<<
 * 
 *         return True
 */
  /*else*/ {
    __pyx_t_1 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_segmentchain_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_cds_genome_start, 1); if (unlikely(__pyx_t_1 == ((long)-1L))) __PYX_ERR(0, 3951, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyInt_From_long((1 + __pyx_t_1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3951, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_GOTREF(__pyx_v_self->cds_end);
    __Pyx_DECREF(__pyx_v_self->cds_end);
    __pyx_v_self->cds_end = __pyx_t_3;
    __pyx_t_3 = 0;
  }
  __pyx_L3:;

  /* "plastid/genomics/roitools.pyx":3953
 *             self.cds_end   = 1 + self.c_get_segmentchain_coordinate(cds_genome_start, True)
 * 
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     cdef bint _update_from_cds_genome_end(self) except False:
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3940
 *         return True
 * 
 *     cdef bint _update_from_cds_genome_start(self) except False:             # <<<<<<<<<<<<<<
 *         """Generate `self.cds_start` and `self.cds_end` from
 *         `self.cds_genome_start` and `self.cds_genome_end` AFTER verifying that
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript._update_from_cds_genome_start", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3955
 *         return True
 * 
 *     cdef bint _update_from_cds_genome_end(self) except False:             # <<<<<<<<<<<<<<
 *         """Generate `self.cds_start` and `self.cds_end` from
 *         `self.cds_genome_start` and `self.cds_genome_end` AFTER verifying that
 */

static int __pyx_f_7plastid_8genomics_8roitools_10Transcript__update_from_cds_genome_end(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_span = 0;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_v_strand;
  CYTHON_UNUSED PyObject *__pyx_v_chrom = 0;
  CYTHON_UNUSED long __pyx_v_cds_genome_start;
  long __pyx_v_cds_genome_end;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_t_2;
  long __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_update_from_cds_genome_end", 0);

  /* "plastid/genomics/roitools.pyx":3961
 *         """
 *         cdef:
 *             GenomicSegment span = self.spanning_segment             # <<<<<<<<<<<<<<
 *             Strand strand = span.c_strand
 *             str chrom = span.chrom
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->__pyx_base.spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_span = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3962
 *         cdef:
 *             GenomicSegment span = self.spanning_segment
 *             Strand strand = span.c_strand             # <<<<<<<<<<<<<<
 *             str chrom = span.chrom
 *             long cds_genome_start = self.cds_genome_start
 */
  __pyx_t_2 = __pyx_v_span->c_strand;
  __pyx_v_strand = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":3963
 *             GenomicSegment span = self.spanning_segment
 *             Strand strand = span.c_strand
 *             str chrom = span.chrom             # <<<<<<<<<<<<<<
 *             long cds_genome_start = self.cds_genome_start
 *             long cds_genome_end   = self.cds_genome_end
 */
  __pyx_t_1 = __pyx_v_span->chrom;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_chrom = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3964
 *             Strand strand = span.c_strand
 *             str chrom = span.chrom
 *             long cds_genome_start = self.cds_genome_start             # <<<<<<<<<<<<<<
 *             long cds_genome_end   = self.cds_genome_end
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_As_long(__pyx_v_self->cds_genome_start); if (unlikely((__pyx_t_3 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3964, __pyx_L1_error)
  __pyx_v_cds_genome_start = __pyx_t_3;

  /* "plastid/genomics/roitools.pyx":3965
 *             str chrom = span.chrom
 *             long cds_genome_start = self.cds_genome_start
 *             long cds_genome_end   = self.cds_genome_end             # <<<<<<<<<<<<<<
 * 
 *         if strand == forward_strand:
 */
  __pyx_t_3 = __Pyx_PyInt_As_long(__pyx_v_self->cds_genome_end); if (unlikely((__pyx_t_3 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 3965, __pyx_L1_error)
  __pyx_v_cds_genome_end = __pyx_t_3;

  /* "plastid/genomics/roitools.pyx":3967
 *             long cds_genome_end   = self.cds_genome_end
 * 
 *         if strand == forward_strand:             # <<<<<<<<<<<<<<
 *             # this is in a try-catch because if the half-open cds_end coincides
 *             # with the end of an exon, it will not be in the end-inclusive position
 */
  __pyx_t_4 = ((__pyx_v_strand == __pyx_e_7plastid_8genomics_8c_common_forward_strand) != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":3970
 *             # this is in a try-catch because if the half-open cds_end coincides
 *             # with the end of an exon, it will not be in the end-inclusive position
 *             try:             # <<<<<<<<<<<<<<
 *                 self.cds_end = self.c_get_segmentchain_coordinate(cds_genome_end, True)
 *             except KeyError:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_7);
      /*try:*/ {

        /* "plastid/genomics/roitools.pyx":3971
 *             # with the end of an exon, it will not be in the end-inclusive position
 *             try:
 *                 self.cds_end = self.c_get_segmentchain_coordinate(cds_genome_end, True)             # <<<<<<<<<<<<<<
 *             except KeyError:
 *                 # minus one, plus one corrections because end-exclusive genome
 */
        __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_segmentchain_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_v_cds_genome_end, 1); if (unlikely(__pyx_t_3 == ((long)-1L))) __PYX_ERR(0, 3971, __pyx_L4_error)
        __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3971, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_1);
        __Pyx_GOTREF(__pyx_v_self->cds_end);
        __Pyx_DECREF(__pyx_v_self->cds_end);
        __pyx_v_self->cds_end = __pyx_t_1;
        __pyx_t_1 = 0;

        /* "plastid/genomics/roitools.pyx":3970
 *             # this is in a try-catch because if the half-open cds_end coincides
 *             # with the end of an exon, it will not be in the end-inclusive position
 *             try:             # <<<<<<<<<<<<<<
 *                 self.cds_end = self.c_get_segmentchain_coordinate(cds_genome_end, True)
 *             except KeyError:
 */
      }
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L9_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "plastid/genomics/roitools.pyx":3972
 *             try:
 *                 self.cds_end = self.c_get_segmentchain_coordinate(cds_genome_end, True)
 *             except KeyError:             # <<<<<<<<<<<<<<
 *                 # minus one, plus one corrections because end-exclusive genome
 *                 # position will not be in position hash if it coincides with
 */
      __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
      if (__pyx_t_8) {
        __Pyx_AddTraceback("plastid.genomics.roitools.Transcript._update_from_cds_genome_end", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_9, &__pyx_t_10) < 0) __PYX_ERR(0, 3972, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GOTREF(__pyx_t_10);

        /* "plastid/genomics/roitools.pyx":3976
 *                 # position will not be in position hash if it coincides with
 *                 # the end of any exon
 *                 self.cds_end   = 1 + self.c_get_segmentchain_coordinate(cds_genome_end - 1, True)             # <<<<<<<<<<<<<<
 *         else:
 *             # likewise for minus-strand
 */
        __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_segmentchain_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), (__pyx_v_cds_genome_end - 1), 1); if (unlikely(__pyx_t_3 == ((long)-1L))) __PYX_ERR(0, 3976, __pyx_L6_except_error)
        __pyx_t_11 = __Pyx_PyInt_From_long((1 + __pyx_t_3)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 3976, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_11);
        __Pyx_GOTREF(__pyx_v_self->cds_end);
        __Pyx_DECREF(__pyx_v_self->cds_end);
        __pyx_v_self->cds_end = __pyx_t_11;
        __pyx_t_11 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L5_exception_handled;
      }
      goto __pyx_L6_except_error;
      __pyx_L6_except_error:;

      /* "plastid/genomics/roitools.pyx":3970
 *             # this is in a try-catch because if the half-open cds_end coincides
 *             # with the end of an exon, it will not be in the end-inclusive position
 *             try:             # <<<<<<<<<<<<<<
 *                 self.cds_end = self.c_get_segmentchain_coordinate(cds_genome_end, True)
 *             except KeyError:
 */
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      goto __pyx_L1_error;
      __pyx_L5_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      __pyx_L9_try_end:;
    }

    /* "plastid/genomics/roitools.pyx":3967
 *             long cds_genome_end   = self.cds_genome_end
 * 
 *         if strand == forward_strand:             # <<<<<<<<<<<<<<
 *             # this is in a try-catch because if the half-open cds_end coincides
 *             # with the end of an exon, it will not be in the end-inclusive position
 */
    goto __pyx_L3;
  }

  /* "plastid/genomics/roitools.pyx":3982
 *             # have been thoroughly tested by examining BED files exported
 *             # for this purpose
 *             self.cds_start = self.c_get_segmentchain_coordinate(cds_genome_end - 1, True)             # <<<<<<<<<<<<<<
 * 
 *         return True
 */
  /*else*/ {
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_segmentchain_coordinate(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), (__pyx_v_cds_genome_end - 1), 1); if (unlikely(__pyx_t_3 == ((long)-1L))) __PYX_ERR(0, 3982, __pyx_L1_error)
    __pyx_t_10 = __Pyx_PyInt_From_long(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3982, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    __Pyx_GOTREF(__pyx_v_self->cds_start);
    __Pyx_DECREF(__pyx_v_self->cds_start);
    __pyx_v_self->cds_start = __pyx_t_10;
    __pyx_t_10 = 0;
  }
  __pyx_L3:;

  /* "plastid/genomics/roitools.pyx":3984
 *             self.cds_start = self.c_get_segmentchain_coordinate(cds_genome_end - 1, True)
 * 
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     def get_name(self):
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3955
 *         return True
 * 
 *     cdef bint _update_from_cds_genome_end(self) except False:             # <<<<<<<<<<<<<<
 *         """Generate `self.cds_start` and `self.cds_end` from
 *         `self.cds_genome_start` and `self.cds_genome_end` AFTER verifying that
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript._update_from_cds_genome_end", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_span);
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":3986
 *         return True
 * 
 *     def get_name(self):             # <<<<<<<<<<<<<<
 *         """Return the name of `self`, first searching through `self.attr` for
 *         the keys `transcript_id`, `ID`, `Name`, and `name`.  If no value is
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_15get_name(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_14get_name[] = "Transcript.get_name(self)\nReturn the name of `self`, first searching through `self.attr` for\n        the keys `transcript_id`, `ID`, `Name`, and `name`.  If no value is\n        found, :meth:`Transcript.__str__` is used.\n\n        Returns\n        -------\n        str\n            Returns in order of preference, `transcript_id`, `ID`, `Name`,\n            or `name` from `self.attr`. If not found, returns ``str(self)``\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_15get_name(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_name (wrapper)", 0);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_14get_name(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self));

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_14get_name(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self) {
  PyObject *__pyx_v_name = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_name", 0);

  /* "plastid/genomics/roitools.pyx":3998
 *         """
 *         cdef str name
 *         name = self.attr.get("transcript_id",             # <<<<<<<<<<<<<<
 *                self.attr.get("ID",
 *                self.attr.get("Name",
 */
  if (unlikely(__pyx_v_self->__pyx_base.attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 3998, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":3999
 *         cdef str name
 *         name = self.attr.get("transcript_id",
 *                self.attr.get("ID",             # <<<<<<<<<<<<<<
 *                self.attr.get("Name",
 *                self.attr.get("name",
 */
  if (unlikely(__pyx_v_self->__pyx_base.attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 3999, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":4000
 *         name = self.attr.get("transcript_id",
 *                self.attr.get("ID",
 *                self.attr.get("Name",             # <<<<<<<<<<<<<<
 *                self.attr.get("name",
 *                              str(self)))))
 */
  if (unlikely(__pyx_v_self->__pyx_base.attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 4000, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":4001
 *                self.attr.get("ID",
 *                self.attr.get("Name",
 *                self.attr.get("name",             # <<<<<<<<<<<<<<
 *                              str(self)))))
 *         return name
 */
  if (unlikely(__pyx_v_self->__pyx_base.attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 4001, __pyx_L1_error)
  }

  /* "plastid/genomics/roitools.pyx":4002
 *                self.attr.get("Name",
 *                self.attr.get("name",
 *                              str(self)))))             # <<<<<<<<<<<<<<
 *         return name
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4002, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "plastid/genomics/roitools.pyx":4001
 *                self.attr.get("ID",
 *                self.attr.get("Name",
 *                self.attr.get("name",             # <<<<<<<<<<<<<<
 *                              str(self)))))
 *         return name
 */
  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->__pyx_base.attr, __pyx_n_u_name_2, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4001, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4000
 *         name = self.attr.get("transcript_id",
 *                self.attr.get("ID",
 *                self.attr.get("Name",             # <<<<<<<<<<<<<<
 *                self.attr.get("name",
 *                              str(self)))))
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->__pyx_base.attr, __pyx_n_u_Name, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":3999
 *         cdef str name
 *         name = self.attr.get("transcript_id",
 *                self.attr.get("ID",             # <<<<<<<<<<<<<<
 *                self.attr.get("Name",
 *                self.attr.get("name",
 */
  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->__pyx_base.attr, __pyx_n_u_ID_2, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":3998
 *         """
 *         cdef str name
 *         name = self.attr.get("transcript_id",             # <<<<<<<<<<<<<<
 *                self.attr.get("ID",
 *                self.attr.get("Name",
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->__pyx_base.attr, __pyx_n_u_transcript_id, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3998, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 3998, __pyx_L1_error)
  __pyx_v_name = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4003
 *                self.attr.get("name",
 *                              str(self)))))
 *         return name             # <<<<<<<<<<<<<<
 * 
 *     def get_cds(self, **extra_attr):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_name);
  __pyx_r = __pyx_v_name;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":3986
 *         return True
 * 
 *     def get_name(self):             # <<<<<<<<<<<<<<
 *         """Return the name of `self`, first searching through `self.attr` for
 *         the keys `transcript_id`, `ID`, `Name`, and `name`.  If no value is
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.get_name", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":4005
 *         return name
 * 
 *     def get_cds(self, **extra_attr):             # <<<<<<<<<<<<<<
 *         """Retrieve |SegmentChain| covering the coding region of `self`, including the stop codon.
 *         If no coding region is present, returns an empty |SegmentChain|.
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_17get_cds(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_16get_cds[] = "Transcript.get_cds(self, **extra_attr)\nRetrieve |SegmentChain| covering the coding region of `self`, including the stop codon.\n        If no coding region is present, returns an empty |SegmentChain|.\n\n        The following attributes are passed from `self.attr` to the new |SegmentChain|\n\n            #. transcript_id, taken from :py:meth:`SegmentChain.get_name`\n            #. gene_id, taken from :py:meth:`SegmentChain.get_gene`\n            #. ID, generated as `\"%s_CDS % self.get_name()`\n\n\n        Parameters\n        ----------\n        extra_attr : keyword arguments\n            Values that will be included in the CDS subchain's `attr` dict.\n            These can be used to overwrite values already present.\n\n        Returns\n        -------\n        |SegmentChain|\n            CDS region of `self` if present, otherwise empty |SegmentChain|\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_17get_cds(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_extra_attr = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_cds (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("get_cds", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return NULL;}
  if (__pyx_kwds && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "get_cds", 1))) return NULL;
  __pyx_v_extra_attr = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New(); if (unlikely(!__pyx_v_extra_attr)) return NULL;
  __Pyx_GOTREF(__pyx_v_extra_attr);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_16get_cds(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), __pyx_v_extra_attr);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_16get_cds(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_extra_attr) {
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_chain = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_transcript = 0;
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  long __pyx_t_5;
  long __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_cds", 0);

  /* "plastid/genomics/roitools.pyx":4029
 *         cdef:
 *             SegmentChain chain
 *             Transcript   transcript = Transcript()             # <<<<<<<<<<<<<<
 *             dict         attr       = {}
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4029, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_transcript = ((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4030
 *             SegmentChain chain
 *             Transcript   transcript = Transcript()
 *             dict         attr       = {}             # <<<<<<<<<<<<<<
 * 
 *         if self.cds_genome_start is not None and self.cds_genome_end is not None:
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4032
 *             dict         attr       = {}
 * 
 *         if self.cds_genome_start is not None and self.cds_genome_end is not None:             # <<<<<<<<<<<<<<
 *             chain = self.c_get_subchain(self.cds_start, self.cds_end, True)
 * 
 */
  __pyx_t_3 = (__pyx_v_self->cds_genome_start != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_self->cds_genome_end != Py_None);
  __pyx_t_3 = (__pyx_t_4 != 0);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":4033
 * 
 *         if self.cds_genome_start is not None and self.cds_genome_end is not None:
 *             chain = self.c_get_subchain(self.cds_start, self.cds_end, True)             # <<<<<<<<<<<<<<
 * 
 *             transcript._set_segments(chain._segments)
 */
    __pyx_t_5 = __Pyx_PyInt_As_long(__pyx_v_self->cds_start); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 4033, __pyx_L1_error)
    __pyx_t_6 = __Pyx_PyInt_As_long(__pyx_v_self->cds_end); if (unlikely((__pyx_t_6 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 4033, __pyx_L1_error)
    __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_subchain(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_t_5, __pyx_t_6, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4033, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_chain = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4035
 *             chain = self.c_get_subchain(self.cds_start, self.cds_end, True)
 * 
 *             transcript._set_segments(chain._segments)             # <<<<<<<<<<<<<<
 *             attr["gene_id"] = self.get_gene()
 *             attr["transcript_id"] = self.get_name()
 */
    __pyx_t_1 = __pyx_v_chain->_segments;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_2 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_transcript->__pyx_base.__pyx_vtab)->__pyx_base._set_segments(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_transcript), ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(0, 4035, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4036
 * 
 *             transcript._set_segments(chain._segments)
 *             attr["gene_id"] = self.get_gene()             # <<<<<<<<<<<<<<
 *             attr["transcript_id"] = self.get_name()
 *             attr["ID"] = "%s_CDS" % self.get_name()
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_gene); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4036, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4036, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_gene_id, __pyx_t_1) < 0)) __PYX_ERR(0, 4036, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4037
 *             transcript._set_segments(chain._segments)
 *             attr["gene_id"] = self.get_gene()
 *             attr["transcript_id"] = self.get_name()             # <<<<<<<<<<<<<<
 *             attr["ID"] = "%s_CDS" % self.get_name()
 * 
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4037, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4037, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_transcript_id, __pyx_t_1) < 0)) __PYX_ERR(0, 4037, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4038
 *             attr["gene_id"] = self.get_gene()
 *             attr["transcript_id"] = self.get_name()
 *             attr["ID"] = "%s_CDS" % self.get_name()             # <<<<<<<<<<<<<<
 * 
 *             transcript.attr = attr
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4038, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4038, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_s_CDS, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4038, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_ID_2, __pyx_t_7) < 0)) __PYX_ERR(0, 4038, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":4040
 *             attr["ID"] = "%s_CDS" % self.get_name()
 * 
 *             transcript.attr = attr             # <<<<<<<<<<<<<<
 *             transcript.attr.update(extra_attr)
 *             transcript.cds_genome_start = self.cds_genome_start
 */
    __Pyx_INCREF(__pyx_v_attr);
    __Pyx_GIVEREF(__pyx_v_attr);
    __Pyx_GOTREF(__pyx_v_transcript->__pyx_base.attr);
    __Pyx_DECREF(__pyx_v_transcript->__pyx_base.attr);
    __pyx_v_transcript->__pyx_base.attr = __pyx_v_attr;

    /* "plastid/genomics/roitools.pyx":4041
 * 
 *             transcript.attr = attr
 *             transcript.attr.update(extra_attr)             # <<<<<<<<<<<<<<
 *             transcript.cds_genome_start = self.cds_genome_start
 *             transcript.cds_genome_end   = self.cds_genome_end
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_transcript->__pyx_base.attr, __pyx_n_s_update); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4041, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_v_extra_attr) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_extra_attr);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4041, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":4042
 *             transcript.attr = attr
 *             transcript.attr.update(extra_attr)
 *             transcript.cds_genome_start = self.cds_genome_start             # <<<<<<<<<<<<<<
 *             transcript.cds_genome_end   = self.cds_genome_end
 *             transcript._update_cds()
 */
    __pyx_t_7 = __pyx_v_self->cds_genome_start;
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_GOTREF(__pyx_v_transcript->cds_genome_start);
    __Pyx_DECREF(__pyx_v_transcript->cds_genome_start);
    __pyx_v_transcript->cds_genome_start = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":4043
 *             transcript.attr.update(extra_attr)
 *             transcript.cds_genome_start = self.cds_genome_start
 *             transcript.cds_genome_end   = self.cds_genome_end             # <<<<<<<<<<<<<<
 *             transcript._update_cds()
 * 
 */
    __pyx_t_7 = __pyx_v_self->cds_genome_end;
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_GOTREF(__pyx_v_transcript->cds_genome_end);
    __Pyx_DECREF(__pyx_v_transcript->cds_genome_end);
    __pyx_v_transcript->cds_genome_end = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "plastid/genomics/roitools.pyx":4044
 *             transcript.cds_genome_start = self.cds_genome_start
 *             transcript.cds_genome_end   = self.cds_genome_end
 *             transcript._update_cds()             # <<<<<<<<<<<<<<
 * 
 *         return transcript
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_transcript->__pyx_base.__pyx_vtab)->_update_cds(__pyx_v_transcript); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(0, 4044, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":4032
 *             dict         attr       = {}
 * 
 *         if self.cds_genome_start is not None and self.cds_genome_end is not None:             # <<<<<<<<<<<<<<
 *             chain = self.c_get_subchain(self.cds_start, self.cds_end, True)
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":4046
 *             transcript._update_cds()
 * 
 *         return transcript             # <<<<<<<<<<<<<<
 * 
 *     def get_utr5(self, **extra_attr):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_transcript));
  __pyx_r = ((PyObject *)__pyx_v_transcript);
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":4005
 *         return name
 * 
 *     def get_cds(self, **extra_attr):             # <<<<<<<<<<<<<<
 *         """Retrieve |SegmentChain| covering the coding region of `self`, including the stop codon.
 *         If no coding region is present, returns an empty |SegmentChain|.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.get_cds", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_chain);
  __Pyx_XDECREF((PyObject *)__pyx_v_transcript);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":4048
 *         return transcript
 * 
 *     def get_utr5(self, **extra_attr):             # <<<<<<<<<<<<<<
 *         """Retrieve sub-|SegmentChain| covering 5'UTR of `self`. If no coding
 *         region, returns an empty |SegmentChain|
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_19get_utr5(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_18get_utr5[] = "Transcript.get_utr5(self, **extra_attr)\nRetrieve sub-|SegmentChain| covering 5'UTR of `self`. If no coding\n        region, returns an empty |SegmentChain|\n\n        The following attributes are passed from `self.attr` to the new |SegmentChain|\n\n            #. transcript_id, taken from :py:meth:`SegmentChain.get_name`\n            #. gene_id, taken from :py:meth:`SegmentChain.get_gene`\n            #. ID, generated as `\"%s_5UTR\" % self.get_name()`\n\n\n        Parameters\n        ----------\n        extra_attr : keyword arguments\n            Values that will be included in the 5'UTR subchain's `attr` dict.\n            These can be used to overwrite values already present.\n\n\n        Returns\n        -------\n        |SegmentChain|\n            5' UTR region of `self` if present, otherwise empty |SegmentChain|\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_19get_utr5(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_extra_attr = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_utr5 (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("get_utr5", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return NULL;}
  if (__pyx_kwds && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "get_utr5", 1))) return NULL;
  __pyx_v_extra_attr = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New(); if (unlikely(!__pyx_v_extra_attr)) return NULL;
  __Pyx_GOTREF(__pyx_v_extra_attr);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_18get_utr5(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), __pyx_v_extra_attr);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_18get_utr5(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_extra_attr) {
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_my_segmentchain = 0;
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  long __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_utr5", 0);

  /* "plastid/genomics/roitools.pyx":4073
 *         cdef:
 *             SegmentChain my_segmentchain
 *             dict attr = {}             # <<<<<<<<<<<<<<
 * 
 *         if self.cds_genome_start is not None and self.cds_genome_end is not None:
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4073, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4075
 *             dict attr = {}
 * 
 *         if self.cds_genome_start is not None and self.cds_genome_end is not None:             # <<<<<<<<<<<<<<
 * 
 *             my_segmentchain = self.c_get_subchain(0, self.cds_start, True)
 */
  __pyx_t_3 = (__pyx_v_self->cds_genome_start != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_self->cds_genome_end != Py_None);
  __pyx_t_3 = (__pyx_t_4 != 0);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":4077
 *         if self.cds_genome_start is not None and self.cds_genome_end is not None:
 * 
 *             my_segmentchain = self.c_get_subchain(0, self.cds_start, True)             # <<<<<<<<<<<<<<
 *             attr["type"] = "5UTR"
 *             attr["gene_id"] = self.get_gene()
 */
    __pyx_t_5 = __Pyx_PyInt_As_long(__pyx_v_self->cds_start); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 4077, __pyx_L1_error)
    __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_subchain(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), 0, __pyx_t_5, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4077, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_my_segmentchain = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4078
 * 
 *             my_segmentchain = self.c_get_subchain(0, self.cds_start, True)
 *             attr["type"] = "5UTR"             # <<<<<<<<<<<<<<
 *             attr["gene_id"] = self.get_gene()
 *             attr["transcript_id"] = self.get_gene()
 */
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_type, __pyx_kp_u_5UTR) < 0)) __PYX_ERR(0, 4078, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":4079
 *             my_segmentchain = self.c_get_subchain(0, self.cds_start, True)
 *             attr["type"] = "5UTR"
 *             attr["gene_id"] = self.get_gene()             # <<<<<<<<<<<<<<
 *             attr["transcript_id"] = self.get_gene()
 *             attr["ID"] = "%s_5UTR" % self.get_name()
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_gene); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4079, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4079, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_gene_id, __pyx_t_1) < 0)) __PYX_ERR(0, 4079, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4080
 *             attr["type"] = "5UTR"
 *             attr["gene_id"] = self.get_gene()
 *             attr["transcript_id"] = self.get_gene()             # <<<<<<<<<<<<<<
 *             attr["ID"] = "%s_5UTR" % self.get_name()
 *             my_segmentchain.attr = attr
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_gene); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4080, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4080, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_transcript_id, __pyx_t_1) < 0)) __PYX_ERR(0, 4080, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4081
 *             attr["gene_id"] = self.get_gene()
 *             attr["transcript_id"] = self.get_gene()
 *             attr["ID"] = "%s_5UTR" % self.get_name()             # <<<<<<<<<<<<<<
 *             my_segmentchain.attr = attr
 *             my_segmentchain.attr.update(extra_attr)
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4081, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4081, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_s_5UTR, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4081, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_ID_2, __pyx_t_6) < 0)) __PYX_ERR(0, 4081, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4082
 *             attr["transcript_id"] = self.get_gene()
 *             attr["ID"] = "%s_5UTR" % self.get_name()
 *             my_segmentchain.attr = attr             # <<<<<<<<<<<<<<
 *             my_segmentchain.attr.update(extra_attr)
 * 
 */
    __Pyx_INCREF(__pyx_v_attr);
    __Pyx_GIVEREF(__pyx_v_attr);
    __Pyx_GOTREF(__pyx_v_my_segmentchain->attr);
    __Pyx_DECREF(__pyx_v_my_segmentchain->attr);
    __pyx_v_my_segmentchain->attr = __pyx_v_attr;

    /* "plastid/genomics/roitools.pyx":4083
 *             attr["ID"] = "%s_5UTR" % self.get_name()
 *             my_segmentchain.attr = attr
 *             my_segmentchain.attr.update(extra_attr)             # <<<<<<<<<<<<<<
 * 
 *             return my_segmentchain
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_my_segmentchain->attr, __pyx_n_s_update); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4083, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_v_extra_attr) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_extra_attr);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4083, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4085
 *             my_segmentchain.attr.update(extra_attr)
 * 
 *             return my_segmentchain             # <<<<<<<<<<<<<<
 *         else:
 *             return SegmentChain()
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_my_segmentchain));
    __pyx_r = ((PyObject *)__pyx_v_my_segmentchain);
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":4075
 *             dict attr = {}
 * 
 *         if self.cds_genome_start is not None and self.cds_genome_end is not None:             # <<<<<<<<<<<<<<
 * 
 *             my_segmentchain = self.c_get_subchain(0, self.cds_start, True)
 */
  }

  /* "plastid/genomics/roitools.pyx":4087
 *             return my_segmentchain
 *         else:
 *             return SegmentChain()             # <<<<<<<<<<<<<<
 * 
 *     def get_utr3(self, **extra_attr):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_6 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4087, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;
  }

  /* "plastid/genomics/roitools.pyx":4048
 *         return transcript
 * 
 *     def get_utr5(self, **extra_attr):             # <<<<<<<<<<<<<<
 *         """Retrieve sub-|SegmentChain| covering 5'UTR of `self`. If no coding
 *         region, returns an empty |SegmentChain|
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.get_utr5", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_my_segmentchain);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":4089
 *             return SegmentChain()
 * 
 *     def get_utr3(self, **extra_attr):             # <<<<<<<<<<<<<<
 *         """Retrieve sub-|SegmentChain| covering 3'UTR of `self`, excluding the
 *         stop codon. If no coding region, returns an empty |SegmentChain|
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_21get_utr3(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_20get_utr3[] = "Transcript.get_utr3(self, **extra_attr)\nRetrieve sub-|SegmentChain| covering 3'UTR of `self`, excluding the\n        stop codon. If no coding region, returns an empty |SegmentChain|\n\n        The following attributes are passed from ``self.attr`` to the new\n        |SegmentChain|\n\n            #. transcript_id, taken from :py:meth:`SegmentChain.get_name`\n            #. gene_id, taken from :py:meth:`SegmentChain.get_gene`\n            #. ID, generated as `\"%s_3UTR\" % self.get_name()`\n\n\n        Parameters\n        ----------\n        extra_attr : keyword arguments\n            Values that will be included in the 3' UTR subchain's `attr` dict.\n            These can be used to overwrite values already present.\n\n\n        Returns\n        -------\n        |SegmentChain|\n            3' UTR region of `self` if present, otherwise empty |SegmentChain|\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_21get_utr3(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_extra_attr = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_utr3 (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("get_utr3", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return NULL;}
  if (__pyx_kwds && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "get_utr3", 1))) return NULL;
  __pyx_v_extra_attr = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New(); if (unlikely(!__pyx_v_extra_attr)) return NULL;
  __Pyx_GOTREF(__pyx_v_extra_attr);
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_20get_utr3(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), __pyx_v_extra_attr);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_20get_utr3(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_extra_attr) {
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_my_segmentchain = 0;
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  long __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_utr3", 0);

  /* "plastid/genomics/roitools.pyx":4115
 *         cdef:
 *             SegmentChain my_segmentchain
 *             dict attr = {}             # <<<<<<<<<<<<<<
 * 
 *         if self.cds_genome_start is not None and self.cds_genome_end is not None:
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4117
 *             dict attr = {}
 * 
 *         if self.cds_genome_start is not None and self.cds_genome_end is not None:             # <<<<<<<<<<<<<<
 * 
 *             my_segmentchain = self.c_get_subchain(self.cds_end, self.length, True)
 */
  __pyx_t_3 = (__pyx_v_self->cds_genome_start != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_self->cds_genome_end != Py_None);
  __pyx_t_3 = (__pyx_t_4 != 0);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "plastid/genomics/roitools.pyx":4119
 *         if self.cds_genome_start is not None and self.cds_genome_end is not None:
 * 
 *             my_segmentchain = self.c_get_subchain(self.cds_end, self.length, True)             # <<<<<<<<<<<<<<
 *             attr["type"] = "3UTR"
 *             attr["gene_id"] = self.get_gene()
 */
    __pyx_t_5 = __Pyx_PyInt_As_long(__pyx_v_self->cds_end); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 4119, __pyx_L1_error)
    __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.c_get_subchain(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_self), __pyx_t_5, __pyx_v_self->__pyx_base.length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4119, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_my_segmentchain = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4120
 * 
 *             my_segmentchain = self.c_get_subchain(self.cds_end, self.length, True)
 *             attr["type"] = "3UTR"             # <<<<<<<<<<<<<<
 *             attr["gene_id"] = self.get_gene()
 *             attr["transcript_id"] = self.get_gene()
 */
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_type, __pyx_kp_u_3UTR) < 0)) __PYX_ERR(0, 4120, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":4121
 *             my_segmentchain = self.c_get_subchain(self.cds_end, self.length, True)
 *             attr["type"] = "3UTR"
 *             attr["gene_id"] = self.get_gene()             # <<<<<<<<<<<<<<
 *             attr["transcript_id"] = self.get_gene()
 *             attr["ID"] = "%s_3UTR" % self.get_name()
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_gene); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4121, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4121, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_gene_id, __pyx_t_1) < 0)) __PYX_ERR(0, 4121, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4122
 *             attr["type"] = "3UTR"
 *             attr["gene_id"] = self.get_gene()
 *             attr["transcript_id"] = self.get_gene()             # <<<<<<<<<<<<<<
 *             attr["ID"] = "%s_3UTR" % self.get_name()
 *             my_segmentchain.attr.update(attr)
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_gene); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4122, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4122, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_transcript_id, __pyx_t_1) < 0)) __PYX_ERR(0, 4122, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4123
 *             attr["gene_id"] = self.get_gene()
 *             attr["transcript_id"] = self.get_gene()
 *             attr["ID"] = "%s_3UTR" % self.get_name()             # <<<<<<<<<<<<<<
 *             my_segmentchain.attr.update(attr)
 *             my_segmentchain.attr.update(extra_attr)
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4123, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4123, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_s_3UTR, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4123, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_ID_2, __pyx_t_6) < 0)) __PYX_ERR(0, 4123, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4124
 *             attr["transcript_id"] = self.get_gene()
 *             attr["ID"] = "%s_3UTR" % self.get_name()
 *             my_segmentchain.attr.update(attr)             # <<<<<<<<<<<<<<
 *             my_segmentchain.attr.update(extra_attr)
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_my_segmentchain->attr, __pyx_n_s_update); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4124, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_v_attr) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_attr);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4124, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4125
 *             attr["ID"] = "%s_3UTR" % self.get_name()
 *             my_segmentchain.attr.update(attr)
 *             my_segmentchain.attr.update(extra_attr)             # <<<<<<<<<<<<<<
 * 
 *             return my_segmentchain
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_my_segmentchain->attr, __pyx_n_s_update); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4125, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_v_extra_attr) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_extra_attr);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4125, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4127
 *             my_segmentchain.attr.update(extra_attr)
 * 
 *             return my_segmentchain             # <<<<<<<<<<<<<<
 *         else:
 *             return SegmentChain()
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_my_segmentchain));
    __pyx_r = ((PyObject *)__pyx_v_my_segmentchain);
    goto __pyx_L0;

    /* "plastid/genomics/roitools.pyx":4117
 *             dict attr = {}
 * 
 *         if self.cds_genome_start is not None and self.cds_genome_end is not None:             # <<<<<<<<<<<<<<
 * 
 *             my_segmentchain = self.c_get_subchain(self.cds_end, self.length, True)
 */
  }

  /* "plastid/genomics/roitools.pyx":4129
 *             return my_segmentchain
 *         else:
 *             return SegmentChain()             # <<<<<<<<<<<<<<
 * 
 *     def as_gtf(self, str feature_type="exon", bint escape=True, list excludes=None):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_6 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4129, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;
  }

  /* "plastid/genomics/roitools.pyx":4089
 *             return SegmentChain()
 * 
 *     def get_utr3(self, **extra_attr):             # <<<<<<<<<<<<<<
 *         """Retrieve sub-|SegmentChain| covering 3'UTR of `self`, excluding the
 *         stop codon. If no coding region, returns an empty |SegmentChain|
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.get_utr3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_my_segmentchain);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":4131
 *             return SegmentChain()
 * 
 *     def as_gtf(self, str feature_type="exon", bint escape=True, list excludes=None):             # <<<<<<<<<<<<<<
 *         """Format `self` as a `GTF2`_ block. |GenomicSegments| are formatted as
 *         `GTF2`_ `'exon'` features. Coding regions, if peresent, are formatted
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_23as_gtf(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_22as_gtf[] = "Transcript.as_gtf(self, unicode feature_type=u'exon', bool escape=True, list excludes=None)\nFormat `self` as a `GTF2`_ block. |GenomicSegments| are formatted as\n        `GTF2`_ `'exon'` features. Coding regions, if peresent, are formatted\n        as `GTF2`_ `'CDS'` features. Stop codons are excluded in the `'CDS'`\n        features, per the `GTF2`_ specification, and exported separately.\n\n        All attributes from `self.attr` are propagated to the exon and CDS\n        features that are generated.\n\n\n        Parameters\n        ----------\n        feature_type : str\n            If not None, overrides the `'type'` attribute of `self.attr`\n\n        escape : bool, optional\n            URL escape tokens in column 9 of `GTF2`_ output (Default: `True`)\n\n\n        Returns\n        -------\n        str\n            Block of GTF2-formatted text\n\n\n        Notes\n        -----\n        `gene_id` and `transcript_id` are required\n            The `GTF2 specification <http://mblab.wustl.edu/GTF22.html>`_\n            requires that attributes `gene_id` and `transcript_id` be defined.\n            If these are not present in `self.attr`, their values will be\n            guessed following the rules in :py:meth:`SegmentChain.get_gene` and\n            :py:meth:`SegmentChain.get_name`, respectively.\n\n        Beware of attribute loss\n            To save memory, only the attributes shared by all of the individual\n            sub-features (e.g. exons) that were used to assemble this\n            |Transcript| have been stored in `self.attr`. This means that upon\n            re-export to `GTF2`_, these sub-features will be lacking any\n            attributes that were specific to them individually. Formally, this\n            is compliant with the `GTF2 specification\n            <http://mblab.wustl.edu/GTF22.html>`_, which states explicitly that\n            only the attributes `gene_id` and `transcript_id` are supported.\n\n        Columns of `GTF2`_ are as follow""s:\n\n            ======== =========\n            Column   Contains\n            ======== =========\n                1     Contig or chromosome\n                2     Source of annotation\n                3     Type of feature (\"exon\", \"CDS\", \"start_codon\", \"stop_codon\")\n                4     Start (1-indexed)\n                5     End (fully-closed)\n                6     Score\n                7     Strand\n                8     Frame. Number of bases within feature before first in-frame codon (if coding)\n                9     Attributes. \"gene_id\" and \"transcript_id\" are required\n            ======== =========\n\n        For more info\n            - `GTF2 file format specification <http://mblab.wustl.edu/GTF22.html>`_\n            - `UCSC file format FAQ <http://genome.ucsc.edu/FAQ/FAQformat.html>`_\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_23as_gtf(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_feature_type = 0;
  int __pyx_v_escape;
  PyObject *__pyx_v_excludes = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("as_gtf (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_feature_type,&__pyx_n_s_escape,&__pyx_n_s_excludes,0};
    PyObject* values[3] = {0,0,0};
    values[0] = ((PyObject*)__pyx_n_u_exon);
    values[2] = ((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  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_feature_type);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_escape);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_excludes);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "as_gtf") < 0)) __PYX_ERR(0, 4131, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_feature_type = ((PyObject*)values[0]);
    if (values[1]) {
      __pyx_v_escape = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_escape == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4131, __pyx_L3_error)
    } else {
      __pyx_v_escape = ((int)1);
    }
    __pyx_v_excludes = ((PyObject*)values[2]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("as_gtf", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 4131, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.as_gtf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_feature_type), (&PyUnicode_Type), 1, "feature_type", 1))) __PYX_ERR(0, 4131, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_excludes), (&PyList_Type), 1, "excludes", 1))) __PYX_ERR(0, 4131, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_22as_gtf(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), __pyx_v_feature_type, __pyx_v_escape, __pyx_v_excludes);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_22as_gtf(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_feature_type, int __pyx_v_escape, PyObject *__pyx_v_excludes) {
  PyObject *__pyx_v_stmp = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_cds_chain_temp = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_start_codon_chain = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_stop_codon_chain = 0;
  PyObject *__pyx_v_child_chain_attr = 0;
  PyObject *__pyx_v_cds_positions = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *__pyx_v_span = 0;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_v_my_strand;
  PyObject *__pyx_v_my_chrom = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_cds_chain = NULL;
  PyObject *__pyx_v_tmplen = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  enum __pyx_t_7plastid_8genomics_8c_common_Strand __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("as_gtf", 0);
  __Pyx_INCREF(__pyx_v_excludes);

  /* "plastid/genomics/roitools.pyx":4200
 *             dict child_chain_attr
 *             list cds_positions
 *             GenomicSegment span = self.spanning_segment             # <<<<<<<<<<<<<<
 *             Strand my_strand = span.c_strand
 *             my_chrom = span.chrom
 */
  __pyx_t_1 = ((PyObject *)__pyx_v_self->__pyx_base.spanning_segment);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_span = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4201
 *             list cds_positions
 *             GenomicSegment span = self.spanning_segment
 *             Strand my_strand = span.c_strand             # <<<<<<<<<<<<<<
 *             my_chrom = span.chrom
 * 
 */
  __pyx_t_2 = __pyx_v_span->c_strand;
  __pyx_v_my_strand = __pyx_t_2;

  /* "plastid/genomics/roitools.pyx":4202
 *             GenomicSegment span = self.spanning_segment
 *             Strand my_strand = span.c_strand
 *             my_chrom = span.chrom             # <<<<<<<<<<<<<<
 * 
 *         excludes = [] if excludes is None else excludes
 */
  __pyx_t_1 = __pyx_v_span->chrom;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_my_chrom = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4204
 *             my_chrom = span.chrom
 * 
 *         excludes = [] if excludes is None else excludes             # <<<<<<<<<<<<<<
 * 
 *         stmp  = SegmentChain.as_gtf(self, feature_type=feature_type, escape=escape, excludes=[])
 */
  __pyx_t_3 = (__pyx_v_excludes == ((PyObject*)Py_None));
  if ((__pyx_t_3 != 0)) {
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __pyx_t_4;
    __pyx_t_4 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_excludes);
    __pyx_t_1 = __pyx_v_excludes;
  }
  __Pyx_DECREF_SET(__pyx_v_excludes, ((PyObject*)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4206
 *         excludes = [] if excludes is None else excludes
 * 
 *         stmp  = SegmentChain.as_gtf(self, feature_type=feature_type, escape=escape, excludes=[])             # <<<<<<<<<<<<<<
 *         cds_chain_temp = self.get_cds()
 *         if len(cds_chain_temp) > 0:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_n_s_as_gtf); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4206, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4206, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_self));
  __pyx_t_5 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4206, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_feature_type, __pyx_v_feature_type) < 0) __PYX_ERR(0, 4206, __pyx_L1_error)
  __pyx_t_6 = __Pyx_PyBool_FromLong(__pyx_v_escape); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4206, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_escape, __pyx_t_6) < 0) __PYX_ERR(0, 4206, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4206, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_excludes, __pyx_t_6) < 0) __PYX_ERR(0, 4206, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4206, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!(likely(PyUnicode_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 4206, __pyx_L1_error)
  __pyx_v_stmp = ((PyObject*)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "plastid/genomics/roitools.pyx":4207
 * 
 *         stmp  = SegmentChain.as_gtf(self, feature_type=feature_type, escape=escape, excludes=[])
 *         cds_chain_temp = self.get_cds()             # <<<<<<<<<<<<<<
 *         if len(cds_chain_temp) > 0:
 *             child_chain_attr  = copy.deepcopy(self.attr)
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_cds); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4207, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_6 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4207, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 4207, __pyx_L1_error)
  __pyx_v_cds_chain_temp = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "plastid/genomics/roitools.pyx":4208
 *         stmp  = SegmentChain.as_gtf(self, feature_type=feature_type, escape=escape, excludes=[])
 *         cds_chain_temp = self.get_cds()
 *         if len(cds_chain_temp) > 0:             # <<<<<<<<<<<<<<
 *             child_chain_attr  = copy.deepcopy(self.attr)
 *             child_chain_attr.pop("type")
 */
  __pyx_t_7 = PyObject_Length(((PyObject *)__pyx_v_cds_chain_temp)); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 4208, __pyx_L1_error)
  __pyx_t_3 = ((__pyx_t_7 > 0) != 0);
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":4209
 *         cds_chain_temp = self.get_cds()
 *         if len(cds_chain_temp) > 0:
 *             child_chain_attr  = copy.deepcopy(self.attr)             # <<<<<<<<<<<<<<
 *             child_chain_attr.pop("type")
 *             cds_positions = list(cds_chain_temp.get_position_list())
 */
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_copy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4209, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4209, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_v_self->__pyx_base.attr) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_self->__pyx_base.attr);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4209, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!(likely(PyDict_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 4209, __pyx_L1_error)
    __pyx_v_child_chain_attr = ((PyObject*)__pyx_t_6);
    __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4210
 *         if len(cds_chain_temp) > 0:
 *             child_chain_attr  = copy.deepcopy(self.attr)
 *             child_chain_attr.pop("type")             # <<<<<<<<<<<<<<
 *             cds_positions = list(cds_chain_temp.get_position_list())
 * 
 */
    if (unlikely(__pyx_v_child_chain_attr == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "pop");
      __PYX_ERR(0, 4210, __pyx_L1_error)
    }
    __pyx_t_6 = __Pyx_PyDict_Pop(__pyx_v_child_chain_attr, __pyx_n_u_type, ((PyObject *)NULL)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4210, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4211
 *             child_chain_attr  = copy.deepcopy(self.attr)
 *             child_chain_attr.pop("type")
 *             cds_positions = list(cds_chain_temp.get_position_list())             # <<<<<<<<<<<<<<
 * 
 *             # remove stop codons from CDS, per GTF2 spec
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cds_chain_temp), __pyx_n_s_get_position_list); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4211, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_6 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4211, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PySequence_List(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4211, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_cds_positions = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":4214
 * 
 *             # remove stop codons from CDS, per GTF2 spec
 *             if my_strand == forward_strand:             # <<<<<<<<<<<<<<
 *                 cds_positions = cds_positions[:-3]
 *             else:
 */
    __pyx_t_3 = ((__pyx_v_my_strand == __pyx_e_7plastid_8genomics_8c_common_forward_strand) != 0);
    if (__pyx_t_3) {

      /* "plastid/genomics/roitools.pyx":4215
 *             # remove stop codons from CDS, per GTF2 spec
 *             if my_strand == forward_strand:
 *                 cds_positions = cds_positions[:-3]             # <<<<<<<<<<<<<<
 *             else:
 *                 cds_positions = cds_positions[3:]
 */
      __pyx_t_4 = __Pyx_PyList_GetSlice(__pyx_v_cds_positions, 0, -3L); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4215, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF_SET(__pyx_v_cds_positions, ((PyObject*)__pyx_t_4));
      __pyx_t_4 = 0;

      /* "plastid/genomics/roitools.pyx":4214
 * 
 *             # remove stop codons from CDS, per GTF2 spec
 *             if my_strand == forward_strand:             # <<<<<<<<<<<<<<
 *                 cds_positions = cds_positions[:-3]
 *             else:
 */
      goto __pyx_L4;
    }

    /* "plastid/genomics/roitools.pyx":4217
 *                 cds_positions = cds_positions[:-3]
 *             else:
 *                 cds_positions = cds_positions[3:]             # <<<<<<<<<<<<<<
 *             cds_chain = SegmentChain(
 *                 *positionlist_to_segments(
 */
    /*else*/ {
      __pyx_t_4 = __Pyx_PyList_GetSlice(__pyx_v_cds_positions, 3, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4217, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF_SET(__pyx_v_cds_positions, ((PyObject*)__pyx_t_4));
      __pyx_t_4 = 0;
    }
    __pyx_L4:;

    /* "plastid/genomics/roitools.pyx":4220
 *             cds_chain = SegmentChain(
 *                 *positionlist_to_segments(
 *                     my_chrom,             # <<<<<<<<<<<<<<
 *                     strand_to_str(my_strand),
 *                     cds_positions
 */
    if (!(likely(PyUnicode_CheckExact(__pyx_v_my_chrom))||((__pyx_v_my_chrom) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_my_chrom)->tp_name), 0))) __PYX_ERR(0, 4220, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":4221
 *                 *positionlist_to_segments(
 *                     my_chrom,
 *                     strand_to_str(my_strand),             # <<<<<<<<<<<<<<
 *                     cds_positions
 *                 ),
 */
    __pyx_t_4 = __pyx_f_7plastid_8genomics_8c_common_strand_to_str(__pyx_v_my_strand); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4221, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "plastid/genomics/roitools.pyx":4219
 *                 cds_positions = cds_positions[3:]
 *             cds_chain = SegmentChain(
 *                 *positionlist_to_segments(             # <<<<<<<<<<<<<<
 *                     my_chrom,
 *                     strand_to_str(my_strand),
 */
    __pyx_t_6 = __pyx_f_7plastid_8genomics_8roitools_positionlist_to_segments(((PyObject*)__pyx_v_my_chrom), ((PyObject*)__pyx_t_4), __pyx_v_cds_positions, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4219, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":4218
 *             else:
 *                 cds_positions = cds_positions[3:]
 *             cds_chain = SegmentChain(             # <<<<<<<<<<<<<<
 *                 *positionlist_to_segments(
 *                     my_chrom,
 */
    __pyx_t_4 = PySequence_Tuple(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4218, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4224
 *                     cds_positions
 *                 ),
 *                 type="CDS",             # <<<<<<<<<<<<<<
 *                 **child_chain_attr
 *             )
 */
    __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4224, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_type, __pyx_n_u_CDS) < 0) __PYX_ERR(0, 4224, __pyx_L1_error)
    __pyx_t_6 = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":4225
 *                 ),
 *                 type="CDS",
 *                 **child_chain_attr             # <<<<<<<<<<<<<<
 *             )
 *             stmp += cds_chain.as_gtf(feature_type="CDS", escape=escape, excludes=excludes)
 */
    if (unlikely(__pyx_v_child_chain_attr == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
      __PYX_ERR(0, 4225, __pyx_L1_error)
    }
    if (__Pyx_MergeKeywords(__pyx_t_6, __pyx_v_child_chain_attr) < 0) __PYX_ERR(0, 4225, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":4218
 *             else:
 *                 cds_positions = cds_positions[3:]
 *             cds_chain = SegmentChain(             # <<<<<<<<<<<<<<
 *                 *positionlist_to_segments(
 *                     my_chrom,
 */
    __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4218, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_cds_chain = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":4227
 *                 **child_chain_attr
 *             )
 *             stmp += cds_chain.as_gtf(feature_type="CDS", escape=escape, excludes=excludes)             # <<<<<<<<<<<<<<
 * 
 *             start_codon_chain = cds_chain_temp.get_subchain(0, 3)
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cds_chain), __pyx_n_s_as_gtf); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_feature_type, __pyx_n_u_CDS) < 0) __PYX_ERR(0, 4227, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_escape); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_escape, __pyx_t_4) < 0) __PYX_ERR(0, 4227, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_excludes, __pyx_v_excludes) < 0) __PYX_ERR(0, 4227, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_v_stmp, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!(likely(PyUnicode_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 4227, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_stmp, ((PyObject*)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4229
 *             stmp += cds_chain.as_gtf(feature_type="CDS", escape=escape, excludes=excludes)
 * 
 *             start_codon_chain = cds_chain_temp.get_subchain(0, 3)             # <<<<<<<<<<<<<<
 *             start_codon_chain.attr.update(child_chain_attr)
 *             stmp += start_codon_chain.as_gtf(
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cds_chain_temp), __pyx_n_s_get_subchain); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4229, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4229, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 4229, __pyx_L1_error)
    __pyx_v_start_codon_chain = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":4230
 * 
 *             start_codon_chain = cds_chain_temp.get_subchain(0, 3)
 *             start_codon_chain.attr.update(child_chain_attr)             # <<<<<<<<<<<<<<
 *             stmp += start_codon_chain.as_gtf(
 *                 feature_type="start_codon",
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_start_codon_chain->attr, __pyx_n_s_update); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4230, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_v_child_chain_attr) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_child_chain_attr);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4230, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "plastid/genomics/roitools.pyx":4231
 *             start_codon_chain = cds_chain_temp.get_subchain(0, 3)
 *             start_codon_chain.attr.update(child_chain_attr)
 *             stmp += start_codon_chain.as_gtf(             # <<<<<<<<<<<<<<
 *                 feature_type="start_codon",
 *                 escape=escape,
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_start_codon_chain), __pyx_n_s_as_gtf); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4231, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "plastid/genomics/roitools.pyx":4232
 *             start_codon_chain.attr.update(child_chain_attr)
 *             stmp += start_codon_chain.as_gtf(
 *                 feature_type="start_codon",             # <<<<<<<<<<<<<<
 *                 escape=escape,
 *                 excludes=excludes
 */
    __pyx_t_6 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4232, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_feature_type, __pyx_n_u_start_codon) < 0) __PYX_ERR(0, 4232, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":4233
 *             stmp += start_codon_chain.as_gtf(
 *                 feature_type="start_codon",
 *                 escape=escape,             # <<<<<<<<<<<<<<
 *                 excludes=excludes
 *             )
 */
    __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_v_escape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4233, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_escape, __pyx_t_5) < 0) __PYX_ERR(0, 4232, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":4234
 *                 feature_type="start_codon",
 *                 escape=escape,
 *                 excludes=excludes             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_excludes, __pyx_v_excludes) < 0) __PYX_ERR(0, 4232, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":4231
 *             start_codon_chain = cds_chain_temp.get_subchain(0, 3)
 *             start_codon_chain.attr.update(child_chain_attr)
 *             stmp += start_codon_chain.as_gtf(             # <<<<<<<<<<<<<<
 *                 feature_type="start_codon",
 *                 escape=escape,
 */
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4231, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_v_stmp, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4231, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (!(likely(PyUnicode_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 4231, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_stmp, ((PyObject*)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4237
 *             )
 * 
 *             tmplen = cds_chain_temp.length             # <<<<<<<<<<<<<<
 *             stop_codon_chain = cds_chain_temp.get_subchain(tmplen-3, tmplen)
 *             stop_codon_chain.attr.update(child_chain_attr)
 */
    __pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_cds_chain_temp->length); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_v_tmplen = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4238
 * 
 *             tmplen = cds_chain_temp.length
 *             stop_codon_chain = cds_chain_temp.get_subchain(tmplen-3, tmplen)             # <<<<<<<<<<<<<<
 *             stop_codon_chain.attr.update(child_chain_attr)
 *             stmp += stop_codon_chain.as_gtf(
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cds_chain_temp), __pyx_n_s_get_subchain); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4238, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyInt_SubtractObjC(__pyx_v_tmplen, __pyx_int_3, 3, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4238, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
        __pyx_t_8 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_4, __pyx_v_tmplen};
      __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4238, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_4, __pyx_v_tmplen};
      __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4238, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4238, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_4);
      __Pyx_INCREF(__pyx_v_tmplen);
      __Pyx_GIVEREF(__pyx_v_tmplen);
      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_tmplen);
      __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4238, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 4238, __pyx_L1_error)
    __pyx_v_stop_codon_chain = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_6);
    __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4239
 *             tmplen = cds_chain_temp.length
 *             stop_codon_chain = cds_chain_temp.get_subchain(tmplen-3, tmplen)
 *             stop_codon_chain.attr.update(child_chain_attr)             # <<<<<<<<<<<<<<
 *             stmp += stop_codon_chain.as_gtf(
 *                 feature_type="stop_codon",
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_stop_codon_chain->attr, __pyx_n_s_update); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4239, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_6 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_9, __pyx_v_child_chain_attr) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_child_chain_attr);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4239, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "plastid/genomics/roitools.pyx":4240
 *             stop_codon_chain = cds_chain_temp.get_subchain(tmplen-3, tmplen)
 *             stop_codon_chain.attr.update(child_chain_attr)
 *             stmp += stop_codon_chain.as_gtf(             # <<<<<<<<<<<<<<
 *                 feature_type="stop_codon",
 *                 escape=escape,
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_stop_codon_chain), __pyx_n_s_as_gtf); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);

    /* "plastid/genomics/roitools.pyx":4241
 *             stop_codon_chain.attr.update(child_chain_attr)
 *             stmp += stop_codon_chain.as_gtf(
 *                 feature_type="stop_codon",             # <<<<<<<<<<<<<<
 *                 escape=escape,
 *                 excludes=excludes
 */
    __pyx_t_5 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4241, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_feature_type, __pyx_n_u_stop_codon) < 0) __PYX_ERR(0, 4241, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":4242
 *             stmp += stop_codon_chain.as_gtf(
 *                 feature_type="stop_codon",
 *                 escape=escape,             # <<<<<<<<<<<<<<
 *                 excludes=excludes
 *             )
 */
    __pyx_t_9 = __Pyx_PyBool_FromLong(__pyx_v_escape); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4242, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_escape, __pyx_t_9) < 0) __PYX_ERR(0, 4241, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "plastid/genomics/roitools.pyx":4243
 *                 feature_type="stop_codon",
 *                 escape=escape,
 *                 excludes=excludes             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_excludes, __pyx_v_excludes) < 0) __PYX_ERR(0, 4241, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":4240
 *             stop_codon_chain = cds_chain_temp.get_subchain(tmplen-3, tmplen)
 *             stop_codon_chain.attr.update(child_chain_attr)
 *             stmp += stop_codon_chain.as_gtf(             # <<<<<<<<<<<<<<
 *                 feature_type="stop_codon",
 *                 escape=escape,
 */
    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_empty_tuple, __pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_stmp, __pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (!(likely(PyUnicode_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 4240, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_stmp, ((PyObject*)__pyx_t_5));
    __pyx_t_5 = 0;

    /* "plastid/genomics/roitools.pyx":4208
 *         stmp  = SegmentChain.as_gtf(self, feature_type=feature_type, escape=escape, excludes=[])
 *         cds_chain_temp = self.get_cds()
 *         if len(cds_chain_temp) > 0:             # <<<<<<<<<<<<<<
 *             child_chain_attr  = copy.deepcopy(self.attr)
 *             child_chain_attr.pop("type")
 */
  }

  /* "plastid/genomics/roitools.pyx":4246
 *             )
 * 
 *         return stmp             # <<<<<<<<<<<<<<
 * 
 *     def as_gff3(self, bint escape=True, list excludes=None, str rna_type="mRNA"):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_stmp);
  __pyx_r = __pyx_v_stmp;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":4131
 *             return SegmentChain()
 * 
 *     def as_gtf(self, str feature_type="exon", bint escape=True, list excludes=None):             # <<<<<<<<<<<<<<
 *         """Format `self` as a `GTF2`_ block. |GenomicSegments| are formatted as
 *         `GTF2`_ `'exon'` features. Coding regions, if peresent, are formatted
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.as_gtf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_stmp);
  __Pyx_XDECREF((PyObject *)__pyx_v_cds_chain_temp);
  __Pyx_XDECREF((PyObject *)__pyx_v_start_codon_chain);
  __Pyx_XDECREF((PyObject *)__pyx_v_stop_codon_chain);
  __Pyx_XDECREF(__pyx_v_child_chain_attr);
  __Pyx_XDECREF(__pyx_v_cds_positions);
  __Pyx_XDECREF((PyObject *)__pyx_v_span);
  __Pyx_XDECREF(__pyx_v_my_chrom);
  __Pyx_XDECREF((PyObject *)__pyx_v_cds_chain);
  __Pyx_XDECREF(__pyx_v_tmplen);
  __Pyx_XDECREF(__pyx_v_excludes);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":4248
 *         return stmp
 * 
 *     def as_gff3(self, bint escape=True, list excludes=None, str rna_type="mRNA"):             # <<<<<<<<<<<<<<
 *         """Format a |Transcript| as a block of `GFF3`_ output, following the
 *         schema set out in the `Sequence Ontology (SO) v2.53
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_25as_gff3(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_24as_gff3[] = "Transcript.as_gff3(self, bool escape=True, list excludes=None, unicode rna_type=u'mRNA')\nFormat a |Transcript| as a block of `GFF3`_ output, following the\n        schema set out in the `Sequence Ontology (SO) v2.53\n        <http://www.sequenceontology.org/browser/>`_\n\n        The |Transcript| will be formatted according to the following rules:\n\n          1. A feature of type `rna_type` will be created, with `Parent` attribute\n             set to the value of ``self.get_gene()``, and `ID` attribute\n             set to ``self.get_name()``\n\n          2. For each |GenomicSegment| in `self`, a child feature of type\n             `exon` will be created. The `Parent` attribute of these features\n             will be set to the value of ``self.get_name()``. These will\n             have unique IDs generated from ``self.get_name()``.\n\n          3. If `self` is coding (i.e. has none-`None` value for\n             `self.cds_genome_start` and `self.cds_genome_end`), child features\n             of type `'five_prime_UTR'`, `'CDS'`, and `'three_prime_UTR'` will be created,\n             with `Parent` attributes set to ``self.get_name()``. These will\n             have unique IDs generated from ``self.get_name()``.\n\n\n        Parameters\n        ----------\n        escape : bool, optional\n            Escape tokens in column 9 of `GFF3`_ output (Default: `True`)\n\n        excludes : list, optional\n            List of attribute key names to exclude from column 9\n            (Default: `[]`)\n\n        rna_type : str, optional\n            Feature type to export RNA as (e.g. `'tRNA'`, `'noncoding_RNA'`,\n            et c. Default: `'mRNA'`)\n\n\n        Returns\n        -------\n        str\n            Multiline block of `GFF3`_-formatted text\n\n\n        Notes\n        -----\n        Beware of attribute loss\n            This |Transcript| was assembled from multiple individual component\n            features (e.g. single exons), which may or may not have had thei""r own\n            unique attributes in their original annotation. To reduce overhead,\n            these individual attributes (if they were present) have not been\n            (entirely) stored, and consequently will not (all) be exported.\n            If this poses problems, consider instead importing, modifying, and\n            exporting the component features\n\n        GFF3 schemas vary\n            Different GFF3s have different schemas (parent-child relationships\n            between features). Here we adopt the commonly-used schema set by\n            `Sequence Ontology (SO) v2.53\n            <http://www.sequenceontology.org/browser/>`_, which may or may not\n            match your schema.\n\n        Columns of `GFF3`_ are as follows\n            ======== =========\n            Column   Contains\n            ======== =========\n                1     Contig or chromosome\n                2     Source of annotation\n                3     Type of feature (\"exon\", \"CDS\", \"start_codon\", \"stop_codon\")\n                4     Start (1-indexed)\n                5     End (fully-closed)\n                6     Score\n                7     Strand\n                8     Frame. Number of bases within feature before first in-frame codon (if coding)\n                9     Attributes\n            ======== =========\n\n        For futher information, see\n            - `GFF3 file format specification <http://www.sequenceontology.org/gff3.shtml>`_\n            - `Sequence Ontology (SO) v2.53 <http://www.sequenceontology.org/browser/>`\n            - `SO releases <http://sourceforge.net/projects/song/files/SO_Feature_Annotation/>`_\n            - `UCSC file format FAQ <http://genome.ucsc.edu/FAQ/FAQformat.html>`_\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_25as_gff3(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_escape;
  PyObject *__pyx_v_excludes = 0;
  PyObject *__pyx_v_rna_type = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("as_gff3 (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_escape,&__pyx_n_s_excludes,&__pyx_n_s_rna_type,0};
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject*)Py_None);
    values[2] = ((PyObject*)__pyx_n_u_mRNA);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_escape);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_excludes);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rna_type);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "as_gff3") < 0)) __PYX_ERR(0, 4248, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    if (values[0]) {
      __pyx_v_escape = __Pyx_PyObject_IsTrue(values[0]); if (unlikely((__pyx_v_escape == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4248, __pyx_L3_error)
    } else {
      __pyx_v_escape = ((int)1);
    }
    __pyx_v_excludes = ((PyObject*)values[1]);
    __pyx_v_rna_type = ((PyObject*)values[2]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("as_gff3", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 4248, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.as_gff3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_excludes), (&PyList_Type), 1, "excludes", 1))) __PYX_ERR(0, 4248, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_rna_type), (&PyUnicode_Type), 1, "rna_type", 1))) __PYX_ERR(0, 4248, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_24as_gff3(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), __pyx_v_escape, __pyx_v_excludes, __pyx_v_rna_type);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_24as_gff3(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, int __pyx_v_escape, PyObject *__pyx_v_excludes, PyObject *__pyx_v_rna_type) {
  PyObject *__pyx_v_gene_id = 0;
  PyObject *__pyx_v_transcript_id = 0;
  PyObject *__pyx_v_ftype = 0;
  PyObject *__pyx_v_my_id = 0;
  PyObject *__pyx_v_ltmp = 0;
  PyObject *__pyx_v_parts = 0;
  PyObject *__pyx_v_child_attr = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_feature = 0;
  int __pyx_v_n;
  PyObject *__pyx_v_keys_to_pop = NULL;
  PyObject *__pyx_v_k = NULL;
  PyObject *__pyx_v_seg = 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;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  Py_UCS4 __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *(*__pyx_t_13)(PyObject *);
  PyObject *(*__pyx_t_14)(PyObject *);
  Py_ssize_t __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("as_gff3", 0);
  __Pyx_INCREF(__pyx_v_excludes);

  /* "plastid/genomics/roitools.pyx":4331
 *         """
 *         cdef:
 *             str gene_id       = self.get_gene()             # <<<<<<<<<<<<<<
 *             str transcript_id = self.get_name()
 *             str ftype, my_id
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_gene); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4331, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4331, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 4331, __pyx_L1_error)
  __pyx_v_gene_id = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4332
 *         cdef:
 *             str gene_id       = self.get_gene()
 *             str transcript_id = self.get_name()             # <<<<<<<<<<<<<<
 *             str ftype, my_id
 *             list ltmp = []
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4332, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4332, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 4332, __pyx_L1_error)
  __pyx_v_transcript_id = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4334
 *             str transcript_id = self.get_name()
 *             str ftype, my_id
 *             list ltmp = []             # <<<<<<<<<<<<<<
 *             list parts = []
 *             dict child_attr = copy.deepcopy(self.attr)
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4334, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_ltmp = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4335
 *             str ftype, my_id
 *             list ltmp = []
 *             list parts = []             # <<<<<<<<<<<<<<
 *             dict child_attr = copy.deepcopy(self.attr)
 *             SegmentChain feature
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4335, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_parts = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4336
 *             list ltmp = []
 *             list parts = []
 *             dict child_attr = copy.deepcopy(self.attr)             # <<<<<<<<<<<<<<
 *             SegmentChain feature
 *             GenomicSegment iv
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_deepcopy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_self->__pyx_base.attr) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->__pyx_base.attr);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 4336, __pyx_L1_error)
  __pyx_v_child_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4341
 *             int n
 * 
 *         excludes = [] if excludes is None else excludes             # <<<<<<<<<<<<<<
 * 
 *         keys_to_pop = ("ID",)
 */
  __pyx_t_4 = (__pyx_v_excludes == ((PyObject*)Py_None));
  if ((__pyx_t_4 != 0)) {
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4341, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __pyx_t_3;
    __pyx_t_3 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_excludes);
    __pyx_t_1 = __pyx_v_excludes;
  }
  __Pyx_DECREF_SET(__pyx_v_excludes, ((PyObject*)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4343
 *         excludes = [] if excludes is None else excludes
 * 
 *         keys_to_pop = ("ID",)             # <<<<<<<<<<<<<<
 *         for k in keys_to_pop:
 *             if k in child_attr:
 */
  __Pyx_INCREF(__pyx_tuple__44);
  __pyx_v_keys_to_pop = __pyx_tuple__44;

  /* "plastid/genomics/roitools.pyx":4344
 * 
 *         keys_to_pop = ("ID",)
 *         for k in keys_to_pop:             # <<<<<<<<<<<<<<
 *             if k in child_attr:
 *                 child_attr.pop(k)
 */
  __pyx_t_1 = __pyx_v_keys_to_pop; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
  for (;;) {
    if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 4344, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4344, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_k, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "plastid/genomics/roitools.pyx":4345
 *         keys_to_pop = ("ID",)
 *         for k in keys_to_pop:
 *             if k in child_attr:             # <<<<<<<<<<<<<<
 *                 child_attr.pop(k)
 * 
 */
    if (unlikely(__pyx_v_child_attr == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 4345, __pyx_L1_error)
    }
    __pyx_t_4 = (__Pyx_PyDict_ContainsTF(__pyx_v_k, __pyx_v_child_attr, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 4345, __pyx_L1_error)
    __pyx_t_6 = (__pyx_t_4 != 0);
    if (__pyx_t_6) {

      /* "plastid/genomics/roitools.pyx":4346
 *         for k in keys_to_pop:
 *             if k in child_attr:
 *                 child_attr.pop(k)             # <<<<<<<<<<<<<<
 * 
 *         # mRNA feature
 */
      if (unlikely(__pyx_v_child_attr == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "pop");
        __PYX_ERR(0, 4346, __pyx_L1_error)
      }
      __pyx_t_3 = __Pyx_PyDict_Pop(__pyx_v_child_attr, __pyx_v_k, ((PyObject *)NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4346, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "plastid/genomics/roitools.pyx":4345
 *         keys_to_pop = ("ID",)
 *         for k in keys_to_pop:
 *             if k in child_attr:             # <<<<<<<<<<<<<<
 *                 child_attr.pop(k)
 * 
 */
    }

    /* "plastid/genomics/roitools.pyx":4344
 * 
 *         keys_to_pop = ("ID",)
 *         for k in keys_to_pop:             # <<<<<<<<<<<<<<
 *             if k in child_attr:
 *                 child_attr.pop(k)
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4349
 * 
 *         # mRNA feature
 *         feature = SegmentChain(             # <<<<<<<<<<<<<<
 *             self.spanning_segment,
 *             ID=transcript_id,
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->__pyx_base.spanning_segment));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->__pyx_base.spanning_segment));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->__pyx_base.spanning_segment));

  /* "plastid/genomics/roitools.pyx":4351
 *         feature = SegmentChain(
 *             self.spanning_segment,
 *             ID=transcript_id,             # <<<<<<<<<<<<<<
 *             Parent=gene_id,
 *             type=rna_type
 */
  __pyx_t_3 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4351, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_ID_2, __pyx_v_transcript_id) < 0) __PYX_ERR(0, 4351, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4352
 *             self.spanning_segment,
 *             ID=transcript_id,
 *             Parent=gene_id,             # <<<<<<<<<<<<<<
 *             type=rna_type
 *         )
 */
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_Parent, __pyx_v_gene_id) < 0) __PYX_ERR(0, 4351, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4353
 *             ID=transcript_id,
 *             Parent=gene_id,
 *             type=rna_type             # <<<<<<<<<<<<<<
 *         )
 *         ltmp.append(feature.as_gff3(excludes=excludes, escape=escape))
 */
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_type, __pyx_v_rna_type) < 0) __PYX_ERR(0, 4351, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4349
 * 
 *         # mRNA feature
 *         feature = SegmentChain(             # <<<<<<<<<<<<<<
 *             self.spanning_segment,
 *             ID=transcript_id,
 */
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_feature = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":4355
 *             type=rna_type
 *         )
 *         ltmp.append(feature.as_gff3(excludes=excludes, escape=escape))             # <<<<<<<<<<<<<<
 * 
 *         # child features
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_feature), __pyx_n_s_as_gff3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_excludes, __pyx_v_excludes) < 0) __PYX_ERR(0, 4355, __pyx_L1_error)
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_escape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_escape, __pyx_t_1) < 0) __PYX_ERR(0, 4355, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_ltmp, __pyx_t_1); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 4355, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4358
 * 
 *         # child features
 *         child_attr["Parent"] = transcript_id             # <<<<<<<<<<<<<<
 * 
 *         # exon feature
 */
  if (unlikely(__pyx_v_child_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 4358, __pyx_L1_error)
  }
  if (unlikely(PyDict_SetItem(__pyx_v_child_attr, __pyx_n_u_Parent, __pyx_v_transcript_id) < 0)) __PYX_ERR(0, 4358, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4361
 * 
 *         # exon feature
 *         child_attr["type"] = "exon"             # <<<<<<<<<<<<<<
 *         for n, seg in enumerate(self._segments):
 *             my_id   = "%s:exon:%s" % (transcript_id, n)
 */
  if (unlikely(__pyx_v_child_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 4361, __pyx_L1_error)
  }
  if (unlikely(PyDict_SetItem(__pyx_v_child_attr, __pyx_n_u_type, __pyx_n_u_exon) < 0)) __PYX_ERR(0, 4361, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4362
 *         # exon feature
 *         child_attr["type"] = "exon"
 *         for n, seg in enumerate(self._segments):             # <<<<<<<<<<<<<<
 *             my_id   = "%s:exon:%s" % (transcript_id, n)
 *             child_attr["ID"]   = my_id
 */
  __pyx_t_8 = 0;
  __pyx_t_1 = __pyx_v_self->__pyx_base._segments; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
  for (;;) {
    if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 4362, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_seg, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_v_n = __pyx_t_8;
    __pyx_t_8 = (__pyx_t_8 + 1);

    /* "plastid/genomics/roitools.pyx":4363
 *         child_attr["type"] = "exon"
 *         for n, seg in enumerate(self._segments):
 *             my_id   = "%s:exon:%s" % (transcript_id, n)             # <<<<<<<<<<<<<<
 *             child_attr["ID"]   = my_id
 *             feature = SegmentChain(seg, **child_attr)
 */
    __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_9 = 0;
    __pyx_t_10 = 127;
    __pyx_t_2 = __Pyx_PyUnicode_Unicode(__pyx_v_transcript_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_10;
    __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_INCREF(__pyx_kp_u_exon_2);
    __pyx_t_9 += 6;
    __Pyx_GIVEREF(__pyx_kp_u_exon_2);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_u_exon_2);
    __pyx_t_2 = __Pyx_PyUnicode_From_int(__pyx_v_n, 0, ' ', 'd'); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_3, 3, __pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF_SET(__pyx_v_my_id, ((PyObject*)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "plastid/genomics/roitools.pyx":4364
 *         for n, seg in enumerate(self._segments):
 *             my_id   = "%s:exon:%s" % (transcript_id, n)
 *             child_attr["ID"]   = my_id             # <<<<<<<<<<<<<<
 *             feature = SegmentChain(seg, **child_attr)
 *             ltmp.append(SegmentChain.as_gff3(feature, excludes=excludes, escape=escape))
 */
    if (unlikely(__pyx_v_child_attr == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 4364, __pyx_L1_error)
    }
    if (unlikely(PyDict_SetItem(__pyx_v_child_attr, __pyx_n_u_ID_2, __pyx_v_my_id) < 0)) __PYX_ERR(0, 4364, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":4365
 *             my_id   = "%s:exon:%s" % (transcript_id, n)
 *             child_attr["ID"]   = my_id
 *             feature = SegmentChain(seg, **child_attr)             # <<<<<<<<<<<<<<
 *             ltmp.append(SegmentChain.as_gff3(feature, excludes=excludes, escape=escape))
 * 
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4365, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_seg);
    __Pyx_GIVEREF(__pyx_v_seg);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_seg);
    if (unlikely(__pyx_v_child_attr == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
      __PYX_ERR(0, 4365, __pyx_L1_error)
    }
    __pyx_t_3 = PyDict_Copy(__pyx_v_child_attr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4365, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_11 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4365, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_feature, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_11));
    __pyx_t_11 = 0;

    /* "plastid/genomics/roitools.pyx":4366
 *             child_attr["ID"]   = my_id
 *             feature = SegmentChain(seg, **child_attr)
 *             ltmp.append(SegmentChain.as_gff3(feature, excludes=excludes, escape=escape))             # <<<<<<<<<<<<<<
 * 
 *         # CDS & UTRs
 */
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_n_s_as_gff3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4366, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4366, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_feature));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_feature));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_feature));
    __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4366, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_excludes, __pyx_v_excludes) < 0) __PYX_ERR(0, 4366, __pyx_L1_error)
    __pyx_t_12 = __Pyx_PyBool_FromLong(__pyx_v_escape); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 4366, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_escape, __pyx_t_12) < 0) __PYX_ERR(0, 4366, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 4366, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_ltmp, __pyx_t_12); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 4366, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

    /* "plastid/genomics/roitools.pyx":4362
 *         # exon feature
 *         child_attr["type"] = "exon"
 *         for n, seg in enumerate(self._segments):             # <<<<<<<<<<<<<<
 *             my_id   = "%s:exon:%s" % (transcript_id, n)
 *             child_attr["ID"]   = my_id
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4369
 * 
 *         # CDS & UTRs
 *         if self.cds_genome_start is not None:             # <<<<<<<<<<<<<<
 *             parts = [("five_prime_UTR", self.get_utr5()),
 *                      ("CDS",            self.get_cds()),
 */
  __pyx_t_6 = (__pyx_v_self->cds_genome_start != Py_None);
  __pyx_t_4 = (__pyx_t_6 != 0);
  if (__pyx_t_4) {

    /* "plastid/genomics/roitools.pyx":4370
 *         # CDS & UTRs
 *         if self.cds_genome_start is not None:
 *             parts = [("five_prime_UTR", self.get_utr5()),             # <<<<<<<<<<<<<<
 *                      ("CDS",            self.get_cds()),
 *                      ("three_prime_UTR",self.get_utr3()),
 */
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_utr5); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 4370, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_12);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_12, function);
      }
    }
    __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_12);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4370, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 4370, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_INCREF(__pyx_n_u_five_prime_UTR);
    __Pyx_GIVEREF(__pyx_n_u_five_prime_UTR);
    PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_n_u_five_prime_UTR);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4371
 *         if self.cds_genome_start is not None:
 *             parts = [("five_prime_UTR", self.get_utr5()),
 *                      ("CDS",            self.get_cds()),             # <<<<<<<<<<<<<<
 *                      ("three_prime_UTR",self.get_utr3()),
 *                     ]
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_cds); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4371, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4371, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4371, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_n_u_CDS);
    __Pyx_GIVEREF(__pyx_n_u_CDS);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_CDS);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4372
 *             parts = [("five_prime_UTR", self.get_utr5()),
 *                      ("CDS",            self.get_cds()),
 *                      ("three_prime_UTR",self.get_utr3()),             # <<<<<<<<<<<<<<
 *                     ]
 *             for ftype, feature in parts:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_utr3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4372, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_11 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_11)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_1 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4372, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4372, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_n_u_three_prime_UTR);
    __Pyx_GIVEREF(__pyx_n_u_three_prime_UTR);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_n_u_three_prime_UTR);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4370
 *         # CDS & UTRs
 *         if self.cds_genome_start is not None:
 *             parts = [("five_prime_UTR", self.get_utr5()),             # <<<<<<<<<<<<<<
 *                      ("CDS",            self.get_cds()),
 *                      ("three_prime_UTR",self.get_utr3()),
 */
    __pyx_t_1 = PyList_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4370, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_12);
    PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_2);
    PyList_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_1, 2, __pyx_t_3);
    __pyx_t_12 = 0;
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_parts, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4374
 *                      ("three_prime_UTR",self.get_utr3()),
 *                     ]
 *             for ftype, feature in parts:             # <<<<<<<<<<<<<<
 *                 child_attr["type"]   = ftype
 *                 child_attr["Parent"] = transcript_id
 */
    __pyx_t_1 = __pyx_v_parts; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    for (;;) {
      if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 4374, __pyx_L1_error)
      #else
      __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4374, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      #endif
      if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
        PyObject* sequence = __pyx_t_3;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 4374, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_12 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_12 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_12);
        #else
        __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4374, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_12 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 4374, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        #endif
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_11 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4374, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_13 = Py_TYPE(__pyx_t_11)->tp_iternext;
        index = 0; __pyx_t_2 = __pyx_t_13(__pyx_t_11); if (unlikely(!__pyx_t_2)) goto __pyx_L11_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_2);
        index = 1; __pyx_t_12 = __pyx_t_13(__pyx_t_11); if (unlikely(!__pyx_t_12)) goto __pyx_L11_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_12);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_11), 2) < 0) __PYX_ERR(0, 4374, __pyx_L1_error)
        __pyx_t_13 = NULL;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L12_unpacking_done;
        __pyx_L11_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_13 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 4374, __pyx_L1_error)
        __pyx_L12_unpacking_done:;
      }
      if (!(likely(PyUnicode_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 4374, __pyx_L1_error)
      if (!(likely(((__pyx_t_12) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_12, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 4374, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_ftype, ((PyObject*)__pyx_t_2));
      __pyx_t_2 = 0;
      __Pyx_DECREF_SET(__pyx_v_feature, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_12));
      __pyx_t_12 = 0;

      /* "plastid/genomics/roitools.pyx":4375
 *                     ]
 *             for ftype, feature in parts:
 *                 child_attr["type"]   = ftype             # <<<<<<<<<<<<<<
 *                 child_attr["Parent"] = transcript_id
 *                 for n, seg in enumerate(feature):
 */
      if (unlikely(__pyx_v_child_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 4375, __pyx_L1_error)
      }
      if (unlikely(PyDict_SetItem(__pyx_v_child_attr, __pyx_n_u_type, __pyx_v_ftype) < 0)) __PYX_ERR(0, 4375, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":4376
 *             for ftype, feature in parts:
 *                 child_attr["type"]   = ftype
 *                 child_attr["Parent"] = transcript_id             # <<<<<<<<<<<<<<
 *                 for n, seg in enumerate(feature):
 *                     my_id   = "%s:%s:%s" % (transcript_id, ftype, n)
 */
      if (unlikely(__pyx_v_child_attr == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 4376, __pyx_L1_error)
      }
      if (unlikely(PyDict_SetItem(__pyx_v_child_attr, __pyx_n_u_Parent, __pyx_v_transcript_id) < 0)) __PYX_ERR(0, 4376, __pyx_L1_error)

      /* "plastid/genomics/roitools.pyx":4377
 *                 child_attr["type"]   = ftype
 *                 child_attr["Parent"] = transcript_id
 *                 for n, seg in enumerate(feature):             # <<<<<<<<<<<<<<
 *                     my_id   = "%s:%s:%s" % (transcript_id, ftype, n)
 *                     child_attr["ID"]   = my_id
 */
      __pyx_t_8 = 0;
      if (likely(PyList_CheckExact(((PyObject *)__pyx_v_feature))) || PyTuple_CheckExact(((PyObject *)__pyx_v_feature))) {
        __pyx_t_3 = ((PyObject *)__pyx_v_feature); __Pyx_INCREF(__pyx_t_3); __pyx_t_9 = 0;
        __pyx_t_14 = NULL;
      } else {
        __pyx_t_9 = -1; __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_feature)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4377, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_14 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 4377, __pyx_L1_error)
      }
      for (;;) {
        if (likely(!__pyx_t_14)) {
          if (likely(PyList_CheckExact(__pyx_t_3))) {
            if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_12 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_12); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 4377, __pyx_L1_error)
            #else
            __pyx_t_12 = PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 4377, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_12);
            #endif
          } else {
            if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_12 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_12); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 4377, __pyx_L1_error)
            #else
            __pyx_t_12 = PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 4377, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_12);
            #endif
          }
        } else {
          __pyx_t_12 = __pyx_t_14(__pyx_t_3);
          if (unlikely(!__pyx_t_12)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 4377, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_12);
        }
        __Pyx_XDECREF_SET(__pyx_v_seg, __pyx_t_12);
        __pyx_t_12 = 0;
        __pyx_v_n = __pyx_t_8;
        __pyx_t_8 = (__pyx_t_8 + 1);

        /* "plastid/genomics/roitools.pyx":4378
 *                 child_attr["Parent"] = transcript_id
 *                 for n, seg in enumerate(feature):
 *                     my_id   = "%s:%s:%s" % (transcript_id, ftype, n)             # <<<<<<<<<<<<<<
 *                     child_attr["ID"]   = my_id
 *                     feature = SegmentChain(seg, **child_attr)
 */
        __pyx_t_12 = PyTuple_New(5); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 4378, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_15 = 0;
        __pyx_t_10 = 127;
        __pyx_t_2 = __Pyx_PyUnicode_Unicode(__pyx_v_transcript_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4378, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_10;
        __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_INCREF(__pyx_kp_u__12);
        __pyx_t_15 += 1;
        __Pyx_GIVEREF(__pyx_kp_u__12);
        PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_kp_u__12);
        __pyx_t_2 = __Pyx_PyUnicode_Unicode(__pyx_v_ftype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4378, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_10;
        __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_12, 2, __pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_INCREF(__pyx_kp_u__12);
        __pyx_t_15 += 1;
        __Pyx_GIVEREF(__pyx_kp_u__12);
        PyTuple_SET_ITEM(__pyx_t_12, 3, __pyx_kp_u__12);
        __pyx_t_2 = __Pyx_PyUnicode_From_int(__pyx_v_n, 0, ' ', 'd'); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4378, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_12, 4, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_12, 5, __pyx_t_15, __pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4378, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_XDECREF_SET(__pyx_v_my_id, ((PyObject*)__pyx_t_2));
        __pyx_t_2 = 0;

        /* "plastid/genomics/roitools.pyx":4379
 *                 for n, seg in enumerate(feature):
 *                     my_id   = "%s:%s:%s" % (transcript_id, ftype, n)
 *                     child_attr["ID"]   = my_id             # <<<<<<<<<<<<<<
 *                     feature = SegmentChain(seg, **child_attr)
 *                     ltmp.append(feature.as_gff3(excludes=excludes, escape=escape))
 */
        if (unlikely(__pyx_v_child_attr == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 4379, __pyx_L1_error)
        }
        if (unlikely(PyDict_SetItem(__pyx_v_child_attr, __pyx_n_u_ID_2, __pyx_v_my_id) < 0)) __PYX_ERR(0, 4379, __pyx_L1_error)

        /* "plastid/genomics/roitools.pyx":4380
 *                     my_id   = "%s:%s:%s" % (transcript_id, ftype, n)
 *                     child_attr["ID"]   = my_id
 *                     feature = SegmentChain(seg, **child_attr)             # <<<<<<<<<<<<<<
 *                     ltmp.append(feature.as_gff3(excludes=excludes, escape=escape))
 * 
 */
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4380, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_v_seg);
        __Pyx_GIVEREF(__pyx_v_seg);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_seg);
        if (unlikely(__pyx_v_child_attr == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
          __PYX_ERR(0, 4380, __pyx_L1_error)
        }
        __pyx_t_12 = PyDict_Copy(__pyx_v_child_attr); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 4380, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_11 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_t_2, __pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4380, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_DECREF_SET(__pyx_v_feature, ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_11));
        __pyx_t_11 = 0;

        /* "plastid/genomics/roitools.pyx":4381
 *                     child_attr["ID"]   = my_id
 *                     feature = SegmentChain(seg, **child_attr)
 *                     ltmp.append(feature.as_gff3(excludes=excludes, escape=escape))             # <<<<<<<<<<<<<<
 * 
 *         return "".join(ltmp)
 */
        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_feature), __pyx_n_s_as_gff3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 4381, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_12 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 4381, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_excludes, __pyx_v_excludes) < 0) __PYX_ERR(0, 4381, __pyx_L1_error)
        __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_escape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4381, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_escape, __pyx_t_2) < 0) __PYX_ERR(0, 4381, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_empty_tuple, __pyx_t_12); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4381, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_ltmp, __pyx_t_2); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 4381, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "plastid/genomics/roitools.pyx":4377
 *                 child_attr["type"]   = ftype
 *                 child_attr["Parent"] = transcript_id
 *                 for n, seg in enumerate(feature):             # <<<<<<<<<<<<<<
 *                     my_id   = "%s:%s:%s" % (transcript_id, ftype, n)
 *                     child_attr["ID"]   = my_id
 */
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "plastid/genomics/roitools.pyx":4374
 *                      ("three_prime_UTR",self.get_utr3()),
 *                     ]
 *             for ftype, feature in parts:             # <<<<<<<<<<<<<<
 *                 child_attr["type"]   = ftype
 *                 child_attr["Parent"] = transcript_id
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "plastid/genomics/roitools.pyx":4369
 * 
 *         # CDS & UTRs
 *         if self.cds_genome_start is not None:             # <<<<<<<<<<<<<<
 *             parts = [("five_prime_UTR", self.get_utr5()),
 *                      ("CDS",            self.get_cds()),
 */
  }

  /* "plastid/genomics/roitools.pyx":4383
 *                     ltmp.append(feature.as_gff3(excludes=excludes, escape=escape))
 * 
 *         return "".join(ltmp)             # <<<<<<<<<<<<<<
 * 
 *     def as_bed(self, as_int=True, color=None, extra_columns=None, empty_value=""):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyUnicode_Join(__pyx_kp_u__33, __pyx_v_ltmp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4383, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":4248
 *         return stmp
 * 
 *     def as_gff3(self, bint escape=True, list excludes=None, str rna_type="mRNA"):             # <<<<<<<<<<<<<<
 *         """Format a |Transcript| as a block of `GFF3`_ output, following the
 *         schema set out in the `Sequence Ontology (SO) v2.53
 */

  /* 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_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.as_gff3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_gene_id);
  __Pyx_XDECREF(__pyx_v_transcript_id);
  __Pyx_XDECREF(__pyx_v_ftype);
  __Pyx_XDECREF(__pyx_v_my_id);
  __Pyx_XDECREF(__pyx_v_ltmp);
  __Pyx_XDECREF(__pyx_v_parts);
  __Pyx_XDECREF(__pyx_v_child_attr);
  __Pyx_XDECREF((PyObject *)__pyx_v_feature);
  __Pyx_XDECREF(__pyx_v_keys_to_pop);
  __Pyx_XDECREF(__pyx_v_k);
  __Pyx_XDECREF(__pyx_v_seg);
  __Pyx_XDECREF(__pyx_v_excludes);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":4385
 *         return "".join(ltmp)
 * 
 *     def as_bed(self, as_int=True, color=None, extra_columns=None, empty_value=""):             # <<<<<<<<<<<<<<
 *         """Format `self` as a BED12[+X] line, assigning CDS boundaries
 *         to the thickstart and thickend columns from `self.attr`
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_27as_bed(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_26as_bed[] = "Transcript.as_bed(self, as_int=True, color=None, extra_columns=None, empty_value=u'')\nFormat `self` as a BED12[+X] line, assigning CDS boundaries\n        to the thickstart and thickend columns from `self.attr`\n\n        If the |SegmentChain| was imported as a `BED`_ file with extra columns,\n        these will be output in the same order, after the `BED`_ columns.\n\n        Parameters\n        ----------\n        as_int : bool, optional\n            Force \"score\" to integer (Default: True)\n\n        color : str or None, optional\n            Color represented as RGB hex string.\n            If not none, overrides the color in `self.attr[\"color\"]`\n\n        extra_columns : None or list-like, optional\n            If `None`, and the |SegmentChain| was imported using the `extra_columns`\n            keyword of :meth:`~plastid.genomics.roitools.SegmentChain.from_bed`,\n            the |SegmentChain| will be exported in BED 12+X format, in which\n            extra columns are in the same order as they were upon import. If no extra columns\n            were present, the |SegmentChain| will be exported as a BED12 line.\n\n            If a list of attribute names, these attributes will be exported as\n            extra columns in order, overriding whatever happened upon import.\n            If an attribute name is not in the `attr` dict of the |SegmentChain|,\n            it will be exported with the value of `empty_value`\n\n            If an empty list, no extra columns will be exported; the |SegmentChain|\n            will be formatted as a BED12 line.\n\n        empty_value : str, optional\n\n\n        Returns\n        -------\n        str\n            Line of BED12-formatted text\n\n\n        Notes\n        -----\n        BED12 columns are as follows\n            ======== =========\n            Column   Contains\n            ======== =========\n               0     Contig or chromosome\n               1     Start of first block in feature (0-indexed)\n       ""        2     End of last block in feature (half-open)\n               3     Feature name\n               4     Feature score\n               5     Strand\n               6     thickstart\n               7     thickend\n               8     Feature color as RGB tuple\n               9     Number of blocks in feature\n               10    Block lengths\n               11    Block starts, relative to start of first block\n            ======== =========\n\n        Fore more information\n            See the `UCSC file format faq <http://genome.ucsc.edu/FAQ/FAQformat.html>`_\n        ";
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_27as_bed(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_as_int = 0;
  PyObject *__pyx_v_color = 0;
  PyObject *__pyx_v_extra_columns = 0;
  PyObject *__pyx_v_empty_value = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("as_bed (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_as_int,&__pyx_n_s_color,&__pyx_n_s_extra_columns,&__pyx_n_s_empty_value,0};
    PyObject* values[4] = {0,0,0,0};
    values[0] = ((PyObject *)Py_True);
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)__pyx_kp_u__33);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_as_int);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_color);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_extra_columns);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_empty_value);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "as_bed") < 0)) __PYX_ERR(0, 4385, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_as_int = values[0];
    __pyx_v_color = values[1];
    __pyx_v_extra_columns = values[2];
    __pyx_v_empty_value = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("as_bed", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 4385, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.as_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_26as_bed(((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_v_self), __pyx_v_as_int, __pyx_v_color, __pyx_v_extra_columns, __pyx_v_empty_value);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_26as_bed(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_self, PyObject *__pyx_v_as_int, PyObject *__pyx_v_color, PyObject *__pyx_v_extra_columns, PyObject *__pyx_v_empty_value) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("as_bed", 0);

  /* "plastid/genomics/roitools.pyx":4448
 *             See the `UCSC file format faq <http://genome.ucsc.edu/FAQ/FAQformat.html>`_
 *         """
 *         return SegmentChain.as_bed(             # <<<<<<<<<<<<<<
 *             self,
 *             thickstart    = self.cds_genome_start,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_n_s_as_bed); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4448, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "plastid/genomics/roitools.pyx":4449
 *         """
 *         return SegmentChain.as_bed(
 *             self,             # <<<<<<<<<<<<<<
 *             thickstart    = self.cds_genome_start,
 *             thickend      = self.cds_genome_end,
 */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4448, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));

  /* "plastid/genomics/roitools.pyx":4450
 *         return SegmentChain.as_bed(
 *             self,
 *             thickstart    = self.cds_genome_start,             # <<<<<<<<<<<<<<
 *             thickend      = self.cds_genome_end,
 *             as_int        = as_int,
 */
  __pyx_t_3 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_thickstart, __pyx_v_self->cds_genome_start) < 0) __PYX_ERR(0, 4450, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4451
 *             self,
 *             thickstart    = self.cds_genome_start,
 *             thickend      = self.cds_genome_end,             # <<<<<<<<<<<<<<
 *             as_int        = as_int,
 *             color         = color,
 */
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_thickend, __pyx_v_self->cds_genome_end) < 0) __PYX_ERR(0, 4450, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4452
 *             thickstart    = self.cds_genome_start,
 *             thickend      = self.cds_genome_end,
 *             as_int        = as_int,             # <<<<<<<<<<<<<<
 *             color         = color,
 *             extra_columns = extra_columns,
 */
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_as_int, __pyx_v_as_int) < 0) __PYX_ERR(0, 4450, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4453
 *             thickend      = self.cds_genome_end,
 *             as_int        = as_int,
 *             color         = color,             # <<<<<<<<<<<<<<
 *             extra_columns = extra_columns,
 *             empty_value   = empty_value
 */
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_color, __pyx_v_color) < 0) __PYX_ERR(0, 4450, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4454
 *             as_int        = as_int,
 *             color         = color,
 *             extra_columns = extra_columns,             # <<<<<<<<<<<<<<
 *             empty_value   = empty_value
 *         )
 */
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_extra_columns, __pyx_v_extra_columns) < 0) __PYX_ERR(0, 4450, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4455
 *             color         = color,
 *             extra_columns = extra_columns,
 *             empty_value   = empty_value             # <<<<<<<<<<<<<<
 *         )
 * 
 */
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_empty_value, __pyx_v_empty_value) < 0) __PYX_ERR(0, 4450, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4448
 *             See the `UCSC file format faq <http://genome.ucsc.edu/FAQ/FAQformat.html>`_
 *         """
 *         return SegmentChain.as_bed(             # <<<<<<<<<<<<<<
 *             self,
 *             thickstart    = self.cds_genome_start,
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4448, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":4385
 *         return "".join(ltmp)
 * 
 *     def as_bed(self, as_int=True, color=None, extra_columns=None, empty_value=""):             # <<<<<<<<<<<<<<
 *         """Format `self` as a BED12[+X] line, assigning CDS boundaries
 *         to the thickstart and thickend columns from `self.attr`
 */

  /* 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("plastid.genomics.roitools.Transcript.as_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":4459
 * 
 *     @staticmethod
 *     def from_bed(str line, extra_columns=0):             # <<<<<<<<<<<<<<
 *         """Create a |Transcript| from a BED line with 4 or more columns.
 *         `thickstart` and `thickend` columns, if present, are assumed to specify
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_29from_bed(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_28from_bed[] = "Transcript.from_bed(unicode line, extra_columns=0)\nCreate a |Transcript| from a BED line with 4 or more columns.\n        `thickstart` and `thickend` columns, if present, are assumed to specify\n        CDS boundaries, a convention that, while common, is formally outside the\n        `BED`_ specification.\n\n    \tSee the `UCSC file format faq <http://genome.ucsc.edu/FAQ/FAQformat.html>`_\n    \tfor more details.\n\n        Parameters\n        ----------\n        line\n            Line from a BED file with at least 4 columns\n\n        extra_columns: int or list, optional\n            Extra, non-BED columns in `BED`_ file corresponding to feature\n            attributes. This is common in `ENCODE`_-specific `BED`_ variants.\n\n            if `extra-columns` is:\n\n              - an :class:`int`: it is taken to be the number of attribute\n                columns. Attributes will be stored in the `attr` dictionary of\n                the |SegmentChain|, under names like `custom0`, `custom1`, ...\n                , `customN`.\n\n              - a :class:`list` of :class:`str`, it is taken to be the names\n                of the attribute columns, in order, from left to right in the\n                file.  In this case, attributes in extra columns will be stored\n                under\n\n              - a :class:`list` of :class:`tuple`, each tuple is taken\n                to be a pair of `(attribute_name, formatter_func)`. In this\n                case, the value of `attribute_name` in the `attr` dict of the\n                |SegmentChain| will be set to `formatter_func(column_value)`.\n\n            (Default: 0)\n\n\n        Returns\n        -------\n        |Transcript|\n        ";
static PyMethodDef __pyx_mdef_7plastid_8genomics_8roitools_10Transcript_29from_bed = {"from_bed", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_29from_bed, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_28from_bed};
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_29from_bed(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_line = 0;
  PyObject *__pyx_v_extra_columns = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_bed (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_line,&__pyx_n_s_extra_columns,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_int_0);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_line)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_extra_columns);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "from_bed") < 0)) __PYX_ERR(0, 4459, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_line = ((PyObject*)values[0]);
    __pyx_v_extra_columns = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("from_bed", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 4459, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.from_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_line), (&PyUnicode_Type), 1, "line", 1))) __PYX_ERR(0, 4459, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_28from_bed(__pyx_v_line, __pyx_v_extra_columns);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_28from_bed(PyObject *__pyx_v_line, PyObject *__pyx_v_extra_columns) {
  PyObject *__pyx_v_attr = 0;
  PyObject *__pyx_v_segments = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_chain = 0;
  PyObject *__pyx_v_cds_genome_start = NULL;
  PyObject *__pyx_v_cds_genome_end = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_7plastid_8genomics_8roitools_get_attr_from_bed __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("from_bed", 0);

  /* "plastid/genomics/roitools.pyx":4502
 *         """
 *         cdef:
 *             dict         attr     = get_attr_from_bed(line, extra_columns=extra_columns)             # <<<<<<<<<<<<<<
 *             list         segments = get_segments_from_bed(attr)
 *             Transcript   chain    = Transcript()
 */
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.extra_columns = __pyx_v_extra_columns;
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed(__pyx_v_line, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4502, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4503
 *         cdef:
 *             dict         attr     = get_attr_from_bed(line, extra_columns=extra_columns)
 *             list         segments = get_segments_from_bed(attr)             # <<<<<<<<<<<<<<
 *             Transcript   chain    = Transcript()
 * 
 */
  __pyx_t_1 = __pyx_f_7plastid_8genomics_8roitools_get_segments_from_bed(__pyx_v_attr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_segments = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4504
 *             dict         attr     = get_attr_from_bed(line, extra_columns=extra_columns)
 *             list         segments = get_segments_from_bed(attr)
 *             Transcript   chain    = Transcript()             # <<<<<<<<<<<<<<
 * 
 *         chain._set_segments(segments)
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4504, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_chain = ((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4506
 *             Transcript   chain    = Transcript()
 * 
 *         chain._set_segments(segments)             # <<<<<<<<<<<<<<
 *         cds_genome_start = attr.get("thickstart", None)
 *         cds_genome_end   = attr.get("thickend", None)
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_chain->__pyx_base.__pyx_vtab)->__pyx_base._set_segments(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_chain), __pyx_v_segments); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 4506, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4507
 * 
 *         chain._set_segments(segments)
 *         cds_genome_start = attr.get("thickstart", None)             # <<<<<<<<<<<<<<
 *         cds_genome_end   = attr.get("thickend", None)
 * 
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 4507, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_attr, __pyx_n_u_thickstart, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_cds_genome_start = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4508
 *         chain._set_segments(segments)
 *         cds_genome_start = attr.get("thickstart", None)
 *         cds_genome_end   = attr.get("thickend", None)             # <<<<<<<<<<<<<<
 * 
 *         if cds_genome_start == cds_genome_end:
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
    __PYX_ERR(0, 4508, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_attr, __pyx_n_u_thickend, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4508, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_cds_genome_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4510
 *         cds_genome_end   = attr.get("thickend", None)
 * 
 *         if cds_genome_start == cds_genome_end:             # <<<<<<<<<<<<<<
 *             cds_genome_start = cds_genome_end = None
 * 
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_cds_genome_start, __pyx_v_cds_genome_end, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4510, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 4510, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":4511
 * 
 *         if cds_genome_start == cds_genome_end:
 *             cds_genome_start = cds_genome_end = None             # <<<<<<<<<<<<<<
 * 
 *         chain.cds_genome_start = cds_genome_start
 */
    __Pyx_INCREF(Py_None);
    __Pyx_DECREF_SET(__pyx_v_cds_genome_start, Py_None);
    __Pyx_INCREF(Py_None);
    __Pyx_DECREF_SET(__pyx_v_cds_genome_end, Py_None);

    /* "plastid/genomics/roitools.pyx":4510
 *         cds_genome_end   = attr.get("thickend", None)
 * 
 *         if cds_genome_start == cds_genome_end:             # <<<<<<<<<<<<<<
 *             cds_genome_start = cds_genome_end = None
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":4513
 *             cds_genome_start = cds_genome_end = None
 * 
 *         chain.cds_genome_start = cds_genome_start             # <<<<<<<<<<<<<<
 *         chain.cds_genome_end   = cds_genome_end
 * 
 */
  __Pyx_INCREF(__pyx_v_cds_genome_start);
  __Pyx_GIVEREF(__pyx_v_cds_genome_start);
  __Pyx_GOTREF(__pyx_v_chain->cds_genome_start);
  __Pyx_DECREF(__pyx_v_chain->cds_genome_start);
  __pyx_v_chain->cds_genome_start = __pyx_v_cds_genome_start;

  /* "plastid/genomics/roitools.pyx":4514
 * 
 *         chain.cds_genome_start = cds_genome_start
 *         chain.cds_genome_end   = cds_genome_end             # <<<<<<<<<<<<<<
 * 
 *         if chain.cds_genome_start is not None and chain.cds_genome_end is not None:
 */
  __Pyx_INCREF(__pyx_v_cds_genome_end);
  __Pyx_GIVEREF(__pyx_v_cds_genome_end);
  __Pyx_GOTREF(__pyx_v_chain->cds_genome_end);
  __Pyx_DECREF(__pyx_v_chain->cds_genome_end);
  __pyx_v_chain->cds_genome_end = __pyx_v_cds_genome_end;

  /* "plastid/genomics/roitools.pyx":4516
 *         chain.cds_genome_end   = cds_genome_end
 * 
 *         if chain.cds_genome_start is not None and chain.cds_genome_end is not None:             # <<<<<<<<<<<<<<
 *             chain._update_cds()
 * 
 */
  __pyx_t_4 = (__pyx_v_chain->cds_genome_start != Py_None);
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {
  } else {
    __pyx_t_3 = __pyx_t_5;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_5 = (__pyx_v_chain->cds_genome_end != Py_None);
  __pyx_t_4 = (__pyx_t_5 != 0);
  __pyx_t_3 = __pyx_t_4;
  __pyx_L5_bool_binop_done:;
  if (__pyx_t_3) {

    /* "plastid/genomics/roitools.pyx":4517
 * 
 *         if chain.cds_genome_start is not None and chain.cds_genome_end is not None:
 *             chain._update_cds()             # <<<<<<<<<<<<<<
 * 
 *         attr["type"] = "mRNA" # default type for SegmentChain is "exon". We want to use "mRNA"
 */
    __pyx_t_3 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_chain->__pyx_base.__pyx_vtab)->_update_cds(__pyx_v_chain); if (unlikely(__pyx_t_3 == ((int)0))) __PYX_ERR(0, 4517, __pyx_L1_error)

    /* "plastid/genomics/roitools.pyx":4516
 *         chain.cds_genome_end   = cds_genome_end
 * 
 *         if chain.cds_genome_start is not None and chain.cds_genome_end is not None:             # <<<<<<<<<<<<<<
 *             chain._update_cds()
 * 
 */
  }

  /* "plastid/genomics/roitools.pyx":4519
 *             chain._update_cds()
 * 
 *         attr["type"] = "mRNA" # default type for SegmentChain is "exon". We want to use "mRNA"             # <<<<<<<<<<<<<<
 *         attr.pop("thickstart")
 *         attr.pop("thickend")
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 4519, __pyx_L1_error)
  }
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_type, __pyx_n_u_mRNA) < 0)) __PYX_ERR(0, 4519, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4520
 * 
 *         attr["type"] = "mRNA" # default type for SegmentChain is "exon". We want to use "mRNA"
 *         attr.pop("thickstart")             # <<<<<<<<<<<<<<
 *         attr.pop("thickend")
 * 
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "pop");
    __PYX_ERR(0, 4520, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_Pop(__pyx_v_attr, __pyx_n_u_thickstart, ((PyObject *)NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4521
 *         attr["type"] = "mRNA" # default type for SegmentChain is "exon". We want to use "mRNA"
 *         attr.pop("thickstart")
 *         attr.pop("thickend")             # <<<<<<<<<<<<<<
 * 
 *         chain.attr = attr
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "pop");
    __PYX_ERR(0, 4521, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_Pop(__pyx_v_attr, __pyx_n_u_thickend, ((PyObject *)NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4521, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4523
 *         attr.pop("thickend")
 * 
 *         chain.attr = attr             # <<<<<<<<<<<<<<
 * 
 *         return chain
 */
  __Pyx_INCREF(__pyx_v_attr);
  __Pyx_GIVEREF(__pyx_v_attr);
  __Pyx_GOTREF(__pyx_v_chain->__pyx_base.attr);
  __Pyx_DECREF(__pyx_v_chain->__pyx_base.attr);
  __pyx_v_chain->__pyx_base.attr = __pyx_v_attr;

  /* "plastid/genomics/roitools.pyx":4525
 *         chain.attr = attr
 * 
 *         return chain             # <<<<<<<<<<<<<<
 * 
 *     @staticmethod
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_chain));
  __pyx_r = ((PyObject *)__pyx_v_chain);
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":4459
 * 
 *     @staticmethod
 *     def from_bed(str line, extra_columns=0):             # <<<<<<<<<<<<<<
 *         """Create a |Transcript| from a BED line with 4 or more columns.
 *         `thickstart` and `thickend` columns, if present, are assumed to specify
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.from_bed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XDECREF(__pyx_v_segments);
  __Pyx_XDECREF((PyObject *)__pyx_v_chain);
  __Pyx_XDECREF(__pyx_v_cds_genome_start);
  __Pyx_XDECREF(__pyx_v_cds_genome_end);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "plastid/genomics/roitools.pyx":4528
 * 
 *     @staticmethod
 *     def from_psl(str psl_line):             # <<<<<<<<<<<<<<
 *         cdef:
 *             Transcript transcript = Transcript()
 */

/* Python wrapper */
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_31from_psl(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7plastid_8genomics_8roitools_10Transcript_30from_psl[] = "Transcript.from_psl(unicode psl_line)";
static PyMethodDef __pyx_mdef_7plastid_8genomics_8roitools_10Transcript_31from_psl = {"from_psl", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_31from_psl, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_30from_psl};
static PyObject *__pyx_pw_7plastid_8genomics_8roitools_10Transcript_31from_psl(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_psl_line = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_psl (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_psl_line,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_psl_line)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "from_psl") < 0)) __PYX_ERR(0, 4528, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_psl_line = ((PyObject*)values[0]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("from_psl", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 4528, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.from_psl", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_psl_line), (&PyUnicode_Type), 1, "psl_line", 1))) __PYX_ERR(0, 4528, __pyx_L1_error)
  __pyx_r = __pyx_pf_7plastid_8genomics_8roitools_10Transcript_30from_psl(__pyx_v_psl_line);

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

static PyObject *__pyx_pf_7plastid_8genomics_8roitools_10Transcript_30from_psl(PyObject *__pyx_v_psl_line) {
  struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *__pyx_v_transcript = 0;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *__pyx_v_segchain = 0;
  PyObject *__pyx_v_attr = 0;
  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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("from_psl", 0);

  /* "plastid/genomics/roitools.pyx":4530
 *     def from_psl(str psl_line):
 *         cdef:
 *             Transcript transcript = Transcript()             # <<<<<<<<<<<<<<
 *             SegmentChain segchain = SegmentChain.from_psl(psl_line)
 *             dict attr = segchain.attr
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4530, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_transcript = ((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4531
 *         cdef:
 *             Transcript transcript = Transcript()
 *             SegmentChain segchain = SegmentChain.from_psl(psl_line)             # <<<<<<<<<<<<<<
 *             dict attr = segchain.attr
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain), __pyx_n_s_from_psl); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_psl_line) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_psl_line);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain))))) __PYX_ERR(0, 4531, __pyx_L1_error)
  __pyx_v_segchain = ((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4532
 *             Transcript transcript = Transcript()
 *             SegmentChain segchain = SegmentChain.from_psl(psl_line)
 *             dict attr = segchain.attr             # <<<<<<<<<<<<<<
 * 
 *         attr["cds_genome_start"] = None
 */
  __pyx_t_1 = __pyx_v_segchain->attr;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_attr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4534
 *             dict attr = segchain.attr
 * 
 *         attr["cds_genome_start"] = None             # <<<<<<<<<<<<<<
 *         attr["cds_genome_end"]   = None
 *         transcript._set_segments(segchain._segments)
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 4534, __pyx_L1_error)
  }
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_cds_genome_start_2, Py_None) < 0)) __PYX_ERR(0, 4534, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4535
 * 
 *         attr["cds_genome_start"] = None
 *         attr["cds_genome_end"]   = None             # <<<<<<<<<<<<<<
 *         transcript._set_segments(segchain._segments)
 *         transcript.attr = attr
 */
  if (unlikely(__pyx_v_attr == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 4535, __pyx_L1_error)
  }
  if (unlikely(PyDict_SetItem(__pyx_v_attr, __pyx_n_u_cds_genome_end_2, Py_None) < 0)) __PYX_ERR(0, 4535, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4536
 *         attr["cds_genome_start"] = None
 *         attr["cds_genome_end"]   = None
 *         transcript._set_segments(segchain._segments)             # <<<<<<<<<<<<<<
 *         transcript.attr = attr
 * 
 */
  __pyx_t_1 = __pyx_v_segchain->_segments;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_4 = ((struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript *)__pyx_v_transcript->__pyx_base.__pyx_vtab)->__pyx_base._set_segments(((struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)__pyx_v_transcript), ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_4 == ((int)0))) __PYX_ERR(0, 4536, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":4537
 *         attr["cds_genome_end"]   = None
 *         transcript._set_segments(segchain._segments)
 *         transcript.attr = attr             # <<<<<<<<<<<<<<
 * 
 *         return transcript
 */
  __Pyx_INCREF(__pyx_v_attr);
  __Pyx_GIVEREF(__pyx_v_attr);
  __Pyx_GOTREF(__pyx_v_transcript->__pyx_base.attr);
  __Pyx_DECREF(__pyx_v_transcript->__pyx_base.attr);
  __pyx_v_transcript->__pyx_base.attr = __pyx_v_attr;

  /* "plastid/genomics/roitools.pyx":4539
 *         transcript.attr = attr
 * 
 *         return transcript             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_transcript));
  __pyx_r = ((PyObject *)__pyx_v_transcript);
  goto __pyx_L0;

  /* "plastid/genomics/roitools.pyx":4528
 * 
 *     @staticmethod
 *     def from_psl(str psl_line):             # <<<<<<<<<<<<<<
 *         cdef:
 *             Transcript transcript = Transcript()
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("plastid.genomics.roitools.Transcript.from_psl", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_transcript);
  __Pyx_XDECREF((PyObject *)__pyx_v_segchain);
  __Pyx_XDECREF(__pyx_v_attr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":93
 *             __data_union data
 * 
 *         def __getbuffer__(self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fulfill the PEP.
 */

/* Python wrapper */
static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7cpython_5array_5array___getbuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));

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

static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags) {
  PyObject *__pyx_v_item_count = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char *__pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  char __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  if (__pyx_v_info == NULL) {
    PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
    return -1;
  }
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(__pyx_v_info->obj);

  /* "array.pxd":98
 *             # In particular strided access is always provided regardless
 *             # of flags
 *             item_count = Py_SIZE(self)             # <<<<<<<<<<<<<<
 * 
 *             info.suboffsets = NULL
 */
  __pyx_t_1 = PyInt_FromSsize_t(Py_SIZE(((PyObject *)__pyx_v_self))); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_item_count = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "array.pxd":100
 *             item_count = Py_SIZE(self)
 * 
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *             info.buf = self.data.as_chars
 *             info.readonly = 0
 */
  __pyx_v_info->suboffsets = NULL;

  /* "array.pxd":101
 * 
 *             info.suboffsets = NULL
 *             info.buf = self.data.as_chars             # <<<<<<<<<<<<<<
 *             info.readonly = 0
 *             info.ndim = 1
 */
  __pyx_t_2 = __pyx_v_self->data.as_chars;
  __pyx_v_info->buf = __pyx_t_2;

  /* "array.pxd":102
 *             info.suboffsets = NULL
 *             info.buf = self.data.as_chars
 *             info.readonly = 0             # <<<<<<<<<<<<<<
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 */
  __pyx_v_info->readonly = 0;

  /* "array.pxd":103
 *             info.buf = self.data.as_chars
 *             info.readonly = 0
 *             info.ndim = 1             # <<<<<<<<<<<<<<
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 *             info.len = info.itemsize * item_count
 */
  __pyx_v_info->ndim = 1;

  /* "array.pxd":104
 *             info.readonly = 0
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)             # <<<<<<<<<<<<<<
 *             info.len = info.itemsize * item_count
 * 
 */
  __pyx_t_3 = __pyx_v_self->ob_descr->itemsize;
  __pyx_v_info->itemsize = __pyx_t_3;

  /* "array.pxd":105
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 *             info.len = info.itemsize * item_count             # <<<<<<<<<<<<<<
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 */
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_info->itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyNumber_Multiply(__pyx_t_1, __pyx_v_item_count); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 105, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_info->len = __pyx_t_5;

  /* "array.pxd":107
 *             info.len = info.itemsize * item_count
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)             # <<<<<<<<<<<<<<
 *             if not info.shape:
 *                 raise MemoryError()
 */
  __pyx_v_info->shape = ((Py_ssize_t *)PyObject_Malloc(((sizeof(Py_ssize_t)) + 2)));

  /* "array.pxd":108
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 *             if not info.shape:             # <<<<<<<<<<<<<<
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing
 */
  __pyx_t_6 = ((!(__pyx_v_info->shape != 0)) != 0);
  if (unlikely(__pyx_t_6)) {

    /* "array.pxd":109
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 *             if not info.shape:
 *                 raise MemoryError()             # <<<<<<<<<<<<<<
 *             info.shape[0] = item_count      # constant regardless of resizing
 *             info.strides = &info.itemsize
 */
    PyErr_NoMemory(); __PYX_ERR(2, 109, __pyx_L1_error)

    /* "array.pxd":108
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 *             if not info.shape:             # <<<<<<<<<<<<<<
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing
 */
  }

  /* "array.pxd":110
 *             if not info.shape:
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing             # <<<<<<<<<<<<<<
 *             info.strides = &info.itemsize
 * 
 */
  __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_item_count); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 110, __pyx_L1_error)
  (__pyx_v_info->shape[0]) = __pyx_t_5;

  /* "array.pxd":111
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing
 *             info.strides = &info.itemsize             # <<<<<<<<<<<<<<
 * 
 *             info.format = <char*> (info.shape + 1)
 */
  __pyx_v_info->strides = (&__pyx_v_info->itemsize);

  /* "array.pxd":113
 *             info.strides = &info.itemsize
 * 
 *             info.format = <char*> (info.shape + 1)             # <<<<<<<<<<<<<<
 *             info.format[0] = self.ob_descr.typecode
 *             info.format[1] = 0
 */
  __pyx_v_info->format = ((char *)(__pyx_v_info->shape + 1));

  /* "array.pxd":114
 * 
 *             info.format = <char*> (info.shape + 1)
 *             info.format[0] = self.ob_descr.typecode             # <<<<<<<<<<<<<<
 *             info.format[1] = 0
 *             info.obj = self
 */
  __pyx_t_7 = __pyx_v_self->ob_descr->typecode;
  (__pyx_v_info->format[0]) = __pyx_t_7;

  /* "array.pxd":115
 *             info.format = <char*> (info.shape + 1)
 *             info.format[0] = self.ob_descr.typecode
 *             info.format[1] = 0             # <<<<<<<<<<<<<<
 *             info.obj = self
 * 
 */
  (__pyx_v_info->format[1]) = 0;

  /* "array.pxd":116
 *             info.format[0] = self.ob_descr.typecode
 *             info.format[1] = 0
 *             info.obj = self             # <<<<<<<<<<<<<<
 * 
 *         def __releasebuffer__(self, Py_buffer* info):
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_GOTREF(__pyx_v_info->obj);
  __Pyx_DECREF(__pyx_v_info->obj);
  __pyx_v_info->obj = ((PyObject *)__pyx_v_self);

  /* "array.pxd":93
 *             __data_union data
 * 
 *         def __getbuffer__(self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fulfill the PEP.
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cpython.array.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  if (__pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_item_count);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":118
 *             info.obj = self
 * 
 *         def __releasebuffer__(self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             PyObject_Free(info.shape)
 * 
 */

/* Python wrapper */
static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/
static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0);
  __pyx_pf_7cpython_5array_5array_2__releasebuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info));

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

static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__releasebuffer__", 0);

  /* "array.pxd":119
 * 
 *         def __releasebuffer__(self, Py_buffer* info):
 *             PyObject_Free(info.shape)             # <<<<<<<<<<<<<<
 * 
 *     array newarrayobject(PyTypeObject* type, Py_ssize_t size, arraydescr *descr)
 */
  PyObject_Free(__pyx_v_info->shape);

  /* "array.pxd":118
 *             info.obj = self
 * 
 *         def __releasebuffer__(self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             PyObject_Free(info.shape)
 * 
 */

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

/* "array.pxd":130
 * 
 * 
 * cdef inline array clone(array template, Py_ssize_t length, bint zero):             # <<<<<<<<<<<<<<
 *     """ fast creation of a new array, given a template array.
 *     type will be same as template.
 */

static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_clone(arrayobject *__pyx_v_template, Py_ssize_t __pyx_v_length, int __pyx_v_zero) {
  arrayobject *__pyx_v_op = 0;
  arrayobject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("clone", 0);

  /* "array.pxd":134
 *     type will be same as template.
 *     if zero is true, new array will be initialized with zeroes."""
 *     cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)             # <<<<<<<<<<<<<<
 *     if zero and op is not None:
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 */
  __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_template)), __pyx_v_length, __pyx_v_template->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_op = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "array.pxd":135
 *     if zero is true, new array will be initialized with zeroes."""
 *     cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
 *     if zero and op is not None:             # <<<<<<<<<<<<<<
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 *     return op
 */
  __pyx_t_3 = (__pyx_v_zero != 0);
  if (__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (((PyObject *)__pyx_v_op) != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "array.pxd":136
 *     cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
 *     if zero and op is not None:
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)             # <<<<<<<<<<<<<<
 *     return op
 * 
 */
    (void)(memset(__pyx_v_op->data.as_chars, 0, (__pyx_v_length * __pyx_v_op->ob_descr->itemsize)));

    /* "array.pxd":135
 *     if zero is true, new array will be initialized with zeroes."""
 *     cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
 *     if zero and op is not None:             # <<<<<<<<<<<<<<
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 *     return op
 */
  }

  /* "array.pxd":137
 *     if zero and op is not None:
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 *     return op             # <<<<<<<<<<<<<<
 * 
 * cdef inline array copy(array self):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_op));
  __pyx_r = __pyx_v_op;
  goto __pyx_L0;

  /* "array.pxd":130
 * 
 * 
 * cdef inline array clone(array template, Py_ssize_t length, bint zero):             # <<<<<<<<<<<<<<
 *     """ fast creation of a new array, given a template array.
 *     type will be same as template.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpython.array.clone", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_op);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":139
 *     return op
 * 
 * cdef inline array copy(array self):             # <<<<<<<<<<<<<<
 *     """ make a copy of an array. """
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 */

static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_copy(arrayobject *__pyx_v_self) {
  arrayobject *__pyx_v_op = 0;
  arrayobject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("copy", 0);

  /* "array.pxd":141
 * cdef inline array copy(array self):
 *     """ make a copy of an array. """
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)             # <<<<<<<<<<<<<<
 *     memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)
 *     return op
 */
  __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_self)), Py_SIZE(((PyObject *)__pyx_v_self)), __pyx_v_self->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 141, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_op = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "array.pxd":142
 *     """ make a copy of an array. """
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 *     memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)             # <<<<<<<<<<<<<<
 *     return op
 * 
 */
  (void)(memcpy(__pyx_v_op->data.as_chars, __pyx_v_self->data.as_chars, (Py_SIZE(((PyObject *)__pyx_v_op)) * __pyx_v_op->ob_descr->itemsize)));

  /* "array.pxd":143
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 *     memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)
 *     return op             # <<<<<<<<<<<<<<
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_op));
  __pyx_r = __pyx_v_op;
  goto __pyx_L0;

  /* "array.pxd":139
 *     return op
 * 
 * cdef inline array copy(array self):             # <<<<<<<<<<<<<<
 *     """ make a copy of an array. """
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpython.array.copy", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_op);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":145
 *     return op
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:             # <<<<<<<<<<<<<<
 *     """ efficient appending of new stuff of same type
 *     (e.g. of same array type)
 */

static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *__pyx_v_self, char *__pyx_v_stuff, Py_ssize_t __pyx_v_n) {
  Py_ssize_t __pyx_v_itemsize;
  Py_ssize_t __pyx_v_origsize;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("extend_buffer", 0);

  /* "array.pxd":149
 *     (e.g. of same array type)
 *     n: number of elements (not number of bytes!) """
 *     cdef Py_ssize_t itemsize = self.ob_descr.itemsize             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t origsize = Py_SIZE(self)
 *     resize_smart(self, origsize + n)
 */
  __pyx_t_1 = __pyx_v_self->ob_descr->itemsize;
  __pyx_v_itemsize = __pyx_t_1;

  /* "array.pxd":150
 *     n: number of elements (not number of bytes!) """
 *     cdef Py_ssize_t itemsize = self.ob_descr.itemsize
 *     cdef Py_ssize_t origsize = Py_SIZE(self)             # <<<<<<<<<<<<<<
 *     resize_smart(self, origsize + n)
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
 */
  __pyx_v_origsize = Py_SIZE(((PyObject *)__pyx_v_self));

  /* "array.pxd":151
 *     cdef Py_ssize_t itemsize = self.ob_descr.itemsize
 *     cdef Py_ssize_t origsize = Py_SIZE(self)
 *     resize_smart(self, origsize + n)             # <<<<<<<<<<<<<<
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
 *     return 0
 */
  __pyx_t_1 = resize_smart(__pyx_v_self, (__pyx_v_origsize + __pyx_v_n)); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(2, 151, __pyx_L1_error)

  /* "array.pxd":152
 *     cdef Py_ssize_t origsize = Py_SIZE(self)
 *     resize_smart(self, origsize + n)
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)             # <<<<<<<<<<<<<<
 *     return 0
 * 
 */
  (void)(memcpy((__pyx_v_self->data.as_chars + (__pyx_v_origsize * __pyx_v_itemsize)), __pyx_v_stuff, (__pyx_v_n * __pyx_v_itemsize)));

  /* "array.pxd":153
 *     resize_smart(self, origsize + n)
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * cdef inline int extend(array self, array other) except -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "array.pxd":145
 *     return op
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:             # <<<<<<<<<<<<<<
 *     """ efficient appending of new stuff of same type
 *     (e.g. of same array type)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpython.array.extend_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":155
 *     return 0
 * 
 * cdef inline int extend(array self, array other) except -1:             # <<<<<<<<<<<<<<
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 */

static CYTHON_INLINE int __pyx_f_7cpython_5array_extend(arrayobject *__pyx_v_self, arrayobject *__pyx_v_other) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("extend", 0);

  /* "array.pxd":157
 * cdef inline int extend(array self, array other) except -1:
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:             # <<<<<<<<<<<<<<
 *         PyErr_BadArgument()
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 */
  __pyx_t_1 = ((__pyx_v_self->ob_descr->typecode != __pyx_v_other->ob_descr->typecode) != 0);
  if (__pyx_t_1) {

    /* "array.pxd":158
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 *         PyErr_BadArgument()             # <<<<<<<<<<<<<<
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 */
    __pyx_t_2 = PyErr_BadArgument(); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(2, 158, __pyx_L1_error)

    /* "array.pxd":157
 * cdef inline int extend(array self, array other) except -1:
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:             # <<<<<<<<<<<<<<
 *         PyErr_BadArgument()
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 */
  }

  /* "array.pxd":159
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 *         PyErr_BadArgument()
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))             # <<<<<<<<<<<<<<
 * 
 * cdef inline void zero(array self):
 */
  __pyx_t_2 = __pyx_f_7cpython_5array_extend_buffer(__pyx_v_self, __pyx_v_other->data.as_chars, Py_SIZE(((PyObject *)__pyx_v_other))); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(2, 159, __pyx_L1_error)
  __pyx_r = __pyx_t_2;
  goto __pyx_L0;

  /* "array.pxd":155
 *     return 0
 * 
 * cdef inline int extend(array self, array other) except -1:             # <<<<<<<<<<<<<<
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpython.array.extend", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":161
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 * cdef inline void zero(array self):             # <<<<<<<<<<<<<<
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)
 */

static CYTHON_INLINE void __pyx_f_7cpython_5array_zero(arrayobject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("zero", 0);

  /* "array.pxd":163
 * cdef inline void zero(array self):
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)             # <<<<<<<<<<<<<<
 */
  (void)(memset(__pyx_v_self->data.as_chars, 0, (Py_SIZE(((PyObject *)__pyx_v_self)) * __pyx_v_self->ob_descr->itemsize)));

  /* "array.pxd":161
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 * cdef inline void zero(array self):             # <<<<<<<<<<<<<<
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)
 */

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

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":735
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__pyx_v_a) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":736
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 *     return PyArray_MultiIterNew(1, <void*>a)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 736, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":735
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */

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

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":738
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__pyx_v_a, PyObject *__pyx_v_b) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":739
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 739, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":738
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */

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

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":741
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":742
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":741
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */

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

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":744
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":745
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":744
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */

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

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":747
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d, PyObject *__pyx_v_e) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":748
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)             # <<<<<<<<<<<<<<
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 748, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":747
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */

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

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":750
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):             # <<<<<<<<<<<<<<
 *     if PyDataType_HASSUBARRAY(d):
 *         return <tuple>d.subarray.shape
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__pyx_v_d) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("PyDataType_SHAPE", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":751
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 *     if PyDataType_HASSUBARRAY(d):             # <<<<<<<<<<<<<<
 *         return <tuple>d.subarray.shape
 *     else:
 */
  __pyx_t_1 = (PyDataType_HASSUBARRAY(__pyx_v_d) != 0);
  if (__pyx_t_1) {

    /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":752
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 *     if PyDataType_HASSUBARRAY(d):
 *         return <tuple>d.subarray.shape             # <<<<<<<<<<<<<<
 *     else:
 *         return ()
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject*)__pyx_v_d->subarray->shape));
    __pyx_r = ((PyObject*)__pyx_v_d->subarray->shape);
    goto __pyx_L0;

    /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":751
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 *     if PyDataType_HASSUBARRAY(d):             # <<<<<<<<<<<<<<
 *         return <tuple>d.subarray.shape
 *     else:
 */
  }

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":754
 *         return <tuple>d.subarray.shape
 *     else:
 *         return ()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_empty_tuple);
    __pyx_r = __pyx_empty_tuple;
    goto __pyx_L0;
  }

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":750
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):             # <<<<<<<<<<<<<<
 *     if PyDataType_HASSUBARRAY(d):
 *         return <tuple>d.subarray.shape
 */

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

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":929
 *     int _import_umath() except -1
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *     Py_INCREF(base) # important to do this before stealing the reference below!
 *     PyArray_SetBaseObject(arr, base)
 */

static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_array_base", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":930
 * 
 * cdef inline void set_array_base(ndarray arr, object base):
 *     Py_INCREF(base) # important to do this before stealing the reference below!             # <<<<<<<<<<<<<<
 *     PyArray_SetBaseObject(arr, base)
 * 
 */
  Py_INCREF(__pyx_v_base);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":931
 * cdef inline void set_array_base(ndarray arr, object base):
 *     Py_INCREF(base) # important to do this before stealing the reference below!
 *     PyArray_SetBaseObject(arr, base)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object get_array_base(ndarray arr):
 */
  (void)(PyArray_SetBaseObject(__pyx_v_arr, __pyx_v_base));

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":929
 *     int _import_umath() except -1
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *     Py_INCREF(base) # important to do this before stealing the reference below!
 *     PyArray_SetBaseObject(arr, base)
 */

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

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":933
 *     PyArray_SetBaseObject(arr, base)
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     base = PyArray_BASE(arr)
 *     if base is NULL:
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) {
  PyObject *__pyx_v_base;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("get_array_base", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":934
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     base = PyArray_BASE(arr)             # <<<<<<<<<<<<<<
 *     if base is NULL:
 *         return None
 */
  __pyx_v_base = PyArray_BASE(__pyx_v_arr);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":935
 * cdef inline object get_array_base(ndarray arr):
 *     base = PyArray_BASE(arr)
 *     if base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     return <object>base
 */
  __pyx_t_1 = ((__pyx_v_base == NULL) != 0);
  if (__pyx_t_1) {

    /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":936
 *     base = PyArray_BASE(arr)
 *     if base is NULL:
 *         return None             # <<<<<<<<<<<<<<
 *     return <object>base
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":935
 * cdef inline object get_array_base(ndarray arr):
 *     base = PyArray_BASE(arr)
 *     if base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     return <object>base
 */
  }

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":937
 *     if base is NULL:
 *         return None
 *     return <object>base             # <<<<<<<<<<<<<<
 * 
 * # Versions of the import_* functions which are more suitable for
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_base));
  __pyx_r = ((PyObject *)__pyx_v_base);
  goto __pyx_L0;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":933
 *     PyArray_SetBaseObject(arr, base)
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     base = PyArray_BASE(arr)
 *     if base is NULL:
 */

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

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":941
 * # Versions of the import_* functions which are more suitable for
 * # Cython code.
 * cdef inline int import_array() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         __pyx_import_array()
 */

static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("import_array", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":942
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         __pyx_import_array()
 *     except Exception:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":943
 * cdef inline int import_array() except -1:
 *     try:
 *         __pyx_import_array()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")
 */
      __pyx_t_4 = _import_array(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(3, 943, __pyx_L3_error)

      /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":942
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         __pyx_import_array()
 *     except Exception:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;

    /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":944
 *     try:
 *         __pyx_import_array()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 */
    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
    if (__pyx_t_4) {
      __Pyx_AddTraceback("numpy.import_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(3, 944, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":945
 *         __pyx_import_array()
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_umath() except -1:
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__45, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 945, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(3, 945, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":942
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         __pyx_import_array()
 *     except Exception:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L8_try_end:;
  }

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":941
 * # Versions of the import_* functions which are more suitable for
 * # Cython code.
 * cdef inline int import_array() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         __pyx_import_array()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.import_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":947
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 * cdef inline int import_umath() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("import_umath", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":948
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":949
 * cdef inline int import_umath() except -1:
 *     try:
 *         _import_umath()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")
 */
      __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(3, 949, __pyx_L3_error)

      /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":948
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;

    /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":950
 *     try:
 *         _import_umath()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 */
    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
    if (__pyx_t_4) {
      __Pyx_AddTraceback("numpy.import_umath", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(3, 950, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":951
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_ufunc() except -1:
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 951, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(3, 951, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":948
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L8_try_end:;
  }

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":947
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 * cdef inline int import_umath() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.import_umath", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":953
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 * cdef inline int import_ufunc() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("import_ufunc", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":954
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":955
 * cdef inline int import_ufunc() except -1:
 *     try:
 *         _import_umath()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")
 */
      __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(3, 955, __pyx_L3_error)

      /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":954
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;

    /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":956
 *     try:
 *         _import_umath()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 */
    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
    if (__pyx_t_4) {
      __Pyx_AddTraceback("numpy.import_ufunc", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(3, 956, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":957
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef extern from *:
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 957, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(3, 957, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":954
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L8_try_end:;
  }

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":953
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 * cdef inline int import_ufunc() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.import_ufunc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":967
 * 
 * 
 * cdef inline bint is_timedelta64_object(object obj):             # <<<<<<<<<<<<<<
 *     """
 *     Cython equivalent of `isinstance(obj, np.timedelta64)`
 */

static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_obj) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_timedelta64_object", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":979
 *     bool
 *     """
 *     return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyTimedeltaArrType_Type));
  goto __pyx_L0;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":967
 * 
 * 
 * cdef inline bint is_timedelta64_object(object obj):             # <<<<<<<<<<<<<<
 *     """
 *     Cython equivalent of `isinstance(obj, np.timedelta64)`
 */

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

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":982
 * 
 * 
 * cdef inline bint is_datetime64_object(object obj):             # <<<<<<<<<<<<<<
 *     """
 *     Cython equivalent of `isinstance(obj, np.datetime64)`
 */

static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_obj) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_datetime64_object", 0);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":994
 *     bool
 *     """
 *     return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyDatetimeArrType_Type));
  goto __pyx_L0;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":982
 * 
 * 
 * cdef inline bint is_datetime64_object(object obj):             # <<<<<<<<<<<<<<
 *     """
 *     Cython equivalent of `isinstance(obj, np.datetime64)`
 */

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

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":997
 * 
 * 
 * cdef inline npy_datetime get_datetime64_value(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the int64 value underlying scalar numpy datetime64 object
 */

static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject *__pyx_v_obj) {
  npy_datetime __pyx_r;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":1004
 *     also needed.  That can be found using `get_datetime64_unit`.
 *     """
 *     return (<PyDatetimeScalarObject*>obj).obval             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = ((PyDatetimeScalarObject *)__pyx_v_obj)->obval;
  goto __pyx_L0;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":997
 * 
 * 
 * cdef inline npy_datetime get_datetime64_value(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the int64 value underlying scalar numpy datetime64 object
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":1007
 * 
 * 
 * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the int64 value underlying scalar numpy timedelta64 object
 */

static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject *__pyx_v_obj) {
  npy_timedelta __pyx_r;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":1011
 *     returns the int64 value underlying scalar numpy timedelta64 object
 *     """
 *     return (<PyTimedeltaScalarObject*>obj).obval             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = ((PyTimedeltaScalarObject *)__pyx_v_obj)->obval;
  goto __pyx_L0;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":1007
 * 
 * 
 * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the int64 value underlying scalar numpy timedelta64 object
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":1014
 * 
 * 
 * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the unit part of the dtype for a numpy datetime64 object.
 */

static CYTHON_INLINE NPY_DATETIMEUNIT __pyx_f_5numpy_get_datetime64_unit(PyObject *__pyx_v_obj) {
  NPY_DATETIMEUNIT __pyx_r;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":1018
 *     returns the unit part of the dtype for a numpy datetime64 object.
 *     """
 *     return <NPY_DATETIMEUNIT>(<PyDatetimeScalarObject*>obj).obmeta.base             # <<<<<<<<<<<<<<
 */
  __pyx_r = ((NPY_DATETIMEUNIT)((PyDatetimeScalarObject *)__pyx_v_obj)->obmeta.base);
  goto __pyx_L0;

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":1014
 * 
 * 
 * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the unit part of the dtype for a numpy datetime64 object.
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "View.MemoryView":122
 *         cdef bint dtype_is_object
 * 
 *     def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None,             # <<<<<<<<<<<<<<
 *                   mode="c", bint allocate_buffer=True):
 * 
 */

/* Python wrapper */
static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_shape = 0;
  Py_ssize_t __pyx_v_itemsize;
  PyObject *__pyx_v_format = 0;
  PyObject *__pyx_v_mode = 0;
  int __pyx_v_allocate_buffer;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_shape,&__pyx_n_s_itemsize,&__pyx_n_s_format,&__pyx_n_s_mode,&__pyx_n_s_allocate_buffer,0};
    PyObject* values[5] = {0,0,0,0,0};
    values[3] = ((PyObject *)__pyx_n_s_c);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_shape)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_itemsize)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); __PYX_ERR(4, 122, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); __PYX_ERR(4, 122, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_allocate_buffer);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(4, 122, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_shape = ((PyObject*)values[0]);
    __pyx_v_itemsize = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_itemsize == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(4, 122, __pyx_L3_error)
    __pyx_v_format = values[2];
    __pyx_v_mode = values[3];
    if (values[4]) {
      __pyx_v_allocate_buffer = __Pyx_PyObject_IsTrue(values[4]); if (unlikely((__pyx_v_allocate_buffer == (int)-1) && PyErr_Occurred())) __PYX_ERR(4, 123, __pyx_L3_error)
    } else {

      /* "View.MemoryView":123
 * 
 *     def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None,
 *                   mode="c", bint allocate_buffer=True):             # <<<<<<<<<<<<<<
 * 
 *         cdef int idx
 */
      __pyx_v_allocate_buffer = ((int)1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(4, 122, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_shape), (&PyTuple_Type), 1, "shape", 1))) __PYX_ERR(4, 122, __pyx_L1_error)
  if (unlikely(((PyObject *)__pyx_v_format) == Py_None)) {
    PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "format"); __PYX_ERR(4, 122, __pyx_L1_error)
  }
  __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(((struct __pyx_array_obj *)__pyx_v_self), __pyx_v_shape, __pyx_v_itemsize, __pyx_v_format, __pyx_v_mode, __pyx_v_allocate_buffer);

  /* "View.MemoryView":122
 *         cdef bint dtype_is_object
 * 
 *     def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None,             # <<<<<<<<<<<<<<
 *                   mode="c", bint allocate_buffer=True):
 * 
 */

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

static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer) {
  int __pyx_v_idx;
  Py_ssize_t __pyx_v_i;
  Py_ssize_t __pyx_v_dim;
  PyObject **__pyx_v_p;
  char __pyx_v_order;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  char *__pyx_t_7;
  int __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  Py_ssize_t __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_INCREF(__pyx_v_format);

  /* "View.MemoryView":129
 *         cdef PyObject **p
 * 
 *         self.ndim = <int> len(shape)             # <<<<<<<<<<<<<<
 *         self.itemsize = itemsize
 * 
 */
  if (unlikely(__pyx_v_shape == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(4, 129, __pyx_L1_error)
  }
  __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_shape); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(4, 129, __pyx_L1_error)
  __pyx_v_self->ndim = ((int)__pyx_t_1);

  /* "View.MemoryView":130
 * 
 *         self.ndim = <int> len(shape)
 *         self.itemsize = itemsize             # <<<<<<<<<<<<<<
 * 
 *         if not self.ndim:
 */
  __pyx_v_self->itemsize = __pyx_v_itemsize;

  /* "View.MemoryView":132
 *         self.itemsize = itemsize
 * 
 *         if not self.ndim:             # <<<<<<<<<<<<<<
 *             raise ValueError("Empty shape tuple for cython.array")
 * 
 */
  __pyx_t_2 = ((!(__pyx_v_self->ndim != 0)) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "View.MemoryView":133
 * 
 *         if not self.ndim:
 *             raise ValueError("Empty shape tuple for cython.array")             # <<<<<<<<<<<<<<
 * 
 *         if itemsize <= 0:
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(4, 133, __pyx_L1_error)

    /* "View.MemoryView":132
 *         self.itemsize = itemsize
 * 
 *         if not self.ndim:             # <<<<<<<<<<<<<<
 *             raise ValueError("Empty shape tuple for cython.array")
 * 
 */
  }

  /* "View.MemoryView":135
 *             raise ValueError("Empty shape tuple for cython.array")
 * 
 *         if itemsize <= 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("itemsize <= 0 for cython.array")
 * 
 */
  __pyx_t_2 = ((__pyx_v_itemsize <= 0) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "View.MemoryView":136
 * 
 *         if itemsize <= 0:
 *             raise ValueError("itemsize <= 0 for cython.array")             # <<<<<<<<<<<<<<
 * 
 *         if not isinstance(format, bytes):
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 136, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(4, 136, __pyx_L1_error)

    /* "View.MemoryView":135
 *             raise ValueError("Empty shape tuple for cython.array")
 * 
 *         if itemsize <= 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("itemsize <= 0 for cython.array")
 * 
 */
  }

  /* "View.MemoryView":138
 *             raise ValueError("itemsize <= 0 for cython.array")
 * 
 *         if not isinstance(format, bytes):             # <<<<<<<<<<<<<<
 *             format = format.encode('ASCII')
 *         self._format = format  # keep a reference to the byte string
 */
  __pyx_t_2 = PyBytes_Check(__pyx_v_format); 
  __pyx_t_4 = ((!(__pyx_t_2 != 0)) != 0);
  if (__pyx_t_4) {

    /* "View.MemoryView":139
 * 
 *         if not isinstance(format, bytes):
 *             format = format.encode('ASCII')             # <<<<<<<<<<<<<<
 *         self._format = format  # keep a reference to the byte string
 *         self.format = self._format
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_format, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 139, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_n_s_ASCII) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_n_s_ASCII);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 139, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_format, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "View.MemoryView":138
 *             raise ValueError("itemsize <= 0 for cython.array")
 * 
 *         if not isinstance(format, bytes):             # <<<<<<<<<<<<<<
 *             format = format.encode('ASCII')
 *         self._format = format  # keep a reference to the byte string
 */
  }

  /* "View.MemoryView":140
 *         if not isinstance(format, bytes):
 *             format = format.encode('ASCII')
 *         self._format = format  # keep a reference to the byte string             # <<<<<<<<<<<<<<
 *         self.format = self._format
 * 
 */
  if (!(likely(PyBytes_CheckExact(__pyx_v_format))||((__pyx_v_format) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_format)->tp_name), 0))) __PYX_ERR(4, 140, __pyx_L1_error)
  __pyx_t_3 = __pyx_v_format;
  __Pyx_INCREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_self->_format);
  __Pyx_DECREF(__pyx_v_self->_format);
  __pyx_v_self->_format = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "View.MemoryView":141
 *             format = format.encode('ASCII')
 *         self._format = format  # keep a reference to the byte string
 *         self.format = self._format             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (unlikely(__pyx_v_self->_format == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
    __PYX_ERR(4, 141, __pyx_L1_error)
  }
  __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_self->_format); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(4, 141, __pyx_L1_error)
  __pyx_v_self->format = __pyx_t_7;

  /* "View.MemoryView":144
 * 
 * 
 *         self._shape = <Py_ssize_t *> PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2)             # <<<<<<<<<<<<<<
 *         self._strides = self._shape + self.ndim
 * 
 */
  __pyx_v_self->_shape = ((Py_ssize_t *)PyObject_Malloc((((sizeof(Py_ssize_t)) * __pyx_v_self->ndim) * 2)));

  /* "View.MemoryView":145
 * 
 *         self._shape = <Py_ssize_t *> PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2)
 *         self._strides = self._shape + self.ndim             # <<<<<<<<<<<<<<
 * 
 *         if not self._shape:
 */
  __pyx_v_self->_strides = (__pyx_v_self->_shape + __pyx_v_self->ndim);

  /* "View.MemoryView":147
 *         self._strides = self._shape + self.ndim
 * 
 *         if not self._shape:             # <<<<<<<<<<<<<<
 *             raise MemoryError("unable to allocate shape and strides.")
 * 
 */
  __pyx_t_4 = ((!(__pyx_v_self->_shape != 0)) != 0);
  if (unlikely(__pyx_t_4)) {

    /* "View.MemoryView":148
 * 
 *         if not self._shape:
 *             raise MemoryError("unable to allocate shape and strides.")             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__49, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 148, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(4, 148, __pyx_L1_error)

    /* "View.MemoryView":147
 *         self._strides = self._shape + self.ndim
 * 
 *         if not self._shape:             # <<<<<<<<<<<<<<
 *             raise MemoryError("unable to allocate shape and strides.")
 * 
 */
  }

  /* "View.MemoryView":151
 * 
 * 
 *         for idx, dim in enumerate(shape):             # <<<<<<<<<<<<<<
 *             if dim <= 0:
 *                 raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
 */
  __pyx_t_8 = 0;
  __pyx_t_3 = __pyx_v_shape; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0;
  for (;;) {
    if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(4, 151, __pyx_L1_error)
    #else
    __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 151, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    #endif
    __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(4, 151, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_dim = __pyx_t_9;
    __pyx_v_idx = __pyx_t_8;
    __pyx_t_8 = (__pyx_t_8 + 1);

    /* "View.MemoryView":152
 * 
 *         for idx, dim in enumerate(shape):
 *             if dim <= 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
 *             self._shape[idx] = dim
 */
    __pyx_t_4 = ((__pyx_v_dim <= 0) != 0);
    if (unlikely(__pyx_t_4)) {

      /* "View.MemoryView":153
 *         for idx, dim in enumerate(shape):
 *             if dim <= 0:
 *                 raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))             # <<<<<<<<<<<<<<
 *             self._shape[idx] = dim
 * 
 */
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(4, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_6);
      __pyx_t_5 = 0;
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(4, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_Raise(__pyx_t_10, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __PYX_ERR(4, 153, __pyx_L1_error)

      /* "View.MemoryView":152
 * 
 *         for idx, dim in enumerate(shape):
 *             if dim <= 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
 *             self._shape[idx] = dim
 */
    }

    /* "View.MemoryView":154
 *             if dim <= 0:
 *                 raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
 *             self._shape[idx] = dim             # <<<<<<<<<<<<<<
 * 
 *         cdef char order
 */
    (__pyx_v_self->_shape[__pyx_v_idx]) = __pyx_v_dim;

    /* "View.MemoryView":151
 * 
 * 
 *         for idx, dim in enumerate(shape):             # <<<<<<<<<<<<<<
 *             if dim <= 0:
 *                 raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "View.MemoryView":157
 * 
 *         cdef char order
 *         if mode == 'fortran':             # <<<<<<<<<<<<<<
 *             order = b'F'
 *             self.mode = u'fortran'
 */
  __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_fortran, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(4, 157, __pyx_L1_error)
  if (__pyx_t_4) {

    /* "View.MemoryView":158
 *         cdef char order
 *         if mode == 'fortran':
 *             order = b'F'             # <<<<<<<<<<<<<<
 *             self.mode = u'fortran'
 *         elif mode == 'c':
 */
    __pyx_v_order = 'F';

    /* "View.MemoryView":159
 *         if mode == 'fortran':
 *             order = b'F'
 *             self.mode = u'fortran'             # <<<<<<<<<<<<<<
 *         elif mode == 'c':
 *             order = b'C'
 */
    __Pyx_INCREF(__pyx_n_u_fortran);
    __Pyx_GIVEREF(__pyx_n_u_fortran);
    __Pyx_GOTREF(__pyx_v_self->mode);
    __Pyx_DECREF(__pyx_v_self->mode);
    __pyx_v_self->mode = __pyx_n_u_fortran;

    /* "View.MemoryView":157
 * 
 *         cdef char order
 *         if mode == 'fortran':             # <<<<<<<<<<<<<<
 *             order = b'F'
 *             self.mode = u'fortran'
 */
    goto __pyx_L10;
  }

  /* "View.MemoryView":160
 *             order = b'F'
 *             self.mode = u'fortran'
 *         elif mode == 'c':             # <<<<<<<<<<<<<<
 *             order = b'C'
 *             self.mode = u'c'
 */
  __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_c, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(4, 160, __pyx_L1_error)
  if (likely(__pyx_t_4)) {

    /* "View.MemoryView":161
 *             self.mode = u'fortran'
 *         elif mode == 'c':
 *             order = b'C'             # <<<<<<<<<<<<<<
 *             self.mode = u'c'
 *         else:
 */
    __pyx_v_order = 'C';

    /* "View.MemoryView":162
 *         elif mode == 'c':
 *             order = b'C'
 *             self.mode = u'c'             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode)
 */
    __Pyx_INCREF(__pyx_n_u_c);
    __Pyx_GIVEREF(__pyx_n_u_c);
    __Pyx_GOTREF(__pyx_v_self->mode);
    __Pyx_DECREF(__pyx_v_self->mode);
    __pyx_v_self->mode = __pyx_n_u_c;

    /* "View.MemoryView":160
 *             order = b'F'
 *             self.mode = u'fortran'
 *         elif mode == 'c':             # <<<<<<<<<<<<<<
 *             order = b'C'
 *             self.mode = u'c'
 */
    goto __pyx_L10;
  }

  /* "View.MemoryView":164
 *             self.mode = u'c'
 *         else:
 *             raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode)             # <<<<<<<<<<<<<<
 * 
 *         self.len = fill_contig_strides_array(self._shape, self._strides,
 */
  /*else*/ {
    __pyx_t_3 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_v_mode); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 164, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(4, 164, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_10, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __PYX_ERR(4, 164, __pyx_L1_error)
  }
  __pyx_L10:;

  /* "View.MemoryView":166
 *             raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode)
 * 
 *         self.len = fill_contig_strides_array(self._shape, self._strides,             # <<<<<<<<<<<<<<
 *                                              itemsize, self.ndim, order)
 * 
 */
  __pyx_v_self->len = __pyx_fill_contig_strides_array(__pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_itemsize, __pyx_v_self->ndim, __pyx_v_order);

  /* "View.MemoryView":169
 *                                              itemsize, self.ndim, order)
 * 
 *         self.free_data = allocate_buffer             # <<<<<<<<<<<<<<
 *         self.dtype_is_object = format == b'O'
 *         if allocate_buffer:
 */
  __pyx_v_self->free_data = __pyx_v_allocate_buffer;

  /* "View.MemoryView":170
 * 
 *         self.free_data = allocate_buffer
 *         self.dtype_is_object = format == b'O'             # <<<<<<<<<<<<<<
 *         if allocate_buffer:
 * 
 */
  __pyx_t_10 = PyObject_RichCompare(__pyx_v_format, __pyx_n_b_O, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(4, 170, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(4, 170, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_v_self->dtype_is_object = __pyx_t_4;

  /* "View.MemoryView":171
 *         self.free_data = allocate_buffer
 *         self.dtype_is_object = format == b'O'
 *         if allocate_buffer:             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_4 = (__pyx_v_allocate_buffer != 0);
  if (__pyx_t_4) {

    /* "View.MemoryView":174
 * 
 * 
 *             self.data = <char *>malloc(self.len)             # <<<<<<<<<<<<<<
 *             if not self.data:
 *                 raise MemoryError("unable to allocate array data.")
 */
    __pyx_v_self->data = ((char *)malloc(__pyx_v_self->len));

    /* "View.MemoryView":175
 * 
 *             self.data = <char *>malloc(self.len)
 *             if not self.data:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("unable to allocate array data.")
 * 
 */
    __pyx_t_4 = ((!(__pyx_v_self->data != 0)) != 0);
    if (unlikely(__pyx_t_4)) {

      /* "View.MemoryView":176
 *             self.data = <char *>malloc(self.len)
 *             if not self.data:
 *                 raise MemoryError("unable to allocate array data.")             # <<<<<<<<<<<<<<
 * 
 *             if self.dtype_is_object:
 */
      __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__50, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(4, 176, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_Raise(__pyx_t_10, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __PYX_ERR(4, 176, __pyx_L1_error)

      /* "View.MemoryView":175
 * 
 *             self.data = <char *>malloc(self.len)
 *             if not self.data:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("unable to allocate array data.")
 * 
 */
    }

    /* "View.MemoryView":178
 *                 raise MemoryError("unable to allocate array data.")
 * 
 *             if self.dtype_is_object:             # <<<<<<<<<<<<<<
 *                 p = <PyObject **> self.data
 *                 for i in range(self.len / itemsize):
 */
    __pyx_t_4 = (__pyx_v_self->dtype_is_object != 0);
    if (__pyx_t_4) {

      /* "View.MemoryView":179
 * 
 *             if self.dtype_is_object:
 *                 p = <PyObject **> self.data             # <<<<<<<<<<<<<<
 *                 for i in range(self.len / itemsize):
 *                     p[i] = Py_None
 */
      __pyx_v_p = ((PyObject **)__pyx_v_self->data);

      /* "View.MemoryView":180
 *             if self.dtype_is_object:
 *                 p = <PyObject **> self.data
 *                 for i in range(self.len / itemsize):             # <<<<<<<<<<<<<<
 *                     p[i] = Py_None
 *                     Py_INCREF(Py_None)
 */
      if (unlikely(__pyx_v_itemsize == 0)) {
        PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
        __PYX_ERR(4, 180, __pyx_L1_error)
      }
      else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1)  && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_self->len))) {
        PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
        __PYX_ERR(4, 180, __pyx_L1_error)
      }
      __pyx_t_1 = __Pyx_div_Py_ssize_t(__pyx_v_self->len, __pyx_v_itemsize);
      __pyx_t_9 = __pyx_t_1;
      for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_9; __pyx_t_11+=1) {
        __pyx_v_i = __pyx_t_11;

        /* "View.MemoryView":181
 *                 p = <PyObject **> self.data
 *                 for i in range(self.len / itemsize):
 *                     p[i] = Py_None             # <<<<<<<<<<<<<<
 *                     Py_INCREF(Py_None)
 * 
 */
        (__pyx_v_p[__pyx_v_i]) = Py_None;

        /* "View.MemoryView":182
 *                 for i in range(self.len / itemsize):
 *                     p[i] = Py_None
 *                     Py_INCREF(Py_None)             # <<<<<<<<<<<<<<
 * 
 *     @cname('getbuffer')
 */
        Py_INCREF(Py_None);
      }

      /* "View.MemoryView":178
 *                 raise MemoryError("unable to allocate array data.")
 * 
 *             if self.dtype_is_object:             # <<<<<<<<<<<<<<
 *                 p = <PyObject **> self.data
 *                 for i in range(self.len / itemsize):
 */
    }

    /* "View.MemoryView":171
 *         self.free_data = allocate_buffer
 *         self.dtype_is_object = format == b'O'
 *         if allocate_buffer:             # <<<<<<<<<<<<<<
 * 
 * 
 */
  }

  /* "View.MemoryView":122
 *         cdef bint dtype_is_object
 * 
 *     def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None,             # <<<<<<<<<<<<<<
 *                   mode="c", bint allocate_buffer=True):
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_format);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":185
 * 
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):             # <<<<<<<<<<<<<<
 *         cdef int bufmode = -1
 *         if self.mode == u"c":
 */

/* Python wrapper */
static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
  __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(((struct __pyx_array_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));

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

static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_v_bufmode;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  char *__pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  Py_ssize_t *__pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  if (__pyx_v_info == NULL) {
    PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
    return -1;
  }
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(__pyx_v_info->obj);

  /* "View.MemoryView":186
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         cdef int bufmode = -1             # <<<<<<<<<<<<<<
 *         if self.mode == u"c":
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 */
  __pyx_v_bufmode = -1;

  /* "View.MemoryView":187
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         cdef int bufmode = -1
 *         if self.mode == u"c":             # <<<<<<<<<<<<<<
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         elif self.mode == u"fortran":
 */
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_c, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(4, 187, __pyx_L1_error)
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":188
 *         cdef int bufmode = -1
 *         if self.mode == u"c":
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS             # <<<<<<<<<<<<<<
 *         elif self.mode == u"fortran":
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 */
    __pyx_v_bufmode = (PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS);

    /* "View.MemoryView":187
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         cdef int bufmode = -1
 *         if self.mode == u"c":             # <<<<<<<<<<<<<<
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         elif self.mode == u"fortran":
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":189
 *         if self.mode == u"c":
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         elif self.mode == u"fortran":             # <<<<<<<<<<<<<<
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         if not (flags & bufmode):
 */
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_fortran, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(4, 189, __pyx_L1_error)
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":190
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         elif self.mode == u"fortran":
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS             # <<<<<<<<<<<<<<
 *         if not (flags & bufmode):
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")
 */
    __pyx_v_bufmode = (PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS);

    /* "View.MemoryView":189
 *         if self.mode == u"c":
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         elif self.mode == u"fortran":             # <<<<<<<<<<<<<<
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         if not (flags & bufmode):
 */
  }
  __pyx_L3:;

  /* "View.MemoryView":191
 *         elif self.mode == u"fortran":
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         if not (flags & bufmode):             # <<<<<<<<<<<<<<
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")
 *         info.buf = self.data
 */
  __pyx_t_1 = ((!((__pyx_v_flags & __pyx_v_bufmode) != 0)) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "View.MemoryView":192
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         if not (flags & bufmode):
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")             # <<<<<<<<<<<<<<
 *         info.buf = self.data
 *         info.len = self.len
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__51, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 192, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(4, 192, __pyx_L1_error)

    /* "View.MemoryView":191
 *         elif self.mode == u"fortran":
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         if not (flags & bufmode):             # <<<<<<<<<<<<<<
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")
 *         info.buf = self.data
 */
  }

  /* "View.MemoryView":193
 *         if not (flags & bufmode):
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")
 *         info.buf = self.data             # <<<<<<<<<<<<<<
 *         info.len = self.len
 *         info.ndim = self.ndim
 */
  __pyx_t_4 = __pyx_v_self->data;
  __pyx_v_info->buf = __pyx_t_4;

  /* "View.MemoryView":194
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")
 *         info.buf = self.data
 *         info.len = self.len             # <<<<<<<<<<<<<<
 *         info.ndim = self.ndim
 *         info.shape = self._shape
 */
  __pyx_t_5 = __pyx_v_self->len;
  __pyx_v_info->len = __pyx_t_5;

  /* "View.MemoryView":195
 *         info.buf = self.data
 *         info.len = self.len
 *         info.ndim = self.ndim             # <<<<<<<<<<<<<<
 *         info.shape = self._shape
 *         info.strides = self._strides
 */
  __pyx_t_6 = __pyx_v_self->ndim;
  __pyx_v_info->ndim = __pyx_t_6;

  /* "View.MemoryView":196
 *         info.len = self.len
 *         info.ndim = self.ndim
 *         info.shape = self._shape             # <<<<<<<<<<<<<<
 *         info.strides = self._strides
 *         info.suboffsets = NULL
 */
  __pyx_t_7 = __pyx_v_self->_shape;
  __pyx_v_info->shape = __pyx_t_7;

  /* "View.MemoryView":197
 *         info.ndim = self.ndim
 *         info.shape = self._shape
 *         info.strides = self._strides             # <<<<<<<<<<<<<<
 *         info.suboffsets = NULL
 *         info.itemsize = self.itemsize
 */
  __pyx_t_7 = __pyx_v_self->_strides;
  __pyx_v_info->strides = __pyx_t_7;

  /* "View.MemoryView":198
 *         info.shape = self._shape
 *         info.strides = self._strides
 *         info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *         info.itemsize = self.itemsize
 *         info.readonly = 0
 */
  __pyx_v_info->suboffsets = NULL;

  /* "View.MemoryView":199
 *         info.strides = self._strides
 *         info.suboffsets = NULL
 *         info.itemsize = self.itemsize             # <<<<<<<<<<<<<<
 *         info.readonly = 0
 * 
 */
  __pyx_t_5 = __pyx_v_self->itemsize;
  __pyx_v_info->itemsize = __pyx_t_5;

  /* "View.MemoryView":200
 *         info.suboffsets = NULL
 *         info.itemsize = self.itemsize
 *         info.readonly = 0             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_FORMAT:
 */
  __pyx_v_info->readonly = 0;

  /* "View.MemoryView":202
 *         info.readonly = 0
 * 
 *         if flags & PyBUF_FORMAT:             # <<<<<<<<<<<<<<
 *             info.format = self.format
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":203
 * 
 *         if flags & PyBUF_FORMAT:
 *             info.format = self.format             # <<<<<<<<<<<<<<
 *         else:
 *             info.format = NULL
 */
    __pyx_t_4 = __pyx_v_self->format;
    __pyx_v_info->format = __pyx_t_4;

    /* "View.MemoryView":202
 *         info.readonly = 0
 * 
 *         if flags & PyBUF_FORMAT:             # <<<<<<<<<<<<<<
 *             info.format = self.format
 *         else:
 */
    goto __pyx_L5;
  }

  /* "View.MemoryView":205
 *             info.format = self.format
 *         else:
 *             info.format = NULL             # <<<<<<<<<<<<<<
 * 
 *         info.obj = self
 */
  /*else*/ {
    __pyx_v_info->format = NULL;
  }
  __pyx_L5:;

  /* "View.MemoryView":207
 *             info.format = NULL
 * 
 *         info.obj = self             # <<<<<<<<<<<<<<
 * 
 *     __pyx_getbuffer = capsule(<void *> &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_GOTREF(__pyx_v_info->obj);
  __Pyx_DECREF(__pyx_v_info->obj);
  __pyx_v_info->obj = ((PyObject *)__pyx_v_self);

  /* "View.MemoryView":185
 * 
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):             # <<<<<<<<<<<<<<
 *         cdef int bufmode = -1
 *         if self.mode == u"c":
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  if (__pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  __pyx_L2:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":211
 *     __pyx_getbuffer = capsule(<void *> &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")
 * 
 *     def __dealloc__(array self):             # <<<<<<<<<<<<<<
 *         if self.callback_free_data != NULL:
 *             self.callback_free_data(self.data)
 */

/* Python wrapper */
static void __pyx_array___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_array___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(((struct __pyx_array_obj *)__pyx_v_self));

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

static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__dealloc__", 0);

  /* "View.MemoryView":212
 * 
 *     def __dealloc__(array self):
 *         if self.callback_free_data != NULL:             # <<<<<<<<<<<<<<
 *             self.callback_free_data(self.data)
 *         elif self.free_data:
 */
  __pyx_t_1 = ((__pyx_v_self->callback_free_data != NULL) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":213
 *     def __dealloc__(array self):
 *         if self.callback_free_data != NULL:
 *             self.callback_free_data(self.data)             # <<<<<<<<<<<<<<
 *         elif self.free_data:
 *             if self.dtype_is_object:
 */
    __pyx_v_self->callback_free_data(__pyx_v_self->data);

    /* "View.MemoryView":212
 * 
 *     def __dealloc__(array self):
 *         if self.callback_free_data != NULL:             # <<<<<<<<<<<<<<
 *             self.callback_free_data(self.data)
 *         elif self.free_data:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":214
 *         if self.callback_free_data != NULL:
 *             self.callback_free_data(self.data)
 *         elif self.free_data:             # <<<<<<<<<<<<<<
 *             if self.dtype_is_object:
 *                 refcount_objects_in_slice(self.data, self._shape,
 */
  __pyx_t_1 = (__pyx_v_self->free_data != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":215
 *             self.callback_free_data(self.data)
 *         elif self.free_data:
 *             if self.dtype_is_object:             # <<<<<<<<<<<<<<
 *                 refcount_objects_in_slice(self.data, self._shape,
 *                                           self._strides, self.ndim, False)
 */
    __pyx_t_1 = (__pyx_v_self->dtype_is_object != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":216
 *         elif self.free_data:
 *             if self.dtype_is_object:
 *                 refcount_objects_in_slice(self.data, self._shape,             # <<<<<<<<<<<<<<
 *                                           self._strides, self.ndim, False)
 *             free(self.data)
 */
      __pyx_memoryview_refcount_objects_in_slice(__pyx_v_self->data, __pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_self->ndim, 0);

      /* "View.MemoryView":215
 *             self.callback_free_data(self.data)
 *         elif self.free_data:
 *             if self.dtype_is_object:             # <<<<<<<<<<<<<<
 *                 refcount_objects_in_slice(self.data, self._shape,
 *                                           self._strides, self.ndim, False)
 */
    }

    /* "View.MemoryView":218
 *                 refcount_objects_in_slice(self.data, self._shape,
 *                                           self._strides, self.ndim, False)
 *             free(self.data)             # <<<<<<<<<<<<<<
 *         PyObject_Free(self._shape)
 * 
 */
    free(__pyx_v_self->data);

    /* "View.MemoryView":214
 *         if self.callback_free_data != NULL:
 *             self.callback_free_data(self.data)
 *         elif self.free_data:             # <<<<<<<<<<<<<<
 *             if self.dtype_is_object:
 *                 refcount_objects_in_slice(self.data, self._shape,
 */
  }
  __pyx_L3:;

  /* "View.MemoryView":219
 *                                           self._strides, self.ndim, False)
 *             free(self.data)
 *         PyObject_Free(self._shape)             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  PyObject_Free(__pyx_v_self->_shape);

  /* "View.MemoryView":211
 *     __pyx_getbuffer = capsule(<void *> &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")
 * 
 *     def __dealloc__(array self):             # <<<<<<<<<<<<<<
 *         if self.callback_free_data != NULL:
 *             self.callback_free_data(self.data)
 */

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

/* "View.MemoryView":222
 * 
 *     @property
 *     def memview(self):             # <<<<<<<<<<<<<<
 *         return self.get_memview()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_5array_7memview___get__(((struct __pyx_array_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__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_RefNannySetupContext("__get__", 0);

  /* "View.MemoryView":223
 *     @property
 *     def memview(self):
 *         return self.get_memview()             # <<<<<<<<<<<<<<
 * 
 *     @cname('get_memview')
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_array *)__pyx_v_self->__pyx_vtab)->get_memview(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 223, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":222
 * 
 *     @property
 *     def memview(self):             # <<<<<<<<<<<<<<
 *         return self.get_memview()
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.array.memview.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":226
 * 
 *     @cname('get_memview')
 *     cdef get_memview(self):             # <<<<<<<<<<<<<<
 *         flags =  PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
 *         return  memoryview(self, flags, self.dtype_is_object)
 */

static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self) {
  int __pyx_v_flags;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_memview", 0);

  /* "View.MemoryView":227
 *     @cname('get_memview')
 *     cdef get_memview(self):
 *         flags =  PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE             # <<<<<<<<<<<<<<
 *         return  memoryview(self, flags, self.dtype_is_object)
 * 
 */
  __pyx_v_flags = ((PyBUF_ANY_CONTIGUOUS | PyBUF_FORMAT) | PyBUF_WRITABLE);

  /* "View.MemoryView":228
 *     cdef get_memview(self):
 *         flags =  PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
 *         return  memoryview(self, flags, self.dtype_is_object)             # <<<<<<<<<<<<<<
 * 
 *     def __len__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":226
 * 
 *     @cname('get_memview')
 *     cdef get_memview(self):             # <<<<<<<<<<<<<<
 *         flags =  PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
 *         return  memoryview(self, flags, self.dtype_is_object)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.array.get_memview", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":230
 *         return  memoryview(self, flags, self.dtype_is_object)
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         return self._shape[0]
 * 
 */

/* Python wrapper */
static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
  __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(((struct __pyx_array_obj *)__pyx_v_self));

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

static Py_ssize_t __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(struct __pyx_array_obj *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__", 0);

  /* "View.MemoryView":231
 * 
 *     def __len__(self):
 *         return self._shape[0]             # <<<<<<<<<<<<<<
 * 
 *     def __getattr__(self, attr):
 */
  __pyx_r = (__pyx_v_self->_shape[0]);
  goto __pyx_L0;

  /* "View.MemoryView":230
 *         return  memoryview(self, flags, self.dtype_is_object)
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         return self._shape[0]
 * 
 */

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

/* "View.MemoryView":233
 *         return self._shape[0]
 * 
 *     def __getattr__(self, attr):             # <<<<<<<<<<<<<<
 *         return getattr(self.memview, attr)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr); /*proto*/
static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0);
  __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_attr));

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

static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getattr__", 0);

  /* "View.MemoryView":234
 * 
 *     def __getattr__(self, attr):
 *         return getattr(self.memview, attr)             # <<<<<<<<<<<<<<
 * 
 *     def __getitem__(self, item):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetAttr(__pyx_t_1, __pyx_v_attr); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":233
 *         return self._shape[0]
 * 
 *     def __getattr__(self, attr):             # <<<<<<<<<<<<<<
 *         return getattr(self.memview, attr)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.array.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":236
 *         return getattr(self.memview, attr)
 * 
 *     def __getitem__(self, item):             # <<<<<<<<<<<<<<
 *         return self.memview[item]
 * 
 */

/* Python wrapper */
static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item); /*proto*/
static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
  __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item));

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

static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getitem__", 0);

  /* "View.MemoryView":237
 * 
 *     def __getitem__(self, item):
 *         return self.memview[item]             # <<<<<<<<<<<<<<
 * 
 *     def __setitem__(self, item, value):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_item); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":236
 *         return getattr(self.memview, attr)
 * 
 *     def __getitem__(self, item):             # <<<<<<<<<<<<<<
 *         return self.memview[item]
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.array.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":239
 *         return self.memview[item]
 * 
 *     def __setitem__(self, item, value):             # <<<<<<<<<<<<<<
 *         self.memview[item] = value
 * 
 */

/* Python wrapper */
static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /*proto*/
static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0);
  __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item), ((PyObject *)__pyx_v_value));

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

static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setitem__", 0);

  /* "View.MemoryView":240
 * 
 *     def __setitem__(self, item, value):
 *         self.memview[item] = value             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_v_item, __pyx_v_value) < 0)) __PYX_ERR(4, 240, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "View.MemoryView":239
 *         return self.memview[item]
 * 
 *     def __setitem__(self, item, value):             # <<<<<<<<<<<<<<
 *         self.memview[item] = value
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.array.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

/* Python wrapper */
static PyObject *__pyx_pw___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_array___reduce_cython__(((struct __pyx_array_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __pyx_array_obj *__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_RefNannySetupContext("__reduce_cython__", 0);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(4, 2, __pyx_L1_error)

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

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.array.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

/* Python wrapper */
static PyObject *__pyx_pw___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static PyObject *__pyx_pw___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_array_2__setstate_cython__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__53, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(4, 4, __pyx_L1_error)

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

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.array.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":244
 * 
 * @cname("__pyx_array_new")
 * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format,             # <<<<<<<<<<<<<<
 *                           char *mode, char *buf):
 *     cdef array result
 */

static struct __pyx_array_obj *__pyx_array_new(PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, char *__pyx_v_format, char *__pyx_v_mode, char *__pyx_v_buf) {
  struct __pyx_array_obj *__pyx_v_result = 0;
  struct __pyx_array_obj *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("array_cwrapper", 0);

  /* "View.MemoryView":248
 *     cdef array result
 * 
 *     if buf == NULL:             # <<<<<<<<<<<<<<
 *         result = array(shape, itemsize, format, mode.decode('ASCII'))
 *     else:
 */
  __pyx_t_1 = ((__pyx_v_buf == NULL) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":249
 * 
 *     if buf == NULL:
 *         result = array(shape, itemsize, format, mode.decode('ASCII'))             # <<<<<<<<<<<<<<
 *     else:
 *         result = array(shape, itemsize, format, mode.decode('ASCII'),
 */
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 249, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 249, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 249, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 249, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_shape);
    __Pyx_GIVEREF(__pyx_v_shape);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_shape);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 249, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "View.MemoryView":248
 *     cdef array result
 * 
 *     if buf == NULL:             # <<<<<<<<<<<<<<
 *         result = array(shape, itemsize, format, mode.decode('ASCII'))
 *     else:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":251
 *         result = array(shape, itemsize, format, mode.decode('ASCII'))
 *     else:
 *         result = array(shape, itemsize, format, mode.decode('ASCII'),             # <<<<<<<<<<<<<<
 *                        allocate_buffer=False)
 *         result.data = buf
 */
  /*else*/ {
    __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 251, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 251, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 251, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 251, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_shape);
    __Pyx_GIVEREF(__pyx_v_shape);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_shape);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_3);
    __pyx_t_4 = 0;
    __pyx_t_5 = 0;
    __pyx_t_3 = 0;

    /* "View.MemoryView":252
 *     else:
 *         result = array(shape, itemsize, format, mode.decode('ASCII'),
 *                        allocate_buffer=False)             # <<<<<<<<<<<<<<
 *         result.data = buf
 * 
 */
    __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_allocate_buffer, Py_False) < 0) __PYX_ERR(4, 252, __pyx_L1_error)

    /* "View.MemoryView":251
 *         result = array(shape, itemsize, format, mode.decode('ASCII'))
 *     else:
 *         result = array(shape, itemsize, format, mode.decode('ASCII'),             # <<<<<<<<<<<<<<
 *                        allocate_buffer=False)
 *         result.data = buf
 */
    __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 251, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "View.MemoryView":253
 *         result = array(shape, itemsize, format, mode.decode('ASCII'),
 *                        allocate_buffer=False)
 *         result.data = buf             # <<<<<<<<<<<<<<
 * 
 *     return result
 */
    __pyx_v_result->data = __pyx_v_buf;
  }
  __pyx_L3:;

  /* "View.MemoryView":255
 *         result.data = buf
 * 
 *     return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "View.MemoryView":244
 * 
 * @cname("__pyx_array_new")
 * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format,             # <<<<<<<<<<<<<<
 *                           char *mode, char *buf):
 *     cdef array result
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.array_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":281
 * cdef class Enum(object):
 *     cdef object name
 *     def __init__(self, name):             # <<<<<<<<<<<<<<
 *         self.name = name
 *     def __repr__(self):
 */

/* Python wrapper */
static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_name = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name_2,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name_2)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(4, 281, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_name = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(4, 281, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("View.MemoryView.Enum.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), __pyx_v_name);

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

static int __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "View.MemoryView":282
 *     cdef object name
 *     def __init__(self, name):
 *         self.name = name             # <<<<<<<<<<<<<<
 *     def __repr__(self):
 *         return self.name
 */
  __Pyx_INCREF(__pyx_v_name);
  __Pyx_GIVEREF(__pyx_v_name);
  __Pyx_GOTREF(__pyx_v_self->name);
  __Pyx_DECREF(__pyx_v_self->name);
  __pyx_v_self->name = __pyx_v_name;

  /* "View.MemoryView":281
 * cdef class Enum(object):
 *     cdef object name
 *     def __init__(self, name):             # <<<<<<<<<<<<<<
 *         self.name = name
 *     def __repr__(self):
 */

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

/* "View.MemoryView":283
 *     def __init__(self, name):
 *         self.name = name
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return self.name
 * 
 */

/* Python wrapper */
static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
  __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self));

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

static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__repr__", 0);

  /* "View.MemoryView":284
 *         self.name = name
 *     def __repr__(self):
 *         return self.name             # <<<<<<<<<<<<<<
 * 
 * cdef generic = Enum("<strided and direct or indirect>")
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->name);
  __pyx_r = __pyx_v_self->name;
  goto __pyx_L0;

  /* "View.MemoryView":283
 *     def __init__(self, name):
 *         self.name = name
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return self.name
 * 
 */

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

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */

/* Python wrapper */
static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_MemviewEnum___reduce_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf___pyx_MemviewEnum___reduce_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self) {
  PyObject *__pyx_v_state = 0;
  PyObject *__pyx_v__dict = 0;
  int __pyx_v_use_setstate;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);

  /* "(tree fragment)":5
 *     cdef object _dict
 *     cdef bint use_setstate
 *     state = (self.name,)             # <<<<<<<<<<<<<<
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_self->name);
  __Pyx_GIVEREF(__pyx_v_self->name);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->name);
  __pyx_v_state = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "(tree fragment)":6
 *     cdef bint use_setstate
 *     state = (self.name,)
 *     _dict = getattr(self, '__dict__', None)             # <<<<<<<<<<<<<<
 *     if _dict is not None:
 *         state += (_dict,)
 */
  __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 6, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v__dict = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "(tree fragment)":7
 *     state = (self.name,)
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:             # <<<<<<<<<<<<<<
 *         state += (_dict,)
 *         use_setstate = True
 */
  __pyx_t_2 = (__pyx_v__dict != Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "(tree fragment)":8
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:
 *         state += (_dict,)             # <<<<<<<<<<<<<<
 *         use_setstate = True
 *     else:
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 8, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v__dict);
    __Pyx_GIVEREF(__pyx_v__dict);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict);
    __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 8, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "(tree fragment)":9
 *     if _dict is not None:
 *         state += (_dict,)
 *         use_setstate = True             # <<<<<<<<<<<<<<
 *     else:
 *         use_setstate = self.name is not None
 */
    __pyx_v_use_setstate = 1;

    /* "(tree fragment)":7
 *     state = (self.name,)
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:             # <<<<<<<<<<<<<<
 *         state += (_dict,)
 *         use_setstate = True
 */
    goto __pyx_L3;
  }

  /* "(tree fragment)":11
 *         use_setstate = True
 *     else:
 *         use_setstate = self.name is not None             # <<<<<<<<<<<<<<
 *     if use_setstate:
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
 */
  /*else*/ {
    __pyx_t_3 = (__pyx_v_self->name != Py_None);
    __pyx_v_use_setstate = __pyx_t_3;
  }
  __pyx_L3:;

  /* "(tree fragment)":12
 *     else:
 *         use_setstate = self.name is not None
 *     if use_setstate:             # <<<<<<<<<<<<<<
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
 *     else:
 */
  __pyx_t_3 = (__pyx_v_use_setstate != 0);
  if (__pyx_t_3) {

    /* "(tree fragment)":13
 *         use_setstate = self.name is not None
 *     if use_setstate:
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state             # <<<<<<<<<<<<<<
 *     else:
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_INCREF(__pyx_int_184977713);
    __Pyx_GIVEREF(__pyx_int_184977713);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713);
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None);
    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
    __Pyx_INCREF(__pyx_v_state);
    __Pyx_GIVEREF(__pyx_v_state);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "(tree fragment)":12
 *     else:
 *         use_setstate = self.name is not None
 *     if use_setstate:             # <<<<<<<<<<<<<<
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
 *     else:
 */
  }

  /* "(tree fragment)":15
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
 *     else:
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, state)             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     __pyx_unpickle_Enum__set_state(self, __pyx_state)
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_INCREF(__pyx_int_184977713);
    __Pyx_GIVEREF(__pyx_int_184977713);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713);
    __Pyx_INCREF(__pyx_v_state);
    __Pyx_GIVEREF(__pyx_v_state);
    PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __pyx_t_5 = 0;
    __pyx_t_1 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.Enum.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_state);
  __Pyx_XDECREF(__pyx_v__dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_Enum__set_state(self, __pyx_state)
 */

/* Python wrapper */
static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_MemviewEnum_2__setstate_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);

  /* "(tree fragment)":17
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
 * def __setstate_cython__(self, __pyx_state):
 *     __pyx_unpickle_Enum__set_state(self, __pyx_state)             # <<<<<<<<<<<<<<
 */
  if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(4, 17, __pyx_L1_error)
  __pyx_t_1 = __pyx_unpickle_Enum__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_Enum__set_state(self, __pyx_state)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.Enum.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":298
 * 
 * @cname('__pyx_align_pointer')
 * cdef void *align_pointer(void *memory, size_t alignment) nogil:             # <<<<<<<<<<<<<<
 *     "Align pointer memory on a given boundary"
 *     cdef Py_intptr_t aligned_p = <Py_intptr_t> memory
 */

static void *__pyx_align_pointer(void *__pyx_v_memory, size_t __pyx_v_alignment) {
  Py_intptr_t __pyx_v_aligned_p;
  size_t __pyx_v_offset;
  void *__pyx_r;
  int __pyx_t_1;

  /* "View.MemoryView":300
 * cdef void *align_pointer(void *memory, size_t alignment) nogil:
 *     "Align pointer memory on a given boundary"
 *     cdef Py_intptr_t aligned_p = <Py_intptr_t> memory             # <<<<<<<<<<<<<<
 *     cdef size_t offset
 * 
 */
  __pyx_v_aligned_p = ((Py_intptr_t)__pyx_v_memory);

  /* "View.MemoryView":304
 * 
 *     with cython.cdivision(True):
 *         offset = aligned_p % alignment             # <<<<<<<<<<<<<<
 * 
 *     if offset > 0:
 */
  __pyx_v_offset = (__pyx_v_aligned_p % __pyx_v_alignment);

  /* "View.MemoryView":306
 *         offset = aligned_p % alignment
 * 
 *     if offset > 0:             # <<<<<<<<<<<<<<
 *         aligned_p += alignment - offset
 * 
 */
  __pyx_t_1 = ((__pyx_v_offset > 0) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":307
 * 
 *     if offset > 0:
 *         aligned_p += alignment - offset             # <<<<<<<<<<<<<<
 * 
 *     return <void *> aligned_p
 */
    __pyx_v_aligned_p = (__pyx_v_aligned_p + (__pyx_v_alignment - __pyx_v_offset));

    /* "View.MemoryView":306
 *         offset = aligned_p % alignment
 * 
 *     if offset > 0:             # <<<<<<<<<<<<<<
 *         aligned_p += alignment - offset
 * 
 */
  }

  /* "View.MemoryView":309
 *         aligned_p += alignment - offset
 * 
 *     return <void *> aligned_p             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = ((void *)__pyx_v_aligned_p);
  goto __pyx_L0;

  /* "View.MemoryView":298
 * 
 * @cname('__pyx_align_pointer')
 * cdef void *align_pointer(void *memory, size_t alignment) nogil:             # <<<<<<<<<<<<<<
 *     "Align pointer memory on a given boundary"
 *     cdef Py_intptr_t aligned_p = <Py_intptr_t> memory
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "View.MemoryView":345
 *     cdef __Pyx_TypeInfo *typeinfo
 * 
 *     def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False):             # <<<<<<<<<<<<<<
 *         self.obj = obj
 *         self.flags = flags
 */

/* Python wrapper */
static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_obj = 0;
  int __pyx_v_flags;
  int __pyx_v_dtype_is_object;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_obj,&__pyx_n_s_flags,&__pyx_n_s_dtype_is_object,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_obj)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flags)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); __PYX_ERR(4, 345, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dtype_is_object);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(4, 345, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_obj = values[0];
    __pyx_v_flags = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) __PYX_ERR(4, 345, __pyx_L3_error)
    if (values[2]) {
      __pyx_v_dtype_is_object = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_dtype_is_object == (int)-1) && PyErr_Occurred())) __PYX_ERR(4, 345, __pyx_L3_error)
    } else {
      __pyx_v_dtype_is_object = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(4, 345, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_obj, __pyx_v_flags, __pyx_v_dtype_is_object);

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

static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "View.MemoryView":346
 * 
 *     def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False):
 *         self.obj = obj             # <<<<<<<<<<<<<<
 *         self.flags = flags
 *         if type(self) is memoryview or obj is not None:
 */
  __Pyx_INCREF(__pyx_v_obj);
  __Pyx_GIVEREF(__pyx_v_obj);
  __Pyx_GOTREF(__pyx_v_self->obj);
  __Pyx_DECREF(__pyx_v_self->obj);
  __pyx_v_self->obj = __pyx_v_obj;

  /* "View.MemoryView":347
 *     def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False):
 *         self.obj = obj
 *         self.flags = flags             # <<<<<<<<<<<<<<
 *         if type(self) is memoryview or obj is not None:
 *             __Pyx_GetBuffer(obj, &self.view, flags)
 */
  __pyx_v_self->flags = __pyx_v_flags;

  /* "View.MemoryView":348
 *         self.obj = obj
 *         self.flags = flags
 *         if type(self) is memoryview or obj is not None:             # <<<<<<<<<<<<<<
 *             __Pyx_GetBuffer(obj, &self.view, flags)
 *             if <PyObject *> self.view.obj == NULL:
 */
  __pyx_t_2 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_memoryview_type));
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (__pyx_v_obj != Py_None);
  __pyx_t_2 = (__pyx_t_3 != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "View.MemoryView":349
 *         self.flags = flags
 *         if type(self) is memoryview or obj is not None:
 *             __Pyx_GetBuffer(obj, &self.view, flags)             # <<<<<<<<<<<<<<
 *             if <PyObject *> self.view.obj == NULL:
 *                 (<__pyx_buffer *> &self.view).obj = Py_None
 */
    __pyx_t_4 = __Pyx_GetBuffer(__pyx_v_obj, (&__pyx_v_self->view), __pyx_v_flags); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(4, 349, __pyx_L1_error)

    /* "View.MemoryView":350
 *         if type(self) is memoryview or obj is not None:
 *             __Pyx_GetBuffer(obj, &self.view, flags)
 *             if <PyObject *> self.view.obj == NULL:             # <<<<<<<<<<<<<<
 *                 (<__pyx_buffer *> &self.view).obj = Py_None
 *                 Py_INCREF(Py_None)
 */
    __pyx_t_1 = ((((PyObject *)__pyx_v_self->view.obj) == NULL) != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":351
 *             __Pyx_GetBuffer(obj, &self.view, flags)
 *             if <PyObject *> self.view.obj == NULL:
 *                 (<__pyx_buffer *> &self.view).obj = Py_None             # <<<<<<<<<<<<<<
 *                 Py_INCREF(Py_None)
 * 
 */
      ((Py_buffer *)(&__pyx_v_self->view))->obj = Py_None;

      /* "View.MemoryView":352
 *             if <PyObject *> self.view.obj == NULL:
 *                 (<__pyx_buffer *> &self.view).obj = Py_None
 *                 Py_INCREF(Py_None)             # <<<<<<<<<<<<<<
 * 
 *         global __pyx_memoryview_thread_locks_used
 */
      Py_INCREF(Py_None);

      /* "View.MemoryView":350
 *         if type(self) is memoryview or obj is not None:
 *             __Pyx_GetBuffer(obj, &self.view, flags)
 *             if <PyObject *> self.view.obj == NULL:             # <<<<<<<<<<<<<<
 *                 (<__pyx_buffer *> &self.view).obj = Py_None
 *                 Py_INCREF(Py_None)
 */
    }

    /* "View.MemoryView":348
 *         self.obj = obj
 *         self.flags = flags
 *         if type(self) is memoryview or obj is not None:             # <<<<<<<<<<<<<<
 *             __Pyx_GetBuffer(obj, &self.view, flags)
 *             if <PyObject *> self.view.obj == NULL:
 */
  }

  /* "View.MemoryView":355
 * 
 *         global __pyx_memoryview_thread_locks_used
 *         if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:             # <<<<<<<<<<<<<<
 *             self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
 *             __pyx_memoryview_thread_locks_used += 1
 */
  __pyx_t_1 = ((__pyx_memoryview_thread_locks_used < 8) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":356
 *         global __pyx_memoryview_thread_locks_used
 *         if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:
 *             self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]             # <<<<<<<<<<<<<<
 *             __pyx_memoryview_thread_locks_used += 1
 *         if self.lock is NULL:
 */
    __pyx_v_self->lock = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]);

    /* "View.MemoryView":357
 *         if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:
 *             self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
 *             __pyx_memoryview_thread_locks_used += 1             # <<<<<<<<<<<<<<
 *         if self.lock is NULL:
 *             self.lock = PyThread_allocate_lock()
 */
    __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used + 1);

    /* "View.MemoryView":355
 * 
 *         global __pyx_memoryview_thread_locks_used
 *         if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:             # <<<<<<<<<<<<<<
 *             self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
 *             __pyx_memoryview_thread_locks_used += 1
 */
  }

  /* "View.MemoryView":358
 *             self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
 *             __pyx_memoryview_thread_locks_used += 1
 *         if self.lock is NULL:             # <<<<<<<<<<<<<<
 *             self.lock = PyThread_allocate_lock()
 *             if self.lock is NULL:
 */
  __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":359
 *             __pyx_memoryview_thread_locks_used += 1
 *         if self.lock is NULL:
 *             self.lock = PyThread_allocate_lock()             # <<<<<<<<<<<<<<
 *             if self.lock is NULL:
 *                 raise MemoryError
 */
    __pyx_v_self->lock = PyThread_allocate_lock();

    /* "View.MemoryView":360
 *         if self.lock is NULL:
 *             self.lock = PyThread_allocate_lock()
 *             if self.lock is NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError
 * 
 */
    __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0);
    if (unlikely(__pyx_t_1)) {

      /* "View.MemoryView":361
 *             self.lock = PyThread_allocate_lock()
 *             if self.lock is NULL:
 *                 raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_FORMAT:
 */
      PyErr_NoMemory(); __PYX_ERR(4, 361, __pyx_L1_error)

      /* "View.MemoryView":360
 *         if self.lock is NULL:
 *             self.lock = PyThread_allocate_lock()
 *             if self.lock is NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError
 * 
 */
    }

    /* "View.MemoryView":358
 *             self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
 *             __pyx_memoryview_thread_locks_used += 1
 *         if self.lock is NULL:             # <<<<<<<<<<<<<<
 *             self.lock = PyThread_allocate_lock()
 *             if self.lock is NULL:
 */
  }

  /* "View.MemoryView":363
 *                 raise MemoryError
 * 
 *         if flags & PyBUF_FORMAT:             # <<<<<<<<<<<<<<
 *             self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":364
 * 
 *         if flags & PyBUF_FORMAT:
 *             self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')             # <<<<<<<<<<<<<<
 *         else:
 *             self.dtype_is_object = dtype_is_object
 */
    __pyx_t_2 = (((__pyx_v_self->view.format[0]) == 'O') != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_2 = (((__pyx_v_self->view.format[1]) == '\x00') != 0);
    __pyx_t_1 = __pyx_t_2;
    __pyx_L11_bool_binop_done:;
    __pyx_v_self->dtype_is_object = __pyx_t_1;

    /* "View.MemoryView":363
 *                 raise MemoryError
 * 
 *         if flags & PyBUF_FORMAT:             # <<<<<<<<<<<<<<
 *             self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')
 *         else:
 */
    goto __pyx_L10;
  }

  /* "View.MemoryView":366
 *             self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')
 *         else:
 *             self.dtype_is_object = dtype_is_object             # <<<<<<<<<<<<<<
 * 
 *         self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer(
 */
  /*else*/ {
    __pyx_v_self->dtype_is_object = __pyx_v_dtype_is_object;
  }
  __pyx_L10:;

  /* "View.MemoryView":368
 *             self.dtype_is_object = dtype_is_object
 * 
 *         self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer(             # <<<<<<<<<<<<<<
 *                   <void *> &self.acquisition_count[0], sizeof(__pyx_atomic_int))
 *         self.typeinfo = NULL
 */
  __pyx_v_self->acquisition_count_aligned_p = ((__pyx_atomic_int *)__pyx_align_pointer(((void *)(&(__pyx_v_self->acquisition_count[0]))), (sizeof(__pyx_atomic_int))));

  /* "View.MemoryView":370
 *         self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer(
 *                   <void *> &self.acquisition_count[0], sizeof(__pyx_atomic_int))
 *         self.typeinfo = NULL             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(memoryview self):
 */
  __pyx_v_self->typeinfo = NULL;

  /* "View.MemoryView":345
 *     cdef __Pyx_TypeInfo *typeinfo
 * 
 *     def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False):             # <<<<<<<<<<<<<<
 *         self.obj = obj
 *         self.flags = flags
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":372
 *         self.typeinfo = NULL
 * 
 *     def __dealloc__(memoryview self):             # <<<<<<<<<<<<<<
 *         if self.obj is not None:
 *             __Pyx_ReleaseBuffer(&self.view)
 */

/* Python wrapper */
static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static void __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self) {
  int __pyx_v_i;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyThread_type_lock __pyx_t_6;
  PyThread_type_lock __pyx_t_7;
  __Pyx_RefNannySetupContext("__dealloc__", 0);

  /* "View.MemoryView":373
 * 
 *     def __dealloc__(memoryview self):
 *         if self.obj is not None:             # <<<<<<<<<<<<<<
 *             __Pyx_ReleaseBuffer(&self.view)
 *         elif (<__pyx_buffer *> &self.view).obj == Py_None:
 */
  __pyx_t_1 = (__pyx_v_self->obj != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":374
 *     def __dealloc__(memoryview self):
 *         if self.obj is not None:
 *             __Pyx_ReleaseBuffer(&self.view)             # <<<<<<<<<<<<<<
 *         elif (<__pyx_buffer *> &self.view).obj == Py_None:
 * 
 */
    __Pyx_ReleaseBuffer((&__pyx_v_self->view));

    /* "View.MemoryView":373
 * 
 *     def __dealloc__(memoryview self):
 *         if self.obj is not None:             # <<<<<<<<<<<<<<
 *             __Pyx_ReleaseBuffer(&self.view)
 *         elif (<__pyx_buffer *> &self.view).obj == Py_None:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":375
 *         if self.obj is not None:
 *             __Pyx_ReleaseBuffer(&self.view)
 *         elif (<__pyx_buffer *> &self.view).obj == Py_None:             # <<<<<<<<<<<<<<
 * 
 *             (<__pyx_buffer *> &self.view).obj = NULL
 */
  __pyx_t_2 = ((((Py_buffer *)(&__pyx_v_self->view))->obj == Py_None) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":377
 *         elif (<__pyx_buffer *> &self.view).obj == Py_None:
 * 
 *             (<__pyx_buffer *> &self.view).obj = NULL             # <<<<<<<<<<<<<<
 *             Py_DECREF(Py_None)
 * 
 */
    ((Py_buffer *)(&__pyx_v_self->view))->obj = NULL;

    /* "View.MemoryView":378
 * 
 *             (<__pyx_buffer *> &self.view).obj = NULL
 *             Py_DECREF(Py_None)             # <<<<<<<<<<<<<<
 * 
 *         cdef int i
 */
    Py_DECREF(Py_None);

    /* "View.MemoryView":375
 *         if self.obj is not None:
 *             __Pyx_ReleaseBuffer(&self.view)
 *         elif (<__pyx_buffer *> &self.view).obj == Py_None:             # <<<<<<<<<<<<<<
 * 
 *             (<__pyx_buffer *> &self.view).obj = NULL
 */
  }
  __pyx_L3:;

  /* "View.MemoryView":382
 *         cdef int i
 *         global __pyx_memoryview_thread_locks_used
 *         if self.lock != NULL:             # <<<<<<<<<<<<<<
 *             for i in range(__pyx_memoryview_thread_locks_used):
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:
 */
  __pyx_t_2 = ((__pyx_v_self->lock != NULL) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":383
 *         global __pyx_memoryview_thread_locks_used
 *         if self.lock != NULL:
 *             for i in range(__pyx_memoryview_thread_locks_used):             # <<<<<<<<<<<<<<
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:
 *                     __pyx_memoryview_thread_locks_used -= 1
 */
    __pyx_t_3 = __pyx_memoryview_thread_locks_used;
    __pyx_t_4 = __pyx_t_3;
    for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
      __pyx_v_i = __pyx_t_5;

      /* "View.MemoryView":384
 *         if self.lock != NULL:
 *             for i in range(__pyx_memoryview_thread_locks_used):
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:             # <<<<<<<<<<<<<<
 *                     __pyx_memoryview_thread_locks_used -= 1
 *                     if i != __pyx_memoryview_thread_locks_used:
 */
      __pyx_t_2 = (((__pyx_memoryview_thread_locks[__pyx_v_i]) == __pyx_v_self->lock) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":385
 *             for i in range(__pyx_memoryview_thread_locks_used):
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:
 *                     __pyx_memoryview_thread_locks_used -= 1             # <<<<<<<<<<<<<<
 *                     if i != __pyx_memoryview_thread_locks_used:
 *                         __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
 */
        __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used - 1);

        /* "View.MemoryView":386
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:
 *                     __pyx_memoryview_thread_locks_used -= 1
 *                     if i != __pyx_memoryview_thread_locks_used:             # <<<<<<<<<<<<<<
 *                         __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
 *                             __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
 */
        __pyx_t_2 = ((__pyx_v_i != __pyx_memoryview_thread_locks_used) != 0);
        if (__pyx_t_2) {

          /* "View.MemoryView":388
 *                     if i != __pyx_memoryview_thread_locks_used:
 *                         __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
 *                             __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])             # <<<<<<<<<<<<<<
 *                     break
 *             else:
 */
          __pyx_t_6 = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]);
          __pyx_t_7 = (__pyx_memoryview_thread_locks[__pyx_v_i]);

          /* "View.MemoryView":387
 *                     __pyx_memoryview_thread_locks_used -= 1
 *                     if i != __pyx_memoryview_thread_locks_used:
 *                         __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (             # <<<<<<<<<<<<<<
 *                             __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
 *                     break
 */
          (__pyx_memoryview_thread_locks[__pyx_v_i]) = __pyx_t_6;
          (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]) = __pyx_t_7;

          /* "View.MemoryView":386
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:
 *                     __pyx_memoryview_thread_locks_used -= 1
 *                     if i != __pyx_memoryview_thread_locks_used:             # <<<<<<<<<<<<<<
 *                         __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
 *                             __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
 */
        }

        /* "View.MemoryView":389
 *                         __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
 *                             __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
 *                     break             # <<<<<<<<<<<<<<
 *             else:
 *                 PyThread_free_lock(self.lock)
 */
        goto __pyx_L6_break;

        /* "View.MemoryView":384
 *         if self.lock != NULL:
 *             for i in range(__pyx_memoryview_thread_locks_used):
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:             # <<<<<<<<<<<<<<
 *                     __pyx_memoryview_thread_locks_used -= 1
 *                     if i != __pyx_memoryview_thread_locks_used:
 */
      }
    }
    /*else*/ {

      /* "View.MemoryView":391
 *                     break
 *             else:
 *                 PyThread_free_lock(self.lock)             # <<<<<<<<<<<<<<
 * 
 *     cdef char *get_item_pointer(memoryview self, object index) except NULL:
 */
      PyThread_free_lock(__pyx_v_self->lock);
    }
    __pyx_L6_break:;

    /* "View.MemoryView":382
 *         cdef int i
 *         global __pyx_memoryview_thread_locks_used
 *         if self.lock != NULL:             # <<<<<<<<<<<<<<
 *             for i in range(__pyx_memoryview_thread_locks_used):
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:
 */
  }

  /* "View.MemoryView":372
 *         self.typeinfo = NULL
 * 
 *     def __dealloc__(memoryview self):             # <<<<<<<<<<<<<<
 *         if self.obj is not None:
 *             __Pyx_ReleaseBuffer(&self.view)
 */

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

/* "View.MemoryView":393
 *                 PyThread_free_lock(self.lock)
 * 
 *     cdef char *get_item_pointer(memoryview self, object index) except NULL:             # <<<<<<<<<<<<<<
 *         cdef Py_ssize_t dim
 *         cdef char *itemp = <char *> self.view.buf
 */

static char *__pyx_memoryview_get_item_pointer(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) {
  Py_ssize_t __pyx_v_dim;
  char *__pyx_v_itemp;
  PyObject *__pyx_v_idx = NULL;
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *(*__pyx_t_4)(PyObject *);
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  char *__pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_item_pointer", 0);

  /* "View.MemoryView":395
 *     cdef char *get_item_pointer(memoryview self, object index) except NULL:
 *         cdef Py_ssize_t dim
 *         cdef char *itemp = <char *> self.view.buf             # <<<<<<<<<<<<<<
 * 
 *         for dim, idx in enumerate(index):
 */
  __pyx_v_itemp = ((char *)__pyx_v_self->view.buf);

  /* "View.MemoryView":397
 *         cdef char *itemp = <char *> self.view.buf
 * 
 *         for dim, idx in enumerate(index):             # <<<<<<<<<<<<<<
 *             itemp = pybuffer_index(&self.view, itemp, idx, dim)
 * 
 */
  __pyx_t_1 = 0;
  if (likely(PyList_CheckExact(__pyx_v_index)) || PyTuple_CheckExact(__pyx_v_index)) {
    __pyx_t_2 = __pyx_v_index; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 397, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 397, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_4)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(4, 397, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 397, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(4, 397, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 397, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_4(__pyx_t_2);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(4, 397, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_v_dim = __pyx_t_1;
    __pyx_t_1 = (__pyx_t_1 + 1);

    /* "View.MemoryView":398
 * 
 *         for dim, idx in enumerate(index):
 *             itemp = pybuffer_index(&self.view, itemp, idx, dim)             # <<<<<<<<<<<<<<
 * 
 *         return itemp
 */
    __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(4, 398, __pyx_L1_error)
    __pyx_t_7 = __pyx_pybuffer_index((&__pyx_v_self->view), __pyx_v_itemp, __pyx_t_6, __pyx_v_dim); if (unlikely(__pyx_t_7 == ((char *)NULL))) __PYX_ERR(4, 398, __pyx_L1_error)
    __pyx_v_itemp = __pyx_t_7;

    /* "View.MemoryView":397
 *         cdef char *itemp = <char *> self.view.buf
 * 
 *         for dim, idx in enumerate(index):             # <<<<<<<<<<<<<<
 *             itemp = pybuffer_index(&self.view, itemp, idx, dim)
 * 
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "View.MemoryView":400
 *             itemp = pybuffer_index(&self.view, itemp, idx, dim)
 * 
 *         return itemp             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_itemp;
  goto __pyx_L0;

  /* "View.MemoryView":393
 *                 PyThread_free_lock(self.lock)
 * 
 *     cdef char *get_item_pointer(memoryview self, object index) except NULL:             # <<<<<<<<<<<<<<
 *         cdef Py_ssize_t dim
 *         cdef char *itemp = <char *> self.view.buf
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.memoryview.get_item_pointer", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_idx);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":403
 * 
 * 
 *     def __getitem__(memoryview self, object index):             # <<<<<<<<<<<<<<
 *         if index is Ellipsis:
 *             return self
 */

/* Python wrapper */
static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index); /*proto*/
static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) {
  PyObject *__pyx_v_have_slices = NULL;
  PyObject *__pyx_v_indices = NULL;
  char *__pyx_v_itemp;
  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;
  char *__pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getitem__", 0);

  /* "View.MemoryView":404
 * 
 *     def __getitem__(memoryview self, object index):
 *         if index is Ellipsis:             # <<<<<<<<<<<<<<
 *             return self
 * 
 */
  __pyx_t_1 = (__pyx_v_index == __pyx_builtin_Ellipsis);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":405
 *     def __getitem__(memoryview self, object index):
 *         if index is Ellipsis:
 *             return self             # <<<<<<<<<<<<<<
 * 
 *         have_slices, indices = _unellipsify(index, self.view.ndim)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __pyx_r = ((PyObject *)__pyx_v_self);
    goto __pyx_L0;

    /* "View.MemoryView":404
 * 
 *     def __getitem__(memoryview self, object index):
 *         if index is Ellipsis:             # <<<<<<<<<<<<<<
 *             return self
 * 
 */
  }

  /* "View.MemoryView":407
 *             return self
 * 
 *         have_slices, indices = _unellipsify(index, self.view.ndim)             # <<<<<<<<<<<<<<
 * 
 *         cdef char *itemp
 */
  __pyx_t_3 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 407, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (likely(__pyx_t_3 != Py_None)) {
    PyObject* sequence = __pyx_t_3;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(4, 407, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_5);
    #else
    __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 407, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 407, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(4, 407, __pyx_L1_error)
  }
  __pyx_v_have_slices = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_indices = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "View.MemoryView":410
 * 
 *         cdef char *itemp
 *         if have_slices:             # <<<<<<<<<<<<<<
 *             return memview_slice(self, indices)
 *         else:
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(4, 410, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "View.MemoryView":411
 *         cdef char *itemp
 *         if have_slices:
 *             return memview_slice(self, indices)             # <<<<<<<<<<<<<<
 *         else:
 *             itemp = self.get_item_pointer(indices)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = ((PyObject *)__pyx_memview_slice(__pyx_v_self, __pyx_v_indices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 411, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "View.MemoryView":410
 * 
 *         cdef char *itemp
 *         if have_slices:             # <<<<<<<<<<<<<<
 *             return memview_slice(self, indices)
 *         else:
 */
  }

  /* "View.MemoryView":413
 *             return memview_slice(self, indices)
 *         else:
 *             itemp = self.get_item_pointer(indices)             # <<<<<<<<<<<<<<
 *             return self.convert_item_to_object(itemp)
 * 
 */
  /*else*/ {
    __pyx_t_6 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_indices); if (unlikely(__pyx_t_6 == ((char *)NULL))) __PYX_ERR(4, 413, __pyx_L1_error)
    __pyx_v_itemp = __pyx_t_6;

    /* "View.MemoryView":414
 *         else:
 *             itemp = self.get_item_pointer(indices)
 *             return self.convert_item_to_object(itemp)             # <<<<<<<<<<<<<<
 * 
 *     def __setitem__(memoryview self, object index, object value):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->convert_item_to_object(__pyx_v_self, __pyx_v_itemp); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 414, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "View.MemoryView":403
 * 
 * 
 *     def __getitem__(memoryview self, object index):             # <<<<<<<<<<<<<<
 *         if index is Ellipsis:
 *             return self
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_have_slices);
  __Pyx_XDECREF(__pyx_v_indices);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":416
 *             return self.convert_item_to_object(itemp)
 * 
 *     def __setitem__(memoryview self, object index, object value):             # <<<<<<<<<<<<<<
 *         if self.view.readonly:
 *             raise TypeError("Cannot assign to read-only memoryview")
 */

/* Python wrapper */
static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /*proto*/
static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index), ((PyObject *)__pyx_v_value));

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

static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) {
  PyObject *__pyx_v_have_slices = NULL;
  PyObject *__pyx_v_obj = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setitem__", 0);
  __Pyx_INCREF(__pyx_v_index);

  /* "View.MemoryView":417
 * 
 *     def __setitem__(memoryview self, object index, object value):
 *         if self.view.readonly:             # <<<<<<<<<<<<<<
 *             raise TypeError("Cannot assign to read-only memoryview")
 * 
 */
  __pyx_t_1 = (__pyx_v_self->view.readonly != 0);
  if (unlikely(__pyx_t_1)) {

    /* "View.MemoryView":418
 *     def __setitem__(memoryview self, object index, object value):
 *         if self.view.readonly:
 *             raise TypeError("Cannot assign to read-only memoryview")             # <<<<<<<<<<<<<<
 * 
 *         have_slices, index = _unellipsify(index, self.view.ndim)
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 418, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(4, 418, __pyx_L1_error)

    /* "View.MemoryView":417
 * 
 *     def __setitem__(memoryview self, object index, object value):
 *         if self.view.readonly:             # <<<<<<<<<<<<<<
 *             raise TypeError("Cannot assign to read-only memoryview")
 * 
 */
  }

  /* "View.MemoryView":420
 *             raise TypeError("Cannot assign to read-only memoryview")
 * 
 *         have_slices, index = _unellipsify(index, self.view.ndim)             # <<<<<<<<<<<<<<
 * 
 *         if have_slices:
 */
  __pyx_t_2 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 420, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (likely(__pyx_t_2 != Py_None)) {
    PyObject* sequence = __pyx_t_2;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(4, 420, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_4);
    #else
    __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 420, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 420, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(4, 420, __pyx_L1_error)
  }
  __pyx_v_have_slices = __pyx_t_3;
  __pyx_t_3 = 0;
  __Pyx_DECREF_SET(__pyx_v_index, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "View.MemoryView":422
 *         have_slices, index = _unellipsify(index, self.view.ndim)
 * 
 *         if have_slices:             # <<<<<<<<<<<<<<
 *             obj = self.is_slice(value)
 *             if obj:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(4, 422, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "View.MemoryView":423
 * 
 *         if have_slices:
 *             obj = self.is_slice(value)             # <<<<<<<<<<<<<<
 *             if obj:
 *                 self.setitem_slice_assignment(self[index], obj)
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->is_slice(__pyx_v_self, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 423, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_obj = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "View.MemoryView":424
 *         if have_slices:
 *             obj = self.is_slice(value)
 *             if obj:             # <<<<<<<<<<<<<<
 *                 self.setitem_slice_assignment(self[index], obj)
 *             else:
 */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_obj); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(4, 424, __pyx_L1_error)
    if (__pyx_t_1) {

      /* "View.MemoryView":425
 *             obj = self.is_slice(value)
 *             if obj:
 *                 self.setitem_slice_assignment(self[index], obj)             # <<<<<<<<<<<<<<
 *             else:
 *                 self.setitem_slice_assign_scalar(self[index], value)
 */
      __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 425, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assignment(__pyx_v_self, __pyx_t_2, __pyx_v_obj); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 425, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "View.MemoryView":424
 *         if have_slices:
 *             obj = self.is_slice(value)
 *             if obj:             # <<<<<<<<<<<<<<
 *                 self.setitem_slice_assignment(self[index], obj)
 *             else:
 */
      goto __pyx_L5;
    }

    /* "View.MemoryView":427
 *                 self.setitem_slice_assignment(self[index], obj)
 *             else:
 *                 self.setitem_slice_assign_scalar(self[index], value)             # <<<<<<<<<<<<<<
 *         else:
 *             self.setitem_indexed(index, value)
 */
    /*else*/ {
      __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 427, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_memoryview_type))))) __PYX_ERR(4, 427, __pyx_L1_error)
      __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assign_scalar(__pyx_v_self, ((struct __pyx_memoryview_obj *)__pyx_t_4), __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 427, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __pyx_L5:;

    /* "View.MemoryView":422
 *         have_slices, index = _unellipsify(index, self.view.ndim)
 * 
 *         if have_slices:             # <<<<<<<<<<<<<<
 *             obj = self.is_slice(value)
 *             if obj:
 */
    goto __pyx_L4;
  }

  /* "View.MemoryView":429
 *                 self.setitem_slice_assign_scalar(self[index], value)
 *         else:
 *             self.setitem_indexed(index, value)             # <<<<<<<<<<<<<<
 * 
 *     cdef is_slice(self, obj):
 */
  /*else*/ {
    __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_indexed(__pyx_v_self, __pyx_v_index, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 429, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_L4:;

  /* "View.MemoryView":416
 *             return self.convert_item_to_object(itemp)
 * 
 *     def __setitem__(memoryview self, object index, object value):             # <<<<<<<<<<<<<<
 *         if self.view.readonly:
 *             raise TypeError("Cannot assign to read-only memoryview")
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_have_slices);
  __Pyx_XDECREF(__pyx_v_obj);
  __Pyx_XDECREF(__pyx_v_index);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":431
 *             self.setitem_indexed(index, value)
 * 
 *     cdef is_slice(self, obj):             # <<<<<<<<<<<<<<
 *         if not isinstance(obj, memoryview):
 *             try:
 */

static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("is_slice", 0);
  __Pyx_INCREF(__pyx_v_obj);

  /* "View.MemoryView":432
 * 
 *     cdef is_slice(self, obj):
 *         if not isinstance(obj, memoryview):             # <<<<<<<<<<<<<<
 *             try:
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_obj, __pyx_memoryview_type); 
  __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":433
 *     cdef is_slice(self, obj):
 *         if not isinstance(obj, memoryview):
 *             try:             # <<<<<<<<<<<<<<
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 *                                  self.dtype_is_object)
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_3);
      __Pyx_XGOTREF(__pyx_t_4);
      __Pyx_XGOTREF(__pyx_t_5);
      /*try:*/ {

        /* "View.MemoryView":434
 *         if not isinstance(obj, memoryview):
 *             try:
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,             # <<<<<<<<<<<<<<
 *                                  self.dtype_is_object)
 *             except TypeError:
 */
        __pyx_t_6 = __Pyx_PyInt_From_int(((__pyx_v_self->flags & (~PyBUF_WRITABLE)) | PyBUF_ANY_CONTIGUOUS)); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 434, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_6);

        /* "View.MemoryView":435
 *             try:
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 *                                  self.dtype_is_object)             # <<<<<<<<<<<<<<
 *             except TypeError:
 *                 return None
 */
        __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_7)) __PYX_ERR(4, 435, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_7);

        /* "View.MemoryView":434
 *         if not isinstance(obj, memoryview):
 *             try:
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,             # <<<<<<<<<<<<<<
 *                                  self.dtype_is_object)
 *             except TypeError:
 */
        __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(4, 434, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_v_obj);
        __Pyx_GIVEREF(__pyx_v_obj);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_obj);
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
        __pyx_t_6 = 0;
        __pyx_t_7 = 0;
        __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(4, 434, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF_SET(__pyx_v_obj, __pyx_t_7);
        __pyx_t_7 = 0;

        /* "View.MemoryView":433
 *     cdef is_slice(self, obj):
 *         if not isinstance(obj, memoryview):
 *             try:             # <<<<<<<<<<<<<<
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 *                                  self.dtype_is_object)
 */
      }
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L9_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "View.MemoryView":436
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 *                                  self.dtype_is_object)
 *             except TypeError:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
      __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError);
      if (__pyx_t_9) {
        __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_6) < 0) __PYX_ERR(4, 436, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GOTREF(__pyx_t_6);

        /* "View.MemoryView":437
 *                                  self.dtype_is_object)
 *             except TypeError:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *         return obj
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L7_except_return;
      }
      goto __pyx_L6_except_error;
      __pyx_L6_except_error:;

      /* "View.MemoryView":433
 *     cdef is_slice(self, obj):
 *         if not isinstance(obj, memoryview):
 *             try:             # <<<<<<<<<<<<<<
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 *                                  self.dtype_is_object)
 */
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      goto __pyx_L1_error;
      __pyx_L7_except_return:;
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      goto __pyx_L0;
      __pyx_L9_try_end:;
    }

    /* "View.MemoryView":432
 * 
 *     cdef is_slice(self, obj):
 *         if not isinstance(obj, memoryview):             # <<<<<<<<<<<<<<
 *             try:
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 */
  }

  /* "View.MemoryView":439
 *                 return None
 * 
 *         return obj             # <<<<<<<<<<<<<<
 * 
 *     cdef setitem_slice_assignment(self, dst, src):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_obj);
  __pyx_r = __pyx_v_obj;
  goto __pyx_L0;

  /* "View.MemoryView":431
 *             self.setitem_indexed(index, value)
 * 
 *     cdef is_slice(self, obj):             # <<<<<<<<<<<<<<
 *         if not isinstance(obj, memoryview):
 *             try:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_obj);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":441
 *         return obj
 * 
 *     cdef setitem_slice_assignment(self, dst, src):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice dst_slice
 *         cdef __Pyx_memviewslice src_slice
 */

static PyObject *__pyx_memoryview_setitem_slice_assignment(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_dst, PyObject *__pyx_v_src) {
  __Pyx_memviewslice __pyx_v_dst_slice;
  __Pyx_memviewslice __pyx_v_src_slice;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice *__pyx_t_1;
  __Pyx_memviewslice *__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("setitem_slice_assignment", 0);

  /* "View.MemoryView":445
 *         cdef __Pyx_memviewslice src_slice
 * 
 *         memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0],             # <<<<<<<<<<<<<<
 *                                  get_slice_from_memview(dst, &dst_slice)[0],
 *                                  src.ndim, dst.ndim, self.dtype_is_object)
 */
  if (!(likely(((__pyx_v_src) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_src, __pyx_memoryview_type))))) __PYX_ERR(4, 445, __pyx_L1_error)
  __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_src), (&__pyx_v_src_slice)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(4, 445, __pyx_L1_error)

  /* "View.MemoryView":446
 * 
 *         memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0],
 *                                  get_slice_from_memview(dst, &dst_slice)[0],             # <<<<<<<<<<<<<<
 *                                  src.ndim, dst.ndim, self.dtype_is_object)
 * 
 */
  if (!(likely(((__pyx_v_dst) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_dst, __pyx_memoryview_type))))) __PYX_ERR(4, 446, __pyx_L1_error)
  __pyx_t_2 = __pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_dst), (&__pyx_v_dst_slice)); if (unlikely(__pyx_t_2 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(4, 446, __pyx_L1_error)

  /* "View.MemoryView":447
 *         memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0],
 *                                  get_slice_from_memview(dst, &dst_slice)[0],
 *                                  src.ndim, dst.ndim, self.dtype_is_object)             # <<<<<<<<<<<<<<
 * 
 *     cdef setitem_slice_assign_scalar(self, memoryview dst, value):
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_src, __pyx_n_s_ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 447, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(4, 447, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dst, __pyx_n_s_ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 447, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(4, 447, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "View.MemoryView":445
 *         cdef __Pyx_memviewslice src_slice
 * 
 *         memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0],             # <<<<<<<<<<<<<<
 *                                  get_slice_from_memview(dst, &dst_slice)[0],
 *                                  src.ndim, dst.ndim, self.dtype_is_object)
 */
  __pyx_t_6 = __pyx_memoryview_copy_contents((__pyx_t_1[0]), (__pyx_t_2[0]), __pyx_t_4, __pyx_t_5, __pyx_v_self->dtype_is_object); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(4, 445, __pyx_L1_error)

  /* "View.MemoryView":441
 *         return obj
 * 
 *     cdef setitem_slice_assignment(self, dst, src):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice dst_slice
 *         cdef __Pyx_memviewslice src_slice
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assignment", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":449
 *                                  src.ndim, dst.ndim, self.dtype_is_object)
 * 
 *     cdef setitem_slice_assign_scalar(self, memoryview dst, value):             # <<<<<<<<<<<<<<
 *         cdef int array[128]
 *         cdef void *tmp = NULL
 */

static PyObject *__pyx_memoryview_setitem_slice_assign_scalar(struct __pyx_memoryview_obj *__pyx_v_self, struct __pyx_memoryview_obj *__pyx_v_dst, PyObject *__pyx_v_value) {
  int __pyx_v_array[0x80];
  void *__pyx_v_tmp;
  void *__pyx_v_item;
  __Pyx_memviewslice *__pyx_v_dst_slice;
  __Pyx_memviewslice __pyx_v_tmp_slice;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  char const *__pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("setitem_slice_assign_scalar", 0);

  /* "View.MemoryView":451
 *     cdef setitem_slice_assign_scalar(self, memoryview dst, value):
 *         cdef int array[128]
 *         cdef void *tmp = NULL             # <<<<<<<<<<<<<<
 *         cdef void *item
 * 
 */
  __pyx_v_tmp = NULL;

  /* "View.MemoryView":456
 *         cdef __Pyx_memviewslice *dst_slice
 *         cdef __Pyx_memviewslice tmp_slice
 *         dst_slice = get_slice_from_memview(dst, &tmp_slice)             # <<<<<<<<<<<<<<
 * 
 *         if <size_t>self.view.itemsize > sizeof(array):
 */
  __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_dst, (&__pyx_v_tmp_slice)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(4, 456, __pyx_L1_error)
  __pyx_v_dst_slice = __pyx_t_1;

  /* "View.MemoryView":458
 *         dst_slice = get_slice_from_memview(dst, &tmp_slice)
 * 
 *         if <size_t>self.view.itemsize > sizeof(array):             # <<<<<<<<<<<<<<
 *             tmp = PyMem_Malloc(self.view.itemsize)
 *             if tmp == NULL:
 */
  __pyx_t_2 = ((((size_t)__pyx_v_self->view.itemsize) > (sizeof(__pyx_v_array))) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":459
 * 
 *         if <size_t>self.view.itemsize > sizeof(array):
 *             tmp = PyMem_Malloc(self.view.itemsize)             # <<<<<<<<<<<<<<
 *             if tmp == NULL:
 *                 raise MemoryError
 */
    __pyx_v_tmp = PyMem_Malloc(__pyx_v_self->view.itemsize);

    /* "View.MemoryView":460
 *         if <size_t>self.view.itemsize > sizeof(array):
 *             tmp = PyMem_Malloc(self.view.itemsize)
 *             if tmp == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError
 *             item = tmp
 */
    __pyx_t_2 = ((__pyx_v_tmp == NULL) != 0);
    if (unlikely(__pyx_t_2)) {

      /* "View.MemoryView":461
 *             tmp = PyMem_Malloc(self.view.itemsize)
 *             if tmp == NULL:
 *                 raise MemoryError             # <<<<<<<<<<<<<<
 *             item = tmp
 *         else:
 */
      PyErr_NoMemory(); __PYX_ERR(4, 461, __pyx_L1_error)

      /* "View.MemoryView":460
 *         if <size_t>self.view.itemsize > sizeof(array):
 *             tmp = PyMem_Malloc(self.view.itemsize)
 *             if tmp == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError
 *             item = tmp
 */
    }

    /* "View.MemoryView":462
 *             if tmp == NULL:
 *                 raise MemoryError
 *             item = tmp             # <<<<<<<<<<<<<<
 *         else:
 *             item = <void *> array
 */
    __pyx_v_item = __pyx_v_tmp;

    /* "View.MemoryView":458
 *         dst_slice = get_slice_from_memview(dst, &tmp_slice)
 * 
 *         if <size_t>self.view.itemsize > sizeof(array):             # <<<<<<<<<<<<<<
 *             tmp = PyMem_Malloc(self.view.itemsize)
 *             if tmp == NULL:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":464
 *             item = tmp
 *         else:
 *             item = <void *> array             # <<<<<<<<<<<<<<
 * 
 *         try:
 */
  /*else*/ {
    __pyx_v_item = ((void *)__pyx_v_array);
  }
  __pyx_L3:;

  /* "View.MemoryView":466
 *             item = <void *> array
 * 
 *         try:             # <<<<<<<<<<<<<<
 *             if self.dtype_is_object:
 *                 (<PyObject **> item)[0] = <PyObject *> value
 */
  /*try:*/ {

    /* "View.MemoryView":467
 * 
 *         try:
 *             if self.dtype_is_object:             # <<<<<<<<<<<<<<
 *                 (<PyObject **> item)[0] = <PyObject *> value
 *             else:
 */
    __pyx_t_2 = (__pyx_v_self->dtype_is_object != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":468
 *         try:
 *             if self.dtype_is_object:
 *                 (<PyObject **> item)[0] = <PyObject *> value             # <<<<<<<<<<<<<<
 *             else:
 *                 self.assign_item_from_object(<char *> item, value)
 */
      (((PyObject **)__pyx_v_item)[0]) = ((PyObject *)__pyx_v_value);

      /* "View.MemoryView":467
 * 
 *         try:
 *             if self.dtype_is_object:             # <<<<<<<<<<<<<<
 *                 (<PyObject **> item)[0] = <PyObject *> value
 *             else:
 */
      goto __pyx_L8;
    }

    /* "View.MemoryView":470
 *                 (<PyObject **> item)[0] = <PyObject *> value
 *             else:
 *                 self.assign_item_from_object(<char *> item, value)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    /*else*/ {
      __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, ((char *)__pyx_v_item), __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 470, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_L8:;

    /* "View.MemoryView":474
 * 
 * 
 *             if self.view.suboffsets != NULL:             # <<<<<<<<<<<<<<
 *                 assert_direct_dimensions(self.view.suboffsets, self.view.ndim)
 *             slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,
 */
    __pyx_t_2 = ((__pyx_v_self->view.suboffsets != NULL) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":475
 * 
 *             if self.view.suboffsets != NULL:
 *                 assert_direct_dimensions(self.view.suboffsets, self.view.ndim)             # <<<<<<<<<<<<<<
 *             slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,
 *                                 item, self.dtype_is_object)
 */
      __pyx_t_3 = assert_direct_dimensions(__pyx_v_self->view.suboffsets, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 475, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "View.MemoryView":474
 * 
 * 
 *             if self.view.suboffsets != NULL:             # <<<<<<<<<<<<<<
 *                 assert_direct_dimensions(self.view.suboffsets, self.view.ndim)
 *             slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,
 */
    }

    /* "View.MemoryView":476
 *             if self.view.suboffsets != NULL:
 *                 assert_direct_dimensions(self.view.suboffsets, self.view.ndim)
 *             slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,             # <<<<<<<<<<<<<<
 *                                 item, self.dtype_is_object)
 *         finally:
 */
    __pyx_memoryview_slice_assign_scalar(__pyx_v_dst_slice, __pyx_v_dst->view.ndim, __pyx_v_self->view.itemsize, __pyx_v_item, __pyx_v_self->dtype_is_object);
  }

  /* "View.MemoryView":479
 *                                 item, self.dtype_is_object)
 *         finally:
 *             PyMem_Free(tmp)             # <<<<<<<<<<<<<<
 * 
 *     cdef setitem_indexed(self, index, value):
 */
  /*finally:*/ {
    /*normal exit:*/{
      PyMem_Free(__pyx_v_tmp);
      goto __pyx_L7;
    }
    __pyx_L6_error:;
    /*exception exit:*/{
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9) < 0)) __Pyx_ErrFetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_8);
      __Pyx_XGOTREF(__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_10);
      __Pyx_XGOTREF(__pyx_t_11);
      __Pyx_XGOTREF(__pyx_t_12);
      __pyx_t_4 = __pyx_lineno; __pyx_t_5 = __pyx_clineno; __pyx_t_6 = __pyx_filename;
      {
        PyMem_Free(__pyx_v_tmp);
      }
      if (PY_MAJOR_VERSION >= 3) {
        __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_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_ErrRestore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
      __pyx_lineno = __pyx_t_4; __pyx_clineno = __pyx_t_5; __pyx_filename = __pyx_t_6;
      goto __pyx_L1_error;
    }
    __pyx_L7:;
  }

  /* "View.MemoryView":449
 *                                  src.ndim, dst.ndim, self.dtype_is_object)
 * 
 *     cdef setitem_slice_assign_scalar(self, memoryview dst, value):             # <<<<<<<<<<<<<<
 *         cdef int array[128]
 *         cdef void *tmp = NULL
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":481
 *             PyMem_Free(tmp)
 * 
 *     cdef setitem_indexed(self, index, value):             # <<<<<<<<<<<<<<
 *         cdef char *itemp = self.get_item_pointer(index)
 *         self.assign_item_from_object(itemp, value)
 */

static PyObject *__pyx_memoryview_setitem_indexed(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) {
  char *__pyx_v_itemp;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  char *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("setitem_indexed", 0);

  /* "View.MemoryView":482
 * 
 *     cdef setitem_indexed(self, index, value):
 *         cdef char *itemp = self.get_item_pointer(index)             # <<<<<<<<<<<<<<
 *         self.assign_item_from_object(itemp, value)
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_index); if (unlikely(__pyx_t_1 == ((char *)NULL))) __PYX_ERR(4, 482, __pyx_L1_error)
  __pyx_v_itemp = __pyx_t_1;

  /* "View.MemoryView":483
 *     cdef setitem_indexed(self, index, value):
 *         cdef char *itemp = self.get_item_pointer(index)
 *         self.assign_item_from_object(itemp, value)             # <<<<<<<<<<<<<<
 * 
 *     cdef convert_item_to_object(self, char *itemp):
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "View.MemoryView":481
 *             PyMem_Free(tmp)
 * 
 *     cdef setitem_indexed(self, index, value):             # <<<<<<<<<<<<<<
 *         cdef char *itemp = self.get_item_pointer(index)
 *         self.assign_item_from_object(itemp, value)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_indexed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":485
 *         self.assign_item_from_object(itemp, value)
 * 
 *     cdef convert_item_to_object(self, char *itemp):             # <<<<<<<<<<<<<<
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 */

static PyObject *__pyx_memoryview_convert_item_to_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp) {
  PyObject *__pyx_v_struct = NULL;
  PyObject *__pyx_v_bytesitem = 0;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  size_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("convert_item_to_object", 0);

  /* "View.MemoryView":488
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 *         import struct             # <<<<<<<<<<<<<<
 *         cdef bytes bytesitem
 * 
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 488, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_struct = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "View.MemoryView":491
 *         cdef bytes bytesitem
 * 
 *         bytesitem = itemp[:self.view.itemsize]             # <<<<<<<<<<<<<<
 *         try:
 *             result = struct.unpack(self.view.format, bytesitem)
 */
  __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_itemp + 0, __pyx_v_self->view.itemsize - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_bytesitem = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "View.MemoryView":492
 * 
 *         bytesitem = itemp[:self.view.itemsize]
 *         try:             # <<<<<<<<<<<<<<
 *             result = struct.unpack(self.view.format, bytesitem)
 *         except struct.error:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_4);
    /*try:*/ {

      /* "View.MemoryView":493
 *         bytesitem = itemp[:self.view.itemsize]
 *         try:
 *             result = struct.unpack(self.view.format, bytesitem)             # <<<<<<<<<<<<<<
 *         except struct.error:
 *             raise ValueError("Unable to convert item to object")
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_unpack); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 493, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 493, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = NULL;
      __pyx_t_8 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_8 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 493, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 493, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      {
        __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 493, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (__pyx_t_7) {
          __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_6);
        __Pyx_INCREF(__pyx_v_bytesitem);
        __Pyx_GIVEREF(__pyx_v_bytesitem);
        PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_bytesitem);
        __pyx_t_6 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 493, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_result = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "View.MemoryView":492
 * 
 *         bytesitem = itemp[:self.view.itemsize]
 *         try:             # <<<<<<<<<<<<<<
 *             result = struct.unpack(self.view.format, bytesitem)
 *         except struct.error:
 */
    }

    /* "View.MemoryView":497
 *             raise ValueError("Unable to convert item to object")
 *         else:
 *             if len(self.view.format) == 1:             # <<<<<<<<<<<<<<
 *                 return result[0]
 *             return result
 */
    /*else:*/ {
      __pyx_t_10 = strlen(__pyx_v_self->view.format); 
      __pyx_t_11 = ((__pyx_t_10 == 1) != 0);
      if (__pyx_t_11) {

        /* "View.MemoryView":498
 *         else:
 *             if len(self.view.format) == 1:
 *                 return result[0]             # <<<<<<<<<<<<<<
 *             return result
 * 
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_result, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 498, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_r = __pyx_t_1;
        __pyx_t_1 = 0;
        goto __pyx_L6_except_return;

        /* "View.MemoryView":497
 *             raise ValueError("Unable to convert item to object")
 *         else:
 *             if len(self.view.format) == 1:             # <<<<<<<<<<<<<<
 *                 return result[0]
 *             return result
 */
      }

      /* "View.MemoryView":499
 *             if len(self.view.format) == 1:
 *                 return result[0]
 *             return result             # <<<<<<<<<<<<<<
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_result);
      __pyx_r = __pyx_v_result;
      goto __pyx_L6_except_return;
    }
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "View.MemoryView":494
 *         try:
 *             result = struct.unpack(self.view.format, bytesitem)
 *         except struct.error:             # <<<<<<<<<<<<<<
 *             raise ValueError("Unable to convert item to object")
 *         else:
 */
    __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_5, &__pyx_t_9);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 494, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_6);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_ErrRestore(__pyx_t_1, __pyx_t_5, __pyx_t_9);
    __pyx_t_1 = 0; __pyx_t_5 = 0; __pyx_t_9 = 0;
    if (__pyx_t_8) {
      __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_5, &__pyx_t_1) < 0) __PYX_ERR(4, 494, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_1);

      /* "View.MemoryView":495
 *             result = struct.unpack(self.view.format, bytesitem)
 *         except struct.error:
 *             raise ValueError("Unable to convert item to object")             # <<<<<<<<<<<<<<
 *         else:
 *             if len(self.view.format) == 1:
 */
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__55, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 495, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __PYX_ERR(4, 495, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "View.MemoryView":492
 * 
 *         bytesitem = itemp[:self.view.itemsize]
 *         try:             # <<<<<<<<<<<<<<
 *             result = struct.unpack(self.view.format, bytesitem)
 *         except struct.error:
 */
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
    goto __pyx_L1_error;
    __pyx_L6_except_return:;
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
    goto __pyx_L0;
  }

  /* "View.MemoryView":485
 *         self.assign_item_from_object(itemp, value)
 * 
 *     cdef convert_item_to_object(self, char *itemp):             # <<<<<<<<<<<<<<
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_struct);
  __Pyx_XDECREF(__pyx_v_bytesitem);
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":501
 *             return result
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):             # <<<<<<<<<<<<<<
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 */

static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) {
  PyObject *__pyx_v_struct = NULL;
  char __pyx_v_c;
  PyObject *__pyx_v_bytesvalue = 0;
  Py_ssize_t __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  Py_ssize_t __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  char *__pyx_t_11;
  char *__pyx_t_12;
  char *__pyx_t_13;
  char *__pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("assign_item_from_object", 0);

  /* "View.MemoryView":504
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 *         import struct             # <<<<<<<<<<<<<<
 *         cdef char c
 *         cdef bytes bytesvalue
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 504, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_struct = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "View.MemoryView":509
 *         cdef Py_ssize_t i
 * 
 *         if isinstance(value, tuple):             # <<<<<<<<<<<<<<
 *             bytesvalue = struct.pack(self.view.format, *value)
 *         else:
 */
  __pyx_t_2 = PyTuple_Check(__pyx_v_value); 
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "View.MemoryView":510
 * 
 *         if isinstance(value, tuple):
 *             bytesvalue = struct.pack(self.view.format, *value)             # <<<<<<<<<<<<<<
 *         else:
 *             bytesvalue = struct.pack(self.view.format, value)
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = PyNumber_Add(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(4, 510, __pyx_L1_error)
    __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "View.MemoryView":509
 *         cdef Py_ssize_t i
 * 
 *         if isinstance(value, tuple):             # <<<<<<<<<<<<<<
 *             bytesvalue = struct.pack(self.view.format, *value)
 *         else:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":512
 *             bytesvalue = struct.pack(self.view.format, *value)
 *         else:
 *             bytesvalue = struct.pack(self.view.format, value)             # <<<<<<<<<<<<<<
 * 
 *         for i, c in enumerate(bytesvalue):
 */
  /*else*/ {
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 512, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 512, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = NULL;
    __pyx_t_7 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
        __pyx_t_7 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value};
      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 512, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value};
      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 512, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    {
      __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(4, 512, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_1);
      __Pyx_INCREF(__pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_v_value);
      __pyx_t_1 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 512, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(4, 512, __pyx_L1_error)
    __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;
  }
  __pyx_L3:;

  /* "View.MemoryView":514
 *             bytesvalue = struct.pack(self.view.format, value)
 * 
 *         for i, c in enumerate(bytesvalue):             # <<<<<<<<<<<<<<
 *             itemp[i] = c
 * 
 */
  __pyx_t_9 = 0;
  if (unlikely(__pyx_v_bytesvalue == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable");
    __PYX_ERR(4, 514, __pyx_L1_error)
  }
  __Pyx_INCREF(__pyx_v_bytesvalue);
  __pyx_t_10 = __pyx_v_bytesvalue;
  __pyx_t_12 = PyBytes_AS_STRING(__pyx_t_10);
  __pyx_t_13 = (__pyx_t_12 + PyBytes_GET_SIZE(__pyx_t_10));
  for (__pyx_t_14 = __pyx_t_12; __pyx_t_14 < __pyx_t_13; __pyx_t_14++) {
    __pyx_t_11 = __pyx_t_14;
    __pyx_v_c = (__pyx_t_11[0]);

    /* "View.MemoryView":515
 * 
 *         for i, c in enumerate(bytesvalue):
 *             itemp[i] = c             # <<<<<<<<<<<<<<
 * 
 *     @cname('getbuffer')
 */
    __pyx_v_i = __pyx_t_9;

    /* "View.MemoryView":514
 *             bytesvalue = struct.pack(self.view.format, value)
 * 
 *         for i, c in enumerate(bytesvalue):             # <<<<<<<<<<<<<<
 *             itemp[i] = c
 * 
 */
    __pyx_t_9 = (__pyx_t_9 + 1);

    /* "View.MemoryView":515
 * 
 *         for i, c in enumerate(bytesvalue):
 *             itemp[i] = c             # <<<<<<<<<<<<<<
 * 
 *     @cname('getbuffer')
 */
    (__pyx_v_itemp[__pyx_v_i]) = __pyx_v_c;
  }
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "View.MemoryView":501
 *             return result
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):             # <<<<<<<<<<<<<<
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 */

  /* 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_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("View.MemoryView.memoryview.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_struct);
  __Pyx_XDECREF(__pyx_v_bytesvalue);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":518
 * 
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):             # <<<<<<<<<<<<<<
 *         if flags & PyBUF_WRITABLE and self.view.readonly:
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")
 */

/* Python wrapper */
static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));

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

static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t *__pyx_t_4;
  char *__pyx_t_5;
  void *__pyx_t_6;
  int __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  if (__pyx_v_info == NULL) {
    PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
    return -1;
  }
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(__pyx_v_info->obj);

  /* "View.MemoryView":519
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         if flags & PyBUF_WRITABLE and self.view.readonly:             # <<<<<<<<<<<<<<
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")
 * 
 */
  __pyx_t_2 = ((__pyx_v_flags & PyBUF_WRITABLE) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = (__pyx_v_self->view.readonly != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (unlikely(__pyx_t_1)) {

    /* "View.MemoryView":520
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         if flags & PyBUF_WRITABLE and self.view.readonly:
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_ND:
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__56, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 520, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(4, 520, __pyx_L1_error)

    /* "View.MemoryView":519
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         if flags & PyBUF_WRITABLE and self.view.readonly:             # <<<<<<<<<<<<<<
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")
 * 
 */
  }

  /* "View.MemoryView":522
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")
 * 
 *         if flags & PyBUF_ND:             # <<<<<<<<<<<<<<
 *             info.shape = self.view.shape
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_ND) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":523
 * 
 *         if flags & PyBUF_ND:
 *             info.shape = self.view.shape             # <<<<<<<<<<<<<<
 *         else:
 *             info.shape = NULL
 */
    __pyx_t_4 = __pyx_v_self->view.shape;
    __pyx_v_info->shape = __pyx_t_4;

    /* "View.MemoryView":522
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")
 * 
 *         if flags & PyBUF_ND:             # <<<<<<<<<<<<<<
 *             info.shape = self.view.shape
 *         else:
 */
    goto __pyx_L6;
  }

  /* "View.MemoryView":525
 *             info.shape = self.view.shape
 *         else:
 *             info.shape = NULL             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_STRIDES:
 */
  /*else*/ {
    __pyx_v_info->shape = NULL;
  }
  __pyx_L6:;

  /* "View.MemoryView":527
 *             info.shape = NULL
 * 
 *         if flags & PyBUF_STRIDES:             # <<<<<<<<<<<<<<
 *             info.strides = self.view.strides
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_STRIDES) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":528
 * 
 *         if flags & PyBUF_STRIDES:
 *             info.strides = self.view.strides             # <<<<<<<<<<<<<<
 *         else:
 *             info.strides = NULL
 */
    __pyx_t_4 = __pyx_v_self->view.strides;
    __pyx_v_info->strides = __pyx_t_4;

    /* "View.MemoryView":527
 *             info.shape = NULL
 * 
 *         if flags & PyBUF_STRIDES:             # <<<<<<<<<<<<<<
 *             info.strides = self.view.strides
 *         else:
 */
    goto __pyx_L7;
  }

  /* "View.MemoryView":530
 *             info.strides = self.view.strides
 *         else:
 *             info.strides = NULL             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_INDIRECT:
 */
  /*else*/ {
    __pyx_v_info->strides = NULL;
  }
  __pyx_L7:;

  /* "View.MemoryView":532
 *             info.strides = NULL
 * 
 *         if flags & PyBUF_INDIRECT:             # <<<<<<<<<<<<<<
 *             info.suboffsets = self.view.suboffsets
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_INDIRECT) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":533
 * 
 *         if flags & PyBUF_INDIRECT:
 *             info.suboffsets = self.view.suboffsets             # <<<<<<<<<<<<<<
 *         else:
 *             info.suboffsets = NULL
 */
    __pyx_t_4 = __pyx_v_self->view.suboffsets;
    __pyx_v_info->suboffsets = __pyx_t_4;

    /* "View.MemoryView":532
 *             info.strides = NULL
 * 
 *         if flags & PyBUF_INDIRECT:             # <<<<<<<<<<<<<<
 *             info.suboffsets = self.view.suboffsets
 *         else:
 */
    goto __pyx_L8;
  }

  /* "View.MemoryView":535
 *             info.suboffsets = self.view.suboffsets
 *         else:
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_FORMAT:
 */
  /*else*/ {
    __pyx_v_info->suboffsets = NULL;
  }
  __pyx_L8:;

  /* "View.MemoryView":537
 *             info.suboffsets = NULL
 * 
 *         if flags & PyBUF_FORMAT:             # <<<<<<<<<<<<<<
 *             info.format = self.view.format
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":538
 * 
 *         if flags & PyBUF_FORMAT:
 *             info.format = self.view.format             # <<<<<<<<<<<<<<
 *         else:
 *             info.format = NULL
 */
    __pyx_t_5 = __pyx_v_self->view.format;
    __pyx_v_info->format = __pyx_t_5;

    /* "View.MemoryView":537
 *             info.suboffsets = NULL
 * 
 *         if flags & PyBUF_FORMAT:             # <<<<<<<<<<<<<<
 *             info.format = self.view.format
 *         else:
 */
    goto __pyx_L9;
  }

  /* "View.MemoryView":540
 *             info.format = self.view.format
 *         else:
 *             info.format = NULL             # <<<<<<<<<<<<<<
 * 
 *         info.buf = self.view.buf
 */
  /*else*/ {
    __pyx_v_info->format = NULL;
  }
  __pyx_L9:;

  /* "View.MemoryView":542
 *             info.format = NULL
 * 
 *         info.buf = self.view.buf             # <<<<<<<<<<<<<<
 *         info.ndim = self.view.ndim
 *         info.itemsize = self.view.itemsize
 */
  __pyx_t_6 = __pyx_v_self->view.buf;
  __pyx_v_info->buf = __pyx_t_6;

  /* "View.MemoryView":543
 * 
 *         info.buf = self.view.buf
 *         info.ndim = self.view.ndim             # <<<<<<<<<<<<<<
 *         info.itemsize = self.view.itemsize
 *         info.len = self.view.len
 */
  __pyx_t_7 = __pyx_v_self->view.ndim;
  __pyx_v_info->ndim = __pyx_t_7;

  /* "View.MemoryView":544
 *         info.buf = self.view.buf
 *         info.ndim = self.view.ndim
 *         info.itemsize = self.view.itemsize             # <<<<<<<<<<<<<<
 *         info.len = self.view.len
 *         info.readonly = self.view.readonly
 */
  __pyx_t_8 = __pyx_v_self->view.itemsize;
  __pyx_v_info->itemsize = __pyx_t_8;

  /* "View.MemoryView":545
 *         info.ndim = self.view.ndim
 *         info.itemsize = self.view.itemsize
 *         info.len = self.view.len             # <<<<<<<<<<<<<<
 *         info.readonly = self.view.readonly
 *         info.obj = self
 */
  __pyx_t_8 = __pyx_v_self->view.len;
  __pyx_v_info->len = __pyx_t_8;

  /* "View.MemoryView":546
 *         info.itemsize = self.view.itemsize
 *         info.len = self.view.len
 *         info.readonly = self.view.readonly             # <<<<<<<<<<<<<<
 *         info.obj = self
 * 
 */
  __pyx_t_1 = __pyx_v_self->view.readonly;
  __pyx_v_info->readonly = __pyx_t_1;

  /* "View.MemoryView":547
 *         info.len = self.view.len
 *         info.readonly = self.view.readonly
 *         info.obj = self             # <<<<<<<<<<<<<<
 * 
 *     __pyx_getbuffer = capsule(<void *> &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_GOTREF(__pyx_v_info->obj);
  __Pyx_DECREF(__pyx_v_info->obj);
  __pyx_v_info->obj = ((PyObject *)__pyx_v_self);

  /* "View.MemoryView":518
 * 
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):             # <<<<<<<<<<<<<<
 *         if flags & PyBUF_WRITABLE and self.view.readonly:
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  if (__pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  __pyx_L2:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":553
 * 
 *     @property
 *     def T(self):             # <<<<<<<<<<<<<<
 *         cdef _memoryviewslice result = memoryview_copy(self)
 *         transpose_memslice(&result.from_slice)
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  struct __pyx_memoryviewslice_obj *__pyx_v_result = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "View.MemoryView":554
 *     @property
 *     def T(self):
 *         cdef _memoryviewslice result = memoryview_copy(self)             # <<<<<<<<<<<<<<
 *         transpose_memslice(&result.from_slice)
 *         return result
 */
  __pyx_t_1 = __pyx_memoryview_copy_object(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 554, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_memoryviewslice_type))))) __PYX_ERR(4, 554, __pyx_L1_error)
  __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "View.MemoryView":555
 *     def T(self):
 *         cdef _memoryviewslice result = memoryview_copy(self)
 *         transpose_memslice(&result.from_slice)             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
  __pyx_t_2 = __pyx_memslice_transpose((&__pyx_v_result->from_slice)); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(4, 555, __pyx_L1_error)

  /* "View.MemoryView":556
 *         cdef _memoryviewslice result = memoryview_copy(self)
 *         transpose_memslice(&result.from_slice)
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__pyx_v_result);
  goto __pyx_L0;

  /* "View.MemoryView":553
 * 
 *     @property
 *     def T(self):             # <<<<<<<<<<<<<<
 *         cdef _memoryviewslice result = memoryview_copy(self)
 *         transpose_memslice(&result.from_slice)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.memoryview.T.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":559
 * 
 *     @property
 *     def base(self):             # <<<<<<<<<<<<<<
 *         return self.obj
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "View.MemoryView":560
 *     @property
 *     def base(self):
 *         return self.obj             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->obj);
  __pyx_r = __pyx_v_self->obj;
  goto __pyx_L0;

  /* "View.MemoryView":559
 * 
 *     @property
 *     def base(self):             # <<<<<<<<<<<<<<
 *         return self.obj
 * 
 */

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

/* "View.MemoryView":563
 * 
 *     @property
 *     def shape(self):             # <<<<<<<<<<<<<<
 *         return tuple([length for length in self.view.shape[:self.view.ndim]])
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  Py_ssize_t __pyx_v_length;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t *__pyx_t_2;
  Py_ssize_t *__pyx_t_3;
  Py_ssize_t *__pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "View.MemoryView":564
 *     @property
 *     def shape(self):
 *         return tuple([length for length in self.view.shape[:self.view.ndim]])             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim);
  for (__pyx_t_4 = __pyx_v_self->view.shape; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) {
    __pyx_t_2 = __pyx_t_4;
    __pyx_v_length = (__pyx_t_2[0]);
    __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(4, 564, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __pyx_t_5 = PyList_AsTuple(((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":563
 * 
 *     @property
 *     def shape(self):             # <<<<<<<<<<<<<<
 *         return tuple([length for length in self.view.shape[:self.view.ndim]])
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.memoryview.shape.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":567
 * 
 *     @property
 *     def strides(self):             # <<<<<<<<<<<<<<
 *         if self.view.strides == NULL:
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  Py_ssize_t __pyx_v_stride;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t *__pyx_t_3;
  Py_ssize_t *__pyx_t_4;
  Py_ssize_t *__pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "View.MemoryView":568
 *     @property
 *     def strides(self):
 *         if self.view.strides == NULL:             # <<<<<<<<<<<<<<
 * 
 *             raise ValueError("Buffer view does not expose strides")
 */
  __pyx_t_1 = ((__pyx_v_self->view.strides == NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "View.MemoryView":570
 *         if self.view.strides == NULL:
 * 
 *             raise ValueError("Buffer view does not expose strides")             # <<<<<<<<<<<<<<
 * 
 *         return tuple([stride for stride in self.view.strides[:self.view.ndim]])
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__57, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 570, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(4, 570, __pyx_L1_error)

    /* "View.MemoryView":568
 *     @property
 *     def strides(self):
 *         if self.view.strides == NULL:             # <<<<<<<<<<<<<<
 * 
 *             raise ValueError("Buffer view does not expose strides")
 */
  }

  /* "View.MemoryView":572
 *             raise ValueError("Buffer view does not expose strides")
 * 
 *         return tuple([stride for stride in self.view.strides[:self.view.ndim]])             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 572, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = (__pyx_v_self->view.strides + __pyx_v_self->view.ndim);
  for (__pyx_t_5 = __pyx_v_self->view.strides; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) {
    __pyx_t_3 = __pyx_t_5;
    __pyx_v_stride = (__pyx_t_3[0]);
    __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_stride); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_6))) __PYX_ERR(4, 572, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __pyx_t_6 = PyList_AsTuple(((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 572, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":567
 * 
 *     @property
 *     def strides(self):             # <<<<<<<<<<<<<<
 *         if self.view.strides == NULL:
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("View.MemoryView.memoryview.strides.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":575
 * 
 *     @property
 *     def suboffsets(self):             # <<<<<<<<<<<<<<
 *         if self.view.suboffsets == NULL:
 *             return (-1,) * self.view.ndim
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  Py_ssize_t __pyx_v_suboffset;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t *__pyx_t_4;
  Py_ssize_t *__pyx_t_5;
  Py_ssize_t *__pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "View.MemoryView":576
 *     @property
 *     def suboffsets(self):
 *         if self.view.suboffsets == NULL:             # <<<<<<<<<<<<<<
 *             return (-1,) * self.view.ndim
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->view.suboffsets == NULL) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":577
 *     def suboffsets(self):
 *         if self.view.suboffsets == NULL:
 *             return (-1,) * self.view.ndim             # <<<<<<<<<<<<<<
 * 
 *         return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]])
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 577, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyNumber_Multiply(__pyx_tuple__58, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 577, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "View.MemoryView":576
 *     @property
 *     def suboffsets(self):
 *         if self.view.suboffsets == NULL:             # <<<<<<<<<<<<<<
 *             return (-1,) * self.view.ndim
 * 
 */
  }

  /* "View.MemoryView":579
 *             return (-1,) * self.view.ndim
 * 
 *         return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]])             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = (__pyx_v_self->view.suboffsets + __pyx_v_self->view.ndim);
  for (__pyx_t_6 = __pyx_v_self->view.suboffsets; __pyx_t_6 < __pyx_t_5; __pyx_t_6++) {
    __pyx_t_4 = __pyx_t_6;
    __pyx_v_suboffset = (__pyx_t_4[0]);
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_suboffset); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 579, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_2))) __PYX_ERR(4, 579, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_t_2 = PyList_AsTuple(((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":575
 * 
 *     @property
 *     def suboffsets(self):             # <<<<<<<<<<<<<<
 *         if self.view.suboffsets == NULL:
 *             return (-1,) * self.view.ndim
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview.suboffsets.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":582
 * 
 *     @property
 *     def ndim(self):             # <<<<<<<<<<<<<<
 *         return self.view.ndim
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__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_RefNannySetupContext("__get__", 0);

  /* "View.MemoryView":583
 *     @property
 *     def ndim(self):
 *         return self.view.ndim             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 583, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":582
 * 
 *     @property
 *     def ndim(self):             # <<<<<<<<<<<<<<
 *         return self.view.ndim
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.memoryview.ndim.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":586
 * 
 *     @property
 *     def itemsize(self):             # <<<<<<<<<<<<<<
 *         return self.view.itemsize
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__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_RefNannySetupContext("__get__", 0);

  /* "View.MemoryView":587
 *     @property
 *     def itemsize(self):
 *         return self.view.itemsize             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":586
 * 
 *     @property
 *     def itemsize(self):             # <<<<<<<<<<<<<<
 *         return self.view.itemsize
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.memoryview.itemsize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":590
 * 
 *     @property
 *     def nbytes(self):             # <<<<<<<<<<<<<<
 *         return self.size * self.view.itemsize
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "View.MemoryView":591
 *     @property
 *     def nbytes(self):
 *         return self.size * self.view.itemsize             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":590
 * 
 *     @property
 *     def nbytes(self):             # <<<<<<<<<<<<<<
 *         return self.size * self.view.itemsize
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview.nbytes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":594
 * 
 *     @property
 *     def size(self):             # <<<<<<<<<<<<<<
 *         if self._size is None:
 *             result = 1
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_length = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  Py_ssize_t *__pyx_t_3;
  Py_ssize_t *__pyx_t_4;
  Py_ssize_t *__pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "View.MemoryView":595
 *     @property
 *     def size(self):
 *         if self._size is None:             # <<<<<<<<<<<<<<
 *             result = 1
 * 
 */
  __pyx_t_1 = (__pyx_v_self->_size == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":596
 *     def size(self):
 *         if self._size is None:
 *             result = 1             # <<<<<<<<<<<<<<
 * 
 *             for length in self.view.shape[:self.view.ndim]:
 */
    __Pyx_INCREF(__pyx_int_1);
    __pyx_v_result = __pyx_int_1;

    /* "View.MemoryView":598
 *             result = 1
 * 
 *             for length in self.view.shape[:self.view.ndim]:             # <<<<<<<<<<<<<<
 *                 result *= length
 * 
 */
    __pyx_t_4 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim);
    for (__pyx_t_5 = __pyx_v_self->view.shape; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) {
      __pyx_t_3 = __pyx_t_5;
      __pyx_t_6 = PyInt_FromSsize_t((__pyx_t_3[0])); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 598, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "View.MemoryView":599
 * 
 *             for length in self.view.shape[:self.view.ndim]:
 *                 result *= length             # <<<<<<<<<<<<<<
 * 
 *             self._size = result
 */
      __pyx_t_6 = PyNumber_InPlaceMultiply(__pyx_v_result, __pyx_v_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 599, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF_SET(__pyx_v_result, __pyx_t_6);
      __pyx_t_6 = 0;
    }

    /* "View.MemoryView":601
 *                 result *= length
 * 
 *             self._size = result             # <<<<<<<<<<<<<<
 * 
 *         return self._size
 */
    __Pyx_INCREF(__pyx_v_result);
    __Pyx_GIVEREF(__pyx_v_result);
    __Pyx_GOTREF(__pyx_v_self->_size);
    __Pyx_DECREF(__pyx_v_self->_size);
    __pyx_v_self->_size = __pyx_v_result;

    /* "View.MemoryView":595
 *     @property
 *     def size(self):
 *         if self._size is None:             # <<<<<<<<<<<<<<
 *             result = 1
 * 
 */
  }

  /* "View.MemoryView":603
 *             self._size = result
 * 
 *         return self._size             # <<<<<<<<<<<<<<
 * 
 *     def __len__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_size);
  __pyx_r = __pyx_v_self->_size;
  goto __pyx_L0;

  /* "View.MemoryView":594
 * 
 *     @property
 *     def size(self):             # <<<<<<<<<<<<<<
 *         if self._size is None:
 *             result = 1
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("View.MemoryView.memoryview.size.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_length);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":605
 *         return self._size
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         if self.view.ndim >= 1:
 *             return self.view.shape[0]
 */

/* Python wrapper */
static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static Py_ssize_t __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__len__", 0);

  /* "View.MemoryView":606
 * 
 *     def __len__(self):
 *         if self.view.ndim >= 1:             # <<<<<<<<<<<<<<
 *             return self.view.shape[0]
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->view.ndim >= 1) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":607
 *     def __len__(self):
 *         if self.view.ndim >= 1:
 *             return self.view.shape[0]             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
    __pyx_r = (__pyx_v_self->view.shape[0]);
    goto __pyx_L0;

    /* "View.MemoryView":606
 * 
 *     def __len__(self):
 *         if self.view.ndim >= 1:             # <<<<<<<<<<<<<<
 *             return self.view.shape[0]
 * 
 */
  }

  /* "View.MemoryView":609
 *             return self.view.shape[0]
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     def __repr__(self):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "View.MemoryView":605
 *         return self._size
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         if self.view.ndim >= 1:
 *             return self.view.shape[0]
 */

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

/* "View.MemoryView":611
 *         return 0
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return "<MemoryView of %r at 0x%x>" % (self.base.__class__.__name__,
 *                                                id(self))
 */

/* Python wrapper */
static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__repr__", 0);

  /* "View.MemoryView":612
 * 
 *     def __repr__(self):
 *         return "<MemoryView of %r at 0x%x>" % (self.base.__class__.__name__,             # <<<<<<<<<<<<<<
 *                                                id(self))
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "View.MemoryView":613
 *     def __repr__(self):
 *         return "<MemoryView of %r at 0x%x>" % (self.base.__class__.__name__,
 *                                                id(self))             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "View.MemoryView":612
 * 
 *     def __repr__(self):
 *         return "<MemoryView of %r at 0x%x>" % (self.base.__class__.__name__,             # <<<<<<<<<<<<<<
 *                                                id(self))
 * 
 */
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":611
 *         return 0
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return "<MemoryView of %r at 0x%x>" % (self.base.__class__.__name__,
 *                                                id(self))
 */

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

/* "View.MemoryView":615
 *                                                id(self))
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "<MemoryView of %r object>" % (self.base.__class__.__name__,)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__str__", 0);

  /* "View.MemoryView":616
 * 
 *     def __str__(self):
 *         return "<MemoryView of %r object>" % (self.base.__class__.__name__,)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_object, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":615
 *                                                id(self))
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "<MemoryView of %r object>" % (self.base.__class__.__name__,)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":619
 * 
 * 
 *     def is_c_contig(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice *mslice
 *         cdef __Pyx_memviewslice tmp
 */

/* Python wrapper */
static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_c_contig (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self) {
  __Pyx_memviewslice *__pyx_v_mslice;
  __Pyx_memviewslice __pyx_v_tmp;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("is_c_contig", 0);

  /* "View.MemoryView":622
 *         cdef __Pyx_memviewslice *mslice
 *         cdef __Pyx_memviewslice tmp
 *         mslice = get_slice_from_memview(self, &tmp)             # <<<<<<<<<<<<<<
 *         return slice_is_contig(mslice[0], 'C', self.view.ndim)
 * 
 */
  __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(4, 622, __pyx_L1_error)
  __pyx_v_mslice = __pyx_t_1;

  /* "View.MemoryView":623
 *         cdef __Pyx_memviewslice tmp
 *         mslice = get_slice_from_memview(self, &tmp)
 *         return slice_is_contig(mslice[0], 'C', self.view.ndim)             # <<<<<<<<<<<<<<
 * 
 *     def is_f_contig(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'C', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":619
 * 
 * 
 *     def is_c_contig(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice *mslice
 *         cdef __Pyx_memviewslice tmp
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.memoryview.is_c_contig", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":625
 *         return slice_is_contig(mslice[0], 'C', self.view.ndim)
 * 
 *     def is_f_contig(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice *mslice
 *         cdef __Pyx_memviewslice tmp
 */

/* Python wrapper */
static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_f_contig (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self) {
  __Pyx_memviewslice *__pyx_v_mslice;
  __Pyx_memviewslice __pyx_v_tmp;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("is_f_contig", 0);

  /* "View.MemoryView":628
 *         cdef __Pyx_memviewslice *mslice
 *         cdef __Pyx_memviewslice tmp
 *         mslice = get_slice_from_memview(self, &tmp)             # <<<<<<<<<<<<<<
 *         return slice_is_contig(mslice[0], 'F', self.view.ndim)
 * 
 */
  __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(4, 628, __pyx_L1_error)
  __pyx_v_mslice = __pyx_t_1;

  /* "View.MemoryView":629
 *         cdef __Pyx_memviewslice tmp
 *         mslice = get_slice_from_memview(self, &tmp)
 *         return slice_is_contig(mslice[0], 'F', self.view.ndim)             # <<<<<<<<<<<<<<
 * 
 *     def copy(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'F', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 629, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":625
 *         return slice_is_contig(mslice[0], 'C', self.view.ndim)
 * 
 *     def is_f_contig(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice *mslice
 *         cdef __Pyx_memviewslice tmp
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.memoryview.is_f_contig", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":631
 *         return slice_is_contig(mslice[0], 'F', self.view.ndim)
 * 
 *     def copy(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice mslice
 *         cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS
 */

/* Python wrapper */
static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("copy (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_mslice;
  int __pyx_v_flags;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("copy", 0);

  /* "View.MemoryView":633
 *     def copy(self):
 *         cdef __Pyx_memviewslice mslice
 *         cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS             # <<<<<<<<<<<<<<
 * 
 *         slice_copy(self, &mslice)
 */
  __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_F_CONTIGUOUS));

  /* "View.MemoryView":635
 *         cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS
 * 
 *         slice_copy(self, &mslice)             # <<<<<<<<<<<<<<
 *         mslice = slice_copy_contig(&mslice, "c", self.view.ndim,
 *                                    self.view.itemsize,
 */
  __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_mslice));

  /* "View.MemoryView":636
 * 
 *         slice_copy(self, &mslice)
 *         mslice = slice_copy_contig(&mslice, "c", self.view.ndim,             # <<<<<<<<<<<<<<
 *                                    self.view.itemsize,
 *                                    flags|PyBUF_C_CONTIGUOUS,
 */
  __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_mslice), ((char *)"c"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_C_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(4, 636, __pyx_L1_error)
  __pyx_v_mslice = __pyx_t_1;

  /* "View.MemoryView":641
 *                                    self.dtype_is_object)
 * 
 *         return memoryview_copy_from_slice(self, &mslice)             # <<<<<<<<<<<<<<
 * 
 *     def copy_fortran(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_mslice)); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 641, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":631
 *         return slice_is_contig(mslice[0], 'F', self.view.ndim)
 * 
 *     def copy(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice mslice
 *         cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.memoryview.copy", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":643
 *         return memoryview_copy_from_slice(self, &mslice)
 * 
 *     def copy_fortran(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice src, dst
 *         cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS
 */

/* Python wrapper */
static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("copy_fortran (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_src;
  __Pyx_memviewslice __pyx_v_dst;
  int __pyx_v_flags;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("copy_fortran", 0);

  /* "View.MemoryView":645
 *     def copy_fortran(self):
 *         cdef __Pyx_memviewslice src, dst
 *         cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS             # <<<<<<<<<<<<<<
 * 
 *         slice_copy(self, &src)
 */
  __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_C_CONTIGUOUS));

  /* "View.MemoryView":647
 *         cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS
 * 
 *         slice_copy(self, &src)             # <<<<<<<<<<<<<<
 *         dst = slice_copy_contig(&src, "fortran", self.view.ndim,
 *                                 self.view.itemsize,
 */
  __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_src));

  /* "View.MemoryView":648
 * 
 *         slice_copy(self, &src)
 *         dst = slice_copy_contig(&src, "fortran", self.view.ndim,             # <<<<<<<<<<<<<<
 *                                 self.view.itemsize,
 *                                 flags|PyBUF_F_CONTIGUOUS,
 */
  __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_src), ((char *)"fortran"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_F_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(4, 648, __pyx_L1_error)
  __pyx_v_dst = __pyx_t_1;

  /* "View.MemoryView":653
 *                                 self.dtype_is_object)
 * 
 *         return memoryview_copy_from_slice(self, &dst)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_dst)); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":643
 *         return memoryview_copy_from_slice(self, &mslice)
 * 
 *     def copy_fortran(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice src, dst
 *         cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.memoryview.copy_fortran", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

/* Python wrapper */
static PyObject *__pyx_pw___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_memoryview___reduce_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__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_RefNannySetupContext("__reduce_cython__", 0);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__59, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(4, 2, __pyx_L1_error)

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

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

/* Python wrapper */
static PyObject *__pyx_pw___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static PyObject *__pyx_pw___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_memoryview_2__setstate_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__60, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(4, 4, __pyx_L1_error)

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

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":657
 * 
 * @cname('__pyx_memoryview_new')
 * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):             # <<<<<<<<<<<<<<
 *     cdef memoryview result = memoryview(o, flags, dtype_is_object)
 *     result.typeinfo = typeinfo
 */

static PyObject *__pyx_memoryview_new(PyObject *__pyx_v_o, int __pyx_v_flags, int __pyx_v_dtype_is_object, __Pyx_TypeInfo *__pyx_v_typeinfo) {
  struct __pyx_memoryview_obj *__pyx_v_result = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("memoryview_cwrapper", 0);

  /* "View.MemoryView":658
 * @cname('__pyx_memoryview_new')
 * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):
 *     cdef memoryview result = memoryview(o, flags, dtype_is_object)             # <<<<<<<<<<<<<<
 *     result.typeinfo = typeinfo
 *     return result
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_o);
  __Pyx_GIVEREF(__pyx_v_o);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_o);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_result = ((struct __pyx_memoryview_obj *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":659
 * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):
 *     cdef memoryview result = memoryview(o, flags, dtype_is_object)
 *     result.typeinfo = typeinfo             # <<<<<<<<<<<<<<
 *     return result
 * 
 */
  __pyx_v_result->typeinfo = __pyx_v_typeinfo;

  /* "View.MemoryView":660
 *     cdef memoryview result = memoryview(o, flags, dtype_is_object)
 *     result.typeinfo = typeinfo
 *     return result             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_check')
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__pyx_v_result);
  goto __pyx_L0;

  /* "View.MemoryView":657
 * 
 * @cname('__pyx_memoryview_new')
 * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):             # <<<<<<<<<<<<<<
 *     cdef memoryview result = memoryview(o, flags, dtype_is_object)
 *     result.typeinfo = typeinfo
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":663
 * 
 * @cname('__pyx_memoryview_check')
 * cdef inline bint memoryview_check(object o):             # <<<<<<<<<<<<<<
 *     return isinstance(o, memoryview)
 * 
 */

static CYTHON_INLINE int __pyx_memoryview_check(PyObject *__pyx_v_o) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("memoryview_check", 0);

  /* "View.MemoryView":664
 * @cname('__pyx_memoryview_check')
 * cdef inline bint memoryview_check(object o):
 *     return isinstance(o, memoryview)             # <<<<<<<<<<<<<<
 * 
 * cdef tuple _unellipsify(object index, int ndim):
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_o, __pyx_memoryview_type); 
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "View.MemoryView":663
 * 
 * @cname('__pyx_memoryview_check')
 * cdef inline bint memoryview_check(object o):             # <<<<<<<<<<<<<<
 *     return isinstance(o, memoryview)
 * 
 */

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

/* "View.MemoryView":666
 *     return isinstance(o, memoryview)
 * 
 * cdef tuple _unellipsify(object index, int ndim):             # <<<<<<<<<<<<<<
 *     """
 *     Replace all ellipses with full slices and fill incomplete indices with
 */

static PyObject *_unellipsify(PyObject *__pyx_v_index, int __pyx_v_ndim) {
  PyObject *__pyx_v_tup = NULL;
  PyObject *__pyx_v_result = NULL;
  int __pyx_v_have_slices;
  int __pyx_v_seen_ellipsis;
  CYTHON_UNUSED PyObject *__pyx_v_idx = NULL;
  PyObject *__pyx_v_item = NULL;
  Py_ssize_t __pyx_v_nslices;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  Py_ssize_t __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_unellipsify", 0);

  /* "View.MemoryView":671
 *     full slices.
 *     """
 *     if not isinstance(index, tuple):             # <<<<<<<<<<<<<<
 *         tup = (index,)
 *     else:
 */
  __pyx_t_1 = PyTuple_Check(__pyx_v_index); 
  __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":672
 *     """
 *     if not isinstance(index, tuple):
 *         tup = (index,)             # <<<<<<<<<<<<<<
 *     else:
 *         tup = index
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_index);
    __Pyx_GIVEREF(__pyx_v_index);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_index);
    __pyx_v_tup = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "View.MemoryView":671
 *     full slices.
 *     """
 *     if not isinstance(index, tuple):             # <<<<<<<<<<<<<<
 *         tup = (index,)
 *     else:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":674
 *         tup = (index,)
 *     else:
 *         tup = index             # <<<<<<<<<<<<<<
 * 
 *     result = []
 */
  /*else*/ {
    __Pyx_INCREF(__pyx_v_index);
    __pyx_v_tup = __pyx_v_index;
  }
  __pyx_L3:;

  /* "View.MemoryView":676
 *         tup = index
 * 
 *     result = []             # <<<<<<<<<<<<<<
 *     have_slices = False
 *     seen_ellipsis = False
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 676, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "View.MemoryView":677
 * 
 *     result = []
 *     have_slices = False             # <<<<<<<<<<<<<<
 *     seen_ellipsis = False
 *     for idx, item in enumerate(tup):
 */
  __pyx_v_have_slices = 0;

  /* "View.MemoryView":678
 *     result = []
 *     have_slices = False
 *     seen_ellipsis = False             # <<<<<<<<<<<<<<
 *     for idx, item in enumerate(tup):
 *         if item is Ellipsis:
 */
  __pyx_v_seen_ellipsis = 0;

  /* "View.MemoryView":679
 *     have_slices = False
 *     seen_ellipsis = False
 *     for idx, item in enumerate(tup):             # <<<<<<<<<<<<<<
 *         if item is Ellipsis:
 *             if not seen_ellipsis:
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_t_3 = __pyx_int_0;
  if (likely(PyList_CheckExact(__pyx_v_tup)) || PyTuple_CheckExact(__pyx_v_tup)) {
    __pyx_t_4 = __pyx_v_tup; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_tup); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 679, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 679, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(4, 679, __pyx_L1_error)
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(4, 679, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(4, 679, __pyx_L1_error)
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(4, 679, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(4, 679, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_3);
    __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(4, 679, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3);
    __pyx_t_3 = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "View.MemoryView":680
 *     seen_ellipsis = False
 *     for idx, item in enumerate(tup):
 *         if item is Ellipsis:             # <<<<<<<<<<<<<<
 *             if not seen_ellipsis:
 *                 result.extend([slice(None)] * (ndim - len(tup) + 1))
 */
    __pyx_t_2 = (__pyx_v_item == __pyx_builtin_Ellipsis);
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":681
 *     for idx, item in enumerate(tup):
 *         if item is Ellipsis:
 *             if not seen_ellipsis:             # <<<<<<<<<<<<<<
 *                 result.extend([slice(None)] * (ndim - len(tup) + 1))
 *                 seen_ellipsis = True
 */
      __pyx_t_1 = ((!(__pyx_v_seen_ellipsis != 0)) != 0);
      if (__pyx_t_1) {

        /* "View.MemoryView":682
 *         if item is Ellipsis:
 *             if not seen_ellipsis:
 *                 result.extend([slice(None)] * (ndim - len(tup) + 1))             # <<<<<<<<<<<<<<
 *                 seen_ellipsis = True
 *             else:
 */
        __pyx_t_8 = PyObject_Length(__pyx_v_tup); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(4, 682, __pyx_L1_error)
        __pyx_t_7 = PyList_New(1 * ((((__pyx_v_ndim - __pyx_t_8) + 1)<0) ? 0:((__pyx_v_ndim - __pyx_t_8) + 1))); if (unlikely(!__pyx_t_7)) __PYX_ERR(4, 682, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        { Py_ssize_t __pyx_temp;
          for (__pyx_temp=0; __pyx_temp < ((__pyx_v_ndim - __pyx_t_8) + 1); __pyx_temp++) {
            __Pyx_INCREF(__pyx_slice__40);
            __Pyx_GIVEREF(__pyx_slice__40);
            PyList_SET_ITEM(__pyx_t_7, __pyx_temp, __pyx_slice__40);
          }
        }
        __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(4, 682, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "View.MemoryView":683
 *             if not seen_ellipsis:
 *                 result.extend([slice(None)] * (ndim - len(tup) + 1))
 *                 seen_ellipsis = True             # <<<<<<<<<<<<<<
 *             else:
 *                 result.append(slice(None))
 */
        __pyx_v_seen_ellipsis = 1;

        /* "View.MemoryView":681
 *     for idx, item in enumerate(tup):
 *         if item is Ellipsis:
 *             if not seen_ellipsis:             # <<<<<<<<<<<<<<
 *                 result.extend([slice(None)] * (ndim - len(tup) + 1))
 *                 seen_ellipsis = True
 */
        goto __pyx_L7;
      }

      /* "View.MemoryView":685
 *                 seen_ellipsis = True
 *             else:
 *                 result.append(slice(None))             # <<<<<<<<<<<<<<
 *             have_slices = True
 *         else:
 */
      /*else*/ {
        __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_slice__40); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(4, 685, __pyx_L1_error)
      }
      __pyx_L7:;

      /* "View.MemoryView":686
 *             else:
 *                 result.append(slice(None))
 *             have_slices = True             # <<<<<<<<<<<<<<
 *         else:
 *             if not isinstance(item, slice) and not PyIndex_Check(item):
 */
      __pyx_v_have_slices = 1;

      /* "View.MemoryView":680
 *     seen_ellipsis = False
 *     for idx, item in enumerate(tup):
 *         if item is Ellipsis:             # <<<<<<<<<<<<<<
 *             if not seen_ellipsis:
 *                 result.extend([slice(None)] * (ndim - len(tup) + 1))
 */
      goto __pyx_L6;
    }

    /* "View.MemoryView":688
 *             have_slices = True
 *         else:
 *             if not isinstance(item, slice) and not PyIndex_Check(item):             # <<<<<<<<<<<<<<
 *                 raise TypeError("Cannot index with type '%s'" % type(item))
 * 
 */
    /*else*/ {
      __pyx_t_2 = PySlice_Check(__pyx_v_item); 
      __pyx_t_10 = ((!(__pyx_t_2 != 0)) != 0);
      if (__pyx_t_10) {
      } else {
        __pyx_t_1 = __pyx_t_10;
        goto __pyx_L9_bool_binop_done;
      }
      __pyx_t_10 = ((!(PyIndex_Check(__pyx_v_item) != 0)) != 0);
      __pyx_t_1 = __pyx_t_10;
      __pyx_L9_bool_binop_done:;
      if (unlikely(__pyx_t_1)) {

        /* "View.MemoryView":689
 *         else:
 *             if not isinstance(item, slice) and not PyIndex_Check(item):
 *                 raise TypeError("Cannot index with type '%s'" % type(item))             # <<<<<<<<<<<<<<
 * 
 *             have_slices = have_slices or isinstance(item, slice)
 */
        __pyx_t_7 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Cannot_index_with_type_s, ((PyObject *)Py_TYPE(__pyx_v_item))); if (unlikely(!__pyx_t_7)) __PYX_ERR(4, 689, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(4, 689, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_Raise(__pyx_t_11, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __PYX_ERR(4, 689, __pyx_L1_error)

        /* "View.MemoryView":688
 *             have_slices = True
 *         else:
 *             if not isinstance(item, slice) and not PyIndex_Check(item):             # <<<<<<<<<<<<<<
 *                 raise TypeError("Cannot index with type '%s'" % type(item))
 * 
 */
      }

      /* "View.MemoryView":691
 *                 raise TypeError("Cannot index with type '%s'" % type(item))
 * 
 *             have_slices = have_slices or isinstance(item, slice)             # <<<<<<<<<<<<<<
 *             result.append(item)
 * 
 */
      __pyx_t_10 = (__pyx_v_have_slices != 0);
      if (!__pyx_t_10) {
      } else {
        __pyx_t_1 = __pyx_t_10;
        goto __pyx_L11_bool_binop_done;
      }
      __pyx_t_10 = PySlice_Check(__pyx_v_item); 
      __pyx_t_2 = (__pyx_t_10 != 0);
      __pyx_t_1 = __pyx_t_2;
      __pyx_L11_bool_binop_done:;
      __pyx_v_have_slices = __pyx_t_1;

      /* "View.MemoryView":692
 * 
 *             have_slices = have_slices or isinstance(item, slice)
 *             result.append(item)             # <<<<<<<<<<<<<<
 * 
 *     nslices = ndim - len(result)
 */
      __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_v_item); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(4, 692, __pyx_L1_error)
    }
    __pyx_L6:;

    /* "View.MemoryView":679
 *     have_slices = False
 *     seen_ellipsis = False
 *     for idx, item in enumerate(tup):             # <<<<<<<<<<<<<<
 *         if item is Ellipsis:
 *             if not seen_ellipsis:
 */
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "View.MemoryView":694
 *             result.append(item)
 * 
 *     nslices = ndim - len(result)             # <<<<<<<<<<<<<<
 *     if nslices:
 *         result.extend([slice(None)] * nslices)
 */
  __pyx_t_5 = PyList_GET_SIZE(__pyx_v_result); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(4, 694, __pyx_L1_error)
  __pyx_v_nslices = (__pyx_v_ndim - __pyx_t_5);

  /* "View.MemoryView":695
 * 
 *     nslices = ndim - len(result)
 *     if nslices:             # <<<<<<<<<<<<<<
 *         result.extend([slice(None)] * nslices)
 * 
 */
  __pyx_t_1 = (__pyx_v_nslices != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":696
 *     nslices = ndim - len(result)
 *     if nslices:
 *         result.extend([slice(None)] * nslices)             # <<<<<<<<<<<<<<
 * 
 *     return have_slices or nslices, tuple(result)
 */
    __pyx_t_3 = PyList_New(1 * ((__pyx_v_nslices<0) ? 0:__pyx_v_nslices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 696, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    { Py_ssize_t __pyx_temp;
      for (__pyx_temp=0; __pyx_temp < __pyx_v_nslices; __pyx_temp++) {
        __Pyx_INCREF(__pyx_slice__40);
        __Pyx_GIVEREF(__pyx_slice__40);
        PyList_SET_ITEM(__pyx_t_3, __pyx_temp, __pyx_slice__40);
      }
    }
    __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(4, 696, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "View.MemoryView":695
 * 
 *     nslices = ndim - len(result)
 *     if nslices:             # <<<<<<<<<<<<<<
 *         result.extend([slice(None)] * nslices)
 * 
 */
  }

  /* "View.MemoryView":698
 *         result.extend([slice(None)] * nslices)
 * 
 *     return have_slices or nslices, tuple(result)             # <<<<<<<<<<<<<<
 * 
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
 */
  __Pyx_XDECREF(__pyx_r);
  if (!__pyx_v_have_slices) {
  } else {
    __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_have_slices); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 698, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L14_bool_binop_done;
  }
  __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_nslices); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_L14_bool_binop_done:;
  __pyx_t_4 = PyList_AsTuple(__pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(4, 698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_4);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_r = ((PyObject*)__pyx_t_11);
  __pyx_t_11 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":666
 *     return isinstance(o, memoryview)
 * 
 * cdef tuple _unellipsify(object index, int ndim):             # <<<<<<<<<<<<<<
 *     """
 *     Replace all ellipses with full slices and fill incomplete indices with
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("View.MemoryView._unellipsify", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_tup);
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_idx);
  __Pyx_XDECREF(__pyx_v_item);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":700
 *     return have_slices or nslices, tuple(result)
 * 
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):             # <<<<<<<<<<<<<<
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:
 */

static PyObject *assert_direct_dimensions(Py_ssize_t *__pyx_v_suboffsets, int __pyx_v_ndim) {
  Py_ssize_t __pyx_v_suboffset;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t *__pyx_t_1;
  Py_ssize_t *__pyx_t_2;
  Py_ssize_t *__pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("assert_direct_dimensions", 0);

  /* "View.MemoryView":701
 * 
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
 *     for suboffset in suboffsets[:ndim]:             # <<<<<<<<<<<<<<
 *         if suboffset >= 0:
 *             raise ValueError("Indirect dimensions not supported")
 */
  __pyx_t_2 = (__pyx_v_suboffsets + __pyx_v_ndim);
  for (__pyx_t_3 = __pyx_v_suboffsets; __pyx_t_3 < __pyx_t_2; __pyx_t_3++) {
    __pyx_t_1 = __pyx_t_3;
    __pyx_v_suboffset = (__pyx_t_1[0]);

    /* "View.MemoryView":702
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("Indirect dimensions not supported")
 * 
 */
    __pyx_t_4 = ((__pyx_v_suboffset >= 0) != 0);
    if (unlikely(__pyx_t_4)) {

      /* "View.MemoryView":703
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:
 *             raise ValueError("Indirect dimensions not supported")             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__61, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 703, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(4, 703, __pyx_L1_error)

      /* "View.MemoryView":702
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("Indirect dimensions not supported")
 * 
 */
    }
  }

  /* "View.MemoryView":700
 *     return have_slices or nslices, tuple(result)
 * 
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):             # <<<<<<<<<<<<<<
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.assert_direct_dimensions", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":710
 * 
 * @cname('__pyx_memview_slice')
 * cdef memoryview memview_slice(memoryview memview, object indices):             # <<<<<<<<<<<<<<
 *     cdef int new_ndim = 0, suboffset_dim = -1, dim
 *     cdef bint negative_step
 */

static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *__pyx_v_memview, PyObject *__pyx_v_indices) {
  int __pyx_v_new_ndim;
  int __pyx_v_suboffset_dim;
  int __pyx_v_dim;
  __Pyx_memviewslice __pyx_v_src;
  __Pyx_memviewslice __pyx_v_dst;
  __Pyx_memviewslice *__pyx_v_p_src;
  struct __pyx_memoryviewslice_obj *__pyx_v_memviewsliceobj = 0;
  __Pyx_memviewslice *__pyx_v_p_dst;
  int *__pyx_v_p_suboffset_dim;
  Py_ssize_t __pyx_v_start;
  Py_ssize_t __pyx_v_stop;
  Py_ssize_t __pyx_v_step;
  int __pyx_v_have_start;
  int __pyx_v_have_stop;
  int __pyx_v_have_step;
  PyObject *__pyx_v_index = NULL;
  struct __pyx_memoryview_obj *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  struct __pyx_memoryview_obj *__pyx_t_4;
  char *__pyx_t_5;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  Py_ssize_t __pyx_t_10;
  int __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("memview_slice", 0);

  /* "View.MemoryView":711
 * @cname('__pyx_memview_slice')
 * cdef memoryview memview_slice(memoryview memview, object indices):
 *     cdef int new_ndim = 0, suboffset_dim = -1, dim             # <<<<<<<<<<<<<<
 *     cdef bint negative_step
 *     cdef __Pyx_memviewslice src, dst
 */
  __pyx_v_new_ndim = 0;
  __pyx_v_suboffset_dim = -1;

  /* "View.MemoryView":718
 * 
 * 
 *     memset(&dst, 0, sizeof(dst))             # <<<<<<<<<<<<<<
 * 
 *     cdef _memoryviewslice memviewsliceobj
 */
  (void)(memset((&__pyx_v_dst), 0, (sizeof(__pyx_v_dst))));

  /* "View.MemoryView":722
 *     cdef _memoryviewslice memviewsliceobj
 * 
 *     assert memview.view.ndim > 0             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(memview, _memoryviewslice):
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_memview->view.ndim > 0) != 0))) {
      PyErr_SetNone(PyExc_AssertionError);
      __PYX_ERR(4, 722, __pyx_L1_error)
    }
  }
  #endif

  /* "View.MemoryView":724
 *     assert memview.view.ndim > 0
 * 
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         memviewsliceobj = memview
 *         p_src = &memviewsliceobj.from_slice
 */
  __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":725
 * 
 *     if isinstance(memview, _memoryviewslice):
 *         memviewsliceobj = memview             # <<<<<<<<<<<<<<
 *         p_src = &memviewsliceobj.from_slice
 *     else:
 */
    if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(4, 725, __pyx_L1_error)
    __pyx_t_3 = ((PyObject *)__pyx_v_memview);
    __Pyx_INCREF(__pyx_t_3);
    __pyx_v_memviewsliceobj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "View.MemoryView":726
 *     if isinstance(memview, _memoryviewslice):
 *         memviewsliceobj = memview
 *         p_src = &memviewsliceobj.from_slice             # <<<<<<<<<<<<<<
 *     else:
 *         slice_copy(memview, &src)
 */
    __pyx_v_p_src = (&__pyx_v_memviewsliceobj->from_slice);

    /* "View.MemoryView":724
 *     assert memview.view.ndim > 0
 * 
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         memviewsliceobj = memview
 *         p_src = &memviewsliceobj.from_slice
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":728
 *         p_src = &memviewsliceobj.from_slice
 *     else:
 *         slice_copy(memview, &src)             # <<<<<<<<<<<<<<
 *         p_src = &src
 * 
 */
  /*else*/ {
    __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_src));

    /* "View.MemoryView":729
 *     else:
 *         slice_copy(memview, &src)
 *         p_src = &src             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_v_p_src = (&__pyx_v_src);
  }
  __pyx_L3:;

  /* "View.MemoryView":735
 * 
 * 
 *     dst.memview = p_src.memview             # <<<<<<<<<<<<<<
 *     dst.data = p_src.data
 * 
 */
  __pyx_t_4 = __pyx_v_p_src->memview;
  __pyx_v_dst.memview = __pyx_t_4;

  /* "View.MemoryView":736
 * 
 *     dst.memview = p_src.memview
 *     dst.data = p_src.data             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = __pyx_v_p_src->data;
  __pyx_v_dst.data = __pyx_t_5;

  /* "View.MemoryView":741
 * 
 * 
 *     cdef __Pyx_memviewslice *p_dst = &dst             # <<<<<<<<<<<<<<
 *     cdef int *p_suboffset_dim = &suboffset_dim
 *     cdef Py_ssize_t start, stop, step
 */
  __pyx_v_p_dst = (&__pyx_v_dst);

  /* "View.MemoryView":742
 * 
 *     cdef __Pyx_memviewslice *p_dst = &dst
 *     cdef int *p_suboffset_dim = &suboffset_dim             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t start, stop, step
 *     cdef bint have_start, have_stop, have_step
 */
  __pyx_v_p_suboffset_dim = (&__pyx_v_suboffset_dim);

  /* "View.MemoryView":746
 *     cdef bint have_start, have_stop, have_step
 * 
 *     for dim, index in enumerate(indices):             # <<<<<<<<<<<<<<
 *         if PyIndex_Check(index):
 *             slice_memviewslice(
 */
  __pyx_t_6 = 0;
  if (likely(PyList_CheckExact(__pyx_v_indices)) || PyTuple_CheckExact(__pyx_v_indices)) {
    __pyx_t_3 = __pyx_v_indices; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0;
    __pyx_t_8 = NULL;
  } else {
    __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_indices); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 746, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(4, 746, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_8)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(4, 746, __pyx_L1_error)
        #else
        __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 746, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
      } else {
        if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(4, 746, __pyx_L1_error)
        #else
        __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 746, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
      }
    } else {
      __pyx_t_9 = __pyx_t_8(__pyx_t_3);
      if (unlikely(!__pyx_t_9)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(4, 746, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_9);
    }
    __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_v_dim = __pyx_t_6;
    __pyx_t_6 = (__pyx_t_6 + 1);

    /* "View.MemoryView":747
 * 
 *     for dim, index in enumerate(indices):
 *         if PyIndex_Check(index):             # <<<<<<<<<<<<<<
 *             slice_memviewslice(
 *                 p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
 */
    __pyx_t_2 = (PyIndex_Check(__pyx_v_index) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":751
 *                 p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
 *                 dim, new_ndim, p_suboffset_dim,
 *                 index, 0, 0, # start, stop, step             # <<<<<<<<<<<<<<
 *                 0, 0, 0, # have_{start,stop,step}
 *                 False)
 */
      __pyx_t_10 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_10 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(4, 751, __pyx_L1_error)

      /* "View.MemoryView":748
 *     for dim, index in enumerate(indices):
 *         if PyIndex_Check(index):
 *             slice_memviewslice(             # <<<<<<<<<<<<<<
 *                 p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
 *                 dim, new_ndim, p_suboffset_dim,
 */
      __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_t_10, 0, 0, 0, 0, 0, 0); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(4, 748, __pyx_L1_error)

      /* "View.MemoryView":747
 * 
 *     for dim, index in enumerate(indices):
 *         if PyIndex_Check(index):             # <<<<<<<<<<<<<<
 *             slice_memviewslice(
 *                 p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
 */
      goto __pyx_L6;
    }

    /* "View.MemoryView":754
 *                 0, 0, 0, # have_{start,stop,step}
 *                 False)
 *         elif index is None:             # <<<<<<<<<<<<<<
 *             p_dst.shape[new_ndim] = 1
 *             p_dst.strides[new_ndim] = 0
 */
    __pyx_t_2 = (__pyx_v_index == Py_None);
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":755
 *                 False)
 *         elif index is None:
 *             p_dst.shape[new_ndim] = 1             # <<<<<<<<<<<<<<
 *             p_dst.strides[new_ndim] = 0
 *             p_dst.suboffsets[new_ndim] = -1
 */
      (__pyx_v_p_dst->shape[__pyx_v_new_ndim]) = 1;

      /* "View.MemoryView":756
 *         elif index is None:
 *             p_dst.shape[new_ndim] = 1
 *             p_dst.strides[new_ndim] = 0             # <<<<<<<<<<<<<<
 *             p_dst.suboffsets[new_ndim] = -1
 *             new_ndim += 1
 */
      (__pyx_v_p_dst->strides[__pyx_v_new_ndim]) = 0;

      /* "View.MemoryView":757
 *             p_dst.shape[new_ndim] = 1
 *             p_dst.strides[new_ndim] = 0
 *             p_dst.suboffsets[new_ndim] = -1             # <<<<<<<<<<<<<<
 *             new_ndim += 1
 *         else:
 */
      (__pyx_v_p_dst->suboffsets[__pyx_v_new_ndim]) = -1L;

      /* "View.MemoryView":758
 *             p_dst.strides[new_ndim] = 0
 *             p_dst.suboffsets[new_ndim] = -1
 *             new_ndim += 1             # <<<<<<<<<<<<<<
 *         else:
 *             start = index.start or 0
 */
      __pyx_v_new_ndim = (__pyx_v_new_ndim + 1);

      /* "View.MemoryView":754
 *                 0, 0, 0, # have_{start,stop,step}
 *                 False)
 *         elif index is None:             # <<<<<<<<<<<<<<
 *             p_dst.shape[new_ndim] = 1
 *             p_dst.strides[new_ndim] = 0
 */
      goto __pyx_L6;
    }

    /* "View.MemoryView":760
 *             new_ndim += 1
 *         else:
 *             start = index.start or 0             # <<<<<<<<<<<<<<
 *             stop = index.stop or 0
 *             step = index.step or 0
 */
    /*else*/ {
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 760, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(4, 760, __pyx_L1_error)
      if (!__pyx_t_1) {
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else {
        __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(4, 760, __pyx_L1_error)
        __pyx_t_10 = __pyx_t_12;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L7_bool_binop_done;
      }
      __pyx_t_10 = 0;
      __pyx_L7_bool_binop_done:;
      __pyx_v_start = __pyx_t_10;

      /* "View.MemoryView":761
 *         else:
 *             start = index.start or 0
 *             stop = index.stop or 0             # <<<<<<<<<<<<<<
 *             step = index.step or 0
 * 
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 761, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(4, 761, __pyx_L1_error)
      if (!__pyx_t_1) {
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else {
        __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(4, 761, __pyx_L1_error)
        __pyx_t_10 = __pyx_t_12;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L9_bool_binop_done;
      }
      __pyx_t_10 = 0;
      __pyx_L9_bool_binop_done:;
      __pyx_v_stop = __pyx_t_10;

      /* "View.MemoryView":762
 *             start = index.start or 0
 *             stop = index.stop or 0
 *             step = index.step or 0             # <<<<<<<<<<<<<<
 * 
 *             have_start = index.start is not None
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 762, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(4, 762, __pyx_L1_error)
      if (!__pyx_t_1) {
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else {
        __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(4, 762, __pyx_L1_error)
        __pyx_t_10 = __pyx_t_12;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L11_bool_binop_done;
      }
      __pyx_t_10 = 0;
      __pyx_L11_bool_binop_done:;
      __pyx_v_step = __pyx_t_10;

      /* "View.MemoryView":764
 *             step = index.step or 0
 * 
 *             have_start = index.start is not None             # <<<<<<<<<<<<<<
 *             have_stop = index.stop is not None
 *             have_step = index.step is not None
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 764, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = (__pyx_t_9 != Py_None);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_have_start = __pyx_t_1;

      /* "View.MemoryView":765
 * 
 *             have_start = index.start is not None
 *             have_stop = index.stop is not None             # <<<<<<<<<<<<<<
 *             have_step = index.step is not None
 * 
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 765, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = (__pyx_t_9 != Py_None);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_have_stop = __pyx_t_1;

      /* "View.MemoryView":766
 *             have_start = index.start is not None
 *             have_stop = index.stop is not None
 *             have_step = index.step is not None             # <<<<<<<<<<<<<<
 * 
 *             slice_memviewslice(
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 766, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = (__pyx_t_9 != Py_None);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_have_step = __pyx_t_1;

      /* "View.MemoryView":768
 *             have_step = index.step is not None
 * 
 *             slice_memviewslice(             # <<<<<<<<<<<<<<
 *                 p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
 *                 dim, new_ndim, p_suboffset_dim,
 */
      __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_v_start, __pyx_v_stop, __pyx_v_step, __pyx_v_have_start, __pyx_v_have_stop, __pyx_v_have_step, 1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(4, 768, __pyx_L1_error)

      /* "View.MemoryView":774
 *                 have_start, have_stop, have_step,
 *                 True)
 *             new_ndim += 1             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(memview, _memoryviewslice):
 */
      __pyx_v_new_ndim = (__pyx_v_new_ndim + 1);
    }
    __pyx_L6:;

    /* "View.MemoryView":746
 *     cdef bint have_start, have_stop, have_step
 * 
 *     for dim, index in enumerate(indices):             # <<<<<<<<<<<<<<
 *         if PyIndex_Check(index):
 *             slice_memviewslice(
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "View.MemoryView":776
 *             new_ndim += 1
 * 
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         return memoryview_fromslice(dst, new_ndim,
 *                                     memviewsliceobj.to_object_func,
 */
  __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":777
 * 
 *     if isinstance(memview, _memoryviewslice):
 *         return memoryview_fromslice(dst, new_ndim,             # <<<<<<<<<<<<<<
 *                                     memviewsliceobj.to_object_func,
 *                                     memviewsliceobj.to_dtype_func,
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));

    /* "View.MemoryView":778
 *     if isinstance(memview, _memoryviewslice):
 *         return memoryview_fromslice(dst, new_ndim,
 *                                     memviewsliceobj.to_object_func,             # <<<<<<<<<<<<<<
 *                                     memviewsliceobj.to_dtype_func,
 *                                     memview.dtype_is_object)
 */
    if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(4, 778, __pyx_L1_error) }

    /* "View.MemoryView":779
 *         return memoryview_fromslice(dst, new_ndim,
 *                                     memviewsliceobj.to_object_func,
 *                                     memviewsliceobj.to_dtype_func,             # <<<<<<<<<<<<<<
 *                                     memview.dtype_is_object)
 *     else:
 */
    if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(4, 779, __pyx_L1_error) }

    /* "View.MemoryView":777
 * 
 *     if isinstance(memview, _memoryviewslice):
 *         return memoryview_fromslice(dst, new_ndim,             # <<<<<<<<<<<<<<
 *                                     memviewsliceobj.to_object_func,
 *                                     memviewsliceobj.to_dtype_func,
 */
    __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, __pyx_v_memviewsliceobj->to_object_func, __pyx_v_memviewsliceobj->to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 777, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(4, 777, __pyx_L1_error)
    __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "View.MemoryView":776
 *             new_ndim += 1
 * 
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         return memoryview_fromslice(dst, new_ndim,
 *                                     memviewsliceobj.to_object_func,
 */
  }

  /* "View.MemoryView":782
 *                                     memview.dtype_is_object)
 *     else:
 *         return memoryview_fromslice(dst, new_ndim, NULL, NULL,             # <<<<<<<<<<<<<<
 *                                     memview.dtype_is_object)
 * 
 */
  /*else*/ {
    __Pyx_XDECREF(((PyObject *)__pyx_r));

    /* "View.MemoryView":783
 *     else:
 *         return memoryview_fromslice(dst, new_ndim, NULL, NULL,
 *                                     memview.dtype_is_object)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, NULL, NULL, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 782, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "View.MemoryView":782
 *                                     memview.dtype_is_object)
 *     else:
 *         return memoryview_fromslice(dst, new_ndim, NULL, NULL,             # <<<<<<<<<<<<<<
 *                                     memview.dtype_is_object)
 * 
 */
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(4, 782, __pyx_L1_error)
    __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "View.MemoryView":710
 * 
 * @cname('__pyx_memview_slice')
 * cdef memoryview memview_slice(memoryview memview, object indices):             # <<<<<<<<<<<<<<
 *     cdef int new_ndim = 0, suboffset_dim = -1, dim
 *     cdef bint negative_step
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("View.MemoryView.memview_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_memviewsliceobj);
  __Pyx_XDECREF(__pyx_v_index);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":807
 * 
 * @cname('__pyx_memoryview_slice_memviewslice')
 * cdef int slice_memviewslice(             # <<<<<<<<<<<<<<
 *         __Pyx_memviewslice *dst,
 *         Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset,
 */

static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *__pyx_v_dst, Py_ssize_t __pyx_v_shape, Py_ssize_t __pyx_v_stride, Py_ssize_t __pyx_v_suboffset, int __pyx_v_dim, int __pyx_v_new_ndim, int *__pyx_v_suboffset_dim, Py_ssize_t __pyx_v_start, Py_ssize_t __pyx_v_stop, Py_ssize_t __pyx_v_step, int __pyx_v_have_start, int __pyx_v_have_stop, int __pyx_v_have_step, int __pyx_v_is_slice) {
  Py_ssize_t __pyx_v_new_shape;
  int __pyx_v_negative_step;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* "View.MemoryView":827
 *     cdef bint negative_step
 * 
 *     if not is_slice:             # <<<<<<<<<<<<<<
 * 
 *         if start < 0:
 */
  __pyx_t_1 = ((!(__pyx_v_is_slice != 0)) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":829
 *     if not is_slice:
 * 
 *         if start < 0:             # <<<<<<<<<<<<<<
 *             start += shape
 *         if not 0 <= start < shape:
 */
    __pyx_t_1 = ((__pyx_v_start < 0) != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":830
 * 
 *         if start < 0:
 *             start += shape             # <<<<<<<<<<<<<<
 *         if not 0 <= start < shape:
 *             _err_dim(IndexError, "Index out of bounds (axis %d)", dim)
 */
      __pyx_v_start = (__pyx_v_start + __pyx_v_shape);

      /* "View.MemoryView":829
 *     if not is_slice:
 * 
 *         if start < 0:             # <<<<<<<<<<<<<<
 *             start += shape
 *         if not 0 <= start < shape:
 */
    }

    /* "View.MemoryView":831
 *         if start < 0:
 *             start += shape
 *         if not 0 <= start < shape:             # <<<<<<<<<<<<<<
 *             _err_dim(IndexError, "Index out of bounds (axis %d)", dim)
 *     else:
 */
    __pyx_t_1 = (0 <= __pyx_v_start);
    if (__pyx_t_1) {
      __pyx_t_1 = (__pyx_v_start < __pyx_v_shape);
    }
    __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":832
 *             start += shape
 *         if not 0 <= start < shape:
 *             _err_dim(IndexError, "Index out of bounds (axis %d)", dim)             # <<<<<<<<<<<<<<
 *     else:
 * 
 */
      __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"Index out of bounds (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(4, 832, __pyx_L1_error)

      /* "View.MemoryView":831
 *         if start < 0:
 *             start += shape
 *         if not 0 <= start < shape:             # <<<<<<<<<<<<<<
 *             _err_dim(IndexError, "Index out of bounds (axis %d)", dim)
 *     else:
 */
    }

    /* "View.MemoryView":827
 *     cdef bint negative_step
 * 
 *     if not is_slice:             # <<<<<<<<<<<<<<
 * 
 *         if start < 0:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":835
 *     else:
 * 
 *         negative_step = have_step != 0 and step < 0             # <<<<<<<<<<<<<<
 * 
 *         if have_step and step == 0:
 */
  /*else*/ {
    __pyx_t_1 = ((__pyx_v_have_step != 0) != 0);
    if (__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_1 = ((__pyx_v_step < 0) != 0);
    __pyx_t_2 = __pyx_t_1;
    __pyx_L6_bool_binop_done:;
    __pyx_v_negative_step = __pyx_t_2;

    /* "View.MemoryView":837
 *         negative_step = have_step != 0 and step < 0
 * 
 *         if have_step and step == 0:             # <<<<<<<<<<<<<<
 *             _err_dim(ValueError, "Step may not be zero (axis %d)", dim)
 * 
 */
    __pyx_t_1 = (__pyx_v_have_step != 0);
    if (__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_1 = ((__pyx_v_step == 0) != 0);
    __pyx_t_2 = __pyx_t_1;
    __pyx_L9_bool_binop_done:;
    if (__pyx_t_2) {

      /* "View.MemoryView":838
 * 
 *         if have_step and step == 0:
 *             _err_dim(ValueError, "Step may not be zero (axis %d)", dim)             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Step may not be zero (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(4, 838, __pyx_L1_error)

      /* "View.MemoryView":837
 *         negative_step = have_step != 0 and step < 0
 * 
 *         if have_step and step == 0:             # <<<<<<<<<<<<<<
 *             _err_dim(ValueError, "Step may not be zero (axis %d)", dim)
 * 
 */
    }

    /* "View.MemoryView":841
 * 
 * 
 *         if have_start:             # <<<<<<<<<<<<<<
 *             if start < 0:
 *                 start += shape
 */
    __pyx_t_2 = (__pyx_v_have_start != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":842
 * 
 *         if have_start:
 *             if start < 0:             # <<<<<<<<<<<<<<
 *                 start += shape
 *                 if start < 0:
 */
      __pyx_t_2 = ((__pyx_v_start < 0) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":843
 *         if have_start:
 *             if start < 0:
 *                 start += shape             # <<<<<<<<<<<<<<
 *                 if start < 0:
 *                     start = 0
 */
        __pyx_v_start = (__pyx_v_start + __pyx_v_shape);

        /* "View.MemoryView":844
 *             if start < 0:
 *                 start += shape
 *                 if start < 0:             # <<<<<<<<<<<<<<
 *                     start = 0
 *             elif start >= shape:
 */
        __pyx_t_2 = ((__pyx_v_start < 0) != 0);
        if (__pyx_t_2) {

          /* "View.MemoryView":845
 *                 start += shape
 *                 if start < 0:
 *                     start = 0             # <<<<<<<<<<<<<<
 *             elif start >= shape:
 *                 if negative_step:
 */
          __pyx_v_start = 0;

          /* "View.MemoryView":844
 *             if start < 0:
 *                 start += shape
 *                 if start < 0:             # <<<<<<<<<<<<<<
 *                     start = 0
 *             elif start >= shape:
 */
        }

        /* "View.MemoryView":842
 * 
 *         if have_start:
 *             if start < 0:             # <<<<<<<<<<<<<<
 *                 start += shape
 *                 if start < 0:
 */
        goto __pyx_L12;
      }

      /* "View.MemoryView":846
 *                 if start < 0:
 *                     start = 0
 *             elif start >= shape:             # <<<<<<<<<<<<<<
 *                 if negative_step:
 *                     start = shape - 1
 */
      __pyx_t_2 = ((__pyx_v_start >= __pyx_v_shape) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":847
 *                     start = 0
 *             elif start >= shape:
 *                 if negative_step:             # <<<<<<<<<<<<<<
 *                     start = shape - 1
 *                 else:
 */
        __pyx_t_2 = (__pyx_v_negative_step != 0);
        if (__pyx_t_2) {

          /* "View.MemoryView":848
 *             elif start >= shape:
 *                 if negative_step:
 *                     start = shape - 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     start = shape
 */
          __pyx_v_start = (__pyx_v_shape - 1);

          /* "View.MemoryView":847
 *                     start = 0
 *             elif start >= shape:
 *                 if negative_step:             # <<<<<<<<<<<<<<
 *                     start = shape - 1
 *                 else:
 */
          goto __pyx_L14;
        }

        /* "View.MemoryView":850
 *                     start = shape - 1
 *                 else:
 *                     start = shape             # <<<<<<<<<<<<<<
 *         else:
 *             if negative_step:
 */
        /*else*/ {
          __pyx_v_start = __pyx_v_shape;
        }
        __pyx_L14:;

        /* "View.MemoryView":846
 *                 if start < 0:
 *                     start = 0
 *             elif start >= shape:             # <<<<<<<<<<<<<<
 *                 if negative_step:
 *                     start = shape - 1
 */
      }
      __pyx_L12:;

      /* "View.MemoryView":841
 * 
 * 
 *         if have_start:             # <<<<<<<<<<<<<<
 *             if start < 0:
 *                 start += shape
 */
      goto __pyx_L11;
    }

    /* "View.MemoryView":852
 *                     start = shape
 *         else:
 *             if negative_step:             # <<<<<<<<<<<<<<
 *                 start = shape - 1
 *             else:
 */
    /*else*/ {
      __pyx_t_2 = (__pyx_v_negative_step != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":853
 *         else:
 *             if negative_step:
 *                 start = shape - 1             # <<<<<<<<<<<<<<
 *             else:
 *                 start = 0
 */
        __pyx_v_start = (__pyx_v_shape - 1);

        /* "View.MemoryView":852
 *                     start = shape
 *         else:
 *             if negative_step:             # <<<<<<<<<<<<<<
 *                 start = shape - 1
 *             else:
 */
        goto __pyx_L15;
      }

      /* "View.MemoryView":855
 *                 start = shape - 1
 *             else:
 *                 start = 0             # <<<<<<<<<<<<<<
 * 
 *         if have_stop:
 */
      /*else*/ {
        __pyx_v_start = 0;
      }
      __pyx_L15:;
    }
    __pyx_L11:;

    /* "View.MemoryView":857
 *                 start = 0
 * 
 *         if have_stop:             # <<<<<<<<<<<<<<
 *             if stop < 0:
 *                 stop += shape
 */
    __pyx_t_2 = (__pyx_v_have_stop != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":858
 * 
 *         if have_stop:
 *             if stop < 0:             # <<<<<<<<<<<<<<
 *                 stop += shape
 *                 if stop < 0:
 */
      __pyx_t_2 = ((__pyx_v_stop < 0) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":859
 *         if have_stop:
 *             if stop < 0:
 *                 stop += shape             # <<<<<<<<<<<<<<
 *                 if stop < 0:
 *                     stop = 0
 */
        __pyx_v_stop = (__pyx_v_stop + __pyx_v_shape);

        /* "View.MemoryView":860
 *             if stop < 0:
 *                 stop += shape
 *                 if stop < 0:             # <<<<<<<<<<<<<<
 *                     stop = 0
 *             elif stop > shape:
 */
        __pyx_t_2 = ((__pyx_v_stop < 0) != 0);
        if (__pyx_t_2) {

          /* "View.MemoryView":861
 *                 stop += shape
 *                 if stop < 0:
 *                     stop = 0             # <<<<<<<<<<<<<<
 *             elif stop > shape:
 *                 stop = shape
 */
          __pyx_v_stop = 0;

          /* "View.MemoryView":860
 *             if stop < 0:
 *                 stop += shape
 *                 if stop < 0:             # <<<<<<<<<<<<<<
 *                     stop = 0
 *             elif stop > shape:
 */
        }

        /* "View.MemoryView":858
 * 
 *         if have_stop:
 *             if stop < 0:             # <<<<<<<<<<<<<<
 *                 stop += shape
 *                 if stop < 0:
 */
        goto __pyx_L17;
      }

      /* "View.MemoryView":862
 *                 if stop < 0:
 *                     stop = 0
 *             elif stop > shape:             # <<<<<<<<<<<<<<
 *                 stop = shape
 *         else:
 */
      __pyx_t_2 = ((__pyx_v_stop > __pyx_v_shape) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":863
 *                     stop = 0
 *             elif stop > shape:
 *                 stop = shape             # <<<<<<<<<<<<<<
 *         else:
 *             if negative_step:
 */
        __pyx_v_stop = __pyx_v_shape;

        /* "View.MemoryView":862
 *                 if stop < 0:
 *                     stop = 0
 *             elif stop > shape:             # <<<<<<<<<<<<<<
 *                 stop = shape
 *         else:
 */
      }
      __pyx_L17:;

      /* "View.MemoryView":857
 *                 start = 0
 * 
 *         if have_stop:             # <<<<<<<<<<<<<<
 *             if stop < 0:
 *                 stop += shape
 */
      goto __pyx_L16;
    }

    /* "View.MemoryView":865
 *                 stop = shape
 *         else:
 *             if negative_step:             # <<<<<<<<<<<<<<
 *                 stop = -1
 *             else:
 */
    /*else*/ {
      __pyx_t_2 = (__pyx_v_negative_step != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":866
 *         else:
 *             if negative_step:
 *                 stop = -1             # <<<<<<<<<<<<<<
 *             else:
 *                 stop = shape
 */
        __pyx_v_stop = -1L;

        /* "View.MemoryView":865
 *                 stop = shape
 *         else:
 *             if negative_step:             # <<<<<<<<<<<<<<
 *                 stop = -1
 *             else:
 */
        goto __pyx_L19;
      }

      /* "View.MemoryView":868
 *                 stop = -1
 *             else:
 *                 stop = shape             # <<<<<<<<<<<<<<
 * 
 *         if not have_step:
 */
      /*else*/ {
        __pyx_v_stop = __pyx_v_shape;
      }
      __pyx_L19:;
    }
    __pyx_L16:;

    /* "View.MemoryView":870
 *                 stop = shape
 * 
 *         if not have_step:             # <<<<<<<<<<<<<<
 *             step = 1
 * 
 */
    __pyx_t_2 = ((!(__pyx_v_have_step != 0)) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":871
 * 
 *         if not have_step:
 *             step = 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_v_step = 1;

      /* "View.MemoryView":870
 *                 stop = shape
 * 
 *         if not have_step:             # <<<<<<<<<<<<<<
 *             step = 1
 * 
 */
    }

    /* "View.MemoryView":875
 * 
 *         with cython.cdivision(True):
 *             new_shape = (stop - start) // step             # <<<<<<<<<<<<<<
 * 
 *             if (stop - start) - step * new_shape:
 */
    __pyx_v_new_shape = ((__pyx_v_stop - __pyx_v_start) / __pyx_v_step);

    /* "View.MemoryView":877
 *             new_shape = (stop - start) // step
 * 
 *             if (stop - start) - step * new_shape:             # <<<<<<<<<<<<<<
 *                 new_shape += 1
 * 
 */
    __pyx_t_2 = (((__pyx_v_stop - __pyx_v_start) - (__pyx_v_step * __pyx_v_new_shape)) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":878
 * 
 *             if (stop - start) - step * new_shape:
 *                 new_shape += 1             # <<<<<<<<<<<<<<
 * 
 *         if new_shape < 0:
 */
      __pyx_v_new_shape = (__pyx_v_new_shape + 1);

      /* "View.MemoryView":877
 *             new_shape = (stop - start) // step
 * 
 *             if (stop - start) - step * new_shape:             # <<<<<<<<<<<<<<
 *                 new_shape += 1
 * 
 */
    }

    /* "View.MemoryView":880
 *                 new_shape += 1
 * 
 *         if new_shape < 0:             # <<<<<<<<<<<<<<
 *             new_shape = 0
 * 
 */
    __pyx_t_2 = ((__pyx_v_new_shape < 0) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":881
 * 
 *         if new_shape < 0:
 *             new_shape = 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_v_new_shape = 0;

      /* "View.MemoryView":880
 *                 new_shape += 1
 * 
 *         if new_shape < 0:             # <<<<<<<<<<<<<<
 *             new_shape = 0
 * 
 */
    }

    /* "View.MemoryView":884
 * 
 * 
 *         dst.strides[new_ndim] = stride * step             # <<<<<<<<<<<<<<
 *         dst.shape[new_ndim] = new_shape
 *         dst.suboffsets[new_ndim] = suboffset
 */
    (__pyx_v_dst->strides[__pyx_v_new_ndim]) = (__pyx_v_stride * __pyx_v_step);

    /* "View.MemoryView":885
 * 
 *         dst.strides[new_ndim] = stride * step
 *         dst.shape[new_ndim] = new_shape             # <<<<<<<<<<<<<<
 *         dst.suboffsets[new_ndim] = suboffset
 * 
 */
    (__pyx_v_dst->shape[__pyx_v_new_ndim]) = __pyx_v_new_shape;

    /* "View.MemoryView":886
 *         dst.strides[new_ndim] = stride * step
 *         dst.shape[new_ndim] = new_shape
 *         dst.suboffsets[new_ndim] = suboffset             # <<<<<<<<<<<<<<
 * 
 * 
 */
    (__pyx_v_dst->suboffsets[__pyx_v_new_ndim]) = __pyx_v_suboffset;
  }
  __pyx_L3:;

  /* "View.MemoryView":889
 * 
 * 
 *     if suboffset_dim[0] < 0:             # <<<<<<<<<<<<<<
 *         dst.data += start * stride
 *     else:
 */
  __pyx_t_2 = (((__pyx_v_suboffset_dim[0]) < 0) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":890
 * 
 *     if suboffset_dim[0] < 0:
 *         dst.data += start * stride             # <<<<<<<<<<<<<<
 *     else:
 *         dst.suboffsets[suboffset_dim[0]] += start * stride
 */
    __pyx_v_dst->data = (__pyx_v_dst->data + (__pyx_v_start * __pyx_v_stride));

    /* "View.MemoryView":889
 * 
 * 
 *     if suboffset_dim[0] < 0:             # <<<<<<<<<<<<<<
 *         dst.data += start * stride
 *     else:
 */
    goto __pyx_L23;
  }

  /* "View.MemoryView":892
 *         dst.data += start * stride
 *     else:
 *         dst.suboffsets[suboffset_dim[0]] += start * stride             # <<<<<<<<<<<<<<
 * 
 *     if suboffset >= 0:
 */
  /*else*/ {
    __pyx_t_3 = (__pyx_v_suboffset_dim[0]);
    (__pyx_v_dst->suboffsets[__pyx_t_3]) = ((__pyx_v_dst->suboffsets[__pyx_t_3]) + (__pyx_v_start * __pyx_v_stride));
  }
  __pyx_L23:;

  /* "View.MemoryView":894
 *         dst.suboffsets[suboffset_dim[0]] += start * stride
 * 
 *     if suboffset >= 0:             # <<<<<<<<<<<<<<
 *         if not is_slice:
 *             if new_ndim == 0:
 */
  __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":895
 * 
 *     if suboffset >= 0:
 *         if not is_slice:             # <<<<<<<<<<<<<<
 *             if new_ndim == 0:
 *                 dst.data = (<char **> dst.data)[0] + suboffset
 */
    __pyx_t_2 = ((!(__pyx_v_is_slice != 0)) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":896
 *     if suboffset >= 0:
 *         if not is_slice:
 *             if new_ndim == 0:             # <<<<<<<<<<<<<<
 *                 dst.data = (<char **> dst.data)[0] + suboffset
 *             else:
 */
      __pyx_t_2 = ((__pyx_v_new_ndim == 0) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":897
 *         if not is_slice:
 *             if new_ndim == 0:
 *                 dst.data = (<char **> dst.data)[0] + suboffset             # <<<<<<<<<<<<<<
 *             else:
 *                 _err_dim(IndexError, "All dimensions preceding dimension %d "
 */
        __pyx_v_dst->data = ((((char **)__pyx_v_dst->data)[0]) + __pyx_v_suboffset);

        /* "View.MemoryView":896
 *     if suboffset >= 0:
 *         if not is_slice:
 *             if new_ndim == 0:             # <<<<<<<<<<<<<<
 *                 dst.data = (<char **> dst.data)[0] + suboffset
 *             else:
 */
        goto __pyx_L26;
      }

      /* "View.MemoryView":899
 *                 dst.data = (<char **> dst.data)[0] + suboffset
 *             else:
 *                 _err_dim(IndexError, "All dimensions preceding dimension %d "             # <<<<<<<<<<<<<<
 *                                      "must be indexed and not sliced", dim)
 *         else:
 */
      /*else*/ {

        /* "View.MemoryView":900
 *             else:
 *                 _err_dim(IndexError, "All dimensions preceding dimension %d "
 *                                      "must be indexed and not sliced", dim)             # <<<<<<<<<<<<<<
 *         else:
 *             suboffset_dim[0] = new_ndim
 */
        __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"All dimensions preceding dimension %d must be indexed and not sliced"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(4, 899, __pyx_L1_error)
      }
      __pyx_L26:;

      /* "View.MemoryView":895
 * 
 *     if suboffset >= 0:
 *         if not is_slice:             # <<<<<<<<<<<<<<
 *             if new_ndim == 0:
 *                 dst.data = (<char **> dst.data)[0] + suboffset
 */
      goto __pyx_L25;
    }

    /* "View.MemoryView":902
 *                                      "must be indexed and not sliced", dim)
 *         else:
 *             suboffset_dim[0] = new_ndim             # <<<<<<<<<<<<<<
 * 
 *     return 0
 */
    /*else*/ {
      (__pyx_v_suboffset_dim[0]) = __pyx_v_new_ndim;
    }
    __pyx_L25:;

    /* "View.MemoryView":894
 *         dst.suboffsets[suboffset_dim[0]] += start * stride
 * 
 *     if suboffset >= 0:             # <<<<<<<<<<<<<<
 *         if not is_slice:
 *             if new_ndim == 0:
 */
  }

  /* "View.MemoryView":904
 *             suboffset_dim[0] = new_ndim
 * 
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "View.MemoryView":807
 * 
 * @cname('__pyx_memoryview_slice_memviewslice')
 * cdef int slice_memviewslice(             # <<<<<<<<<<<<<<
 *         __Pyx_memviewslice *dst,
 *         Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset,
 */

  /* function exit code */
  __pyx_L1_error:;
  {
    #ifdef WITH_THREAD
    PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
    #endif
    __Pyx_AddTraceback("View.MemoryView.slice_memviewslice", __pyx_clineno, __pyx_lineno, __pyx_filename);
    #ifdef WITH_THREAD
    __Pyx_PyGILState_Release(__pyx_gilstate_save);
    #endif
  }
  __pyx_r = -1;
  __pyx_L0:;
  return __pyx_r;
}

/* "View.MemoryView":910
 * 
 * @cname('__pyx_pybuffer_index')
 * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,             # <<<<<<<<<<<<<<
 *                           Py_ssize_t dim) except NULL:
 *     cdef Py_ssize_t shape, stride, suboffset = -1
 */

static char *__pyx_pybuffer_index(Py_buffer *__pyx_v_view, char *__pyx_v_bufp, Py_ssize_t __pyx_v_index, Py_ssize_t __pyx_v_dim) {
  Py_ssize_t __pyx_v_shape;
  Py_ssize_t __pyx_v_stride;
  Py_ssize_t __pyx_v_suboffset;
  Py_ssize_t __pyx_v_itemsize;
  char *__pyx_v_resultp;
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("pybuffer_index", 0);

  /* "View.MemoryView":912
 * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,
 *                           Py_ssize_t dim) except NULL:
 *     cdef Py_ssize_t shape, stride, suboffset = -1             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t itemsize = view.itemsize
 *     cdef char *resultp
 */
  __pyx_v_suboffset = -1L;

  /* "View.MemoryView":913
 *                           Py_ssize_t dim) except NULL:
 *     cdef Py_ssize_t shape, stride, suboffset = -1
 *     cdef Py_ssize_t itemsize = view.itemsize             # <<<<<<<<<<<<<<
 *     cdef char *resultp
 * 
 */
  __pyx_t_1 = __pyx_v_view->itemsize;
  __pyx_v_itemsize = __pyx_t_1;

  /* "View.MemoryView":916
 *     cdef char *resultp
 * 
 *     if view.ndim == 0:             # <<<<<<<<<<<<<<
 *         shape = view.len / itemsize
 *         stride = itemsize
 */
  __pyx_t_2 = ((__pyx_v_view->ndim == 0) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":917
 * 
 *     if view.ndim == 0:
 *         shape = view.len / itemsize             # <<<<<<<<<<<<<<
 *         stride = itemsize
 *     else:
 */
    if (unlikely(__pyx_v_itemsize == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
      __PYX_ERR(4, 917, __pyx_L1_error)
    }
    else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1)  && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_view->len))) {
      PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
      __PYX_ERR(4, 917, __pyx_L1_error)
    }
    __pyx_v_shape = __Pyx_div_Py_ssize_t(__pyx_v_view->len, __pyx_v_itemsize);

    /* "View.MemoryView":918
 *     if view.ndim == 0:
 *         shape = view.len / itemsize
 *         stride = itemsize             # <<<<<<<<<<<<<<
 *     else:
 *         shape = view.shape[dim]
 */
    __pyx_v_stride = __pyx_v_itemsize;

    /* "View.MemoryView":916
 *     cdef char *resultp
 * 
 *     if view.ndim == 0:             # <<<<<<<<<<<<<<
 *         shape = view.len / itemsize
 *         stride = itemsize
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":920
 *         stride = itemsize
 *     else:
 *         shape = view.shape[dim]             # <<<<<<<<<<<<<<
 *         stride = view.strides[dim]
 *         if view.suboffsets != NULL:
 */
  /*else*/ {
    __pyx_v_shape = (__pyx_v_view->shape[__pyx_v_dim]);

    /* "View.MemoryView":921
 *     else:
 *         shape = view.shape[dim]
 *         stride = view.strides[dim]             # <<<<<<<<<<<<<<
 *         if view.suboffsets != NULL:
 *             suboffset = view.suboffsets[dim]
 */
    __pyx_v_stride = (__pyx_v_view->strides[__pyx_v_dim]);

    /* "View.MemoryView":922
 *         shape = view.shape[dim]
 *         stride = view.strides[dim]
 *         if view.suboffsets != NULL:             # <<<<<<<<<<<<<<
 *             suboffset = view.suboffsets[dim]
 * 
 */
    __pyx_t_2 = ((__pyx_v_view->suboffsets != NULL) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":923
 *         stride = view.strides[dim]
 *         if view.suboffsets != NULL:
 *             suboffset = view.suboffsets[dim]             # <<<<<<<<<<<<<<
 * 
 *     if index < 0:
 */
      __pyx_v_suboffset = (__pyx_v_view->suboffsets[__pyx_v_dim]);

      /* "View.MemoryView":922
 *         shape = view.shape[dim]
 *         stride = view.strides[dim]
 *         if view.suboffsets != NULL:             # <<<<<<<<<<<<<<
 *             suboffset = view.suboffsets[dim]
 * 
 */
    }
  }
  __pyx_L3:;

  /* "View.MemoryView":925
 *             suboffset = view.suboffsets[dim]
 * 
 *     if index < 0:             # <<<<<<<<<<<<<<
 *         index += view.shape[dim]
 *         if index < 0:
 */
  __pyx_t_2 = ((__pyx_v_index < 0) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":926
 * 
 *     if index < 0:
 *         index += view.shape[dim]             # <<<<<<<<<<<<<<
 *         if index < 0:
 *             raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 */
    __pyx_v_index = (__pyx_v_index + (__pyx_v_view->shape[__pyx_v_dim]));

    /* "View.MemoryView":927
 *     if index < 0:
 *         index += view.shape[dim]
 *         if index < 0:             # <<<<<<<<<<<<<<
 *             raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 */
    __pyx_t_2 = ((__pyx_v_index < 0) != 0);
    if (unlikely(__pyx_t_2)) {

      /* "View.MemoryView":928
 *         index += view.shape[dim]
 *         if index < 0:
 *             raise IndexError("Out of bounds on buffer access (axis %d)" % dim)             # <<<<<<<<<<<<<<
 * 
 *     if index >= shape:
 */
      __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 928, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 928, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 928, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(4, 928, __pyx_L1_error)

      /* "View.MemoryView":927
 *     if index < 0:
 *         index += view.shape[dim]
 *         if index < 0:             # <<<<<<<<<<<<<<
 *             raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 */
    }

    /* "View.MemoryView":925
 *             suboffset = view.suboffsets[dim]
 * 
 *     if index < 0:             # <<<<<<<<<<<<<<
 *         index += view.shape[dim]
 *         if index < 0:
 */
  }

  /* "View.MemoryView":930
 *             raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 *     if index >= shape:             # <<<<<<<<<<<<<<
 *         raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 */
  __pyx_t_2 = ((__pyx_v_index >= __pyx_v_shape) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "View.MemoryView":931
 * 
 *     if index >= shape:
 *         raise IndexError("Out of bounds on buffer access (axis %d)" % dim)             # <<<<<<<<<<<<<<
 * 
 *     resultp = bufp + index * stride
 */
    __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 931, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 931, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 931, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(4, 931, __pyx_L1_error)

    /* "View.MemoryView":930
 *             raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 *     if index >= shape:             # <<<<<<<<<<<<<<
 *         raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 */
  }

  /* "View.MemoryView":933
 *         raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 *     resultp = bufp + index * stride             # <<<<<<<<<<<<<<
 *     if suboffset >= 0:
 *         resultp = (<char **> resultp)[0] + suboffset
 */
  __pyx_v_resultp = (__pyx_v_bufp + (__pyx_v_index * __pyx_v_stride));

  /* "View.MemoryView":934
 * 
 *     resultp = bufp + index * stride
 *     if suboffset >= 0:             # <<<<<<<<<<<<<<
 *         resultp = (<char **> resultp)[0] + suboffset
 * 
 */
  __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":935
 *     resultp = bufp + index * stride
 *     if suboffset >= 0:
 *         resultp = (<char **> resultp)[0] + suboffset             # <<<<<<<<<<<<<<
 * 
 *     return resultp
 */
    __pyx_v_resultp = ((((char **)__pyx_v_resultp)[0]) + __pyx_v_suboffset);

    /* "View.MemoryView":934
 * 
 *     resultp = bufp + index * stride
 *     if suboffset >= 0:             # <<<<<<<<<<<<<<
 *         resultp = (<char **> resultp)[0] + suboffset
 * 
 */
  }

  /* "View.MemoryView":937
 *         resultp = (<char **> resultp)[0] + suboffset
 * 
 *     return resultp             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_resultp;
  goto __pyx_L0;

  /* "View.MemoryView":910
 * 
 * @cname('__pyx_pybuffer_index')
 * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,             # <<<<<<<<<<<<<<
 *                           Py_ssize_t dim) except NULL:
 *     cdef Py_ssize_t shape, stride, suboffset = -1
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("View.MemoryView.pybuffer_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":943
 * 
 * @cname('__pyx_memslice_transpose')
 * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0:             # <<<<<<<<<<<<<<
 *     cdef int ndim = memslice.memview.view.ndim
 * 
 */

static int __pyx_memslice_transpose(__Pyx_memviewslice *__pyx_v_memslice) {
  int __pyx_v_ndim;
  Py_ssize_t *__pyx_v_shape;
  Py_ssize_t *__pyx_v_strides;
  int __pyx_v_i;
  int __pyx_v_j;
  int __pyx_r;
  int __pyx_t_1;
  Py_ssize_t *__pyx_t_2;
  long __pyx_t_3;
  long __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* "View.MemoryView":944
 * @cname('__pyx_memslice_transpose')
 * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0:
 *     cdef int ndim = memslice.memview.view.ndim             # <<<<<<<<<<<<<<
 * 
 *     cdef Py_ssize_t *shape = memslice.shape
 */
  __pyx_t_1 = __pyx_v_memslice->memview->view.ndim;
  __pyx_v_ndim = __pyx_t_1;

  /* "View.MemoryView":946
 *     cdef int ndim = memslice.memview.view.ndim
 * 
 *     cdef Py_ssize_t *shape = memslice.shape             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t *strides = memslice.strides
 * 
 */
  __pyx_t_2 = __pyx_v_memslice->shape;
  __pyx_v_shape = __pyx_t_2;

  /* "View.MemoryView":947
 * 
 *     cdef Py_ssize_t *shape = memslice.shape
 *     cdef Py_ssize_t *strides = memslice.strides             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = __pyx_v_memslice->strides;
  __pyx_v_strides = __pyx_t_2;

  /* "View.MemoryView":951
 * 
 *     cdef int i, j
 *     for i in range(ndim / 2):             # <<<<<<<<<<<<<<
 *         j = ndim - 1 - i
 *         strides[i], strides[j] = strides[j], strides[i]
 */
  __pyx_t_3 = __Pyx_div_long(__pyx_v_ndim, 2);
  __pyx_t_4 = __pyx_t_3;
  for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_4; __pyx_t_1+=1) {
    __pyx_v_i = __pyx_t_1;

    /* "View.MemoryView":952
 *     cdef int i, j
 *     for i in range(ndim / 2):
 *         j = ndim - 1 - i             # <<<<<<<<<<<<<<
 *         strides[i], strides[j] = strides[j], strides[i]
 *         shape[i], shape[j] = shape[j], shape[i]
 */
    __pyx_v_j = ((__pyx_v_ndim - 1) - __pyx_v_i);

    /* "View.MemoryView":953
 *     for i in range(ndim / 2):
 *         j = ndim - 1 - i
 *         strides[i], strides[j] = strides[j], strides[i]             # <<<<<<<<<<<<<<
 *         shape[i], shape[j] = shape[j], shape[i]
 * 
 */
    __pyx_t_5 = (__pyx_v_strides[__pyx_v_j]);
    __pyx_t_6 = (__pyx_v_strides[__pyx_v_i]);
    (__pyx_v_strides[__pyx_v_i]) = __pyx_t_5;
    (__pyx_v_strides[__pyx_v_j]) = __pyx_t_6;

    /* "View.MemoryView":954
 *         j = ndim - 1 - i
 *         strides[i], strides[j] = strides[j], strides[i]
 *         shape[i], shape[j] = shape[j], shape[i]             # <<<<<<<<<<<<<<
 * 
 *         if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0:
 */
    __pyx_t_6 = (__pyx_v_shape[__pyx_v_j]);
    __pyx_t_5 = (__pyx_v_shape[__pyx_v_i]);
    (__pyx_v_shape[__pyx_v_i]) = __pyx_t_6;
    (__pyx_v_shape[__pyx_v_j]) = __pyx_t_5;

    /* "View.MemoryView":956
 *         shape[i], shape[j] = shape[j], shape[i]
 * 
 *         if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0:             # <<<<<<<<<<<<<<
 *             _err(ValueError, "Cannot transpose memoryview with indirect dimensions")
 * 
 */
    __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_i]) >= 0) != 0);
    if (!__pyx_t_8) {
    } else {
      __pyx_t_7 = __pyx_t_8;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_j]) >= 0) != 0);
    __pyx_t_7 = __pyx_t_8;
    __pyx_L6_bool_binop_done:;
    if (__pyx_t_7) {

      /* "View.MemoryView":957
 * 
 *         if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0:
 *             _err(ValueError, "Cannot transpose memoryview with indirect dimensions")             # <<<<<<<<<<<<<<
 * 
 *     return 1
 */
      __pyx_t_9 = __pyx_memoryview_err(__pyx_builtin_ValueError, ((char *)"Cannot transpose memoryview with indirect dimensions")); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(4, 957, __pyx_L1_error)

      /* "View.MemoryView":956
 *         shape[i], shape[j] = shape[j], shape[i]
 * 
 *         if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0:             # <<<<<<<<<<<<<<
 *             _err(ValueError, "Cannot transpose memoryview with indirect dimensions")
 * 
 */
    }
  }

  /* "View.MemoryView":959
 *             _err(ValueError, "Cannot transpose memoryview with indirect dimensions")
 * 
 *     return 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "View.MemoryView":943
 * 
 * @cname('__pyx_memslice_transpose')
 * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0:             # <<<<<<<<<<<<<<
 *     cdef int ndim = memslice.memview.view.ndim
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  {
    #ifdef WITH_THREAD
    PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
    #endif
    __Pyx_AddTraceback("View.MemoryView.transpose_memslice", __pyx_clineno, __pyx_lineno, __pyx_filename);
    #ifdef WITH_THREAD
    __Pyx_PyGILState_Release(__pyx_gilstate_save);
    #endif
  }
  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

/* "View.MemoryView":976
 *     cdef int (*to_dtype_func)(char *, object) except 0
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
 * 
 */

/* Python wrapper */
static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self));

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

static void __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__", 0);

  /* "View.MemoryView":977
 * 
 *     def __dealloc__(self):
 *         __PYX_XDEC_MEMVIEW(&self.from_slice, 1)             # <<<<<<<<<<<<<<
 * 
 *     cdef convert_item_to_object(self, char *itemp):
 */
  __PYX_XDEC_MEMVIEW((&__pyx_v_self->from_slice), 1);

  /* "View.MemoryView":976
 *     cdef int (*to_dtype_func)(char *, object) except 0
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
 * 
 */

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

/* "View.MemoryView":979
 *         __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
 * 
 *     cdef convert_item_to_object(self, char *itemp):             # <<<<<<<<<<<<<<
 *         if self.to_object_func != NULL:
 *             return self.to_object_func(itemp)
 */

static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp) {
  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_RefNannySetupContext("convert_item_to_object", 0);

  /* "View.MemoryView":980
 * 
 *     cdef convert_item_to_object(self, char *itemp):
 *         if self.to_object_func != NULL:             # <<<<<<<<<<<<<<
 *             return self.to_object_func(itemp)
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_self->to_object_func != NULL) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":981
 *     cdef convert_item_to_object(self, char *itemp):
 *         if self.to_object_func != NULL:
 *             return self.to_object_func(itemp)             # <<<<<<<<<<<<<<
 *         else:
 *             return memoryview.convert_item_to_object(self, itemp)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_v_self->to_object_func(__pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 981, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "View.MemoryView":980
 * 
 *     cdef convert_item_to_object(self, char *itemp):
 *         if self.to_object_func != NULL:             # <<<<<<<<<<<<<<
 *             return self.to_object_func(itemp)
 *         else:
 */
  }

  /* "View.MemoryView":983
 *             return self.to_object_func(itemp)
 *         else:
 *             return memoryview.convert_item_to_object(self, itemp)             # <<<<<<<<<<<<<<
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_memoryview_convert_item_to_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 983, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "View.MemoryView":979
 *         __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
 * 
 *     cdef convert_item_to_object(self, char *itemp):             # <<<<<<<<<<<<<<
 *         if self.to_object_func != NULL:
 *             return self.to_object_func(itemp)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView._memoryviewslice.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":985
 *             return memoryview.convert_item_to_object(self, itemp)
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):             # <<<<<<<<<<<<<<
 *         if self.to_dtype_func != NULL:
 *             self.to_dtype_func(itemp, value)
 */

static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("assign_item_from_object", 0);

  /* "View.MemoryView":986
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):
 *         if self.to_dtype_func != NULL:             # <<<<<<<<<<<<<<
 *             self.to_dtype_func(itemp, value)
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_self->to_dtype_func != NULL) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":987
 *     cdef assign_item_from_object(self, char *itemp, object value):
 *         if self.to_dtype_func != NULL:
 *             self.to_dtype_func(itemp, value)             # <<<<<<<<<<<<<<
 *         else:
 *             memoryview.assign_item_from_object(self, itemp, value)
 */
    __pyx_t_2 = __pyx_v_self->to_dtype_func(__pyx_v_itemp, __pyx_v_value); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(4, 987, __pyx_L1_error)

    /* "View.MemoryView":986
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):
 *         if self.to_dtype_func != NULL:             # <<<<<<<<<<<<<<
 *             self.to_dtype_func(itemp, value)
 *         else:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":989
 *             self.to_dtype_func(itemp, value)
 *         else:
 *             memoryview.assign_item_from_object(self, itemp, value)             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  /*else*/ {
    __pyx_t_3 = __pyx_memoryview_assign_item_from_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 989, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_L3:;

  /* "View.MemoryView":985
 *             return memoryview.convert_item_to_object(self, itemp)
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):             # <<<<<<<<<<<<<<
 *         if self.to_dtype_func != NULL:
 *             self.to_dtype_func(itemp, value)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView._memoryviewslice.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":992
 * 
 *     @property
 *     def base(self):             # <<<<<<<<<<<<<<
 *         return self.from_object
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "View.MemoryView":993
 *     @property
 *     def base(self):
 *         return self.from_object             # <<<<<<<<<<<<<<
 * 
 *     __pyx_getbuffer = capsule(<void *> &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->from_object);
  __pyx_r = __pyx_v_self->from_object;
  goto __pyx_L0;

  /* "View.MemoryView":992
 * 
 *     @property
 *     def base(self):             # <<<<<<<<<<<<<<
 *         return self.from_object
 * 
 */

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

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

/* Python wrapper */
static PyObject *__pyx_pw___pyx_memoryviewslice_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw___pyx_memoryviewslice_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_memoryviewslice___reduce_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf___pyx_memoryviewslice___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__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_RefNannySetupContext("__reduce_cython__", 0);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(4, 2, __pyx_L1_error)

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

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView._memoryviewslice.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

/* Python wrapper */
static PyObject *__pyx_pw___pyx_memoryviewslice_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static PyObject *__pyx_pw___pyx_memoryviewslice_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_memoryviewslice_2__setstate_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf___pyx_memoryviewslice_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__63, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(4, 4, __pyx_L1_error)

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

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView._memoryviewslice.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":999
 * 
 * @cname('__pyx_memoryview_fromslice')
 * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice,             # <<<<<<<<<<<<<<
 *                           int ndim,
 *                           object (*to_object_func)(char *),
 */

static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice __pyx_v_memviewslice, int __pyx_v_ndim, PyObject *(*__pyx_v_to_object_func)(char *), int (*__pyx_v_to_dtype_func)(char *, PyObject *), int __pyx_v_dtype_is_object) {
  struct __pyx_memoryviewslice_obj *__pyx_v_result = 0;
  Py_ssize_t __pyx_v_suboffset;
  PyObject *__pyx_v_length = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_TypeInfo *__pyx_t_4;
  Py_buffer __pyx_t_5;
  Py_ssize_t *__pyx_t_6;
  Py_ssize_t *__pyx_t_7;
  Py_ssize_t *__pyx_t_8;
  Py_ssize_t __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("memoryview_fromslice", 0);

  /* "View.MemoryView":1007
 *     cdef _memoryviewslice result
 * 
 *     if <PyObject *> memviewslice.memview == Py_None:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = ((((PyObject *)__pyx_v_memviewslice.memview) == Py_None) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1008
 * 
 *     if <PyObject *> memviewslice.memview == Py_None:
 *         return None             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "View.MemoryView":1007
 *     cdef _memoryviewslice result
 * 
 *     if <PyObject *> memviewslice.memview == Py_None:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  }

  /* "View.MemoryView":1013
 * 
 * 
 *     result = _memoryviewslice(None, 0, dtype_is_object)             # <<<<<<<<<<<<<<
 * 
 *     result.from_slice = memviewslice
 */
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 1013, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 1013, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  PyTuple_SET_ITEM(__pyx_t_3, 0, Py_None);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryviewslice_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 1013, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":1015
 *     result = _memoryviewslice(None, 0, dtype_is_object)
 * 
 *     result.from_slice = memviewslice             # <<<<<<<<<<<<<<
 *     __PYX_INC_MEMVIEW(&memviewslice, 1)
 * 
 */
  __pyx_v_result->from_slice = __pyx_v_memviewslice;

  /* "View.MemoryView":1016
 * 
 *     result.from_slice = memviewslice
 *     __PYX_INC_MEMVIEW(&memviewslice, 1)             # <<<<<<<<<<<<<<
 * 
 *     result.from_object = (<memoryview> memviewslice.memview).base
 */
  __PYX_INC_MEMVIEW((&__pyx_v_memviewslice), 1);

  /* "View.MemoryView":1018
 *     __PYX_INC_MEMVIEW(&memviewslice, 1)
 * 
 *     result.from_object = (<memoryview> memviewslice.memview).base             # <<<<<<<<<<<<<<
 *     result.typeinfo = memviewslice.memview.typeinfo
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_memviewslice.memview), __pyx_n_s_base); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 1018, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF(__pyx_v_result->from_object);
  __Pyx_DECREF(__pyx_v_result->from_object);
  __pyx_v_result->from_object = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "View.MemoryView":1019
 * 
 *     result.from_object = (<memoryview> memviewslice.memview).base
 *     result.typeinfo = memviewslice.memview.typeinfo             # <<<<<<<<<<<<<<
 * 
 *     result.view = memviewslice.memview.view
 */
  __pyx_t_4 = __pyx_v_memviewslice.memview->typeinfo;
  __pyx_v_result->__pyx_base.typeinfo = __pyx_t_4;

  /* "View.MemoryView":1021
 *     result.typeinfo = memviewslice.memview.typeinfo
 * 
 *     result.view = memviewslice.memview.view             # <<<<<<<<<<<<<<
 *     result.view.buf = <void *> memviewslice.data
 *     result.view.ndim = ndim
 */
  __pyx_t_5 = __pyx_v_memviewslice.memview->view;
  __pyx_v_result->__pyx_base.view = __pyx_t_5;

  /* "View.MemoryView":1022
 * 
 *     result.view = memviewslice.memview.view
 *     result.view.buf = <void *> memviewslice.data             # <<<<<<<<<<<<<<
 *     result.view.ndim = ndim
 *     (<__pyx_buffer *> &result.view).obj = Py_None
 */
  __pyx_v_result->__pyx_base.view.buf = ((void *)__pyx_v_memviewslice.data);

  /* "View.MemoryView":1023
 *     result.view = memviewslice.memview.view
 *     result.view.buf = <void *> memviewslice.data
 *     result.view.ndim = ndim             # <<<<<<<<<<<<<<
 *     (<__pyx_buffer *> &result.view).obj = Py_None
 *     Py_INCREF(Py_None)
 */
  __pyx_v_result->__pyx_base.view.ndim = __pyx_v_ndim;

  /* "View.MemoryView":1024
 *     result.view.buf = <void *> memviewslice.data
 *     result.view.ndim = ndim
 *     (<__pyx_buffer *> &result.view).obj = Py_None             # <<<<<<<<<<<<<<
 *     Py_INCREF(Py_None)
 * 
 */
  ((Py_buffer *)(&__pyx_v_result->__pyx_base.view))->obj = Py_None;

  /* "View.MemoryView":1025
 *     result.view.ndim = ndim
 *     (<__pyx_buffer *> &result.view).obj = Py_None
 *     Py_INCREF(Py_None)             # <<<<<<<<<<<<<<
 * 
 *     if (<memoryview>memviewslice.memview).flags & PyBUF_WRITABLE:
 */
  Py_INCREF(Py_None);

  /* "View.MemoryView":1027
 *     Py_INCREF(Py_None)
 * 
 *     if (<memoryview>memviewslice.memview).flags & PyBUF_WRITABLE:             # <<<<<<<<<<<<<<
 *         result.flags = PyBUF_RECORDS
 *     else:
 */
  __pyx_t_1 = ((((struct __pyx_memoryview_obj *)__pyx_v_memviewslice.memview)->flags & PyBUF_WRITABLE) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1028
 * 
 *     if (<memoryview>memviewslice.memview).flags & PyBUF_WRITABLE:
 *         result.flags = PyBUF_RECORDS             # <<<<<<<<<<<<<<
 *     else:
 *         result.flags = PyBUF_RECORDS_RO
 */
    __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS;

    /* "View.MemoryView":1027
 *     Py_INCREF(Py_None)
 * 
 *     if (<memoryview>memviewslice.memview).flags & PyBUF_WRITABLE:             # <<<<<<<<<<<<<<
 *         result.flags = PyBUF_RECORDS
 *     else:
 */
    goto __pyx_L4;
  }

  /* "View.MemoryView":1030
 *         result.flags = PyBUF_RECORDS
 *     else:
 *         result.flags = PyBUF_RECORDS_RO             # <<<<<<<<<<<<<<
 * 
 *     result.view.shape = <Py_ssize_t *> result.from_slice.shape
 */
  /*else*/ {
    __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS_RO;
  }
  __pyx_L4:;

  /* "View.MemoryView":1032
 *         result.flags = PyBUF_RECORDS_RO
 * 
 *     result.view.shape = <Py_ssize_t *> result.from_slice.shape             # <<<<<<<<<<<<<<
 *     result.view.strides = <Py_ssize_t *> result.from_slice.strides
 * 
 */
  __pyx_v_result->__pyx_base.view.shape = ((Py_ssize_t *)__pyx_v_result->from_slice.shape);

  /* "View.MemoryView":1033
 * 
 *     result.view.shape = <Py_ssize_t *> result.from_slice.shape
 *     result.view.strides = <Py_ssize_t *> result.from_slice.strides             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_v_result->__pyx_base.view.strides = ((Py_ssize_t *)__pyx_v_result->from_slice.strides);

  /* "View.MemoryView":1036
 * 
 * 
 *     result.view.suboffsets = NULL             # <<<<<<<<<<<<<<
 *     for suboffset in result.from_slice.suboffsets[:ndim]:
 *         if suboffset >= 0:
 */
  __pyx_v_result->__pyx_base.view.suboffsets = NULL;

  /* "View.MemoryView":1037
 * 
 *     result.view.suboffsets = NULL
 *     for suboffset in result.from_slice.suboffsets[:ndim]:             # <<<<<<<<<<<<<<
 *         if suboffset >= 0:
 *             result.view.suboffsets = <Py_ssize_t *> result.from_slice.suboffsets
 */
  __pyx_t_7 = (__pyx_v_result->from_slice.suboffsets + __pyx_v_ndim);
  for (__pyx_t_8 = __pyx_v_result->from_slice.suboffsets; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) {
    __pyx_t_6 = __pyx_t_8;
    __pyx_v_suboffset = (__pyx_t_6[0]);

    /* "View.MemoryView":1038
 *     result.view.suboffsets = NULL
 *     for suboffset in result.from_slice.suboffsets[:ndim]:
 *         if suboffset >= 0:             # <<<<<<<<<<<<<<
 *             result.view.suboffsets = <Py_ssize_t *> result.from_slice.suboffsets
 *             break
 */
    __pyx_t_1 = ((__pyx_v_suboffset >= 0) != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":1039
 *     for suboffset in result.from_slice.suboffsets[:ndim]:
 *         if suboffset >= 0:
 *             result.view.suboffsets = <Py_ssize_t *> result.from_slice.suboffsets             # <<<<<<<<<<<<<<
 *             break
 * 
 */
      __pyx_v_result->__pyx_base.view.suboffsets = ((Py_ssize_t *)__pyx_v_result->from_slice.suboffsets);

      /* "View.MemoryView":1040
 *         if suboffset >= 0:
 *             result.view.suboffsets = <Py_ssize_t *> result.from_slice.suboffsets
 *             break             # <<<<<<<<<<<<<<
 * 
 *     result.view.len = result.view.itemsize
 */
      goto __pyx_L6_break;

      /* "View.MemoryView":1038
 *     result.view.suboffsets = NULL
 *     for suboffset in result.from_slice.suboffsets[:ndim]:
 *         if suboffset >= 0:             # <<<<<<<<<<<<<<
 *             result.view.suboffsets = <Py_ssize_t *> result.from_slice.suboffsets
 *             break
 */
    }
  }
  __pyx_L6_break:;

  /* "View.MemoryView":1042
 *             break
 * 
 *     result.view.len = result.view.itemsize             # <<<<<<<<<<<<<<
 *     for length in result.view.shape[:ndim]:
 *         result.view.len *= length
 */
  __pyx_t_9 = __pyx_v_result->__pyx_base.view.itemsize;
  __pyx_v_result->__pyx_base.view.len = __pyx_t_9;

  /* "View.MemoryView":1043
 * 
 *     result.view.len = result.view.itemsize
 *     for length in result.view.shape[:ndim]:             # <<<<<<<<<<<<<<
 *         result.view.len *= length
 * 
 */
  __pyx_t_7 = (__pyx_v_result->__pyx_base.view.shape + __pyx_v_ndim);
  for (__pyx_t_8 = __pyx_v_result->__pyx_base.view.shape; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) {
    __pyx_t_6 = __pyx_t_8;
    __pyx_t_2 = PyInt_FromSsize_t((__pyx_t_6[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 1043, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "View.MemoryView":1044
 *     result.view.len = result.view.itemsize
 *     for length in result.view.shape[:ndim]:
 *         result.view.len *= length             # <<<<<<<<<<<<<<
 * 
 *     result.to_object_func = to_object_func
 */
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_result->__pyx_base.view.len); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 1044, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyNumber_InPlaceMultiply(__pyx_t_2, __pyx_v_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 1044, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(4, 1044, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_result->__pyx_base.view.len = __pyx_t_9;
  }

  /* "View.MemoryView":1046
 *         result.view.len *= length
 * 
 *     result.to_object_func = to_object_func             # <<<<<<<<<<<<<<
 *     result.to_dtype_func = to_dtype_func
 * 
 */
  __pyx_v_result->to_object_func = __pyx_v_to_object_func;

  /* "View.MemoryView":1047
 * 
 *     result.to_object_func = to_object_func
 *     result.to_dtype_func = to_dtype_func             # <<<<<<<<<<<<<<
 * 
 *     return result
 */
  __pyx_v_result->to_dtype_func = __pyx_v_to_dtype_func;

  /* "View.MemoryView":1049
 *     result.to_dtype_func = to_dtype_func
 * 
 *     return result             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_get_slice_from_memoryview')
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__pyx_v_result);
  goto __pyx_L0;

  /* "View.MemoryView":999
 * 
 * @cname('__pyx_memoryview_fromslice')
 * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice,             # <<<<<<<<<<<<<<
 *                           int ndim,
 *                           object (*to_object_func)(char *),
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview_fromslice", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_length);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":1052
 * 
 * @cname('__pyx_memoryview_get_slice_from_memoryview')
 * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview,             # <<<<<<<<<<<<<<
 *                                                    __Pyx_memviewslice *mslice) except NULL:
 *     cdef _memoryviewslice obj
 */

static __Pyx_memviewslice *__pyx_memoryview_get_slice_from_memoryview(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_mslice) {
  struct __pyx_memoryviewslice_obj *__pyx_v_obj = 0;
  __Pyx_memviewslice *__pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_slice_from_memview", 0);

  /* "View.MemoryView":1055
 *                                                    __Pyx_memviewslice *mslice) except NULL:
 *     cdef _memoryviewslice obj
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         obj = memview
 *         return &obj.from_slice
 */
  __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1056
 *     cdef _memoryviewslice obj
 *     if isinstance(memview, _memoryviewslice):
 *         obj = memview             # <<<<<<<<<<<<<<
 *         return &obj.from_slice
 *     else:
 */
    if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(4, 1056, __pyx_L1_error)
    __pyx_t_3 = ((PyObject *)__pyx_v_memview);
    __Pyx_INCREF(__pyx_t_3);
    __pyx_v_obj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "View.MemoryView":1057
 *     if isinstance(memview, _memoryviewslice):
 *         obj = memview
 *         return &obj.from_slice             # <<<<<<<<<<<<<<
 *     else:
 *         slice_copy(memview, mslice)
 */
    __pyx_r = (&__pyx_v_obj->from_slice);
    goto __pyx_L0;

    /* "View.MemoryView":1055
 *                                                    __Pyx_memviewslice *mslice) except NULL:
 *     cdef _memoryviewslice obj
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         obj = memview
 *         return &obj.from_slice
 */
  }

  /* "View.MemoryView":1059
 *         return &obj.from_slice
 *     else:
 *         slice_copy(memview, mslice)             # <<<<<<<<<<<<<<
 *         return mslice
 * 
 */
  /*else*/ {
    __pyx_memoryview_slice_copy(__pyx_v_memview, __pyx_v_mslice);

    /* "View.MemoryView":1060
 *     else:
 *         slice_copy(memview, mslice)
 *         return mslice             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_slice_copy')
 */
    __pyx_r = __pyx_v_mslice;
    goto __pyx_L0;
  }

  /* "View.MemoryView":1052
 * 
 * @cname('__pyx_memoryview_get_slice_from_memoryview')
 * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview,             # <<<<<<<<<<<<<<
 *                                                    __Pyx_memviewslice *mslice) except NULL:
 *     cdef _memoryviewslice obj
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.get_slice_from_memview", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_obj);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":1063
 * 
 * @cname('__pyx_memoryview_slice_copy')
 * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst):             # <<<<<<<<<<<<<<
 *     cdef int dim
 *     cdef (Py_ssize_t*) shape, strides, suboffsets
 */

static void __pyx_memoryview_slice_copy(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_dst) {
  int __pyx_v_dim;
  Py_ssize_t *__pyx_v_shape;
  Py_ssize_t *__pyx_v_strides;
  Py_ssize_t *__pyx_v_suboffsets;
  __Pyx_RefNannyDeclarations
  Py_ssize_t *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  __Pyx_RefNannySetupContext("slice_copy", 0);

  /* "View.MemoryView":1067
 *     cdef (Py_ssize_t*) shape, strides, suboffsets
 * 
 *     shape = memview.view.shape             # <<<<<<<<<<<<<<
 *     strides = memview.view.strides
 *     suboffsets = memview.view.suboffsets
 */
  __pyx_t_1 = __pyx_v_memview->view.shape;
  __pyx_v_shape = __pyx_t_1;

  /* "View.MemoryView":1068
 * 
 *     shape = memview.view.shape
 *     strides = memview.view.strides             # <<<<<<<<<<<<<<
 *     suboffsets = memview.view.suboffsets
 * 
 */
  __pyx_t_1 = __pyx_v_memview->view.strides;
  __pyx_v_strides = __pyx_t_1;

  /* "View.MemoryView":1069
 *     shape = memview.view.shape
 *     strides = memview.view.strides
 *     suboffsets = memview.view.suboffsets             # <<<<<<<<<<<<<<
 * 
 *     dst.memview = <__pyx_memoryview *> memview
 */
  __pyx_t_1 = __pyx_v_memview->view.suboffsets;
  __pyx_v_suboffsets = __pyx_t_1;

  /* "View.MemoryView":1071
 *     suboffsets = memview.view.suboffsets
 * 
 *     dst.memview = <__pyx_memoryview *> memview             # <<<<<<<<<<<<<<
 *     dst.data = <char *> memview.view.buf
 * 
 */
  __pyx_v_dst->memview = ((struct __pyx_memoryview_obj *)__pyx_v_memview);

  /* "View.MemoryView":1072
 * 
 *     dst.memview = <__pyx_memoryview *> memview
 *     dst.data = <char *> memview.view.buf             # <<<<<<<<<<<<<<
 * 
 *     for dim in range(memview.view.ndim):
 */
  __pyx_v_dst->data = ((char *)__pyx_v_memview->view.buf);

  /* "View.MemoryView":1074
 *     dst.data = <char *> memview.view.buf
 * 
 *     for dim in range(memview.view.ndim):             # <<<<<<<<<<<<<<
 *         dst.shape[dim] = shape[dim]
 *         dst.strides[dim] = strides[dim]
 */
  __pyx_t_2 = __pyx_v_memview->view.ndim;
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_dim = __pyx_t_4;

    /* "View.MemoryView":1075
 * 
 *     for dim in range(memview.view.ndim):
 *         dst.shape[dim] = shape[dim]             # <<<<<<<<<<<<<<
 *         dst.strides[dim] = strides[dim]
 *         dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1
 */
    (__pyx_v_dst->shape[__pyx_v_dim]) = (__pyx_v_shape[__pyx_v_dim]);

    /* "View.MemoryView":1076
 *     for dim in range(memview.view.ndim):
 *         dst.shape[dim] = shape[dim]
 *         dst.strides[dim] = strides[dim]             # <<<<<<<<<<<<<<
 *         dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1
 * 
 */
    (__pyx_v_dst->strides[__pyx_v_dim]) = (__pyx_v_strides[__pyx_v_dim]);

    /* "View.MemoryView":1077
 *         dst.shape[dim] = shape[dim]
 *         dst.strides[dim] = strides[dim]
 *         dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_copy_object')
 */
    if ((__pyx_v_suboffsets != 0)) {
      __pyx_t_5 = (__pyx_v_suboffsets[__pyx_v_dim]);
    } else {
      __pyx_t_5 = -1L;
    }
    (__pyx_v_dst->suboffsets[__pyx_v_dim]) = __pyx_t_5;
  }

  /* "View.MemoryView":1063
 * 
 * @cname('__pyx_memoryview_slice_copy')
 * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst):             # <<<<<<<<<<<<<<
 *     cdef int dim
 *     cdef (Py_ssize_t*) shape, strides, suboffsets
 */

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

/* "View.MemoryView":1080
 * 
 * @cname('__pyx_memoryview_copy_object')
 * cdef memoryview_copy(memoryview memview):             # <<<<<<<<<<<<<<
 *     "Create a new memoryview object"
 *     cdef __Pyx_memviewslice memviewslice
 */

static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *__pyx_v_memview) {
  __Pyx_memviewslice __pyx_v_memviewslice;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("memoryview_copy", 0);

  /* "View.MemoryView":1083
 *     "Create a new memoryview object"
 *     cdef __Pyx_memviewslice memviewslice
 *     slice_copy(memview, &memviewslice)             # <<<<<<<<<<<<<<
 *     return memoryview_copy_from_slice(memview, &memviewslice)
 * 
 */
  __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_memviewslice));

  /* "View.MemoryView":1084
 *     cdef __Pyx_memviewslice memviewslice
 *     slice_copy(memview, &memviewslice)
 *     return memoryview_copy_from_slice(memview, &memviewslice)             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_copy_object_from_slice')
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_memoryview_copy_object_from_slice(__pyx_v_memview, (&__pyx_v_memviewslice)); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 1084, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":1080
 * 
 * @cname('__pyx_memoryview_copy_object')
 * cdef memoryview_copy(memoryview memview):             # <<<<<<<<<<<<<<
 *     "Create a new memoryview object"
 *     cdef __Pyx_memviewslice memviewslice
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.memoryview_copy", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":1087
 * 
 * @cname('__pyx_memoryview_copy_object_from_slice')
 * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice):             # <<<<<<<<<<<<<<
 *     """
 *     Create a new memoryview object from a given memoryview object and slice.
 */

static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_memviewslice) {
  PyObject *(*__pyx_v_to_object_func)(char *);
  int (*__pyx_v_to_dtype_func)(char *, PyObject *);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *(*__pyx_t_3)(char *);
  int (*__pyx_t_4)(char *, PyObject *);
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("memoryview_copy_from_slice", 0);

  /* "View.MemoryView":1094
 *     cdef int (*to_dtype_func)(char *, object) except 0
 * 
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         to_object_func = (<_memoryviewslice> memview).to_object_func
 *         to_dtype_func = (<_memoryviewslice> memview).to_dtype_func
 */
  __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1095
 * 
 *     if isinstance(memview, _memoryviewslice):
 *         to_object_func = (<_memoryviewslice> memview).to_object_func             # <<<<<<<<<<<<<<
 *         to_dtype_func = (<_memoryviewslice> memview).to_dtype_func
 *     else:
 */
    __pyx_t_3 = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_object_func;
    __pyx_v_to_object_func = __pyx_t_3;

    /* "View.MemoryView":1096
 *     if isinstance(memview, _memoryviewslice):
 *         to_object_func = (<_memoryviewslice> memview).to_object_func
 *         to_dtype_func = (<_memoryviewslice> memview).to_dtype_func             # <<<<<<<<<<<<<<
 *     else:
 *         to_object_func = NULL
 */
    __pyx_t_4 = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_dtype_func;
    __pyx_v_to_dtype_func = __pyx_t_4;

    /* "View.MemoryView":1094
 *     cdef int (*to_dtype_func)(char *, object) except 0
 * 
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         to_object_func = (<_memoryviewslice> memview).to_object_func
 *         to_dtype_func = (<_memoryviewslice> memview).to_dtype_func
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":1098
 *         to_dtype_func = (<_memoryviewslice> memview).to_dtype_func
 *     else:
 *         to_object_func = NULL             # <<<<<<<<<<<<<<
 *         to_dtype_func = NULL
 * 
 */
  /*else*/ {
    __pyx_v_to_object_func = NULL;

    /* "View.MemoryView":1099
 *     else:
 *         to_object_func = NULL
 *         to_dtype_func = NULL             # <<<<<<<<<<<<<<
 * 
 *     return memoryview_fromslice(memviewslice[0], memview.view.ndim,
 */
    __pyx_v_to_dtype_func = NULL;
  }
  __pyx_L3:;

  /* "View.MemoryView":1101
 *         to_dtype_func = NULL
 * 
 *     return memoryview_fromslice(memviewslice[0], memview.view.ndim,             # <<<<<<<<<<<<<<
 *                                 to_object_func, to_dtype_func,
 *                                 memview.dtype_is_object)
 */
  __Pyx_XDECREF(__pyx_r);

  /* "View.MemoryView":1103
 *     return memoryview_fromslice(memviewslice[0], memview.view.ndim,
 *                                 to_object_func, to_dtype_func,
 *                                 memview.dtype_is_object)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = __pyx_memoryview_fromslice((__pyx_v_memviewslice[0]), __pyx_v_memview->view.ndim, __pyx_v_to_object_func, __pyx_v_to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 1101, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":1087
 * 
 * @cname('__pyx_memoryview_copy_object_from_slice')
 * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice):             # <<<<<<<<<<<<<<
 *     """
 *     Create a new memoryview object from a given memoryview object and slice.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.memoryview_copy_from_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":1109
 * 
 * 
 * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil:             # <<<<<<<<<<<<<<
 *     if arg < 0:
 *         return -arg
 */

static Py_ssize_t abs_py_ssize_t(Py_ssize_t __pyx_v_arg) {
  Py_ssize_t __pyx_r;
  int __pyx_t_1;

  /* "View.MemoryView":1110
 * 
 * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil:
 *     if arg < 0:             # <<<<<<<<<<<<<<
 *         return -arg
 *     else:
 */
  __pyx_t_1 = ((__pyx_v_arg < 0) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1111
 * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil:
 *     if arg < 0:
 *         return -arg             # <<<<<<<<<<<<<<
 *     else:
 *         return arg
 */
    __pyx_r = (-__pyx_v_arg);
    goto __pyx_L0;

    /* "View.MemoryView":1110
 * 
 * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil:
 *     if arg < 0:             # <<<<<<<<<<<<<<
 *         return -arg
 *     else:
 */
  }

  /* "View.MemoryView":1113
 *         return -arg
 *     else:
 *         return arg             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_get_best_slice_order')
 */
  /*else*/ {
    __pyx_r = __pyx_v_arg;
    goto __pyx_L0;
  }

  /* "View.MemoryView":1109
 * 
 * 
 * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil:             # <<<<<<<<<<<<<<
 *     if arg < 0:
 *         return -arg
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "View.MemoryView":1116
 * 
 * @cname('__pyx_get_best_slice_order')
 * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     Figure out the best memory access order for a given slice.
 */

static char __pyx_get_best_slice_order(__Pyx_memviewslice *__pyx_v_mslice, int __pyx_v_ndim) {
  int __pyx_v_i;
  Py_ssize_t __pyx_v_c_stride;
  Py_ssize_t __pyx_v_f_stride;
  char __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;

  /* "View.MemoryView":1121
 *     """
 *     cdef int i
 *     cdef Py_ssize_t c_stride = 0             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t f_stride = 0
 * 
 */
  __pyx_v_c_stride = 0;

  /* "View.MemoryView":1122
 *     cdef int i
 *     cdef Py_ssize_t c_stride = 0
 *     cdef Py_ssize_t f_stride = 0             # <<<<<<<<<<<<<<
 * 
 *     for i in range(ndim - 1, -1, -1):
 */
  __pyx_v_f_stride = 0;

  /* "View.MemoryView":1124
 *     cdef Py_ssize_t f_stride = 0
 * 
 *     for i in range(ndim - 1, -1, -1):             # <<<<<<<<<<<<<<
 *         if mslice.shape[i] > 1:
 *             c_stride = mslice.strides[i]
 */
  for (__pyx_t_1 = (__pyx_v_ndim - 1); __pyx_t_1 > -1; __pyx_t_1-=1) {
    __pyx_v_i = __pyx_t_1;

    /* "View.MemoryView":1125
 * 
 *     for i in range(ndim - 1, -1, -1):
 *         if mslice.shape[i] > 1:             # <<<<<<<<<<<<<<
 *             c_stride = mslice.strides[i]
 *             break
 */
    __pyx_t_2 = (((__pyx_v_mslice->shape[__pyx_v_i]) > 1) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1126
 *     for i in range(ndim - 1, -1, -1):
 *         if mslice.shape[i] > 1:
 *             c_stride = mslice.strides[i]             # <<<<<<<<<<<<<<
 *             break
 * 
 */
      __pyx_v_c_stride = (__pyx_v_mslice->strides[__pyx_v_i]);

      /* "View.MemoryView":1127
 *         if mslice.shape[i] > 1:
 *             c_stride = mslice.strides[i]
 *             break             # <<<<<<<<<<<<<<
 * 
 *     for i in range(ndim):
 */
      goto __pyx_L4_break;

      /* "View.MemoryView":1125
 * 
 *     for i in range(ndim - 1, -1, -1):
 *         if mslice.shape[i] > 1:             # <<<<<<<<<<<<<<
 *             c_stride = mslice.strides[i]
 *             break
 */
    }
  }
  __pyx_L4_break:;

  /* "View.MemoryView":1129
 *             break
 * 
 *     for i in range(ndim):             # <<<<<<<<<<<<<<
 *         if mslice.shape[i] > 1:
 *             f_stride = mslice.strides[i]
 */
  __pyx_t_1 = __pyx_v_ndim;
  __pyx_t_3 = __pyx_t_1;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;

    /* "View.MemoryView":1130
 * 
 *     for i in range(ndim):
 *         if mslice.shape[i] > 1:             # <<<<<<<<<<<<<<
 *             f_stride = mslice.strides[i]
 *             break
 */
    __pyx_t_2 = (((__pyx_v_mslice->shape[__pyx_v_i]) > 1) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1131
 *     for i in range(ndim):
 *         if mslice.shape[i] > 1:
 *             f_stride = mslice.strides[i]             # <<<<<<<<<<<<<<
 *             break
 * 
 */
      __pyx_v_f_stride = (__pyx_v_mslice->strides[__pyx_v_i]);

      /* "View.MemoryView":1132
 *         if mslice.shape[i] > 1:
 *             f_stride = mslice.strides[i]
 *             break             # <<<<<<<<<<<<<<
 * 
 *     if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride):
 */
      goto __pyx_L7_break;

      /* "View.MemoryView":1130
 * 
 *     for i in range(ndim):
 *         if mslice.shape[i] > 1:             # <<<<<<<<<<<<<<
 *             f_stride = mslice.strides[i]
 *             break
 */
    }
  }
  __pyx_L7_break:;

  /* "View.MemoryView":1134
 *             break
 * 
 *     if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride):             # <<<<<<<<<<<<<<
 *         return 'C'
 *     else:
 */
  __pyx_t_2 = ((abs_py_ssize_t(__pyx_v_c_stride) <= abs_py_ssize_t(__pyx_v_f_stride)) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1135
 * 
 *     if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride):
 *         return 'C'             # <<<<<<<<<<<<<<
 *     else:
 *         return 'F'
 */
    __pyx_r = 'C';
    goto __pyx_L0;

    /* "View.MemoryView":1134
 *             break
 * 
 *     if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride):             # <<<<<<<<<<<<<<
 *         return 'C'
 *     else:
 */
  }

  /* "View.MemoryView":1137
 *         return 'C'
 *     else:
 *         return 'F'             # <<<<<<<<<<<<<<
 * 
 * @cython.cdivision(True)
 */
  /*else*/ {
    __pyx_r = 'F';
    goto __pyx_L0;
  }

  /* "View.MemoryView":1116
 * 
 * @cname('__pyx_get_best_slice_order')
 * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     Figure out the best memory access order for a given slice.
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "View.MemoryView":1140
 * 
 * @cython.cdivision(True)
 * cdef void _copy_strided_to_strided(char *src_data, Py_ssize_t *src_strides,             # <<<<<<<<<<<<<<
 *                                    char *dst_data, Py_ssize_t *dst_strides,
 *                                    Py_ssize_t *src_shape, Py_ssize_t *dst_shape,
 */

static void _copy_strided_to_strided(char *__pyx_v_src_data, Py_ssize_t *__pyx_v_src_strides, char *__pyx_v_dst_data, Py_ssize_t *__pyx_v_dst_strides, Py_ssize_t *__pyx_v_src_shape, Py_ssize_t *__pyx_v_dst_shape, int __pyx_v_ndim, size_t __pyx_v_itemsize) {
  CYTHON_UNUSED Py_ssize_t __pyx_v_i;
  CYTHON_UNUSED Py_ssize_t __pyx_v_src_extent;
  Py_ssize_t __pyx_v_dst_extent;
  Py_ssize_t __pyx_v_src_stride;
  Py_ssize_t __pyx_v_dst_stride;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  Py_ssize_t __pyx_t_6;

  /* "View.MemoryView":1147
 * 
 *     cdef Py_ssize_t i
 *     cdef Py_ssize_t src_extent = src_shape[0]             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t dst_extent = dst_shape[0]
 *     cdef Py_ssize_t src_stride = src_strides[0]
 */
  __pyx_v_src_extent = (__pyx_v_src_shape[0]);

  /* "View.MemoryView":1148
 *     cdef Py_ssize_t i
 *     cdef Py_ssize_t src_extent = src_shape[0]
 *     cdef Py_ssize_t dst_extent = dst_shape[0]             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t src_stride = src_strides[0]
 *     cdef Py_ssize_t dst_stride = dst_strides[0]
 */
  __pyx_v_dst_extent = (__pyx_v_dst_shape[0]);

  /* "View.MemoryView":1149
 *     cdef Py_ssize_t src_extent = src_shape[0]
 *     cdef Py_ssize_t dst_extent = dst_shape[0]
 *     cdef Py_ssize_t src_stride = src_strides[0]             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t dst_stride = dst_strides[0]
 * 
 */
  __pyx_v_src_stride = (__pyx_v_src_strides[0]);

  /* "View.MemoryView":1150
 *     cdef Py_ssize_t dst_extent = dst_shape[0]
 *     cdef Py_ssize_t src_stride = src_strides[0]
 *     cdef Py_ssize_t dst_stride = dst_strides[0]             # <<<<<<<<<<<<<<
 * 
 *     if ndim == 1:
 */
  __pyx_v_dst_stride = (__pyx_v_dst_strides[0]);

  /* "View.MemoryView":1152
 *     cdef Py_ssize_t dst_stride = dst_strides[0]
 * 
 *     if ndim == 1:             # <<<<<<<<<<<<<<
 *        if (src_stride > 0 and dst_stride > 0 and
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):
 */
  __pyx_t_1 = ((__pyx_v_ndim == 1) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1153
 * 
 *     if ndim == 1:
 *        if (src_stride > 0 and dst_stride > 0 and             # <<<<<<<<<<<<<<
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):
 *            memcpy(dst_data, src_data, itemsize * dst_extent)
 */
    __pyx_t_2 = ((__pyx_v_src_stride > 0) != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L5_bool_binop_done;
    }
    __pyx_t_2 = ((__pyx_v_dst_stride > 0) != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L5_bool_binop_done;
    }

    /* "View.MemoryView":1154
 *     if ndim == 1:
 *        if (src_stride > 0 and dst_stride > 0 and
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):             # <<<<<<<<<<<<<<
 *            memcpy(dst_data, src_data, itemsize * dst_extent)
 *        else:
 */
    __pyx_t_2 = (((size_t)__pyx_v_src_stride) == __pyx_v_itemsize);
    if (__pyx_t_2) {
      __pyx_t_2 = (__pyx_v_itemsize == ((size_t)__pyx_v_dst_stride));
    }
    __pyx_t_3 = (__pyx_t_2 != 0);
    __pyx_t_1 = __pyx_t_3;
    __pyx_L5_bool_binop_done:;

    /* "View.MemoryView":1153
 * 
 *     if ndim == 1:
 *        if (src_stride > 0 and dst_stride > 0 and             # <<<<<<<<<<<<<<
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):
 *            memcpy(dst_data, src_data, itemsize * dst_extent)
 */
    if (__pyx_t_1) {

      /* "View.MemoryView":1155
 *        if (src_stride > 0 and dst_stride > 0 and
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):
 *            memcpy(dst_data, src_data, itemsize * dst_extent)             # <<<<<<<<<<<<<<
 *        else:
 *            for i in range(dst_extent):
 */
      (void)(memcpy(__pyx_v_dst_data, __pyx_v_src_data, (__pyx_v_itemsize * __pyx_v_dst_extent)));

      /* "View.MemoryView":1153
 * 
 *     if ndim == 1:
 *        if (src_stride > 0 and dst_stride > 0 and             # <<<<<<<<<<<<<<
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):
 *            memcpy(dst_data, src_data, itemsize * dst_extent)
 */
      goto __pyx_L4;
    }

    /* "View.MemoryView":1157
 *            memcpy(dst_data, src_data, itemsize * dst_extent)
 *        else:
 *            for i in range(dst_extent):             # <<<<<<<<<<<<<<
 *                memcpy(dst_data, src_data, itemsize)
 *                src_data += src_stride
 */
    /*else*/ {
      __pyx_t_4 = __pyx_v_dst_extent;
      __pyx_t_5 = __pyx_t_4;
      for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
        __pyx_v_i = __pyx_t_6;

        /* "View.MemoryView":1158
 *        else:
 *            for i in range(dst_extent):
 *                memcpy(dst_data, src_data, itemsize)             # <<<<<<<<<<<<<<
 *                src_data += src_stride
 *                dst_data += dst_stride
 */
        (void)(memcpy(__pyx_v_dst_data, __pyx_v_src_data, __pyx_v_itemsize));

        /* "View.MemoryView":1159
 *            for i in range(dst_extent):
 *                memcpy(dst_data, src_data, itemsize)
 *                src_data += src_stride             # <<<<<<<<<<<<<<
 *                dst_data += dst_stride
 *     else:
 */
        __pyx_v_src_data = (__pyx_v_src_data + __pyx_v_src_stride);

        /* "View.MemoryView":1160
 *                memcpy(dst_data, src_data, itemsize)
 *                src_data += src_stride
 *                dst_data += dst_stride             # <<<<<<<<<<<<<<
 *     else:
 *         for i in range(dst_extent):
 */
        __pyx_v_dst_data = (__pyx_v_dst_data + __pyx_v_dst_stride);
      }
    }
    __pyx_L4:;

    /* "View.MemoryView":1152
 *     cdef Py_ssize_t dst_stride = dst_strides[0]
 * 
 *     if ndim == 1:             # <<<<<<<<<<<<<<
 *        if (src_stride > 0 and dst_stride > 0 and
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":1162
 *                dst_data += dst_stride
 *     else:
 *         for i in range(dst_extent):             # <<<<<<<<<<<<<<
 *             _copy_strided_to_strided(src_data, src_strides + 1,
 *                                      dst_data, dst_strides + 1,
 */
  /*else*/ {
    __pyx_t_4 = __pyx_v_dst_extent;
    __pyx_t_5 = __pyx_t_4;
    for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
      __pyx_v_i = __pyx_t_6;

      /* "View.MemoryView":1163
 *     else:
 *         for i in range(dst_extent):
 *             _copy_strided_to_strided(src_data, src_strides + 1,             # <<<<<<<<<<<<<<
 *                                      dst_data, dst_strides + 1,
 *                                      src_shape + 1, dst_shape + 1,
 */
      _copy_strided_to_strided(__pyx_v_src_data, (__pyx_v_src_strides + 1), __pyx_v_dst_data, (__pyx_v_dst_strides + 1), (__pyx_v_src_shape + 1), (__pyx_v_dst_shape + 1), (__pyx_v_ndim - 1), __pyx_v_itemsize);

      /* "View.MemoryView":1167
 *                                      src_shape + 1, dst_shape + 1,
 *                                      ndim - 1, itemsize)
 *             src_data += src_stride             # <<<<<<<<<<<<<<
 *             dst_data += dst_stride
 * 
 */
      __pyx_v_src_data = (__pyx_v_src_data + __pyx_v_src_stride);

      /* "View.MemoryView":1168
 *                                      ndim - 1, itemsize)
 *             src_data += src_stride
 *             dst_data += dst_stride             # <<<<<<<<<<<<<<
 * 
 * cdef void copy_strided_to_strided(__Pyx_memviewslice *src,
 */
      __pyx_v_dst_data = (__pyx_v_dst_data + __pyx_v_dst_stride);
    }
  }
  __pyx_L3:;

  /* "View.MemoryView":1140
 * 
 * @cython.cdivision(True)
 * cdef void _copy_strided_to_strided(char *src_data, Py_ssize_t *src_strides,             # <<<<<<<<<<<<<<
 *                                    char *dst_data, Py_ssize_t *dst_strides,
 *                                    Py_ssize_t *src_shape, Py_ssize_t *dst_shape,
 */

  /* function exit code */
}

/* "View.MemoryView":1170
 *             dst_data += dst_stride
 * 
 * cdef void copy_strided_to_strided(__Pyx_memviewslice *src,             # <<<<<<<<<<<<<<
 *                                   __Pyx_memviewslice *dst,
 *                                   int ndim, size_t itemsize) nogil:
 */

static void copy_strided_to_strided(__Pyx_memviewslice *__pyx_v_src, __Pyx_memviewslice *__pyx_v_dst, int __pyx_v_ndim, size_t __pyx_v_itemsize) {

  /* "View.MemoryView":1173
 *                                   __Pyx_memviewslice *dst,
 *                                   int ndim, size_t itemsize) nogil:
 *     _copy_strided_to_strided(src.data, src.strides, dst.data, dst.strides,             # <<<<<<<<<<<<<<
 *                              src.shape, dst.shape, ndim, itemsize)
 * 
 */
  _copy_strided_to_strided(__pyx_v_src->data, __pyx_v_src->strides, __pyx_v_dst->data, __pyx_v_dst->strides, __pyx_v_src->shape, __pyx_v_dst->shape, __pyx_v_ndim, __pyx_v_itemsize);

  /* "View.MemoryView":1170
 *             dst_data += dst_stride
 * 
 * cdef void copy_strided_to_strided(__Pyx_memviewslice *src,             # <<<<<<<<<<<<<<
 *                                   __Pyx_memviewslice *dst,
 *                                   int ndim, size_t itemsize) nogil:
 */

  /* function exit code */
}

/* "View.MemoryView":1177
 * 
 * @cname('__pyx_memoryview_slice_get_size')
 * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil:             # <<<<<<<<<<<<<<
 *     "Return the size of the memory occupied by the slice in number of bytes"
 *     cdef Py_ssize_t shape, size = src.memview.view.itemsize
 */

static Py_ssize_t __pyx_memoryview_slice_get_size(__Pyx_memviewslice *__pyx_v_src, int __pyx_v_ndim) {
  Py_ssize_t __pyx_v_shape;
  Py_ssize_t __pyx_v_size;
  Py_ssize_t __pyx_r;
  Py_ssize_t __pyx_t_1;
  Py_ssize_t *__pyx_t_2;
  Py_ssize_t *__pyx_t_3;
  Py_ssize_t *__pyx_t_4;

  /* "View.MemoryView":1179
 * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil:
 *     "Return the size of the memory occupied by the slice in number of bytes"
 *     cdef Py_ssize_t shape, size = src.memview.view.itemsize             # <<<<<<<<<<<<<<
 * 
 *     for shape in src.shape[:ndim]:
 */
  __pyx_t_1 = __pyx_v_src->memview->view.itemsize;
  __pyx_v_size = __pyx_t_1;

  /* "View.MemoryView":1181
 *     cdef Py_ssize_t shape, size = src.memview.view.itemsize
 * 
 *     for shape in src.shape[:ndim]:             # <<<<<<<<<<<<<<
 *         size *= shape
 * 
 */
  __pyx_t_3 = (__pyx_v_src->shape + __pyx_v_ndim);
  for (__pyx_t_4 = __pyx_v_src->shape; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) {
    __pyx_t_2 = __pyx_t_4;
    __pyx_v_shape = (__pyx_t_2[0]);

    /* "View.MemoryView":1182
 * 
 *     for shape in src.shape[:ndim]:
 *         size *= shape             # <<<<<<<<<<<<<<
 * 
 *     return size
 */
    __pyx_v_size = (__pyx_v_size * __pyx_v_shape);
  }

  /* "View.MemoryView":1184
 *         size *= shape
 * 
 *     return size             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_fill_contig_strides_array')
 */
  __pyx_r = __pyx_v_size;
  goto __pyx_L0;

  /* "View.MemoryView":1177
 * 
 * @cname('__pyx_memoryview_slice_get_size')
 * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil:             # <<<<<<<<<<<<<<
 *     "Return the size of the memory occupied by the slice in number of bytes"
 *     cdef Py_ssize_t shape, size = src.memview.view.itemsize
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "View.MemoryView":1187
 * 
 * @cname('__pyx_fill_contig_strides_array')
 * cdef Py_ssize_t fill_contig_strides_array(             # <<<<<<<<<<<<<<
 *                 Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride,
 *                 int ndim, char order) nogil:
 */

static Py_ssize_t __pyx_fill_contig_strides_array(Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, Py_ssize_t __pyx_v_stride, int __pyx_v_ndim, char __pyx_v_order) {
  int __pyx_v_idx;
  Py_ssize_t __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;

  /* "View.MemoryView":1196
 *     cdef int idx
 * 
 *     if order == 'F':             # <<<<<<<<<<<<<<
 *         for idx in range(ndim):
 *             strides[idx] = stride
 */
  __pyx_t_1 = ((__pyx_v_order == 'F') != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1197
 * 
 *     if order == 'F':
 *         for idx in range(ndim):             # <<<<<<<<<<<<<<
 *             strides[idx] = stride
 *             stride *= shape[idx]
 */
    __pyx_t_2 = __pyx_v_ndim;
    __pyx_t_3 = __pyx_t_2;
    for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
      __pyx_v_idx = __pyx_t_4;

      /* "View.MemoryView":1198
 *     if order == 'F':
 *         for idx in range(ndim):
 *             strides[idx] = stride             # <<<<<<<<<<<<<<
 *             stride *= shape[idx]
 *     else:
 */
      (__pyx_v_strides[__pyx_v_idx]) = __pyx_v_stride;

      /* "View.MemoryView":1199
 *         for idx in range(ndim):
 *             strides[idx] = stride
 *             stride *= shape[idx]             # <<<<<<<<<<<<<<
 *     else:
 *         for idx in range(ndim - 1, -1, -1):
 */
      __pyx_v_stride = (__pyx_v_stride * (__pyx_v_shape[__pyx_v_idx]));
    }

    /* "View.MemoryView":1196
 *     cdef int idx
 * 
 *     if order == 'F':             # <<<<<<<<<<<<<<
 *         for idx in range(ndim):
 *             strides[idx] = stride
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":1201
 *             stride *= shape[idx]
 *     else:
 *         for idx in range(ndim - 1, -1, -1):             # <<<<<<<<<<<<<<
 *             strides[idx] = stride
 *             stride *= shape[idx]
 */
  /*else*/ {
    for (__pyx_t_2 = (__pyx_v_ndim - 1); __pyx_t_2 > -1; __pyx_t_2-=1) {
      __pyx_v_idx = __pyx_t_2;

      /* "View.MemoryView":1202
 *     else:
 *         for idx in range(ndim - 1, -1, -1):
 *             strides[idx] = stride             # <<<<<<<<<<<<<<
 *             stride *= shape[idx]
 * 
 */
      (__pyx_v_strides[__pyx_v_idx]) = __pyx_v_stride;

      /* "View.MemoryView":1203
 *         for idx in range(ndim - 1, -1, -1):
 *             strides[idx] = stride
 *             stride *= shape[idx]             # <<<<<<<<<<<<<<
 * 
 *     return stride
 */
      __pyx_v_stride = (__pyx_v_stride * (__pyx_v_shape[__pyx_v_idx]));
    }
  }
  __pyx_L3:;

  /* "View.MemoryView":1205
 *             stride *= shape[idx]
 * 
 *     return stride             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_copy_data_to_temp')
 */
  __pyx_r = __pyx_v_stride;
  goto __pyx_L0;

  /* "View.MemoryView":1187
 * 
 * @cname('__pyx_fill_contig_strides_array')
 * cdef Py_ssize_t fill_contig_strides_array(             # <<<<<<<<<<<<<<
 *                 Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride,
 *                 int ndim, char order) nogil:
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "View.MemoryView":1208
 * 
 * @cname('__pyx_memoryview_copy_data_to_temp')
 * cdef void *copy_data_to_temp(__Pyx_memviewslice *src,             # <<<<<<<<<<<<<<
 *                              __Pyx_memviewslice *tmpslice,
 *                              char order,
 */

static void *__pyx_memoryview_copy_data_to_temp(__Pyx_memviewslice *__pyx_v_src, __Pyx_memviewslice *__pyx_v_tmpslice, char __pyx_v_order, int __pyx_v_ndim) {
  int __pyx_v_i;
  void *__pyx_v_result;
  size_t __pyx_v_itemsize;
  size_t __pyx_v_size;
  void *__pyx_r;
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  struct __pyx_memoryview_obj *__pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* "View.MemoryView":1219
 *     cdef void *result
 * 
 *     cdef size_t itemsize = src.memview.view.itemsize             # <<<<<<<<<<<<<<
 *     cdef size_t size = slice_get_size(src, ndim)
 * 
 */
  __pyx_t_1 = __pyx_v_src->memview->view.itemsize;
  __pyx_v_itemsize = __pyx_t_1;

  /* "View.MemoryView":1220
 * 
 *     cdef size_t itemsize = src.memview.view.itemsize
 *     cdef size_t size = slice_get_size(src, ndim)             # <<<<<<<<<<<<<<
 * 
 *     result = malloc(size)
 */
  __pyx_v_size = __pyx_memoryview_slice_get_size(__pyx_v_src, __pyx_v_ndim);

  /* "View.MemoryView":1222
 *     cdef size_t size = slice_get_size(src, ndim)
 * 
 *     result = malloc(size)             # <<<<<<<<<<<<<<
 *     if not result:
 *         _err(MemoryError, NULL)
 */
  __pyx_v_result = malloc(__pyx_v_size);

  /* "View.MemoryView":1223
 * 
 *     result = malloc(size)
 *     if not result:             # <<<<<<<<<<<<<<
 *         _err(MemoryError, NULL)
 * 
 */
  __pyx_t_2 = ((!(__pyx_v_result != 0)) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1224
 *     result = malloc(size)
 *     if not result:
 *         _err(MemoryError, NULL)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_3 = __pyx_memoryview_err(__pyx_builtin_MemoryError, NULL); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(4, 1224, __pyx_L1_error)

    /* "View.MemoryView":1223
 * 
 *     result = malloc(size)
 *     if not result:             # <<<<<<<<<<<<<<
 *         _err(MemoryError, NULL)
 * 
 */
  }

  /* "View.MemoryView":1227
 * 
 * 
 *     tmpslice.data = <char *> result             # <<<<<<<<<<<<<<
 *     tmpslice.memview = src.memview
 *     for i in range(ndim):
 */
  __pyx_v_tmpslice->data = ((char *)__pyx_v_result);

  /* "View.MemoryView":1228
 * 
 *     tmpslice.data = <char *> result
 *     tmpslice.memview = src.memview             # <<<<<<<<<<<<<<
 *     for i in range(ndim):
 *         tmpslice.shape[i] = src.shape[i]
 */
  __pyx_t_4 = __pyx_v_src->memview;
  __pyx_v_tmpslice->memview = __pyx_t_4;

  /* "View.MemoryView":1229
 *     tmpslice.data = <char *> result
 *     tmpslice.memview = src.memview
 *     for i in range(ndim):             # <<<<<<<<<<<<<<
 *         tmpslice.shape[i] = src.shape[i]
 *         tmpslice.suboffsets[i] = -1
 */
  __pyx_t_3 = __pyx_v_ndim;
  __pyx_t_5 = __pyx_t_3;
  for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
    __pyx_v_i = __pyx_t_6;

    /* "View.MemoryView":1230
 *     tmpslice.memview = src.memview
 *     for i in range(ndim):
 *         tmpslice.shape[i] = src.shape[i]             # <<<<<<<<<<<<<<
 *         tmpslice.suboffsets[i] = -1
 * 
 */
    (__pyx_v_tmpslice->shape[__pyx_v_i]) = (__pyx_v_src->shape[__pyx_v_i]);

    /* "View.MemoryView":1231
 *     for i in range(ndim):
 *         tmpslice.shape[i] = src.shape[i]
 *         tmpslice.suboffsets[i] = -1             # <<<<<<<<<<<<<<
 * 
 *     fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize,
 */
    (__pyx_v_tmpslice->suboffsets[__pyx_v_i]) = -1L;
  }

  /* "View.MemoryView":1233
 *         tmpslice.suboffsets[i] = -1
 * 
 *     fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize,             # <<<<<<<<<<<<<<
 *                               ndim, order)
 * 
 */
  (void)(__pyx_fill_contig_strides_array((&(__pyx_v_tmpslice->shape[0])), (&(__pyx_v_tmpslice->strides[0])), __pyx_v_itemsize, __pyx_v_ndim, __pyx_v_order));

  /* "View.MemoryView":1237
 * 
 * 
 *     for i in range(ndim):             # <<<<<<<<<<<<<<
 *         if tmpslice.shape[i] == 1:
 *             tmpslice.strides[i] = 0
 */
  __pyx_t_3 = __pyx_v_ndim;
  __pyx_t_5 = __pyx_t_3;
  for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
    __pyx_v_i = __pyx_t_6;

    /* "View.MemoryView":1238
 * 
 *     for i in range(ndim):
 *         if tmpslice.shape[i] == 1:             # <<<<<<<<<<<<<<
 *             tmpslice.strides[i] = 0
 * 
 */
    __pyx_t_2 = (((__pyx_v_tmpslice->shape[__pyx_v_i]) == 1) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1239
 *     for i in range(ndim):
 *         if tmpslice.shape[i] == 1:
 *             tmpslice.strides[i] = 0             # <<<<<<<<<<<<<<
 * 
 *     if slice_is_contig(src[0], order, ndim):
 */
      (__pyx_v_tmpslice->strides[__pyx_v_i]) = 0;

      /* "View.MemoryView":1238
 * 
 *     for i in range(ndim):
 *         if tmpslice.shape[i] == 1:             # <<<<<<<<<<<<<<
 *             tmpslice.strides[i] = 0
 * 
 */
    }
  }

  /* "View.MemoryView":1241
 *             tmpslice.strides[i] = 0
 * 
 *     if slice_is_contig(src[0], order, ndim):             # <<<<<<<<<<<<<<
 *         memcpy(result, src.data, size)
 *     else:
 */
  __pyx_t_2 = (__pyx_memviewslice_is_contig((__pyx_v_src[0]), __pyx_v_order, __pyx_v_ndim) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1242
 * 
 *     if slice_is_contig(src[0], order, ndim):
 *         memcpy(result, src.data, size)             # <<<<<<<<<<<<<<
 *     else:
 *         copy_strided_to_strided(src, tmpslice, ndim, itemsize)
 */
    (void)(memcpy(__pyx_v_result, __pyx_v_src->data, __pyx_v_size));

    /* "View.MemoryView":1241
 *             tmpslice.strides[i] = 0
 * 
 *     if slice_is_contig(src[0], order, ndim):             # <<<<<<<<<<<<<<
 *         memcpy(result, src.data, size)
 *     else:
 */
    goto __pyx_L9;
  }

  /* "View.MemoryView":1244
 *         memcpy(result, src.data, size)
 *     else:
 *         copy_strided_to_strided(src, tmpslice, ndim, itemsize)             # <<<<<<<<<<<<<<
 * 
 *     return result
 */
  /*else*/ {
    copy_strided_to_strided(__pyx_v_src, __pyx_v_tmpslice, __pyx_v_ndim, __pyx_v_itemsize);
  }
  __pyx_L9:;

  /* "View.MemoryView":1246
 *         copy_strided_to_strided(src, tmpslice, ndim, itemsize)
 * 
 *     return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "View.MemoryView":1208
 * 
 * @cname('__pyx_memoryview_copy_data_to_temp')
 * cdef void *copy_data_to_temp(__Pyx_memviewslice *src,             # <<<<<<<<<<<<<<
 *                              __Pyx_memviewslice *tmpslice,
 *                              char order,
 */

  /* function exit code */
  __pyx_L1_error:;
  {
    #ifdef WITH_THREAD
    PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
    #endif
    __Pyx_AddTraceback("View.MemoryView.copy_data_to_temp", __pyx_clineno, __pyx_lineno, __pyx_filename);
    #ifdef WITH_THREAD
    __Pyx_PyGILState_Release(__pyx_gilstate_save);
    #endif
  }
  __pyx_r = NULL;
  __pyx_L0:;
  return __pyx_r;
}

/* "View.MemoryView":1251
 * 
 * @cname('__pyx_memoryview_err_extents')
 * cdef int _err_extents(int i, Py_ssize_t extent1,             # <<<<<<<<<<<<<<
 *                              Py_ssize_t extent2) except -1 with gil:
 *     raise ValueError("got differing extents in dimension %d (got %d and %d)" %
 */

static int __pyx_memoryview_err_extents(int __pyx_v_i, Py_ssize_t __pyx_v_extent1, Py_ssize_t __pyx_v_extent2) {
  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;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("_err_extents", 0);

  /* "View.MemoryView":1254
 *                              Py_ssize_t extent2) except -1 with gil:
 *     raise ValueError("got differing extents in dimension %d (got %d and %d)" %
 *                                                         (i, extent1, extent2))             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_err_dim')
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 1254, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_extent1); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 1254, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_extent2); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 1254, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 1254, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "View.MemoryView":1253
 * cdef int _err_extents(int i, Py_ssize_t extent1,
 *                              Py_ssize_t extent2) except -1 with gil:
 *     raise ValueError("got differing extents in dimension %d (got %d and %d)" %             # <<<<<<<<<<<<<<
 *                                                         (i, extent1, extent2))
 * 
 */
  __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_got_differing_extents_in_dimensi, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 1253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 1253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_Raise(__pyx_t_4, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __PYX_ERR(4, 1253, __pyx_L1_error)

  /* "View.MemoryView":1251
 * 
 * @cname('__pyx_memoryview_err_extents')
 * cdef int _err_extents(int i, Py_ssize_t extent1,             # <<<<<<<<<<<<<<
 *                              Py_ssize_t extent2) except -1 with gil:
 *     raise ValueError("got differing extents in dimension %d (got %d and %d)" %
 */

  /* 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("View.MemoryView._err_extents", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __Pyx_RefNannyFinishContext();
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "View.MemoryView":1257
 * 
 * @cname('__pyx_memoryview_err_dim')
 * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil:             # <<<<<<<<<<<<<<
 *     raise error(msg.decode('ascii') % dim)
 * 
 */

static int __pyx_memoryview_err_dim(PyObject *__pyx_v_error, char *__pyx_v_msg, int __pyx_v_dim) {
  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;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("_err_dim", 0);
  __Pyx_INCREF(__pyx_v_error);

  /* "View.MemoryView":1258
 * @cname('__pyx_memoryview_err_dim')
 * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil:
 *     raise error(msg.decode('ascii') % dim)             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_err')
 */
  __pyx_t_2 = __Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 1258, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 1258, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyUnicode_Format(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 1258, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_INCREF(__pyx_v_error);
  __pyx_t_3 = __pyx_v_error; __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 1258, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(4, 1258, __pyx_L1_error)

  /* "View.MemoryView":1257
 * 
 * @cname('__pyx_memoryview_err_dim')
 * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil:             # <<<<<<<<<<<<<<
 *     raise error(msg.decode('ascii') % dim)
 * 
 */

  /* 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("View.MemoryView._err_dim", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __Pyx_XDECREF(__pyx_v_error);
  __Pyx_RefNannyFinishContext();
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "View.MemoryView":1261
 * 
 * @cname('__pyx_memoryview_err')
 * cdef int _err(object error, char *msg) except -1 with gil:             # <<<<<<<<<<<<<<
 *     if msg != NULL:
 *         raise error(msg.decode('ascii'))
 */

static int __pyx_memoryview_err(PyObject *__pyx_v_error, char *__pyx_v_msg) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("_err", 0);
  __Pyx_INCREF(__pyx_v_error);

  /* "View.MemoryView":1262
 * @cname('__pyx_memoryview_err')
 * cdef int _err(object error, char *msg) except -1 with gil:
 *     if msg != NULL:             # <<<<<<<<<<<<<<
 *         raise error(msg.decode('ascii'))
 *     else:
 */
  __pyx_t_1 = ((__pyx_v_msg != NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "View.MemoryView":1263
 * cdef int _err(object error, char *msg) except -1 with gil:
 *     if msg != NULL:
 *         raise error(msg.decode('ascii'))             # <<<<<<<<<<<<<<
 *     else:
 *         raise error
 */
    __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 1263, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_error);
    __pyx_t_4 = __pyx_v_error; __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 1263, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(4, 1263, __pyx_L1_error)

    /* "View.MemoryView":1262
 * @cname('__pyx_memoryview_err')
 * cdef int _err(object error, char *msg) except -1 with gil:
 *     if msg != NULL:             # <<<<<<<<<<<<<<
 *         raise error(msg.decode('ascii'))
 *     else:
 */
  }

  /* "View.MemoryView":1265
 *         raise error(msg.decode('ascii'))
 *     else:
 *         raise error             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_copy_contents')
 */
  /*else*/ {
    __Pyx_Raise(__pyx_v_error, 0, 0, 0);
    __PYX_ERR(4, 1265, __pyx_L1_error)
  }

  /* "View.MemoryView":1261
 * 
 * @cname('__pyx_memoryview_err')
 * cdef int _err(object error, char *msg) except -1 with gil:             # <<<<<<<<<<<<<<
 *     if msg != NULL:
 *         raise error(msg.decode('ascii'))
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView._err", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __Pyx_XDECREF(__pyx_v_error);
  __Pyx_RefNannyFinishContext();
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "View.MemoryView":1268
 * 
 * @cname('__pyx_memoryview_copy_contents')
 * cdef int memoryview_copy_contents(__Pyx_memviewslice src,             # <<<<<<<<<<<<<<
 *                                   __Pyx_memviewslice dst,
 *                                   int src_ndim, int dst_ndim,
 */

static int __pyx_memoryview_copy_contents(__Pyx_memviewslice __pyx_v_src, __Pyx_memviewslice __pyx_v_dst, int __pyx_v_src_ndim, int __pyx_v_dst_ndim, int __pyx_v_dtype_is_object) {
  void *__pyx_v_tmpdata;
  size_t __pyx_v_itemsize;
  int __pyx_v_i;
  char __pyx_v_order;
  int __pyx_v_broadcasting;
  int __pyx_v_direct_copy;
  __Pyx_memviewslice __pyx_v_tmp;
  int __pyx_v_ndim;
  int __pyx_r;
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  void *__pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* "View.MemoryView":1276
 *     Check for overlapping memory and verify the shapes.
 *     """
 *     cdef void *tmpdata = NULL             # <<<<<<<<<<<<<<
 *     cdef size_t itemsize = src.memview.view.itemsize
 *     cdef int i
 */
  __pyx_v_tmpdata = NULL;

  /* "View.MemoryView":1277
 *     """
 *     cdef void *tmpdata = NULL
 *     cdef size_t itemsize = src.memview.view.itemsize             # <<<<<<<<<<<<<<
 *     cdef int i
 *     cdef char order = get_best_order(&src, src_ndim)
 */
  __pyx_t_1 = __pyx_v_src.memview->view.itemsize;
  __pyx_v_itemsize = __pyx_t_1;

  /* "View.MemoryView":1279
 *     cdef size_t itemsize = src.memview.view.itemsize
 *     cdef int i
 *     cdef char order = get_best_order(&src, src_ndim)             # <<<<<<<<<<<<<<
 *     cdef bint broadcasting = False
 *     cdef bint direct_copy = False
 */
  __pyx_v_order = __pyx_get_best_slice_order((&__pyx_v_src), __pyx_v_src_ndim);

  /* "View.MemoryView":1280
 *     cdef int i
 *     cdef char order = get_best_order(&src, src_ndim)
 *     cdef bint broadcasting = False             # <<<<<<<<<<<<<<
 *     cdef bint direct_copy = False
 *     cdef __Pyx_memviewslice tmp
 */
  __pyx_v_broadcasting = 0;

  /* "View.MemoryView":1281
 *     cdef char order = get_best_order(&src, src_ndim)
 *     cdef bint broadcasting = False
 *     cdef bint direct_copy = False             # <<<<<<<<<<<<<<
 *     cdef __Pyx_memviewslice tmp
 * 
 */
  __pyx_v_direct_copy = 0;

  /* "View.MemoryView":1284
 *     cdef __Pyx_memviewslice tmp
 * 
 *     if src_ndim < dst_ndim:             # <<<<<<<<<<<<<<
 *         broadcast_leading(&src, src_ndim, dst_ndim)
 *     elif dst_ndim < src_ndim:
 */
  __pyx_t_2 = ((__pyx_v_src_ndim < __pyx_v_dst_ndim) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1285
 * 
 *     if src_ndim < dst_ndim:
 *         broadcast_leading(&src, src_ndim, dst_ndim)             # <<<<<<<<<<<<<<
 *     elif dst_ndim < src_ndim:
 *         broadcast_leading(&dst, dst_ndim, src_ndim)
 */
    __pyx_memoryview_broadcast_leading((&__pyx_v_src), __pyx_v_src_ndim, __pyx_v_dst_ndim);

    /* "View.MemoryView":1284
 *     cdef __Pyx_memviewslice tmp
 * 
 *     if src_ndim < dst_ndim:             # <<<<<<<<<<<<<<
 *         broadcast_leading(&src, src_ndim, dst_ndim)
 *     elif dst_ndim < src_ndim:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":1286
 *     if src_ndim < dst_ndim:
 *         broadcast_leading(&src, src_ndim, dst_ndim)
 *     elif dst_ndim < src_ndim:             # <<<<<<<<<<<<<<
 *         broadcast_leading(&dst, dst_ndim, src_ndim)
 * 
 */
  __pyx_t_2 = ((__pyx_v_dst_ndim < __pyx_v_src_ndim) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1287
 *         broadcast_leading(&src, src_ndim, dst_ndim)
 *     elif dst_ndim < src_ndim:
 *         broadcast_leading(&dst, dst_ndim, src_ndim)             # <<<<<<<<<<<<<<
 * 
 *     cdef int ndim = max(src_ndim, dst_ndim)
 */
    __pyx_memoryview_broadcast_leading((&__pyx_v_dst), __pyx_v_dst_ndim, __pyx_v_src_ndim);

    /* "View.MemoryView":1286
 *     if src_ndim < dst_ndim:
 *         broadcast_leading(&src, src_ndim, dst_ndim)
 *     elif dst_ndim < src_ndim:             # <<<<<<<<<<<<<<
 *         broadcast_leading(&dst, dst_ndim, src_ndim)
 * 
 */
  }
  __pyx_L3:;

  /* "View.MemoryView":1289
 *         broadcast_leading(&dst, dst_ndim, src_ndim)
 * 
 *     cdef int ndim = max(src_ndim, dst_ndim)             # <<<<<<<<<<<<<<
 * 
 *     for i in range(ndim):
 */
  __pyx_t_3 = __pyx_v_dst_ndim;
  __pyx_t_4 = __pyx_v_src_ndim;
  if (((__pyx_t_3 > __pyx_t_4) != 0)) {
    __pyx_t_5 = __pyx_t_3;
  } else {
    __pyx_t_5 = __pyx_t_4;
  }
  __pyx_v_ndim = __pyx_t_5;

  /* "View.MemoryView":1291
 *     cdef int ndim = max(src_ndim, dst_ndim)
 * 
 *     for i in range(ndim):             # <<<<<<<<<<<<<<
 *         if src.shape[i] != dst.shape[i]:
 *             if src.shape[i] == 1:
 */
  __pyx_t_5 = __pyx_v_ndim;
  __pyx_t_3 = __pyx_t_5;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;

    /* "View.MemoryView":1292
 * 
 *     for i in range(ndim):
 *         if src.shape[i] != dst.shape[i]:             # <<<<<<<<<<<<<<
 *             if src.shape[i] == 1:
 *                 broadcasting = True
 */
    __pyx_t_2 = (((__pyx_v_src.shape[__pyx_v_i]) != (__pyx_v_dst.shape[__pyx_v_i])) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1293
 *     for i in range(ndim):
 *         if src.shape[i] != dst.shape[i]:
 *             if src.shape[i] == 1:             # <<<<<<<<<<<<<<
 *                 broadcasting = True
 *                 src.strides[i] = 0
 */
      __pyx_t_2 = (((__pyx_v_src.shape[__pyx_v_i]) == 1) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":1294
 *         if src.shape[i] != dst.shape[i]:
 *             if src.shape[i] == 1:
 *                 broadcasting = True             # <<<<<<<<<<<<<<
 *                 src.strides[i] = 0
 *             else:
 */
        __pyx_v_broadcasting = 1;

        /* "View.MemoryView":1295
 *             if src.shape[i] == 1:
 *                 broadcasting = True
 *                 src.strides[i] = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 _err_extents(i, dst.shape[i], src.shape[i])
 */
        (__pyx_v_src.strides[__pyx_v_i]) = 0;

        /* "View.MemoryView":1293
 *     for i in range(ndim):
 *         if src.shape[i] != dst.shape[i]:
 *             if src.shape[i] == 1:             # <<<<<<<<<<<<<<
 *                 broadcasting = True
 *                 src.strides[i] = 0
 */
        goto __pyx_L7;
      }

      /* "View.MemoryView":1297
 *                 src.strides[i] = 0
 *             else:
 *                 _err_extents(i, dst.shape[i], src.shape[i])             # <<<<<<<<<<<<<<
 * 
 *         if src.suboffsets[i] >= 0:
 */
      /*else*/ {
        __pyx_t_6 = __pyx_memoryview_err_extents(__pyx_v_i, (__pyx_v_dst.shape[__pyx_v_i]), (__pyx_v_src.shape[__pyx_v_i])); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(4, 1297, __pyx_L1_error)
      }
      __pyx_L7:;

      /* "View.MemoryView":1292
 * 
 *     for i in range(ndim):
 *         if src.shape[i] != dst.shape[i]:             # <<<<<<<<<<<<<<
 *             if src.shape[i] == 1:
 *                 broadcasting = True
 */
    }

    /* "View.MemoryView":1299
 *                 _err_extents(i, dst.shape[i], src.shape[i])
 * 
 *         if src.suboffsets[i] >= 0:             # <<<<<<<<<<<<<<
 *             _err_dim(ValueError, "Dimension %d is not direct", i)
 * 
 */
    __pyx_t_2 = (((__pyx_v_src.suboffsets[__pyx_v_i]) >= 0) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1300
 * 
 *         if src.suboffsets[i] >= 0:
 *             _err_dim(ValueError, "Dimension %d is not direct", i)             # <<<<<<<<<<<<<<
 * 
 *     if slices_overlap(&src, &dst, ndim, itemsize):
 */
      __pyx_t_6 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Dimension %d is not direct"), __pyx_v_i); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(4, 1300, __pyx_L1_error)

      /* "View.MemoryView":1299
 *                 _err_extents(i, dst.shape[i], src.shape[i])
 * 
 *         if src.suboffsets[i] >= 0:             # <<<<<<<<<<<<<<
 *             _err_dim(ValueError, "Dimension %d is not direct", i)
 * 
 */
    }
  }

  /* "View.MemoryView":1302
 *             _err_dim(ValueError, "Dimension %d is not direct", i)
 * 
 *     if slices_overlap(&src, &dst, ndim, itemsize):             # <<<<<<<<<<<<<<
 * 
 *         if not slice_is_contig(src, order, ndim):
 */
  __pyx_t_2 = (__pyx_slices_overlap((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1304
 *     if slices_overlap(&src, &dst, ndim, itemsize):
 * 
 *         if not slice_is_contig(src, order, ndim):             # <<<<<<<<<<<<<<
 *             order = get_best_order(&dst, ndim)
 * 
 */
    __pyx_t_2 = ((!(__pyx_memviewslice_is_contig(__pyx_v_src, __pyx_v_order, __pyx_v_ndim) != 0)) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1305
 * 
 *         if not slice_is_contig(src, order, ndim):
 *             order = get_best_order(&dst, ndim)             # <<<<<<<<<<<<<<
 * 
 *         tmpdata = copy_data_to_temp(&src, &tmp, order, ndim)
 */
      __pyx_v_order = __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim);

      /* "View.MemoryView":1304
 *     if slices_overlap(&src, &dst, ndim, itemsize):
 * 
 *         if not slice_is_contig(src, order, ndim):             # <<<<<<<<<<<<<<
 *             order = get_best_order(&dst, ndim)
 * 
 */
    }

    /* "View.MemoryView":1307
 *             order = get_best_order(&dst, ndim)
 * 
 *         tmpdata = copy_data_to_temp(&src, &tmp, order, ndim)             # <<<<<<<<<<<<<<
 *         src = tmp
 * 
 */
    __pyx_t_7 = __pyx_memoryview_copy_data_to_temp((&__pyx_v_src), (&__pyx_v_tmp), __pyx_v_order, __pyx_v_ndim); if (unlikely(__pyx_t_7 == ((void *)NULL))) __PYX_ERR(4, 1307, __pyx_L1_error)
    __pyx_v_tmpdata = __pyx_t_7;

    /* "View.MemoryView":1308
 * 
 *         tmpdata = copy_data_to_temp(&src, &tmp, order, ndim)
 *         src = tmp             # <<<<<<<<<<<<<<
 * 
 *     if not broadcasting:
 */
    __pyx_v_src = __pyx_v_tmp;

    /* "View.MemoryView":1302
 *             _err_dim(ValueError, "Dimension %d is not direct", i)
 * 
 *     if slices_overlap(&src, &dst, ndim, itemsize):             # <<<<<<<<<<<<<<
 * 
 *         if not slice_is_contig(src, order, ndim):
 */
  }

  /* "View.MemoryView":1310
 *         src = tmp
 * 
 *     if not broadcasting:             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = ((!(__pyx_v_broadcasting != 0)) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1313
 * 
 * 
 *         if slice_is_contig(src, 'C', ndim):             # <<<<<<<<<<<<<<
 *             direct_copy = slice_is_contig(dst, 'C', ndim)
 *         elif slice_is_contig(src, 'F', ndim):
 */
    __pyx_t_2 = (__pyx_memviewslice_is_contig(__pyx_v_src, 'C', __pyx_v_ndim) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1314
 * 
 *         if slice_is_contig(src, 'C', ndim):
 *             direct_copy = slice_is_contig(dst, 'C', ndim)             # <<<<<<<<<<<<<<
 *         elif slice_is_contig(src, 'F', ndim):
 *             direct_copy = slice_is_contig(dst, 'F', ndim)
 */
      __pyx_v_direct_copy = __pyx_memviewslice_is_contig(__pyx_v_dst, 'C', __pyx_v_ndim);

      /* "View.MemoryView":1313
 * 
 * 
 *         if slice_is_contig(src, 'C', ndim):             # <<<<<<<<<<<<<<
 *             direct_copy = slice_is_contig(dst, 'C', ndim)
 *         elif slice_is_contig(src, 'F', ndim):
 */
      goto __pyx_L12;
    }

    /* "View.MemoryView":1315
 *         if slice_is_contig(src, 'C', ndim):
 *             direct_copy = slice_is_contig(dst, 'C', ndim)
 *         elif slice_is_contig(src, 'F', ndim):             # <<<<<<<<<<<<<<
 *             direct_copy = slice_is_contig(dst, 'F', ndim)
 * 
 */
    __pyx_t_2 = (__pyx_memviewslice_is_contig(__pyx_v_src, 'F', __pyx_v_ndim) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1316
 *             direct_copy = slice_is_contig(dst, 'C', ndim)
 *         elif slice_is_contig(src, 'F', ndim):
 *             direct_copy = slice_is_contig(dst, 'F', ndim)             # <<<<<<<<<<<<<<
 * 
 *         if direct_copy:
 */
      __pyx_v_direct_copy = __pyx_memviewslice_is_contig(__pyx_v_dst, 'F', __pyx_v_ndim);

      /* "View.MemoryView":1315
 *         if slice_is_contig(src, 'C', ndim):
 *             direct_copy = slice_is_contig(dst, 'C', ndim)
 *         elif slice_is_contig(src, 'F', ndim):             # <<<<<<<<<<<<<<
 *             direct_copy = slice_is_contig(dst, 'F', ndim)
 * 
 */
    }
    __pyx_L12:;

    /* "View.MemoryView":1318
 *             direct_copy = slice_is_contig(dst, 'F', ndim)
 * 
 *         if direct_copy:             # <<<<<<<<<<<<<<
 * 
 *             refcount_copying(&dst, dtype_is_object, ndim, False)
 */
    __pyx_t_2 = (__pyx_v_direct_copy != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1320
 *         if direct_copy:
 * 
 *             refcount_copying(&dst, dtype_is_object, ndim, False)             # <<<<<<<<<<<<<<
 *             memcpy(dst.data, src.data, slice_get_size(&src, ndim))
 *             refcount_copying(&dst, dtype_is_object, ndim, True)
 */
      __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 0);

      /* "View.MemoryView":1321
 * 
 *             refcount_copying(&dst, dtype_is_object, ndim, False)
 *             memcpy(dst.data, src.data, slice_get_size(&src, ndim))             # <<<<<<<<<<<<<<
 *             refcount_copying(&dst, dtype_is_object, ndim, True)
 *             free(tmpdata)
 */
      (void)(memcpy(__pyx_v_dst.data, __pyx_v_src.data, __pyx_memoryview_slice_get_size((&__pyx_v_src), __pyx_v_ndim)));

      /* "View.MemoryView":1322
 *             refcount_copying(&dst, dtype_is_object, ndim, False)
 *             memcpy(dst.data, src.data, slice_get_size(&src, ndim))
 *             refcount_copying(&dst, dtype_is_object, ndim, True)             # <<<<<<<<<<<<<<
 *             free(tmpdata)
 *             return 0
 */
      __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1);

      /* "View.MemoryView":1323
 *             memcpy(dst.data, src.data, slice_get_size(&src, ndim))
 *             refcount_copying(&dst, dtype_is_object, ndim, True)
 *             free(tmpdata)             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
      free(__pyx_v_tmpdata);

      /* "View.MemoryView":1324
 *             refcount_copying(&dst, dtype_is_object, ndim, True)
 *             free(tmpdata)
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *     if order == 'F' == get_best_order(&dst, ndim):
 */
      __pyx_r = 0;
      goto __pyx_L0;

      /* "View.MemoryView":1318
 *             direct_copy = slice_is_contig(dst, 'F', ndim)
 * 
 *         if direct_copy:             # <<<<<<<<<<<<<<
 * 
 *             refcount_copying(&dst, dtype_is_object, ndim, False)
 */
    }

    /* "View.MemoryView":1310
 *         src = tmp
 * 
 *     if not broadcasting:             # <<<<<<<<<<<<<<
 * 
 * 
 */
  }

  /* "View.MemoryView":1326
 *             return 0
 * 
 *     if order == 'F' == get_best_order(&dst, ndim):             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = (__pyx_v_order == 'F');
  if (__pyx_t_2) {
    __pyx_t_2 = ('F' == __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim));
  }
  __pyx_t_8 = (__pyx_t_2 != 0);
  if (__pyx_t_8) {

    /* "View.MemoryView":1329
 * 
 * 
 *         transpose_memslice(&src)             # <<<<<<<<<<<<<<
 *         transpose_memslice(&dst)
 * 
 */
    __pyx_t_5 = __pyx_memslice_transpose((&__pyx_v_src)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(4, 1329, __pyx_L1_error)

    /* "View.MemoryView":1330
 * 
 *         transpose_memslice(&src)
 *         transpose_memslice(&dst)             # <<<<<<<<<<<<<<
 * 
 *     refcount_copying(&dst, dtype_is_object, ndim, False)
 */
    __pyx_t_5 = __pyx_memslice_transpose((&__pyx_v_dst)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(4, 1330, __pyx_L1_error)

    /* "View.MemoryView":1326
 *             return 0
 * 
 *     if order == 'F' == get_best_order(&dst, ndim):             # <<<<<<<<<<<<<<
 * 
 * 
 */
  }

  /* "View.MemoryView":1332
 *         transpose_memslice(&dst)
 * 
 *     refcount_copying(&dst, dtype_is_object, ndim, False)             # <<<<<<<<<<<<<<
 *     copy_strided_to_strided(&src, &dst, ndim, itemsize)
 *     refcount_copying(&dst, dtype_is_object, ndim, True)
 */
  __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 0);

  /* "View.MemoryView":1333
 * 
 *     refcount_copying(&dst, dtype_is_object, ndim, False)
 *     copy_strided_to_strided(&src, &dst, ndim, itemsize)             # <<<<<<<<<<<<<<
 *     refcount_copying(&dst, dtype_is_object, ndim, True)
 * 
 */
  copy_strided_to_strided((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize);

  /* "View.MemoryView":1334
 *     refcount_copying(&dst, dtype_is_object, ndim, False)
 *     copy_strided_to_strided(&src, &dst, ndim, itemsize)
 *     refcount_copying(&dst, dtype_is_object, ndim, True)             # <<<<<<<<<<<<<<
 * 
 *     free(tmpdata)
 */
  __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1);

  /* "View.MemoryView":1336
 *     refcount_copying(&dst, dtype_is_object, ndim, True)
 * 
 *     free(tmpdata)             # <<<<<<<<<<<<<<
 *     return 0
 * 
 */
  free(__pyx_v_tmpdata);

  /* "View.MemoryView":1337
 * 
 *     free(tmpdata)
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_broadcast_leading')
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "View.MemoryView":1268
 * 
 * @cname('__pyx_memoryview_copy_contents')
 * cdef int memoryview_copy_contents(__Pyx_memviewslice src,             # <<<<<<<<<<<<<<
 *                                   __Pyx_memviewslice dst,
 *                                   int src_ndim, int dst_ndim,
 */

  /* function exit code */
  __pyx_L1_error:;
  {
    #ifdef WITH_THREAD
    PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
    #endif
    __Pyx_AddTraceback("View.MemoryView.memoryview_copy_contents", __pyx_clineno, __pyx_lineno, __pyx_filename);
    #ifdef WITH_THREAD
    __Pyx_PyGILState_Release(__pyx_gilstate_save);
    #endif
  }
  __pyx_r = -1;
  __pyx_L0:;
  return __pyx_r;
}

/* "View.MemoryView":1340
 * 
 * @cname('__pyx_memoryview_broadcast_leading')
 * cdef void broadcast_leading(__Pyx_memviewslice *mslice,             # <<<<<<<<<<<<<<
 *                             int ndim,
 *                             int ndim_other) nogil:
 */

static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *__pyx_v_mslice, int __pyx_v_ndim, int __pyx_v_ndim_other) {
  int __pyx_v_i;
  int __pyx_v_offset;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;

  /* "View.MemoryView":1344
 *                             int ndim_other) nogil:
 *     cdef int i
 *     cdef int offset = ndim_other - ndim             # <<<<<<<<<<<<<<
 * 
 *     for i in range(ndim - 1, -1, -1):
 */
  __pyx_v_offset = (__pyx_v_ndim_other - __pyx_v_ndim);

  /* "View.MemoryView":1346
 *     cdef int offset = ndim_other - ndim
 * 
 *     for i in range(ndim - 1, -1, -1):             # <<<<<<<<<<<<<<
 *         mslice.shape[i + offset] = mslice.shape[i]
 *         mslice.strides[i + offset] = mslice.strides[i]
 */
  for (__pyx_t_1 = (__pyx_v_ndim - 1); __pyx_t_1 > -1; __pyx_t_1-=1) {
    __pyx_v_i = __pyx_t_1;

    /* "View.MemoryView":1347
 * 
 *     for i in range(ndim - 1, -1, -1):
 *         mslice.shape[i + offset] = mslice.shape[i]             # <<<<<<<<<<<<<<
 *         mslice.strides[i + offset] = mslice.strides[i]
 *         mslice.suboffsets[i + offset] = mslice.suboffsets[i]
 */
    (__pyx_v_mslice->shape[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->shape[__pyx_v_i]);

    /* "View.MemoryView":1348
 *     for i in range(ndim - 1, -1, -1):
 *         mslice.shape[i + offset] = mslice.shape[i]
 *         mslice.strides[i + offset] = mslice.strides[i]             # <<<<<<<<<<<<<<
 *         mslice.suboffsets[i + offset] = mslice.suboffsets[i]
 * 
 */
    (__pyx_v_mslice->strides[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->strides[__pyx_v_i]);

    /* "View.MemoryView":1349
 *         mslice.shape[i + offset] = mslice.shape[i]
 *         mslice.strides[i + offset] = mslice.strides[i]
 *         mslice.suboffsets[i + offset] = mslice.suboffsets[i]             # <<<<<<<<<<<<<<
 * 
 *     for i in range(offset):
 */
    (__pyx_v_mslice->suboffsets[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->suboffsets[__pyx_v_i]);
  }

  /* "View.MemoryView":1351
 *         mslice.suboffsets[i + offset] = mslice.suboffsets[i]
 * 
 *     for i in range(offset):             # <<<<<<<<<<<<<<
 *         mslice.shape[i] = 1
 *         mslice.strides[i] = mslice.strides[0]
 */
  __pyx_t_1 = __pyx_v_offset;
  __pyx_t_2 = __pyx_t_1;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_i = __pyx_t_3;

    /* "View.MemoryView":1352
 * 
 *     for i in range(offset):
 *         mslice.shape[i] = 1             # <<<<<<<<<<<<<<
 *         mslice.strides[i] = mslice.strides[0]
 *         mslice.suboffsets[i] = -1
 */
    (__pyx_v_mslice->shape[__pyx_v_i]) = 1;

    /* "View.MemoryView":1353
 *     for i in range(offset):
 *         mslice.shape[i] = 1
 *         mslice.strides[i] = mslice.strides[0]             # <<<<<<<<<<<<<<
 *         mslice.suboffsets[i] = -1
 * 
 */
    (__pyx_v_mslice->strides[__pyx_v_i]) = (__pyx_v_mslice->strides[0]);

    /* "View.MemoryView":1354
 *         mslice.shape[i] = 1
 *         mslice.strides[i] = mslice.strides[0]
 *         mslice.suboffsets[i] = -1             # <<<<<<<<<<<<<<
 * 
 * 
 */
    (__pyx_v_mslice->suboffsets[__pyx_v_i]) = -1L;
  }

  /* "View.MemoryView":1340
 * 
 * @cname('__pyx_memoryview_broadcast_leading')
 * cdef void broadcast_leading(__Pyx_memviewslice *mslice,             # <<<<<<<<<<<<<<
 *                             int ndim,
 *                             int ndim_other) nogil:
 */

  /* function exit code */
}

/* "View.MemoryView":1362
 * 
 * @cname('__pyx_memoryview_refcount_copying')
 * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object,             # <<<<<<<<<<<<<<
 *                            int ndim, bint inc) nogil:
 * 
 */

static void __pyx_memoryview_refcount_copying(__Pyx_memviewslice *__pyx_v_dst, int __pyx_v_dtype_is_object, int __pyx_v_ndim, int __pyx_v_inc) {
  int __pyx_t_1;

  /* "View.MemoryView":1366
 * 
 * 
 *     if dtype_is_object:             # <<<<<<<<<<<<<<
 *         refcount_objects_in_slice_with_gil(dst.data, dst.shape,
 *                                            dst.strides, ndim, inc)
 */
  __pyx_t_1 = (__pyx_v_dtype_is_object != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1367
 * 
 *     if dtype_is_object:
 *         refcount_objects_in_slice_with_gil(dst.data, dst.shape,             # <<<<<<<<<<<<<<
 *                                            dst.strides, ndim, inc)
 * 
 */
    __pyx_memoryview_refcount_objects_in_slice_with_gil(__pyx_v_dst->data, __pyx_v_dst->shape, __pyx_v_dst->strides, __pyx_v_ndim, __pyx_v_inc);

    /* "View.MemoryView":1366
 * 
 * 
 *     if dtype_is_object:             # <<<<<<<<<<<<<<
 *         refcount_objects_in_slice_with_gil(dst.data, dst.shape,
 *                                            dst.strides, ndim, inc)
 */
  }

  /* "View.MemoryView":1362
 * 
 * @cname('__pyx_memoryview_refcount_copying')
 * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object,             # <<<<<<<<<<<<<<
 *                            int ndim, bint inc) nogil:
 * 
 */

  /* function exit code */
}

/* "View.MemoryView":1371
 * 
 * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil')
 * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                                              Py_ssize_t *strides, int ndim,
 *                                              bint inc) with gil:
 */

static void __pyx_memoryview_refcount_objects_in_slice_with_gil(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, int __pyx_v_inc) {
  __Pyx_RefNannyDeclarations
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("refcount_objects_in_slice_with_gil", 0);

  /* "View.MemoryView":1374
 *                                              Py_ssize_t *strides, int ndim,
 *                                              bint inc) with gil:
 *     refcount_objects_in_slice(data, shape, strides, ndim, inc)             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_refcount_objects_in_slice')
 */
  __pyx_memoryview_refcount_objects_in_slice(__pyx_v_data, __pyx_v_shape, __pyx_v_strides, __pyx_v_ndim, __pyx_v_inc);

  /* "View.MemoryView":1371
 * 
 * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil')
 * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                                              Py_ssize_t *strides, int ndim,
 *                                              bint inc) with gil:
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif
}

/* "View.MemoryView":1377
 * 
 * @cname('__pyx_memoryview_refcount_objects_in_slice')
 * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                                     Py_ssize_t *strides, int ndim, bint inc):
 *     cdef Py_ssize_t i
 */

static void __pyx_memoryview_refcount_objects_in_slice(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, int __pyx_v_inc) {
  CYTHON_UNUSED Py_ssize_t __pyx_v_i;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  __Pyx_RefNannySetupContext("refcount_objects_in_slice", 0);

  /* "View.MemoryView":1381
 *     cdef Py_ssize_t i
 * 
 *     for i in range(shape[0]):             # <<<<<<<<<<<<<<
 *         if ndim == 1:
 *             if inc:
 */
  __pyx_t_1 = (__pyx_v_shape[0]);
  __pyx_t_2 = __pyx_t_1;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_i = __pyx_t_3;

    /* "View.MemoryView":1382
 * 
 *     for i in range(shape[0]):
 *         if ndim == 1:             # <<<<<<<<<<<<<<
 *             if inc:
 *                 Py_INCREF((<PyObject **> data)[0])
 */
    __pyx_t_4 = ((__pyx_v_ndim == 1) != 0);
    if (__pyx_t_4) {

      /* "View.MemoryView":1383
 *     for i in range(shape[0]):
 *         if ndim == 1:
 *             if inc:             # <<<<<<<<<<<<<<
 *                 Py_INCREF((<PyObject **> data)[0])
 *             else:
 */
      __pyx_t_4 = (__pyx_v_inc != 0);
      if (__pyx_t_4) {

        /* "View.MemoryView":1384
 *         if ndim == 1:
 *             if inc:
 *                 Py_INCREF((<PyObject **> data)[0])             # <<<<<<<<<<<<<<
 *             else:
 *                 Py_DECREF((<PyObject **> data)[0])
 */
        Py_INCREF((((PyObject **)__pyx_v_data)[0]));

        /* "View.MemoryView":1383
 *     for i in range(shape[0]):
 *         if ndim == 1:
 *             if inc:             # <<<<<<<<<<<<<<
 *                 Py_INCREF((<PyObject **> data)[0])
 *             else:
 */
        goto __pyx_L6;
      }

      /* "View.MemoryView":1386
 *                 Py_INCREF((<PyObject **> data)[0])
 *             else:
 *                 Py_DECREF((<PyObject **> data)[0])             # <<<<<<<<<<<<<<
 *         else:
 *             refcount_objects_in_slice(data, shape + 1, strides + 1,
 */
      /*else*/ {
        Py_DECREF((((PyObject **)__pyx_v_data)[0]));
      }
      __pyx_L6:;

      /* "View.MemoryView":1382
 * 
 *     for i in range(shape[0]):
 *         if ndim == 1:             # <<<<<<<<<<<<<<
 *             if inc:
 *                 Py_INCREF((<PyObject **> data)[0])
 */
      goto __pyx_L5;
    }

    /* "View.MemoryView":1388
 *                 Py_DECREF((<PyObject **> data)[0])
 *         else:
 *             refcount_objects_in_slice(data, shape + 1, strides + 1,             # <<<<<<<<<<<<<<
 *                                       ndim - 1, inc)
 * 
 */
    /*else*/ {

      /* "View.MemoryView":1389
 *         else:
 *             refcount_objects_in_slice(data, shape + 1, strides + 1,
 *                                       ndim - 1, inc)             # <<<<<<<<<<<<<<
 * 
 *         data += strides[0]
 */
      __pyx_memoryview_refcount_objects_in_slice(__pyx_v_data, (__pyx_v_shape + 1), (__pyx_v_strides + 1), (__pyx_v_ndim - 1), __pyx_v_inc);
    }
    __pyx_L5:;

    /* "View.MemoryView":1391
 *                                       ndim - 1, inc)
 * 
 *         data += strides[0]             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_v_data = (__pyx_v_data + (__pyx_v_strides[0]));
  }

  /* "View.MemoryView":1377
 * 
 * @cname('__pyx_memoryview_refcount_objects_in_slice')
 * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                                     Py_ssize_t *strides, int ndim, bint inc):
 *     cdef Py_ssize_t i
 */

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

/* "View.MemoryView":1397
 * 
 * @cname('__pyx_memoryview_slice_assign_scalar')
 * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim,             # <<<<<<<<<<<<<<
 *                               size_t itemsize, void *item,
 *                               bint dtype_is_object) nogil:
 */

static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *__pyx_v_dst, int __pyx_v_ndim, size_t __pyx_v_itemsize, void *__pyx_v_item, int __pyx_v_dtype_is_object) {

  /* "View.MemoryView":1400
 *                               size_t itemsize, void *item,
 *                               bint dtype_is_object) nogil:
 *     refcount_copying(dst, dtype_is_object, ndim, False)             # <<<<<<<<<<<<<<
 *     _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim,
 *                          itemsize, item)
 */
  __pyx_memoryview_refcount_copying(__pyx_v_dst, __pyx_v_dtype_is_object, __pyx_v_ndim, 0);

  /* "View.MemoryView":1401
 *                               bint dtype_is_object) nogil:
 *     refcount_copying(dst, dtype_is_object, ndim, False)
 *     _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim,             # <<<<<<<<<<<<<<
 *                          itemsize, item)
 *     refcount_copying(dst, dtype_is_object, ndim, True)
 */
  __pyx_memoryview__slice_assign_scalar(__pyx_v_dst->data, __pyx_v_dst->shape, __pyx_v_dst->strides, __pyx_v_ndim, __pyx_v_itemsize, __pyx_v_item);

  /* "View.MemoryView":1403
 *     _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim,
 *                          itemsize, item)
 *     refcount_copying(dst, dtype_is_object, ndim, True)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_memoryview_refcount_copying(__pyx_v_dst, __pyx_v_dtype_is_object, __pyx_v_ndim, 1);

  /* "View.MemoryView":1397
 * 
 * @cname('__pyx_memoryview_slice_assign_scalar')
 * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim,             # <<<<<<<<<<<<<<
 *                               size_t itemsize, void *item,
 *                               bint dtype_is_object) nogil:
 */

  /* function exit code */
}

/* "View.MemoryView":1407
 * 
 * @cname('__pyx_memoryview__slice_assign_scalar')
 * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                               Py_ssize_t *strides, int ndim,
 *                               size_t itemsize, void *item) nogil:
 */

static void __pyx_memoryview__slice_assign_scalar(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, size_t __pyx_v_itemsize, void *__pyx_v_item) {
  CYTHON_UNUSED Py_ssize_t __pyx_v_i;
  Py_ssize_t __pyx_v_stride;
  Py_ssize_t __pyx_v_extent;
  int __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  Py_ssize_t __pyx_t_4;

  /* "View.MemoryView":1411
 *                               size_t itemsize, void *item) nogil:
 *     cdef Py_ssize_t i
 *     cdef Py_ssize_t stride = strides[0]             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t extent = shape[0]
 * 
 */
  __pyx_v_stride = (__pyx_v_strides[0]);

  /* "View.MemoryView":1412
 *     cdef Py_ssize_t i
 *     cdef Py_ssize_t stride = strides[0]
 *     cdef Py_ssize_t extent = shape[0]             # <<<<<<<<<<<<<<
 * 
 *     if ndim == 1:
 */
  __pyx_v_extent = (__pyx_v_shape[0]);

  /* "View.MemoryView":1414
 *     cdef Py_ssize_t extent = shape[0]
 * 
 *     if ndim == 1:             # <<<<<<<<<<<<<<
 *         for i in range(extent):
 *             memcpy(data, item, itemsize)
 */
  __pyx_t_1 = ((__pyx_v_ndim == 1) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1415
 * 
 *     if ndim == 1:
 *         for i in range(extent):             # <<<<<<<<<<<<<<
 *             memcpy(data, item, itemsize)
 *             data += stride
 */
    __pyx_t_2 = __pyx_v_extent;
    __pyx_t_3 = __pyx_t_2;
    for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
      __pyx_v_i = __pyx_t_4;

      /* "View.MemoryView":1416
 *     if ndim == 1:
 *         for i in range(extent):
 *             memcpy(data, item, itemsize)             # <<<<<<<<<<<<<<
 *             data += stride
 *     else:
 */
      (void)(memcpy(__pyx_v_data, __pyx_v_item, __pyx_v_itemsize));

      /* "View.MemoryView":1417
 *         for i in range(extent):
 *             memcpy(data, item, itemsize)
 *             data += stride             # <<<<<<<<<<<<<<
 *     else:
 *         for i in range(extent):
 */
      __pyx_v_data = (__pyx_v_data + __pyx_v_stride);
    }

    /* "View.MemoryView":1414
 *     cdef Py_ssize_t extent = shape[0]
 * 
 *     if ndim == 1:             # <<<<<<<<<<<<<<
 *         for i in range(extent):
 *             memcpy(data, item, itemsize)
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":1419
 *             data += stride
 *     else:
 *         for i in range(extent):             # <<<<<<<<<<<<<<
 *             _slice_assign_scalar(data, shape + 1, strides + 1,
 *                                 ndim - 1, itemsize, item)
 */
  /*else*/ {
    __pyx_t_2 = __pyx_v_extent;
    __pyx_t_3 = __pyx_t_2;
    for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
      __pyx_v_i = __pyx_t_4;

      /* "View.MemoryView":1420
 *     else:
 *         for i in range(extent):
 *             _slice_assign_scalar(data, shape + 1, strides + 1,             # <<<<<<<<<<<<<<
 *                                 ndim - 1, itemsize, item)
 *             data += stride
 */
      __pyx_memoryview__slice_assign_scalar(__pyx_v_data, (__pyx_v_shape + 1), (__pyx_v_strides + 1), (__pyx_v_ndim - 1), __pyx_v_itemsize, __pyx_v_item);

      /* "View.MemoryView":1422
 *             _slice_assign_scalar(data, shape + 1, strides + 1,
 *                                 ndim - 1, itemsize, item)
 *             data += stride             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_v_data = (__pyx_v_data + __pyx_v_stride);
    }
  }
  __pyx_L3:;

  /* "View.MemoryView":1407
 * 
 * @cname('__pyx_memoryview__slice_assign_scalar')
 * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                               Py_ssize_t *strides, int ndim,
 *                               size_t itemsize, void *item) nogil:
 */

  /* function exit code */
}

/* "(tree fragment)":1
 * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_15View_dot_MemoryView_1__pyx_unpickle_Enum = {"__pyx_unpickle_Enum", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v___pyx_type = 0;
  long __pyx_v___pyx_checksum;
  PyObject *__pyx_v___pyx_state = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__pyx_unpickle_Enum (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, 1); __PYX_ERR(4, 1, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, 2); __PYX_ERR(4, 1, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_Enum") < 0)) __PYX_ERR(4, 1, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v___pyx_type = values[0];
    __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(4, 1, __pyx_L3_error)
    __pyx_v___pyx_state = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(4, 1, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state);

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

static PyObject *__pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_v___pyx_PickleError = 0;
  PyObject *__pyx_v___pyx_result = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_unpickle_Enum", 0);

  /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum != 0xb068931:             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum)
 */
  __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xb068931) != 0);
  if (__pyx_t_1) {

    /* "(tree fragment)":5
 *     cdef object __pyx_result
 *     if __pyx_checksum != 0xb068931:
 *         from pickle import PickleError as __pyx_PickleError             # <<<<<<<<<<<<<<
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum)
 *     __pyx_result = Enum.__new__(__pyx_type)
 */
    __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_n_s_PickleError);
    __Pyx_GIVEREF(__pyx_n_s_PickleError);
    PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError);
    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_2);
    __pyx_v___pyx_PickleError = __pyx_t_2;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "(tree fragment)":6
 *     if __pyx_checksum != 0xb068931:
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum)             # <<<<<<<<<<<<<<
 *     __pyx_result = Enum.__new__(__pyx_type)
 *     if __pyx_state is not None:
 */
    __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xb0, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_INCREF(__pyx_v___pyx_PickleError);
    __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(4, 6, __pyx_L1_error)

    /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum != 0xb068931:             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum)
 */
  }

  /* "(tree fragment)":7
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum)
 *     __pyx_result = Enum.__new__(__pyx_type)             # <<<<<<<<<<<<<<
 *     if __pyx_state is not None:
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_MemviewEnum_type), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v___pyx_result = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "(tree fragment)":8
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum)
 *     __pyx_result = Enum.__new__(__pyx_type)
 *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 *     return __pyx_result
 */
  __pyx_t_1 = (__pyx_v___pyx_state != Py_None);
  __pyx_t_6 = (__pyx_t_1 != 0);
  if (__pyx_t_6) {

    /* "(tree fragment)":9
 *     __pyx_result = Enum.__new__(__pyx_type)
 *     if __pyx_state is not None:
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)             # <<<<<<<<<<<<<<
 *     return __pyx_result
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):
 */
    if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(4, 9, __pyx_L1_error)
    __pyx_t_3 = __pyx_unpickle_Enum__set_state(((struct __pyx_MemviewEnum_obj *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 9, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "(tree fragment)":8
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum)
 *     __pyx_result = Enum.__new__(__pyx_type)
 *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 *     return __pyx_result
 */
  }

  /* "(tree fragment)":10
 *     if __pyx_state is not None:
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 *     return __pyx_result             # <<<<<<<<<<<<<<
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):
 *     __pyx_result.name = __pyx_state[0]
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v___pyx_result);
  __pyx_r = __pyx_v___pyx_result;
  goto __pyx_L0;

  /* "(tree fragment)":1
 * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v___pyx_PickleError);
  __Pyx_XDECREF(__pyx_v___pyx_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":11
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result.name = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 */

static PyObject *__pyx_unpickle_Enum__set_state(struct __pyx_MemviewEnum_obj *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_unpickle_Enum__set_state", 0);

  /* "(tree fragment)":12
 *     return __pyx_result
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):
 *     __pyx_result.name = __pyx_state[0]             # <<<<<<<<<<<<<<
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 *         __pyx_result.__dict__.update(__pyx_state[1])
 */
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(4, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v___pyx_result->name);
  __Pyx_DECREF(__pyx_v___pyx_result->name);
  __pyx_v___pyx_result->name = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "(tree fragment)":13
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):
 *     __pyx_result.name = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
 *         __pyx_result.__dict__.update(__pyx_state[1])
 */
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(4, 13, __pyx_L1_error)
  }
  __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(4, 13, __pyx_L1_error)
  __pyx_t_4 = ((__pyx_t_3 > 1) != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(4, 13, __pyx_L1_error)
  __pyx_t_5 = (__pyx_t_4 != 0);
  __pyx_t_2 = __pyx_t_5;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "(tree fragment)":14
 *     __pyx_result.name = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 *         __pyx_result.__dict__.update(__pyx_state[1])             # <<<<<<<<<<<<<<
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(4, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(__pyx_v___pyx_state == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(4, 14, __pyx_L1_error)
    }
    __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "(tree fragment)":13
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):
 *     __pyx_result.name = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
 *         __pyx_result.__dict__.update(__pyx_state[1])
 */
  }

  /* "(tree fragment)":11
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result.name = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_7plastid_8genomics_8roitools_GenomicSegment __pyx_vtable_7plastid_8genomics_8roitools_GenomicSegment;

static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools_GenomicSegment(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *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_7plastid_8genomics_8roitools_GenomicSegment *)o);
  p->__pyx_vtab = __pyx_vtabptr_7plastid_8genomics_8roitools_GenomicSegment;
  p->chrom = ((PyObject*)Py_None); Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_7plastid_8genomics_8roitools_GenomicSegment(PyObject *o) {
  struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *p = (struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  Py_CLEAR(p->chrom);
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_14GenomicSegment_start(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_5start_1__get__(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_14GenomicSegment_end(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_3end_1__get__(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_14GenomicSegment_chrom(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_5chrom_1__get__(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_14GenomicSegment_strand(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_6strand_1__get__(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_14GenomicSegment_c_strand(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_8c_strand_1__get__(o);
}

static PyMethodDef __pyx_methods_7plastid_8genomics_8roitools_GenomicSegment[] = {
  {"__reduce__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_3__reduce__, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_2__reduce__},
  {"from_str", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_11from_str, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_10from_str},
  {"__copy__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_13__copy__, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_12__copy__},
  {"__deepcopy__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_15__deepcopy__, METH_O, __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_14__deepcopy__},
  {"_cmp_helper", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_21_cmp_helper, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_20_cmp_helper},
  {"contains", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_25contains, METH_O, __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_24contains},
  {"overlaps", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_27overlaps, METH_O, __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_26overlaps},
  {"as_igv_str", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_29as_igv_str, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_28as_igv_str},
  {"from_igv_str", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_31from_igv_str, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_30from_igv_str},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_7plastid_8genomics_8roitools_GenomicSegment[] = {
  {(char *)"start", __pyx_getprop_7plastid_8genomics_8roitools_14GenomicSegment_start, 0, (char *)"Zero-indexed (Pythonic) start coordinate of |GenomicSegment|", 0},
  {(char *)"end", __pyx_getprop_7plastid_8genomics_8roitools_14GenomicSegment_end, 0, (char *)"Zero-indexed, half-open (Pythonic) end coordinate of |GenomicSegment|", 0},
  {(char *)"chrom", __pyx_getprop_7plastid_8genomics_8roitools_14GenomicSegment_chrom, 0, (char *)"Chromosome where |GenomicSegment| resides", 0},
  {(char *)"strand", __pyx_getprop_7plastid_8genomics_8roitools_14GenomicSegment_strand, 0, (char *)"Strand of |GenomicSegment|\n\n          - '+' for forward / Watson strand\n          - '-' for reverse / Crick strand\n          - '.' for unstranded / both strands\n        ", 0},
  {(char *)"c_strand", __pyx_getprop_7plastid_8genomics_8roitools_14GenomicSegment_c_strand, 0, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PySequenceMethods __pyx_tp_as_sequence_GenomicSegment = {
  __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_17__len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_23__contains__, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_GenomicSegment = {
  __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_17__len__, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyTypeObject __pyx_type_7plastid_8genomics_8roitools_GenomicSegment = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.GenomicSegment", /*tp_name*/
  sizeof(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_7plastid_8genomics_8roitools_GenomicSegment, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_5__repr__, /*tp_repr*/
  0, /*tp_as_number*/
  &__pyx_tp_as_sequence_GenomicSegment, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_GenomicSegment, /*tp_as_mapping*/
  __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_9__hash__, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_7__str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "\n    GenomicSegment(chrom, start, end, strand)\n\n    Building block for |SegmentChain|: a continuous segment of the genome\n    defined by a chromosome name, start coordinate,  end coordinate, and strand.\n\n    Attributes\n    ----------\n    chrom : str\n        Name of chromosome\n\n    start : int\n        0-indexed, left most position of segment\n\n    end : int\n        0-indexed, half-open right most position of segment\n\n    strand : str\n        Chromosome strand (`'+'`, `'-'`, or `'.'`)\n\n\n    Examples\n    --------\n\n    |GenomicSegments| sort lexically by chromosome, start position, end position,\n    and finally strand::\n\n        >>> GenomicSegment(\"chrA\", 50, 100, \"+\") < GenomicSegment(\"chrB\", 0, 10, \"+\")\n        True\n\n        >>> GenomicSegment(\"chrA\", 50, 100, \"+\") < GenomicSegment(\"chrA\", 75, 100, \"+\")\n        True\n\n        >>> GenomicSegment(\"chrA\", 50, 100, \"+\") < GenomicSegment(\"chrA\", 55, 75, \"+\")\n        True\n\n        >>> GenomicSegment(\"chrA\", 50, 100, \"+\") < GenomicSegment(\"chrA\", 50, 150, \"+\")\n        True\n\n        >>> GenomicSegment(\"chrA\", 50, 100, \"+\") < GenomicSegment(\"chrA\", 50, 100, \"-\")\n        True\n\n\n    They also provide a few convenience methods for containment or overlap. To be\n    contained, a segment must be on the same chromosome and strand as its container,\n    and its coordinates must be within or equal to its endpoints::\n\n        >>> GenomicSegment(\"chrA\", 50, 100, \"+\") in GenomicSegment(\"chrA\", 25, 100, \"+\")\n        True\n\n        >>> GenomicSegment(\"chrA\", 50, 100, \"+\") in GenomicSegment(\"chrA\", 50, 100, \"+\")\n        True\n\n        >>> GenomicSegment(\"chrA\", 50, 100, \"+\") in GenomicSegment(\"chrA\", 25, 100, \"-\")\n        False\n\n        >>> GenomicSegment(\"chrA\", 50, 100, \"+\") in GenomicSegment(\"chrA\", 75, 200, \"+\")\n        False\n\n    Similarly, to overlap, |GenomicSegments| must be on the same strand and\n    chromos""ome.\n    ", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  __pyx_pw_7plastid_8genomics_8roitools_14GenomicSegment_19__richcmp__, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_7plastid_8genomics_8roitools_GenomicSegment, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_7plastid_8genomics_8roitools_GenomicSegment, /*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_7plastid_8genomics_8roitools_GenomicSegment, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain;

static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools_SegmentChain(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *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_7plastid_8genomics_8roitools_SegmentChain *)o);
  p->__pyx_vtab = __pyx_vtabptr_7plastid_8genomics_8roitools_SegmentChain;
  p->_segments = ((PyObject*)Py_None); Py_INCREF(Py_None);
  p->_mask_segments = ((PyObject*)Py_None); Py_INCREF(Py_None);
  p->spanning_segment = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)Py_None); Py_INCREF(Py_None);
  p->_position_hash = ((arrayobject *)Py_None); Py_INCREF(Py_None);
  p->_position_mask = ((arrayobject *)Py_None); Py_INCREF(Py_None);
  p->_endmap = ((arrayobject *)Py_None); Py_INCREF(Py_None);
  p->attr = ((PyObject*)Py_None); Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_7plastid_8genomics_8roitools_SegmentChain(PyObject *o) {
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *p = (struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->_segments);
  Py_CLEAR(p->_mask_segments);
  Py_CLEAR(p->spanning_segment);
  Py_CLEAR(p->_position_hash);
  Py_CLEAR(p->_position_mask);
  Py_CLEAR(p->_endmap);
  Py_CLEAR(p->attr);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_7plastid_8genomics_8roitools_SegmentChain(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *p = (struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)o;
  if (p->_segments) {
    e = (*v)(p->_segments, a); if (e) return e;
  }
  if (p->_mask_segments) {
    e = (*v)(p->_mask_segments, a); if (e) return e;
  }
  if (p->spanning_segment) {
    e = (*v)(((PyObject *)p->spanning_segment), a); if (e) return e;
  }
  if (p->_position_hash) {
    e = (*v)(((PyObject *)p->_position_hash), a); if (e) return e;
  }
  if (p->_position_mask) {
    e = (*v)(((PyObject *)p->_position_mask), a); if (e) return e;
  }
  if (p->_endmap) {
    e = (*v)(((PyObject *)p->_endmap), a); if (e) return e;
  }
  if (p->attr) {
    e = (*v)(p->attr, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_7plastid_8genomics_8roitools_SegmentChain(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *p = (struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *)o;
  tmp = ((PyObject*)p->_segments);
  p->_segments = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_mask_segments);
  p->_mask_segments = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->spanning_segment);
  p->spanning_segment = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_position_hash);
  p->_position_hash = ((arrayobject *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_position_mask);
  p->_position_mask = ((arrayobject *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_endmap);
  p->_endmap = ((arrayobject *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->attr);
  p->attr = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}
static PyObject *__pyx_sq_item_7plastid_8genomics_8roitools_SegmentChain(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_7plastid_8genomics_8roitools_12SegmentChain_chrom(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_5chrom_1__get__(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_strand(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_6strand_1__get__(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_c_strand(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_8c_strand_1__get__(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_segments(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_8segments_1__get__(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_mask_segments(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_13mask_segments_1__get__(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_spanning_segment(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_16spanning_segment_1__get__(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_6length_1__get__(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_masked_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_13masked_length_1__get__(o);
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_attr(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_4attr_1__get__(o);
}

static int __pyx_setprop_7plastid_8genomics_8roitools_12SegmentChain_attr(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_4attr_3__set__(o, v);
  }
  else {
    return __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_4attr_5__del__(o);
  }
}

static PyObject *__pyx_specialmethod___pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_25__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {return __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_25__next__(self);}

static PyMethodDef __pyx_methods_7plastid_8genomics_8roitools_SegmentChain[] = {
  {"sort", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_3sort, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_2sort},
  {"__reduce__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_5__reduce__, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_4__reduce__},
  {"__getstate__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_7__getstate__, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_6__getstate__},
  {"__setstate__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_9__setstate__, METH_O, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_8__setstate__},
  {"__copy__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_11__copy__, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_10__copy__},
  {"__deepcopy__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_13__deepcopy__, METH_O, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_12__deepcopy__},
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_25__next__, METH_NOARGS|METH_COEXIST, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_24__next__},
  {"next", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_27next, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_26next},
  {"shares_segments_with", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_33shares_segments_with, METH_O, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_32shares_segments_with},
  {"unstranded_overlaps", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_35unstranded_overlaps, METH_O, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_34unstranded_overlaps},
  {"overlaps", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_37overlaps, METH_O, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_36overlaps},
  {"antisense_overlaps", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_39antisense_overlaps, METH_O, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_38antisense_overlaps},
  {"covers", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_41covers, METH_O, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_40covers},
  {"get_unstranded", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_43get_unstranded, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_42get_unstranded},
  {"get_antisense", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_45get_antisense, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_44get_antisense},
  {"get_position_list", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_47get_position_list, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_46get_position_list},
  {"get_position_set", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_49get_position_set, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_48get_position_set},
  {"get_masked_position_set", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_51get_masked_position_set, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_50get_masked_position_set},
  {"get_name", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_53get_name, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_52get_name},
  {"get_gene", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_55get_gene, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_54get_gene},
  {"add_segments", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_57add_segments, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_56add_segments},
  {"add_masks", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_59add_masks, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_58add_masks},
  {"get_masks", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_61get_masks, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_60get_masks},
  {"get_masks_as_segmentchain", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_63get_masks_as_segmentchain, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_62get_masks_as_segmentchain},
  {"reset_masks", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_65reset_masks, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_64reset_masks},
  {"get_junctions", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_67get_junctions, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_66get_junctions},
  {"as_gff3", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_69as_gff3, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_68as_gff3},
  {"as_gtf", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_71as_gtf, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_70as_gtf},
  {"_get_8_gff_columns", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_73_get_8_gff_columns, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_72_get_8_gff_columns},
  {"as_bed", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_75as_bed, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_74as_bed},
  {"as_psl", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_77as_psl, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_76as_psl},
  {"get_segmentchain_coordinate", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_79get_segmentchain_coordinate, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_78get_segmentchain_coordinate},
  {"get_genomic_coordinate", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_81get_genomic_coordinate, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_80get_genomic_coordinate},
  {"get_subchain", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_83get_subchain, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_82get_subchain},
  {"get_counts", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_85get_counts, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_84get_counts},
  {"get_masked_counts", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_87get_masked_counts, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_86get_masked_counts},
  {"get_sequence", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_89get_sequence, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_88get_sequence},
  {"get_fasta", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_91get_fasta, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_90get_fasta},
  {"from_str", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_93from_str, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_92from_str},
  {"from_bed", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_95from_bed, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_94from_bed},
  {"from_psl", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_97from_psl, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_96from_psl},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_7plastid_8genomics_8roitools_SegmentChain[] = {
  {(char *)"chrom", __pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_chrom, 0, (char *)"Chromosome the SegmentChain resides on", 0},
  {(char *)"strand", __pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_strand, 0, (char *)"Strand of the SegmentChain", 0},
  {(char *)"c_strand", __pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_c_strand, 0, (char *)0, 0},
  {(char *)"segments", __pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_segments, 0, (char *)"Copy of list of |GenomicSegments| that comprise `self`.\n        Changing this list will do nothing to `self`.\n        ", 0},
  {(char *)"mask_segments", __pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_mask_segments, 0, (char *)"Copy of list of |GenomicSegments| representing regions masked in `self.`\n        Changing this list will do nothing to the masks in `self`.\n        ", 0},
  {(char *)"spanning_segment", __pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_spanning_segment, 0, (char *)0, 0},
  {(char *)"length", __pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_length, 0, (char *)0, 0},
  {(char *)"masked_length", __pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_masked_length, 0, (char *)0, 0},
  {(char *)"attr", __pyx_getprop_7plastid_8genomics_8roitools_12SegmentChain_attr, __pyx_setprop_7plastid_8genomics_8roitools_12SegmentChain_attr, (char *)"attr: dict", 0},
  {0, 0, 0, 0, 0}
};

static PySequenceMethods __pyx_tp_as_sequence_SegmentChain = {
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_29__len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  __pyx_sq_item_7plastid_8genomics_8roitools_SegmentChain, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_31__contains__, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_SegmentChain = {
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_29__len__, /*mp_length*/
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_21__getitem__, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyTypeObject __pyx_type_7plastid_8genomics_8roitools_SegmentChain = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.SegmentChain", /*tp_name*/
  sizeof(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_7plastid_8genomics_8roitools_SegmentChain, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_17__repr__, /*tp_repr*/
  0, /*tp_as_number*/
  &__pyx_tp_as_sequence_SegmentChain, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_SegmentChain, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_19__str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "\n    SegmentChain(*segments, **attributes)\n\n    Base class for genomic features, composed of zero or more |GenomicSegments|.\n    |SegmentChains| can therefore model discontinuous, features -- such as\n    multi-exon transcripts or gapped alignments -- in addition, to continuous\n    features.\n\n    Numerous convenience functions are supplied for:\n\n      - converting between coordinates relative to the genome and relative\n        to the internal coordinates of a spliced |SegmentChain|\n\n      - fetching genomic sequence, read alignments, or count data, accounting\n        for splicing of the segments, and, in the case of reverse-strand\n        features, reverse-complementing\n\n      - slicing or fetching sub-regions of a |SegmentChain|\n\n      - testing equality, inequality, overlap, containment, coverage of, or\n        sharing of segments with other |SegmentChain| or |GenomicSegment|\n        objects\n\n      - import/export to `BED`_, `PSL`_, `GTF2`_, and `GFF3`_ formats,\n        for use in other software packages or in a genome browser.\n\n    Intervals are sorted from lowest to greatest starting coordinate on their\n    reference sequence, regardless of strand. Iteration over the SegmentChain\n    will yield intervals from left-to-right in the genome.\n\n\n    Parameters\n    ----------\n    *segments : |GenomicSegment|\n        0 or more GenomicSegments on the same strand\n\n    **attr : keyword arguments\n        Arbitrary attributes, including, for example:\n\n        ====================    ============================================\n        **Attribute**           **Description**\n        ====================    ============================================\n        ``type``                A feature type used for `GTF2`_/`GFF3`_ export\n                                of each interval in the |SegmentChain|. (Default: `'exon'`)\n\n        ``ID``                  A unique ID for the |SegmentChain|.\n\n        ``transcript_id``       A transcript"" ID used for `GTF2`_ export\n\n        ``gene_id``             A gene ID used for `GTF2`_ export\n        ====================    ============================================\n\n\n    Attributes\n    ----------\n    spanning_segment : |GenomicSegment|\n        A |GenomicSegment| spanning the endpoints of the |SegmentChain|\n\n    strand : str\n        The chromosome strand (`'+'`, `'-'`, or `'.'`)\n\n    chrom : str\n        Name of the chromosome on which the |SegmentChain| resides\n\n    attr : dict\n        Any miscellaneous attributes or annotation data\n\n    segments : list\n        List of |GenomicSegments| in the chain\n\n    mask_segments : list\n        List of |GenomicSegments| that mask positions in the chain.\n\n    See Also\n    --------\n    Transcript\n        Transcript subclass, additionally providing richer `GTF2`_, `GFF3`_,\n        and `BED`_ export, as well as methods for fetching coding regions\n        and UTRs as subsegments\n    ", /*tp_doc*/
  __pyx_tp_traverse_7plastid_8genomics_8roitools_SegmentChain, /*tp_traverse*/
  __pyx_tp_clear_7plastid_8genomics_8roitools_SegmentChain, /*tp_clear*/
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_15__richcmp__, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_23__iter__, /*tp_iter*/
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_25__next__, /*tp_iternext*/
  __pyx_methods_7plastid_8genomics_8roitools_SegmentChain, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_7plastid_8genomics_8roitools_SegmentChain, /*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_7plastid_8genomics_8roitools_SegmentChain, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_7plastid_8genomics_8roitools_Transcript __pyx_vtable_7plastid_8genomics_8roitools_Transcript;

static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools_Transcript(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *p;
  PyObject *o = __pyx_tp_new_7plastid_8genomics_8roitools_SegmentChain(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_7plastid_8genomics_8roitools_SegmentChain*)__pyx_vtabptr_7plastid_8genomics_8roitools_Transcript;
  p->cds_genome_start = Py_None; Py_INCREF(Py_None);
  p->cds_genome_end = Py_None; Py_INCREF(Py_None);
  p->cds_start = Py_None; Py_INCREF(Py_None);
  p->cds_end = Py_None; Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_7plastid_8genomics_8roitools_10Transcript_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_7plastid_8genomics_8roitools_Transcript(PyObject *o) {
  struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *p = (struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->cds_genome_start);
  Py_CLEAR(p->cds_genome_end);
  Py_CLEAR(p->cds_start);
  Py_CLEAR(p->cds_end);
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_7plastid_8genomics_8roitools_SegmentChain(o);
}

static int __pyx_tp_traverse_7plastid_8genomics_8roitools_Transcript(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *p = (struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)o;
  e = __pyx_tp_traverse_7plastid_8genomics_8roitools_SegmentChain(o, v, a); if (e) return e;
  if (p->cds_genome_start) {
    e = (*v)(p->cds_genome_start, a); if (e) return e;
  }
  if (p->cds_genome_end) {
    e = (*v)(p->cds_genome_end, a); if (e) return e;
  }
  if (p->cds_start) {
    e = (*v)(p->cds_start, a); if (e) return e;
  }
  if (p->cds_end) {
    e = (*v)(p->cds_end, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_7plastid_8genomics_8roitools_Transcript(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *p = (struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *)o;
  __pyx_tp_clear_7plastid_8genomics_8roitools_SegmentChain(o);
  tmp = ((PyObject*)p->cds_genome_start);
  p->cds_genome_start = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->cds_genome_end);
  p->cds_genome_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->cds_start);
  p->cds_start = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->cds_end);
  p->cds_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_10Transcript_cds_start(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_10Transcript_9cds_start_1__get__(o);
}

static int __pyx_setprop_7plastid_8genomics_8roitools_10Transcript_cds_start(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_7plastid_8genomics_8roitools_10Transcript_9cds_start_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_10Transcript_cds_end(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_10Transcript_7cds_end_1__get__(o);
}

static int __pyx_setprop_7plastid_8genomics_8roitools_10Transcript_cds_end(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_7plastid_8genomics_8roitools_10Transcript_7cds_end_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_10Transcript_cds_genome_start(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_10Transcript_16cds_genome_start_1__get__(o);
}

static int __pyx_setprop_7plastid_8genomics_8roitools_10Transcript_cds_genome_start(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_7plastid_8genomics_8roitools_10Transcript_16cds_genome_start_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_7plastid_8genomics_8roitools_10Transcript_cds_genome_end(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_7plastid_8genomics_8roitools_10Transcript_14cds_genome_end_1__get__(o);
}

static int __pyx_setprop_7plastid_8genomics_8roitools_10Transcript_cds_genome_end(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_7plastid_8genomics_8roitools_10Transcript_14cds_genome_end_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_7plastid_8genomics_8roitools_Transcript[] = {
  {"__copy__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_3__copy__, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_2__copy__},
  {"__deepcopy__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_5__deepcopy__, METH_O, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_4__deepcopy__},
  {"__reduce__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_7__reduce__, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_6__reduce__},
  {"__getstate__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_9__getstate__, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_8__getstate__},
  {"__setstate__", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_11__setstate__, METH_O, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_10__setstate__},
  {"get_name", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_15get_name, METH_NOARGS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_14get_name},
  {"get_cds", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_17get_cds, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_16get_cds},
  {"get_utr5", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_19get_utr5, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_18get_utr5},
  {"get_utr3", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_21get_utr3, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_20get_utr3},
  {"as_gtf", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_23as_gtf, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_22as_gtf},
  {"as_gff3", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_25as_gff3, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_24as_gff3},
  {"as_bed", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_27as_bed, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_26as_bed},
  {"from_bed", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_29from_bed, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_28from_bed},
  {"from_psl", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_10Transcript_31from_psl, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_10Transcript_30from_psl},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_7plastid_8genomics_8roitools_Transcript[] = {
  {(char *)"cds_start", __pyx_getprop_7plastid_8genomics_8roitools_10Transcript_cds_start, __pyx_setprop_7plastid_8genomics_8roitools_10Transcript_cds_start, (char *)"Start of coding region relative to 5' end of transcript, in\n        direction of transcript.  Setting to None also sets `self.cds_end`,\n        `self.cds_genome_start` and `self.cds_genome_end` to None\n        ", 0},
  {(char *)"cds_end", __pyx_getprop_7plastid_8genomics_8roitools_10Transcript_cds_end, __pyx_setprop_7plastid_8genomics_8roitools_10Transcript_cds_end, (char *)"End of coding region relative to 5' end of transcript, in direction\n        of transcript.  Setting to None also sets `self.cds_start`,\n        `self.cds_genome_start` and `self.cds_genome_end` to None\n        ", 0},
  {(char *)"cds_genome_start", __pyx_getprop_7plastid_8genomics_8roitools_10Transcript_cds_genome_start, __pyx_setprop_7plastid_8genomics_8roitools_10Transcript_cds_genome_start, (char *)"Starting coordinate of coding region, relative to genome (i.e.\n        leftmost; is start codon for forward-strand features, stop codon for\n        reverse-strand features). Setting to None also sets `self.cds_start`,\n        `self.cds_end`, and `self.cds_genome_end` to None\n        ", 0},
  {(char *)"cds_genome_end", __pyx_getprop_7plastid_8genomics_8roitools_10Transcript_cds_genome_end, __pyx_setprop_7plastid_8genomics_8roitools_10Transcript_cds_genome_end, (char *)"Ending coordinate of coding region, relative to genome (i.e.\n        leftmost; is stop codon for forward-strand features, start codon for\n        reverse-strand features. Setting to None also sets `self.cds_start`,\n        `self.cds_end`, and `self.cds_genome_start` to None\n        ", 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_7plastid_8genomics_8roitools_Transcript = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.Transcript", /*tp_name*/
  sizeof(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_7plastid_8genomics_8roitools_Transcript, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_17__repr__, /*tp_repr*/
  #else
  0, /*tp_repr*/
  #endif
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_19__str__, /*tp_str*/
  #else
  0, /*tp_str*/
  #endif
  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*/
  "\n    Transcript(*segments, **attributes)\n\n    Subclass of |SegmentChain| specifically for RNA transcripts.  In addition\n    to coordinate-conversion, count fetching, sequence fetching, and various\n    other methods inherited from |SegmentChain|, |Transcript| provides\n    convenience methods for fetching sub-chains corresponding to CDS features,\n    5' UTRs, and 3' UTRs.\n\n\n    Parameters\n    ----------\n    *segments : |GenomicSegment|\n        0 or more GenomicSegments on the same strand\n\n    **attr : keyword arguments\n        Arbitrary attributes, including, for example:\n\n        ====================    ============================================\n        **Attribute**           **Description**\n        ====================    ============================================\n        ``cds_genome_start``    Location of CDS start, in genomic coordinates\n\n        ``cds_genome_start``    Location of CDS end, in genomic coordinates\n\n        ``ID``                  A unique ID for the |SegmentChain|.\n\n        ``transcript_id``       A transcript ID used for `GTF2`_ export\n\n        ``gene_id``             A gene ID used for `GTF2`_ export\n        ====================    ============================================\n\n\n\n\n    Attributes\n    ----------\n    cds_genome_start : int or None\n        Leftmost position in genomic coordinates of coding region, 0-indexed\n\n    cds_genome_end : int or None\n        Rightmost position in genomic coordinates of coding region, 0-indexed\n        and half-open\n\n    cds_start : int or None\n        Stranded position relative to 5' end of transcript at which coding\n        region starts (note: for minus-strand features this will be higher in\n        genomic coordinates than `cds_end`).\n\n    cds_end : int or None\n        Stranded position relative to 5' end of transcript at which coding\n        region ends (note: for minus-strand features this will be lower in\n        genomic coordinates than `cds_start""`).\n\n    spanning_segment : |GenomicSegment|\n        A GenomicSegment spanning the endpoints of the Transcript\n\n    strand : str\n        The chromosome strand ('+', '-', or '.')\n\n    chrom : str\n        The chromosome name\n\n    segments : list\n        List of |GenomicSegments| in the chain\n\n    mask_segments : list\n        List of |GenomicSegments| that mask positions in the chain.\n\n    attr : dict\n        Miscellaneous attributes\n    ", /*tp_doc*/
  __pyx_tp_traverse_7plastid_8genomics_8roitools_Transcript, /*tp_traverse*/
  __pyx_tp_clear_7plastid_8genomics_8roitools_Transcript, /*tp_clear*/
  __pyx_pw_7plastid_8genomics_8roitools_10Transcript_13__richcmp__, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_23__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_7plastid_8genomics_8roitools_12SegmentChain_25__next__, /*tp_iternext*/
  #else
  0, /*tp_iternext*/
  #endif
  __pyx_methods_7plastid_8genomics_8roitools_Transcript, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_7plastid_8genomics_8roitools_Transcript, /*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_7plastid_8genomics_8roitools_Transcript, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed[8];
static int __pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed = 0;

static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed)))) {
    o = (PyObject*)__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed[--__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed];
    memset(o, 0, sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed));
    (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_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed(PyObject *o) {
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *p = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_color);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed)))) {
    __pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed[__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed++] = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

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

static int __pyx_tp_clear_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *p = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed *)o;
  tmp = ((PyObject*)p->__pyx_v_color);
  p->__pyx_v_color = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.__pyx_scope_struct__as_bed", /*tp_name*/
  sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed, /*tp_traverse*/
  __pyx_tp_clear_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed, /*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_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr *__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr[8];
static int __pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr = 0;

static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___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_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr)))) {
    o = (PyObject*)__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr[--__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___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_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr(PyObject *o) {
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_X);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr)))) {
    __pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr[__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr++] = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_7plastid_8genomics_8roitools___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;
  }
  return 0;
}

static PyTypeObject __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.__pyx_scope_struct_1_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_7plastid_8genomics_8roitools___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
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr *__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr[8];
static int __pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr = 0;

static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___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_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr)))) {
    o = (PyObject*)__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr[--__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___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_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr(PyObject *o) {
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_X);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr)))) {
    __pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr[__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr++] = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_7plastid_8genomics_8roitools___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;
  }
  return 0;
}

static PyTypeObject __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.__pyx_scope_struct_2_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_7plastid_8genomics_8roitools___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
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr *__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr[8];
static int __pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr = 0;

static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr)))) {
    o = (PyObject*)__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr[--__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_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_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr(PyObject *o) {
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_X);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr)))) {
    __pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr[__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr++] = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_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;
  }
  return 0;
}

static PyTypeObject __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.__pyx_scope_struct_3_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_3_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
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr *__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr[8];
static int __pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr = 0;

static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr)))) {
    o = (PyObject*)__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr[--__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_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_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr(PyObject *o) {
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr *p = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_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_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr)))) {
    __pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr[__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr++] = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr *p = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_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 PyTypeObject __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.__pyx_scope_struct_4_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_4_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
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl *__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl[8];
static int __pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl = 0;

static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl)))) {
    o = (PyObject*)__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl[--__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl];
    memset(o, 0, sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl));
    (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_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl(PyObject *o) {
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl *p = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_ltmp);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl)))) {
    __pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl[__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl++] = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

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

static int __pyx_tp_clear_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl *p = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl *)o;
  tmp = ((PyObject*)p->__pyx_v_ltmp);
  p->__pyx_v_ltmp = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.__pyx_scope_struct_5_as_psl", /*tp_name*/
  sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl, /*tp_traverse*/
  __pyx_tp_clear_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl, /*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_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr *__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr[8];
static int __pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr = 0;

static PyObject *__pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr)))) {
    o = (PyObject*)__pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr[--__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_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_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr(PyObject *o) {
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr *p = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_X);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr)))) {
    __pyx_freelist_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr[__pyx_freecount_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr++] = ((struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr *p = (struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_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;
  }
  return 0;
}

static PyTypeObject __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.__pyx_scope_struct_6_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_7plastid_8genomics_8roitools___pyx_scope_struct_6_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
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_array __pyx_vtable_array;

static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_array_obj *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_array_obj *)o);
  p->__pyx_vtab = __pyx_vtabptr_array;
  p->mode = ((PyObject*)Py_None); Py_INCREF(Py_None);
  p->_format = ((PyObject*)Py_None); Py_INCREF(Py_None);
  if (unlikely(__pyx_array___cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_array(PyObject *o) {
  struct __pyx_array_obj *p = (struct __pyx_array_obj *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_array___dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->mode);
  Py_CLEAR(p->_format);
  (*Py_TYPE(o)->tp_free)(o);
}
static PyObject *__pyx_sq_item_array(PyObject *o, Py_ssize_t i) {
  PyObject *r;
  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
  r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);
  Py_DECREF(x);
  return r;
}

static int __pyx_mp_ass_subscript_array(PyObject *o, PyObject *i, PyObject *v) {
  if (v) {
    return __pyx_array___setitem__(o, i, v);
  }
  else {
    PyErr_Format(PyExc_NotImplementedError,
      "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name);
    return -1;
  }
}

static PyObject *__pyx_tp_getattro_array(PyObject *o, PyObject *n) {
  PyObject *v = __Pyx_PyObject_GenericGetAttr(o, n);
  if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) {
    PyErr_Clear();
    v = __pyx_array___getattr__(o, n);
  }
  return v;
}

static PyObject *__pyx_getprop___pyx_array_memview(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(o);
}

static PyMethodDef __pyx_methods_array[] = {
  {"__getattr__", (PyCFunction)__pyx_array___getattr__, METH_O|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_array_1__reduce_cython__, METH_NOARGS, 0},
  {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_array_3__setstate_cython__, METH_O, 0},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_array[] = {
  {(char *)"memview", __pyx_getprop___pyx_array_memview, 0, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PySequenceMethods __pyx_tp_as_sequence_array = {
  __pyx_array___len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  __pyx_sq_item_array, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_array = {
  __pyx_array___len__, /*mp_length*/
  __pyx_array___getitem__, /*mp_subscript*/
  __pyx_mp_ass_subscript_array, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_array = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  __pyx_array_getbuffer, /*bf_getbuffer*/
  0, /*bf_releasebuffer*/
};

static PyTypeObject __pyx_type___pyx_array = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.array", /*tp_name*/
  sizeof(struct __pyx_array_obj), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_array, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  &__pyx_tp_as_sequence_array, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_array, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  __pyx_tp_getattro_array, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_array, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_array, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_array, /*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_array, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_MemviewEnum_obj *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_MemviewEnum_obj *)o);
  p->name = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_Enum(PyObject *o) {
  struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->name);
  (*Py_TYPE(o)->tp_free)(o);
}

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

static int __pyx_tp_clear_Enum(PyObject *o) {
  PyObject* tmp;
  struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o;
  tmp = ((PyObject*)p->name);
  p->name = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_Enum[] = {
  {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_1__reduce_cython__, METH_NOARGS, 0},
  {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_3__setstate_cython__, METH_O, 0},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type___pyx_MemviewEnum = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.Enum", /*tp_name*/
  sizeof(struct __pyx_MemviewEnum_obj), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_Enum, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  __pyx_MemviewEnum___repr__, /*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_Enum, /*tp_traverse*/
  __pyx_tp_clear_Enum, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_Enum, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_MemviewEnum___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_Enum, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_memoryview __pyx_vtable_memoryview;

static PyObject *__pyx_tp_new_memoryview(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_memoryview_obj *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_memoryview_obj *)o);
  p->__pyx_vtab = __pyx_vtabptr_memoryview;
  p->obj = Py_None; Py_INCREF(Py_None);
  p->_size = Py_None; Py_INCREF(Py_None);
  p->_array_interface = Py_None; Py_INCREF(Py_None);
  p->view.obj = NULL;
  if (unlikely(__pyx_memoryview___cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_memoryview(PyObject *o) {
  struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_memoryview___dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->obj);
  Py_CLEAR(p->_size);
  Py_CLEAR(p->_array_interface);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_memoryview(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o;
  if (p->obj) {
    e = (*v)(p->obj, a); if (e) return e;
  }
  if (p->_size) {
    e = (*v)(p->_size, a); if (e) return e;
  }
  if (p->_array_interface) {
    e = (*v)(p->_array_interface, a); if (e) return e;
  }
  if (p->view.obj) {
    e = (*v)(p->view.obj, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_memoryview(PyObject *o) {
  PyObject* tmp;
  struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o;
  tmp = ((PyObject*)p->obj);
  p->obj = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_size);
  p->_size = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_array_interface);
  p->_array_interface = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  Py_CLEAR(p->view.obj);
  return 0;
}
static PyObject *__pyx_sq_item_memoryview(PyObject *o, Py_ssize_t i) {
  PyObject *r;
  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
  r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);
  Py_DECREF(x);
  return r;
}

static int __pyx_mp_ass_subscript_memoryview(PyObject *o, PyObject *i, PyObject *v) {
  if (v) {
    return __pyx_memoryview___setitem__(o, i, v);
  }
  else {
    PyErr_Format(PyExc_NotImplementedError,
      "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name);
    return -1;
  }
}

static PyObject *__pyx_getprop___pyx_memoryview_T(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_base(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_shape(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_strides(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_suboffsets(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_ndim(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_itemsize(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_nbytes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_size(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(o);
}

static PyMethodDef __pyx_methods_memoryview[] = {
  {"is_c_contig", (PyCFunction)__pyx_memoryview_is_c_contig, METH_NOARGS, 0},
  {"is_f_contig", (PyCFunction)__pyx_memoryview_is_f_contig, METH_NOARGS, 0},
  {"copy", (PyCFunction)__pyx_memoryview_copy, METH_NOARGS, 0},
  {"copy_fortran", (PyCFunction)__pyx_memoryview_copy_fortran, METH_NOARGS, 0},
  {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_1__reduce_cython__, METH_NOARGS, 0},
  {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_3__setstate_cython__, METH_O, 0},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_memoryview[] = {
  {(char *)"T", __pyx_getprop___pyx_memoryview_T, 0, (char *)0, 0},
  {(char *)"base", __pyx_getprop___pyx_memoryview_base, 0, (char *)0, 0},
  {(char *)"shape", __pyx_getprop___pyx_memoryview_shape, 0, (char *)0, 0},
  {(char *)"strides", __pyx_getprop___pyx_memoryview_strides, 0, (char *)0, 0},
  {(char *)"suboffsets", __pyx_getprop___pyx_memoryview_suboffsets, 0, (char *)0, 0},
  {(char *)"ndim", __pyx_getprop___pyx_memoryview_ndim, 0, (char *)0, 0},
  {(char *)"itemsize", __pyx_getprop___pyx_memoryview_itemsize, 0, (char *)0, 0},
  {(char *)"nbytes", __pyx_getprop___pyx_memoryview_nbytes, 0, (char *)0, 0},
  {(char *)"size", __pyx_getprop___pyx_memoryview_size, 0, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PySequenceMethods __pyx_tp_as_sequence_memoryview = {
  __pyx_memoryview___len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  __pyx_sq_item_memoryview, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_memoryview = {
  __pyx_memoryview___len__, /*mp_length*/
  __pyx_memoryview___getitem__, /*mp_subscript*/
  __pyx_mp_ass_subscript_memoryview, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_memoryview = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  __pyx_memoryview_getbuffer, /*bf_getbuffer*/
  0, /*bf_releasebuffer*/
};

static PyTypeObject __pyx_type___pyx_memoryview = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools.memoryview", /*tp_name*/
  sizeof(struct __pyx_memoryview_obj), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_memoryview, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  __pyx_memoryview___repr__, /*tp_repr*/
  0, /*tp_as_number*/
  &__pyx_tp_as_sequence_memoryview, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_memoryview, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_memoryview___str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_memoryview, /*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_memoryview, /*tp_traverse*/
  __pyx_tp_clear_memoryview, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_memoryview, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_memoryview, /*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_memoryview, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct__memoryviewslice __pyx_vtable__memoryviewslice;

static PyObject *__pyx_tp_new__memoryviewslice(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_memoryviewslice_obj *p;
  PyObject *o = __pyx_tp_new_memoryview(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_memoryviewslice_obj *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_memoryview*)__pyx_vtabptr__memoryviewslice;
  p->from_object = Py_None; Py_INCREF(Py_None);
  p->from_slice.memview = NULL;
  return o;
}

static void __pyx_tp_dealloc__memoryviewslice(PyObject *o) {
  struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_memoryviewslice___dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->from_object);
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_memoryview(o);
}

static int __pyx_tp_traverse__memoryviewslice(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o;
  e = __pyx_tp_traverse_memoryview(o, v, a); if (e) return e;
  if (p->from_object) {
    e = (*v)(p->from_object, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear__memoryviewslice(PyObject *o) {
  PyObject* tmp;
  struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o;
  __pyx_tp_clear_memoryview(o);
  tmp = ((PyObject*)p->from_object);
  p->from_object = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  __PYX_XDEC_MEMVIEW(&p->from_slice, 1);
  return 0;
}

static PyObject *__pyx_getprop___pyx_memoryviewslice_base(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(o);
}

static PyMethodDef __pyx_methods__memoryviewslice[] = {
  {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_1__reduce_cython__, METH_NOARGS, 0},
  {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_3__setstate_cython__, METH_O, 0},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets__memoryviewslice[] = {
  {(char *)"base", __pyx_getprop___pyx_memoryviewslice_base, 0, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type___pyx_memoryviewslice = {
  PyVarObject_HEAD_INIT(0, 0)
  "plastid.genomics.roitools._memoryviewslice", /*tp_name*/
  sizeof(struct __pyx_memoryviewslice_obj), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc__memoryviewslice, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_memoryview___repr__, /*tp_repr*/
  #else
  0, /*tp_repr*/
  #endif
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_memoryview___str__, /*tp_str*/
  #else
  0, /*tp_str*/
  #endif
  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*/
  "Internal class for passing memoryview slices to Python", /*tp_doc*/
  __pyx_tp_traverse__memoryviewslice, /*tp_traverse*/
  __pyx_tp_clear__memoryviewslice, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods__memoryviewslice, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets__memoryviewslice, /*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__memoryviewslice, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {"merge_segments", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_7merge_segments, METH_O, __pyx_doc_7plastid_8genomics_8roitools_6merge_segments},
  {"positions_to_segments", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_9positions_to_segments, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_8positions_to_segments},
  {"positionlist_to_segments", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7plastid_8genomics_8roitools_11positionlist_to_segments, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7plastid_8genomics_8roitools_10positionlist_to_segments},
  {"add_three_for_stop_codon", (PyCFunction)__pyx_pw_7plastid_8genomics_8roitools_13add_three_for_stop_codon, METH_O, __pyx_doc_7plastid_8genomics_8roitools_12add_three_for_stop_codon},
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
#if CYTHON_PEP489_MULTI_PHASE_INIT
static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
static int __pyx_pymod_exec_roitools(PyObject* module); /*proto*/
static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  {Py_mod_create, (void*)__pyx_pymod_create},
  {Py_mod_exec, (void*)__pyx_pymod_exec_roitools},
  {0, NULL}
};
#endif

static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    "roitools",
    __pyx_k_This_module_contains_classes_for, /* m_doc */
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    0, /* m_size */
  #else
    -1, /* m_size */
  #endif
    __pyx_methods /* m_methods */,
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    __pyx_moduledef_slots, /* m_slots */
  #else
    NULL, /* m_reload */
  #endif
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
    #define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
    #define CYTHON_SMALL_CODE __attribute__((cold))
#else
    #define CYTHON_SMALL_CODE
#endif
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_u_, __pyx_k_, sizeof(__pyx_k_), 0, 1, 0, 0},
  {&__pyx_kp_u_0, __pyx_k_0, sizeof(__pyx_k_0), 0, 1, 0, 0},
  {&__pyx_kp_u_000000, __pyx_k_000000, sizeof(__pyx_k_000000), 0, 1, 0, 0},
  {&__pyx_kp_u_0_0_0, __pyx_k_0_0_0, sizeof(__pyx_k_0_0_0), 0, 1, 0, 0},
  {&__pyx_kp_u_0_9_0_9, __pyx_k_0_9_0_9, sizeof(__pyx_k_0_9_0_9), 0, 1, 0, 0},
  {&__pyx_kp_u_0_9_0_9_2, __pyx_k_0_9_0_9_2, sizeof(__pyx_k_0_9_0_9_2), 0, 1, 0, 0},
  {&__pyx_kp_u_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 1, 0, 0},
  {&__pyx_kp_u_3UTR, __pyx_k_3UTR, sizeof(__pyx_k_3UTR), 0, 1, 0, 0},
  {&__pyx_kp_u_5UTR, __pyx_k_5UTR, sizeof(__pyx_k_5UTR), 0, 1, 0, 0},
  {&__pyx_n_s_ASCII, __pyx_k_ASCII, sizeof(__pyx_k_ASCII), 0, 0, 1, 1},
  {&__pyx_kp_u_Attempted_export_of_multi_interv, __pyx_k_Attempted_export_of_multi_interv, sizeof(__pyx_k_Attempted_export_of_multi_interv), 0, 1, 0, 0},
  {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1},
  {&__pyx_kp_u_BED_format_requires_at_least_3_c, __pyx_k_BED_format_requires_at_least_3_c, sizeof(__pyx_k_BED_format_requires_at_least_3_c), 0, 1, 0, 0},
  {&__pyx_n_s_Bio_Seq, __pyx_k_Bio_Seq, sizeof(__pyx_k_Bio_Seq), 0, 0, 1, 1},
  {&__pyx_n_s_Bio_SeqRecord, __pyx_k_Bio_SeqRecord, sizeof(__pyx_k_Bio_SeqRecord), 0, 0, 1, 1},
  {&__pyx_kp_s_Buffer_view_does_not_expose_stri, __pyx_k_Buffer_view_does_not_expose_stri, sizeof(__pyx_k_Buffer_view_does_not_expose_stri), 0, 0, 1, 0},
  {&__pyx_n_u_CDS, __pyx_k_CDS, sizeof(__pyx_k_CDS), 0, 1, 0, 1},
  {&__pyx_kp_s_Can_only_create_a_buffer_that_is, __pyx_k_Can_only_create_a_buffer_that_is, sizeof(__pyx_k_Can_only_create_a_buffer_that_is), 0, 0, 1, 0},
  {&__pyx_kp_s_Cannot_assign_to_read_only_memor, __pyx_k_Cannot_assign_to_read_only_memor, sizeof(__pyx_k_Cannot_assign_to_read_only_memor), 0, 0, 1, 0},
  {&__pyx_kp_s_Cannot_create_writable_memory_vi, __pyx_k_Cannot_create_writable_memory_vi, sizeof(__pyx_k_Cannot_create_writable_memory_vi), 0, 0, 1, 0},
  {&__pyx_kp_u_Cannot_fetch_coordinate, __pyx_k_Cannot_fetch_coordinate, sizeof(__pyx_k_Cannot_fetch_coordinate), 0, 1, 0, 0},
  {&__pyx_kp_s_Cannot_index_with_type_s, __pyx_k_Cannot_index_with_type_s, sizeof(__pyx_k_Cannot_index_with_type_s), 0, 0, 1, 0},
  {&__pyx_kp_u_Comparison_operation_not_defined, __pyx_k_Comparison_operation_not_defined, sizeof(__pyx_k_Comparison_operation_not_defined), 0, 1, 0, 0},
  {&__pyx_kp_u_Could_not_parse_BED_line_s, __pyx_k_Could_not_parse_BED_line_s, sizeof(__pyx_k_Could_not_parse_BED_line_s), 0, 1, 0, 0},
  {&__pyx_n_s_DOUBLE, __pyx_k_DOUBLE, sizeof(__pyx_k_DOUBLE), 0, 0, 1, 1},
  {&__pyx_n_s_DataWarning, __pyx_k_DataWarning, sizeof(__pyx_k_DataWarning), 0, 0, 1, 1},
  {&__pyx_kp_u_Defaulting_to_type_str, __pyx_k_Defaulting_to_type_str, sizeof(__pyx_k_Defaulting_to_type_str), 0, 1, 0, 0},
  {&__pyx_n_s_Ellipsis, __pyx_k_Ellipsis, sizeof(__pyx_k_Ellipsis), 0, 0, 1, 1},
  {&__pyx_kp_s_Empty_shape_tuple_for_cython_arr, __pyx_k_Empty_shape_tuple_for_cython_arr, sizeof(__pyx_k_Empty_shape_tuple_for_cython_arr), 0, 0, 1, 0},
  {&__pyx_n_s_FLOAT, __pyx_k_FLOAT, sizeof(__pyx_k_FLOAT), 0, 0, 1, 1},
  {&__pyx_kp_u_Falling_back_to_default_value, __pyx_k_Falling_back_to_default_value, sizeof(__pyx_k_Falling_back_to_default_value), 0, 1, 0, 0},
  {&__pyx_kp_u_GenomicSegment, __pyx_k_GenomicSegment, sizeof(__pyx_k_GenomicSegment), 0, 1, 0, 0},
  {&__pyx_kp_u_GenomicSegment_2, __pyx_k_GenomicSegment_2, sizeof(__pyx_k_GenomicSegment_2), 0, 1, 0, 0},
  {&__pyx_n_s_GenomicSegment_3, __pyx_k_GenomicSegment_3, sizeof(__pyx_k_GenomicSegment_3), 0, 0, 1, 1},
  {&__pyx_kp_u_GenomicSegment___eq, __pyx_k_GenomicSegment___eq, sizeof(__pyx_k_GenomicSegment___eq), 0, 1, 0, 0},
  {&__pyx_kp_u_GenomicSegment_contains, __pyx_k_GenomicSegment_contains, sizeof(__pyx_k_GenomicSegment_contains), 0, 1, 0, 0},
  {&__pyx_kp_u_GenomicSegment_eq_neq, __pyx_k_GenomicSegment_eq_neq, sizeof(__pyx_k_GenomicSegment_eq_neq), 0, 1, 0, 0},
  {&__pyx_kp_u_GenomicSegment_overlaps, __pyx_k_GenomicSegment_overlaps, sizeof(__pyx_k_GenomicSegment_overlaps), 0, 1, 0, 0},
  {&__pyx_kp_u_GenomicSegment_start_coordinate, __pyx_k_GenomicSegment_start_coordinate, sizeof(__pyx_k_GenomicSegment_start_coordinate), 0, 1, 0, 0},
  {&__pyx_kp_u_ID, __pyx_k_ID, sizeof(__pyx_k_ID), 0, 1, 0, 0},
  {&__pyx_n_s_ID_2, __pyx_k_ID_2, sizeof(__pyx_k_ID_2), 0, 0, 1, 1},
  {&__pyx_n_u_ID_2, __pyx_k_ID_2, sizeof(__pyx_k_ID_2), 0, 1, 0, 1},
  {&__pyx_n_s_INT, __pyx_k_INT, sizeof(__pyx_k_INT), 0, 0, 1, 1},
  {&__pyx_n_s_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1},
  {&__pyx_kp_s_Incompatible_checksums_s_vs_0xb0, __pyx_k_Incompatible_checksums_s_vs_0xb0, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xb0), 0, 0, 1, 0},
  {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1},
  {&__pyx_kp_s_Indirect_dimensions_not_supporte, __pyx_k_Indirect_dimensions_not_supporte, sizeof(__pyx_k_Indirect_dimensions_not_supporte), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_k_Invalid_mode_expected_c_or_fortr, sizeof(__pyx_k_Invalid_mode_expected_c_or_fortr), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_k_Invalid_shape_in_axis_d_d, sizeof(__pyx_k_Invalid_shape_in_axis_d_d), 0, 0, 1, 0},
  {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1},
  {&__pyx_n_s_LONG, __pyx_k_LONG, sizeof(__pyx_k_LONG), 0, 0, 1, 1},
  {&__pyx_n_s_MaskedArray, __pyx_k_MaskedArray, sizeof(__pyx_k_MaskedArray), 0, 0, 1, 1},
  {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1},
  {&__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_k_MemoryView_of_r_at_0x_x, sizeof(__pyx_k_MemoryView_of_r_at_0x_x), 0, 0, 1, 0},
  {&__pyx_kp_s_MemoryView_of_r_object, __pyx_k_MemoryView_of_r_object, sizeof(__pyx_k_MemoryView_of_r_object), 0, 0, 1, 0},
  {&__pyx_n_u_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 1, 0, 1},
  {&__pyx_n_u_Name, __pyx_k_Name, sizeof(__pyx_k_Name), 0, 1, 0, 1},
  {&__pyx_kp_u_None, __pyx_k_None, sizeof(__pyx_k_None), 0, 1, 0, 0},
  {&__pyx_kp_u_None_None, __pyx_k_None_None, sizeof(__pyx_k_None_None), 0, 1, 0, 0},
  {&__pyx_n_u_NullChromosome, __pyx_k_NullChromosome, sizeof(__pyx_k_NullChromosome), 0, 1, 0, 1},
  {&__pyx_n_s_NullSegment, __pyx_k_NullSegment, sizeof(__pyx_k_NullSegment), 0, 0, 1, 1},
  {&__pyx_n_b_O, __pyx_k_O, sizeof(__pyx_k_O), 0, 0, 0, 1},
  {&__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_k_Out_of_bounds_on_buffer_access_a, sizeof(__pyx_k_Out_of_bounds_on_buffer_access_a), 0, 0, 1, 0},
  {&__pyx_n_s_Parent, __pyx_k_Parent, sizeof(__pyx_k_Parent), 0, 0, 1, 1},
  {&__pyx_n_u_Parent, __pyx_k_Parent, sizeof(__pyx_k_Parent), 0, 1, 0, 1},
  {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1},
  {&__pyx_kp_u_Position, __pyx_k_Position, sizeof(__pyx_k_Position), 0, 1, 0, 0},
  {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1},
  {&__pyx_kp_u_SegmentChain, __pyx_k_SegmentChain, sizeof(__pyx_k_SegmentChain), 0, 1, 0, 0},
  {&__pyx_n_s_SegmentChain_2, __pyx_k_SegmentChain_2, sizeof(__pyx_k_SegmentChain_2), 0, 0, 1, 1},
  {&__pyx_kp_u_SegmentChain_add_segments_incomi, __pyx_k_SegmentChain_add_segments_incomi, sizeof(__pyx_k_SegmentChain_add_segments_incomi), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChain_antisense_overlaps, __pyx_k_SegmentChain_antisense_overlaps, sizeof(__pyx_k_SegmentChain_antisense_overlaps), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChain_antisense_overlaps_2, __pyx_k_SegmentChain_antisense_overlaps_2, sizeof(__pyx_k_SegmentChain_antisense_overlaps_2), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChain_covers_is_only_defi, __pyx_k_SegmentChain_covers_is_only_defi, sizeof(__pyx_k_SegmentChain_covers_is_only_defi), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChain_eq_ineq_et_c_is_onl, __pyx_k_SegmentChain_eq_ineq_et_c_is_onl, sizeof(__pyx_k_SegmentChain_eq_ineq_et_c_is_onl), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChain_from_bed_Could_not, __pyx_k_SegmentChain_from_bed_Could_not, sizeof(__pyx_k_SegmentChain_from_bed_Could_not), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChain_get_masks_is_deprec, __pyx_k_SegmentChain_get_masks_is_deprec, sizeof(__pyx_k_SegmentChain_get_masks_is_deprec), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChain_get_segmentchain_co, __pyx_k_SegmentChain_get_segmentchain_co, sizeof(__pyx_k_SegmentChain_get_segmentchain_co), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChain_get_segmentchain_co_2, __pyx_k_SegmentChain_get_segmentchain_co_2, sizeof(__pyx_k_SegmentChain_get_segmentchain_co_2), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChain_overlaps_is_defined, __pyx_k_SegmentChain_overlaps_is_defined, sizeof(__pyx_k_SegmentChain_overlaps_is_defined), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChain_shares_segments_wit, __pyx_k_SegmentChain_shares_segments_wit, sizeof(__pyx_k_SegmentChain_shares_segments_wit), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChain_unstranded_overlaps, __pyx_k_SegmentChain_unstranded_overlaps, sizeof(__pyx_k_SegmentChain_unstranded_overlaps), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChain_unstranded_overlaps_2, __pyx_k_SegmentChain_unstranded_overlaps_2, sizeof(__pyx_k_SegmentChain_unstranded_overlaps_2), 0, 1, 0, 0},
  {&__pyx_kp_u_SegmentChains_only_support_PSL_o, __pyx_k_SegmentChains_only_support_PSL_o, sizeof(__pyx_k_SegmentChains_only_support_PSL_o), 0, 1, 0, 0},
  {&__pyx_kp_u_Segmentchain_adding_segments_to, __pyx_k_Segmentchain_adding_segments_to, sizeof(__pyx_k_Segmentchain_adding_segments_to), 0, 1, 0, 0},
  {&__pyx_n_s_Seq, __pyx_k_Seq, sizeof(__pyx_k_Seq), 0, 0, 1, 1},
  {&__pyx_n_s_SeqRecord, __pyx_k_SeqRecord, sizeof(__pyx_k_SeqRecord), 0, 0, 1, 1},
  {&__pyx_kp_u_Strand_for_SegmentChain_s_is_und, __pyx_k_Strand_for_SegmentChain_s_is_und, sizeof(__pyx_k_Strand_for_SegmentChain_s_is_und), 0, 1, 0, 0},
  {&__pyx_kp_u_The_in_containment_operator_is_o, __pyx_k_The_in_containment_operator_is_o, sizeof(__pyx_k_The_in_containment_operator_is_o), 0, 1, 0, 0},
  {&__pyx_kp_u_This_operation_is_not_defined_fo, __pyx_k_This_operation_is_not_defined_fo, sizeof(__pyx_k_This_operation_is_not_defined_fo), 0, 1, 0, 0},
  {&__pyx_kp_u_This_operation_is_not_defined_fo_2, __pyx_k_This_operation_is_not_defined_fo_2, sizeof(__pyx_k_This_operation_is_not_defined_fo_2), 0, 1, 0, 0},
  {&__pyx_kp_u_Transcript, __pyx_k_Transcript, sizeof(__pyx_k_Transcript), 0, 1, 0, 0},
  {&__pyx_kp_u_Transcript_2, __pyx_k_Transcript_2, sizeof(__pyx_k_Transcript_2), 0, 1, 0, 0},
  {&__pyx_n_s_Transcript_3, __pyx_k_Transcript_3, sizeof(__pyx_k_Transcript_3), 0, 0, 1, 1},
  {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
  {&__pyx_kp_s_Unable_to_convert_item_to_object, __pyx_k_Unable_to_convert_item_to_object, sizeof(__pyx_k_Unable_to_convert_item_to_object), 0, 0, 1, 0},
  {&__pyx_n_s_UserWarning, __pyx_k_UserWarning, sizeof(__pyx_k_UserWarning), 0, 0, 1, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_n_s_View_MemoryView, __pyx_k_View_MemoryView, sizeof(__pyx_k_View_MemoryView), 0, 0, 1, 1},
  {&__pyx_kp_u__10, __pyx_k__10, sizeof(__pyx_k__10), 0, 1, 0, 0},
  {&__pyx_kp_u__11, __pyx_k__11, sizeof(__pyx_k__11), 0, 1, 0, 0},
  {&__pyx_kp_u__12, __pyx_k__12, sizeof(__pyx_k__12), 0, 1, 0, 0},
  {&__pyx_kp_u__13, __pyx_k__13, sizeof(__pyx_k__13), 0, 1, 0, 0},
  {&__pyx_kp_u__14, __pyx_k__14, sizeof(__pyx_k__14), 0, 1, 0, 0},
  {&__pyx_kp_u__15, __pyx_k__15, sizeof(__pyx_k__15), 0, 1, 0, 0},
  {&__pyx_kp_u__17, __pyx_k__17, sizeof(__pyx_k__17), 0, 1, 0, 0},
  {&__pyx_kp_u__18, __pyx_k__18, sizeof(__pyx_k__18), 0, 1, 0, 0},
  {&__pyx_kp_u__19, __pyx_k__19, sizeof(__pyx_k__19), 0, 1, 0, 0},
  {&__pyx_kp_u__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 1, 0, 0},
  {&__pyx_kp_u__25, __pyx_k__25, sizeof(__pyx_k__25), 0, 1, 0, 0},
  {&__pyx_kp_u__26, __pyx_k__26, sizeof(__pyx_k__26), 0, 1, 0, 0},
  {&__pyx_kp_u__29, __pyx_k__29, sizeof(__pyx_k__29), 0, 1, 0, 0},
  {&__pyx_kp_u__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 1, 0, 0},
  {&__pyx_kp_u__30, __pyx_k__30, sizeof(__pyx_k__30), 0, 1, 0, 0},
  {&__pyx_kp_u__31, __pyx_k__31, sizeof(__pyx_k__31), 0, 1, 0, 0},
  {&__pyx_kp_u__33, __pyx_k__33, sizeof(__pyx_k__33), 0, 1, 0, 0},
  {&__pyx_kp_u__35, __pyx_k__35, sizeof(__pyx_k__35), 0, 1, 0, 0},
  {&__pyx_kp_u__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 1, 0, 0},
  {&__pyx_kp_u__42, __pyx_k__42, sizeof(__pyx_k__42), 0, 1, 0, 0},
  {&__pyx_kp_u__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 1, 0, 0},
  {&__pyx_kp_u__6, __pyx_k__6, sizeof(__pyx_k__6), 0, 1, 0, 0},
  {&__pyx_kp_u__66, __pyx_k__66, sizeof(__pyx_k__66), 0, 1, 0, 0},
  {&__pyx_kp_u__68, __pyx_k__68, sizeof(__pyx_k__68), 0, 1, 0, 0},
  {&__pyx_kp_u__7, __pyx_k__7, sizeof(__pyx_k__7), 0, 1, 0, 0},
  {&__pyx_kp_u__8, __pyx_k__8, sizeof(__pyx_k__8), 0, 1, 0, 0},
  {&__pyx_kp_u__9, __pyx_k__9, sizeof(__pyx_k__9), 0, 1, 0, 0},
  {&__pyx_n_u_alignment, __pyx_k_alignment, sizeof(__pyx_k_alignment), 0, 1, 0, 1},
  {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1},
  {&__pyx_n_s_allocate_buffer, __pyx_k_allocate_buffer, sizeof(__pyx_k_allocate_buffer), 0, 0, 1, 1},
  {&__pyx_kp_u_and_object, __pyx_k_and_object, sizeof(__pyx_k_and_object), 0, 1, 0, 0},
  {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
  {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1},
  {&__pyx_kp_u_as, __pyx_k_as, sizeof(__pyx_k_as), 0, 1, 0, 0},
  {&__pyx_n_s_as_bed, __pyx_k_as_bed, sizeof(__pyx_k_as_bed), 0, 0, 1, 1},
  {&__pyx_n_s_as_bed_locals_genexpr, __pyx_k_as_bed_locals_genexpr, sizeof(__pyx_k_as_bed_locals_genexpr), 0, 0, 1, 1},
  {&__pyx_n_s_as_gff3, __pyx_k_as_gff3, sizeof(__pyx_k_as_gff3), 0, 0, 1, 1},
  {&__pyx_n_s_as_gtf, __pyx_k_as_gtf, sizeof(__pyx_k_as_gtf), 0, 0, 1, 1},
  {&__pyx_n_s_as_igv_str, __pyx_k_as_igv_str, sizeof(__pyx_k_as_igv_str), 0, 0, 1, 1},
  {&__pyx_n_s_as_int, __pyx_k_as_int, sizeof(__pyx_k_as_int), 0, 0, 1, 1},
  {&__pyx_n_s_as_psl_locals_genexpr, __pyx_k_as_psl_locals_genexpr, sizeof(__pyx_k_as_psl_locals_genexpr), 0, 0, 1, 1},
  {&__pyx_n_s_asarray, __pyx_k_asarray, sizeof(__pyx_k_asarray), 0, 0, 1, 1},
  {&__pyx_n_s_astype, __pyx_k_astype, sizeof(__pyx_k_astype), 0, 0, 1, 1},
  {&__pyx_n_s_attr, __pyx_k_attr, sizeof(__pyx_k_attr), 0, 0, 1, 1},
  {&__pyx_n_s_base, __pyx_k_base, sizeof(__pyx_k_base), 0, 0, 1, 1},
  {&__pyx_n_u_bedx_column_order, __pyx_k_bedx_column_order, sizeof(__pyx_k_bedx_column_order), 0, 1, 0, 1},
  {&__pyx_n_s_block_size, __pyx_k_block_size, sizeof(__pyx_k_block_size), 0, 0, 1, 1},
  {&__pyx_n_s_block_sizes, __pyx_k_block_sizes, sizeof(__pyx_k_block_sizes), 0, 0, 1, 1},
  {&__pyx_n_u_blocks, __pyx_k_blocks, sizeof(__pyx_k_blocks), 0, 1, 0, 1},
  {&__pyx_n_u_blocksizes, __pyx_k_blocksizes, sizeof(__pyx_k_blocksizes), 0, 1, 0, 1},
  {&__pyx_n_u_blockstarts, __pyx_k_blockstarts, sizeof(__pyx_k_blockstarts), 0, 1, 0, 1},
  {&__pyx_kp_u_bounds, __pyx_k_bounds, sizeof(__pyx_k_bounds), 0, 1, 0, 0},
  {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1},
  {&__pyx_n_u_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 1, 0, 1},
  {&__pyx_n_s_c_strand, __pyx_k_c_strand, sizeof(__pyx_k_c_strand), 0, 0, 1, 1},
  {&__pyx_kp_u_cannot_be_None, __pyx_k_cannot_be_None, sizeof(__pyx_k_cannot_be_None), 0, 1, 0, 0},
  {&__pyx_kp_u_cds_end, __pyx_k_cds_end, sizeof(__pyx_k_cds_end), 0, 1, 0, 0},
  {&__pyx_kp_u_cds_genome_end, __pyx_k_cds_genome_end, sizeof(__pyx_k_cds_genome_end), 0, 1, 0, 0},
  {&__pyx_n_s_cds_genome_end_2, __pyx_k_cds_genome_end_2, sizeof(__pyx_k_cds_genome_end_2), 0, 0, 1, 1},
  {&__pyx_n_u_cds_genome_end_2, __pyx_k_cds_genome_end_2, sizeof(__pyx_k_cds_genome_end_2), 0, 1, 0, 1},
  {&__pyx_kp_u_cds_genome_end_3, __pyx_k_cds_genome_end_3, sizeof(__pyx_k_cds_genome_end_3), 0, 1, 0, 0},
  {&__pyx_kp_u_cds_genome_start, __pyx_k_cds_genome_start, sizeof(__pyx_k_cds_genome_start), 0, 1, 0, 0},
  {&__pyx_n_s_cds_genome_start_2, __pyx_k_cds_genome_start_2, sizeof(__pyx_k_cds_genome_start_2), 0, 0, 1, 1},
  {&__pyx_n_u_cds_genome_start_2, __pyx_k_cds_genome_start_2, sizeof(__pyx_k_cds_genome_start_2), 0, 1, 0, 1},
  {&__pyx_kp_u_cds_genome_start_3, __pyx_k_cds_genome_start_3, sizeof(__pyx_k_cds_genome_start_3), 0, 1, 0, 0},
  {&__pyx_kp_u_cds_start, __pyx_k_cds_start, sizeof(__pyx_k_cds_start), 0, 1, 0, 0},
  {&__pyx_n_s_chain, __pyx_k_chain, sizeof(__pyx_k_chain), 0, 0, 1, 1},
  {&__pyx_n_s_chrom, __pyx_k_chrom, sizeof(__pyx_k_chrom), 0, 0, 1, 1},
  {&__pyx_n_u_chrom, __pyx_k_chrom, sizeof(__pyx_k_chrom), 0, 1, 0, 1},
  {&__pyx_n_u_chrom_start, __pyx_k_chrom_start, sizeof(__pyx_k_chrom_start), 0, 1, 0, 1},
  {&__pyx_n_s_class, __pyx_k_class, sizeof(__pyx_k_class), 0, 0, 1, 1},
  {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_n_s_cmp_helper, __pyx_k_cmp_helper, sizeof(__pyx_k_cmp_helper), 0, 0, 1, 1},
  {&__pyx_n_s_cmptype, __pyx_k_cmptype, sizeof(__pyx_k_cmptype), 0, 0, 1, 1},
  {&__pyx_n_s_color, __pyx_k_color, sizeof(__pyx_k_color), 0, 0, 1, 1},
  {&__pyx_n_u_color, __pyx_k_color, sizeof(__pyx_k_color), 0, 1, 0, 1},
  {&__pyx_n_s_compile, __pyx_k_compile, sizeof(__pyx_k_compile), 0, 0, 1, 1},
  {&__pyx_n_s_contains, __pyx_k_contains, sizeof(__pyx_k_contains), 0, 0, 1, 1},
  {&__pyx_n_s_contains_2, __pyx_k_contains_2, sizeof(__pyx_k_contains_2), 0, 0, 1, 1},
  {&__pyx_kp_s_contiguous_and_direct, __pyx_k_contiguous_and_direct, sizeof(__pyx_k_contiguous_and_direct), 0, 0, 1, 0},
  {&__pyx_kp_s_contiguous_and_indirect, __pyx_k_contiguous_and_indirect, sizeof(__pyx_k_contiguous_and_indirect), 0, 0, 1, 0},
  {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1},
  {&__pyx_n_s_copy_2, __pyx_k_copy_2, sizeof(__pyx_k_copy_2), 0, 0, 1, 1},
  {&__pyx_kp_u_custom_s, __pyx_k_custom_s, sizeof(__pyx_k_custom_s), 0, 1, 0, 0},
  {&__pyx_n_s_deepcopy, __pyx_k_deepcopy, sizeof(__pyx_k_deepcopy), 0, 0, 1, 1},
  {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1},
  {&__pyx_kp_u_does_not_match_chain, __pyx_k_does_not_match_chain, sizeof(__pyx_k_does_not_match_chain), 0, 1, 0, 0},
  {&__pyx_n_s_double, __pyx_k_double, sizeof(__pyx_k_double), 0, 0, 1, 1},
  {&__pyx_n_s_dtmp, __pyx_k_dtmp, sizeof(__pyx_k_dtmp), 0, 0, 1, 1},
  {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_is_object, __pyx_k_dtype_is_object, sizeof(__pyx_k_dtype_is_object), 0, 0, 1, 1},
  {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1},
  {&__pyx_n_s_empty_like, __pyx_k_empty_like, sizeof(__pyx_k_empty_like), 0, 0, 1, 1},
  {&__pyx_n_s_empty_value, __pyx_k_empty_value, sizeof(__pyx_k_empty_value), 0, 0, 1, 1},
  {&__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_u_end_coordinate_supplied_is_None, __pyx_k_end_coordinate_supplied_is_None, sizeof(__pyx_k_end_coordinate_supplied_is_None), 0, 1, 0, 0},
  {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
  {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1},
  {&__pyx_n_s_escape, __pyx_k_escape, sizeof(__pyx_k_escape), 0, 0, 1, 1},
  {&__pyx_n_s_excludes, __pyx_k_excludes, sizeof(__pyx_k_excludes), 0, 0, 1, 1},
  {&__pyx_n_u_exon, __pyx_k_exon, sizeof(__pyx_k_exon), 0, 1, 0, 1},
  {&__pyx_kp_u_exon_2, __pyx_k_exon_2, sizeof(__pyx_k_exon_2), 0, 1, 0, 0},
  {&__pyx_n_s_extra_columns, __pyx_k_extra_columns, sizeof(__pyx_k_extra_columns), 0, 0, 1, 1},
  {&__pyx_n_s_feature_type, __pyx_k_feature_type, sizeof(__pyx_k_feature_type), 0, 0, 1, 1},
  {&__pyx_n_u_five_prime_UTR, __pyx_k_five_prime_UTR, sizeof(__pyx_k_five_prime_UTR), 0, 1, 0, 1},
  {&__pyx_n_s_flags, __pyx_k_flags, sizeof(__pyx_k_flags), 0, 0, 1, 1},
  {&__pyx_n_s_float, __pyx_k_float, sizeof(__pyx_k_float), 0, 0, 1, 1},
  {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
  {&__pyx_n_s_format_segmentchain, __pyx_k_format_segmentchain, sizeof(__pyx_k_format_segmentchain), 0, 0, 1, 1},
  {&__pyx_n_s_format_transcript, __pyx_k_format_transcript, sizeof(__pyx_k_format_transcript), 0, 0, 1, 1},
  {&__pyx_n_s_fortran, __pyx_k_fortran, sizeof(__pyx_k_fortran), 0, 0, 1, 1},
  {&__pyx_n_u_fortran, __pyx_k_fortran, sizeof(__pyx_k_fortran), 0, 1, 0, 1},
  {&__pyx_n_u_frame, __pyx_k_frame, sizeof(__pyx_k_frame), 0, 1, 0, 1},
  {&__pyx_kp_u_from_SegmentChain, __pyx_k_from_SegmentChain, sizeof(__pyx_k_from_SegmentChain), 0, 1, 0, 0},
  {&__pyx_n_s_from_bed, __pyx_k_from_bed, sizeof(__pyx_k_from_bed), 0, 0, 1, 1},
  {&__pyx_n_s_from_igv_str, __pyx_k_from_igv_str, sizeof(__pyx_k_from_igv_str), 0, 0, 1, 1},
  {&__pyx_n_s_from_psl, __pyx_k_from_psl, sizeof(__pyx_k_from_psl), 0, 0, 1, 1},
  {&__pyx_n_s_from_str, __pyx_k_from_str, sizeof(__pyx_k_from_str), 0, 0, 1, 1},
  {&__pyx_n_s_frombuffer, __pyx_k_frombuffer, sizeof(__pyx_k_frombuffer), 0, 0, 1, 1},
  {&__pyx_n_s_ga, __pyx_k_ga, sizeof(__pyx_k_ga), 0, 0, 1, 1},
  {&__pyx_kp_u_gene__s, __pyx_k_gene__s, sizeof(__pyx_k_gene__s), 0, 1, 0, 0},
  {&__pyx_n_u_gene_id, __pyx_k_gene_id, sizeof(__pyx_k_gene_id), 0, 1, 0, 1},
  {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1},
  {&__pyx_n_s_genome, __pyx_k_genome, sizeof(__pyx_k_genome), 0, 0, 1, 1},
  {&__pyx_n_s_genomic_x, __pyx_k_genomic_x, sizeof(__pyx_k_genomic_x), 0, 0, 1, 1},
  {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1},
  {&__pyx_n_s_get_8_gff_columns, __pyx_k_get_8_gff_columns, sizeof(__pyx_k_get_8_gff_columns), 0, 0, 1, 1},
  {&__pyx_n_s_get_antisense, __pyx_k_get_antisense, sizeof(__pyx_k_get_antisense), 0, 0, 1, 1},
  {&__pyx_n_s_get_attr, __pyx_k_get_attr, sizeof(__pyx_k_get_attr), 0, 0, 1, 1},
  {&__pyx_kp_u_get_attr_from_bed_Cannot_make_Se, __pyx_k_get_attr_from_bed_Cannot_make_Se, sizeof(__pyx_k_get_attr_from_bed_Cannot_make_Se), 0, 1, 0, 0},
  {&__pyx_kp_u_get_attr_from_bed_Cannot_make_Se_2, __pyx_k_get_attr_from_bed_Cannot_make_Se_2, sizeof(__pyx_k_get_attr_from_bed_Cannot_make_Se_2), 0, 1, 0, 0},
  {&__pyx_kp_u_get_attr_from_bed_Couldn_t_figur, __pyx_k_get_attr_from_bed_Couldn_t_figur, sizeof(__pyx_k_get_attr_from_bed_Couldn_t_figur), 0, 1, 0, 0},
  {&__pyx_kp_u_get_attr_from_bed_List_of_extra, __pyx_k_get_attr_from_bed_List_of_extra, sizeof(__pyx_k_get_attr_from_bed_List_of_extra), 0, 1, 0, 0},
  {&__pyx_n_s_get_cds, __pyx_k_get_cds, sizeof(__pyx_k_get_cds), 0, 0, 1, 1},
  {&__pyx_n_s_get_counts, __pyx_k_get_counts, sizeof(__pyx_k_get_counts), 0, 0, 1, 1},
  {&__pyx_n_s_get_gene, __pyx_k_get_gene, sizeof(__pyx_k_get_gene), 0, 0, 1, 1},
  {&__pyx_n_s_get_junctions, __pyx_k_get_junctions, sizeof(__pyx_k_get_junctions), 0, 0, 1, 1},
  {&__pyx_n_s_get_masked_position_set, __pyx_k_get_masked_position_set, sizeof(__pyx_k_get_masked_position_set), 0, 0, 1, 1},
  {&__pyx_n_s_get_name, __pyx_k_get_name, sizeof(__pyx_k_get_name), 0, 0, 1, 1},
  {&__pyx_n_s_get_position_list, __pyx_k_get_position_list, sizeof(__pyx_k_get_position_list), 0, 0, 1, 1},
  {&__pyx_n_s_get_rgb255, __pyx_k_get_rgb255, sizeof(__pyx_k_get_rgb255), 0, 0, 1, 1},
  {&__pyx_n_s_get_segmentchain_coordinate, __pyx_k_get_segmentchain_coordinate, sizeof(__pyx_k_get_segmentchain_coordinate), 0, 0, 1, 1},
  {&__pyx_kp_u_get_segmentchain_coordinate_quer, __pyx_k_get_segmentchain_coordinate_quer, sizeof(__pyx_k_get_segmentchain_coordinate_quer), 0, 1, 0, 0},
  {&__pyx_kp_u_get_segmentchain_coordinate_quer_2, __pyx_k_get_segmentchain_coordinate_quer_2, sizeof(__pyx_k_get_segmentchain_coordinate_quer_2), 0, 1, 0, 0},
  {&__pyx_n_s_get_sequence, __pyx_k_get_sequence, sizeof(__pyx_k_get_sequence), 0, 0, 1, 1},
  {&__pyx_kp_u_get_standard_bed_attr_Could_not, __pyx_k_get_standard_bed_attr_Could_not, sizeof(__pyx_k_get_standard_bed_attr_Could_not), 0, 1, 0, 0},
  {&__pyx_n_s_get_str_from_rgb, __pyx_k_get_str_from_rgb, sizeof(__pyx_k_get_str_from_rgb), 0, 0, 1, 1},
  {&__pyx_n_s_get_str_from_rgb255, __pyx_k_get_str_from_rgb255, sizeof(__pyx_k_get_str_from_rgb255), 0, 0, 1, 1},
  {&__pyx_n_s_get_subchain, __pyx_k_get_subchain, sizeof(__pyx_k_get_subchain), 0, 0, 1, 1},
  {&__pyx_n_s_get_unstranded, __pyx_k_get_unstranded, sizeof(__pyx_k_get_unstranded), 0, 0, 1, 1},
  {&__pyx_n_s_get_utr3, __pyx_k_get_utr3, sizeof(__pyx_k_get_utr3), 0, 0, 1, 1},
  {&__pyx_n_s_get_utr5, __pyx_k_get_utr5, sizeof(__pyx_k_get_utr5), 0, 0, 1, 1},
  {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1},
  {&__pyx_kp_s_got_differing_extents_in_dimensi, __pyx_k_got_differing_extents_in_dimensi, sizeof(__pyx_k_got_differing_extents_in_dimensi), 0, 0, 1, 0},
  {&__pyx_n_s_groups, __pyx_k_groups, sizeof(__pyx_k_groups), 0, 0, 1, 1},
  {&__pyx_n_u_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 1, 0, 1},
  {&__pyx_n_s_id, __pyx_k_id, sizeof(__pyx_k_id), 0, 0, 1, 1},
  {&__pyx_n_s_igvpat, __pyx_k_igvpat, sizeof(__pyx_k_igvpat), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_inp, __pyx_k_inp, sizeof(__pyx_k_inp), 0, 0, 1, 1},
  {&__pyx_n_s_int, __pyx_k_int, sizeof(__pyx_k_int), 0, 0, 1, 1},
  {&__pyx_n_s_intc, __pyx_k_intc, sizeof(__pyx_k_intc), 0, 0, 1, 1},
  {&__pyx_kp_u_is_not_in_chain, __pyx_k_is_not_in_chain, sizeof(__pyx_k_is_not_in_chain), 0, 1, 0, 0},
  {&__pyx_kp_u_is_outside_bounds_0, __pyx_k_is_outside_bounds_0, sizeof(__pyx_k_is_outside_bounds_0), 0, 1, 0, 0},
  {&__pyx_n_s_isnan, __pyx_k_isnan, sizeof(__pyx_k_isnan), 0, 0, 1, 1},
  {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1},
  {&__pyx_n_s_itemsize, __pyx_k_itemsize, sizeof(__pyx_k_itemsize), 0, 0, 1, 1},
  {&__pyx_kp_s_itemsize_0_for_cython_array, __pyx_k_itemsize_0_for_cython_array, sizeof(__pyx_k_itemsize_0_for_cython_array), 0, 0, 1, 0},
  {&__pyx_n_s_iv, __pyx_k_iv, sizeof(__pyx_k_iv), 0, 0, 1, 1},
  {&__pyx_n_s_iv_ltmp, __pyx_k_iv_ltmp, sizeof(__pyx_k_iv_ltmp), 0, 0, 1, 1},
  {&__pyx_n_s_ivcpat, __pyx_k_ivcpat, sizeof(__pyx_k_ivcpat), 0, 0, 1, 1},
  {&__pyx_n_s_k, __pyx_k_k, sizeof(__pyx_k_k), 0, 0, 1, 1},
  {&__pyx_n_u_l, __pyx_k_l, sizeof(__pyx_k_l), 0, 1, 0, 1},
  {&__pyx_kp_u_length, __pyx_k_length, sizeof(__pyx_k_length), 0, 1, 0, 0},
  {&__pyx_n_s_line, __pyx_k_line, sizeof(__pyx_k_line), 0, 0, 1, 1},
  {&__pyx_n_s_loc_str, __pyx_k_loc_str, sizeof(__pyx_k_loc_str), 0, 0, 1, 1},
  {&__pyx_n_s_long, __pyx_k_long, sizeof(__pyx_k_long), 0, 0, 1, 1},
  {&__pyx_n_s_ltmp, __pyx_k_ltmp, sizeof(__pyx_k_ltmp), 0, 0, 1, 1},
  {&__pyx_n_u_mRNA, __pyx_k_mRNA, sizeof(__pyx_k_mRNA), 0, 1, 0, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_make_GFF3_tokens, __pyx_k_make_GFF3_tokens, sizeof(__pyx_k_make_GFF3_tokens), 0, 0, 1, 1},
  {&__pyx_n_s_make_GTF2_tokens, __pyx_k_make_GTF2_tokens, sizeof(__pyx_k_make_GTF2_tokens), 0, 0, 1, 1},
  {&__pyx_n_s_mask, __pyx_k_mask, sizeof(__pyx_k_mask), 0, 0, 1, 1},
  {&__pyx_n_u_match_length, __pyx_k_match_length, sizeof(__pyx_k_match_length), 0, 1, 0, 1},
  {&__pyx_n_s_memview, __pyx_k_memview, sizeof(__pyx_k_memview), 0, 0, 1, 1},
  {&__pyx_n_s_middle, __pyx_k_middle, sizeof(__pyx_k_middle), 0, 0, 1, 1},
  {&__pyx_n_u_mismatches, __pyx_k_mismatches, sizeof(__pyx_k_mismatches), 0, 1, 0, 1},
  {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1},
  {&__pyx_kp_u_must_be_0, __pyx_k_must_be_0, sizeof(__pyx_k_must_be_0), 0, 1, 0, 0},
  {&__pyx_kp_u_must_be_cds_end, __pyx_k_must_be_cds_end, sizeof(__pyx_k_must_be_cds_end), 0, 1, 0, 0},
  {&__pyx_kp_u_must_be_cds_genome_end, __pyx_k_must_be_cds_genome_end, sizeof(__pyx_k_must_be_cds_genome_end), 0, 1, 0, 0},
  {&__pyx_kp_u_must_be_cds_genome_start, __pyx_k_must_be_cds_genome_start, sizeof(__pyx_k_must_be_cds_genome_start), 0, 1, 0, 0},
  {&__pyx_kp_u_must_be_cds_start, __pyx_k_must_be_cds_start, sizeof(__pyx_k_must_be_cds_start), 0, 1, 0, 0},
  {&__pyx_kp_u_must_be_end, __pyx_k_must_be_end, sizeof(__pyx_k_must_be_end), 0, 1, 0, 0},
  {&__pyx_kp_u_must_be_self_length, __pyx_k_must_be_self_length, sizeof(__pyx_k_must_be_self_length), 0, 1, 0, 0},
  {&__pyx_n_u_na, __pyx_k_na, sizeof(__pyx_k_na), 0, 1, 0, 1},
  {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1},
  {&__pyx_n_u_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 1, 0, 1},
  {&__pyx_kp_u_name_s, __pyx_k_name_s, sizeof(__pyx_k_name_s), 0, 1, 0, 0},
  {&__pyx_n_s_nan, __pyx_k_nan, sizeof(__pyx_k_nan), 0, 0, 1, 1},
  {&__pyx_n_u_nan, __pyx_k_nan, sizeof(__pyx_k_nan), 0, 1, 0, 1},
  {&__pyx_n_s_ndim, __pyx_k_ndim, sizeof(__pyx_k_ndim), 0, 0, 1, 1},
  {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1},
  {&__pyx_n_s_next, __pyx_k_next, sizeof(__pyx_k_next), 0, 0, 1, 1},
  {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0},
  {&__pyx_n_u_none, __pyx_k_none, sizeof(__pyx_k_none), 0, 1, 0, 1},
  {&__pyx_kp_u_not_in_SegmentChain, __pyx_k_not_in_SegmentChain, sizeof(__pyx_k_not_in_SegmentChain), 0, 1, 0, 0},
  {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1},
  {&__pyx_kp_u_numpy_core_multiarray_failed_to, __pyx_k_numpy_core_multiarray_failed_to, sizeof(__pyx_k_numpy_core_multiarray_failed_to), 0, 1, 0, 0},
  {&__pyx_kp_u_numpy_core_umath_failed_to_impor, __pyx_k_numpy_core_umath_failed_to_impor, sizeof(__pyx_k_numpy_core_umath_failed_to_impor), 0, 1, 0, 0},
  {&__pyx_n_s_numpy_ma, __pyx_k_numpy_ma, sizeof(__pyx_k_numpy_ma), 0, 0, 1, 1},
  {&__pyx_n_s_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 0, 0, 1, 1},
  {&__pyx_kp_u_of_SegmentChain, __pyx_k_of_SegmentChain, sizeof(__pyx_k_of_SegmentChain), 0, 1, 0, 0},
  {&__pyx_kp_u_of_types, __pyx_k_of_types, sizeof(__pyx_k_of_types), 0, 1, 0, 0},
  {&__pyx_n_s_other, __pyx_k_other, sizeof(__pyx_k_other), 0, 0, 1, 1},
  {&__pyx_n_u_other, __pyx_k_other, sizeof(__pyx_k_other), 0, 1, 0, 1},
  {&__pyx_n_s_overlaps, __pyx_k_overlaps, sizeof(__pyx_k_overlaps), 0, 0, 1, 1},
  {&__pyx_n_s_pack, __pyx_k_pack, sizeof(__pyx_k_pack), 0, 0, 1, 1},
  {&__pyx_n_u_phase, __pyx_k_phase, sizeof(__pyx_k_phase), 0, 1, 0, 1},
  {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1},
  {&__pyx_n_s_piece, __pyx_k_piece, sizeof(__pyx_k_piece), 0, 0, 1, 1},
  {&__pyx_n_s_plastid_genomics_roitools, __pyx_k_plastid_genomics_roitools, sizeof(__pyx_k_plastid_genomics_roitools), 0, 0, 1, 1},
  {&__pyx_kp_s_plastid_genomics_roitools_pyx, __pyx_k_plastid_genomics_roitools_pyx, sizeof(__pyx_k_plastid_genomics_roitools_pyx), 0, 0, 1, 0},
  {&__pyx_n_s_plastid_plotting_colors, __pyx_k_plastid_plotting_colors, sizeof(__pyx_k_plastid_plotting_colors), 0, 0, 1, 1},
  {&__pyx_n_s_plastid_readers_gff_tokens, __pyx_k_plastid_readers_gff_tokens, sizeof(__pyx_k_plastid_readers_gff_tokens), 0, 0, 1, 1},
  {&__pyx_n_s_plastid_util_services_exceptions, __pyx_k_plastid_util_services_exceptions, sizeof(__pyx_k_plastid_util_services_exceptions), 0, 0, 1, 1},
  {&__pyx_n_s_pop, __pyx_k_pop, sizeof(__pyx_k_pop), 0, 0, 1, 1},
  {&__pyx_n_s_positions, __pyx_k_positions, sizeof(__pyx_k_positions), 0, 0, 1, 1},
  {&__pyx_n_s_psl_line, __pyx_k_psl_line, sizeof(__pyx_k_psl_line), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_capi, __pyx_k_pyx_capi, sizeof(__pyx_k_pyx_capi), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_getbuffer, __pyx_k_pyx_getbuffer, sizeof(__pyx_k_pyx_getbuffer), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_unpickle_Enum, __pyx_k_pyx_unpickle_Enum, sizeof(__pyx_k_pyx_unpickle_Enum), 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_q_starts, __pyx_k_q_starts, sizeof(__pyx_k_q_starts), 0, 0, 1, 1},
  {&__pyx_n_u_q_starts, __pyx_k_q_starts, sizeof(__pyx_k_q_starts), 0, 1, 0, 1},
  {&__pyx_n_u_query_end, __pyx_k_query_end, sizeof(__pyx_k_query_end), 0, 1, 0, 1},
  {&__pyx_n_u_query_gap_bases, __pyx_k_query_gap_bases, sizeof(__pyx_k_query_gap_bases), 0, 1, 0, 1},
  {&__pyx_n_u_query_gap_count, __pyx_k_query_gap_count, sizeof(__pyx_k_query_gap_count), 0, 1, 0, 1},
  {&__pyx_n_u_query_length, __pyx_k_query_length, sizeof(__pyx_k_query_length), 0, 1, 0, 1},
  {&__pyx_n_u_query_name, __pyx_k_query_name, sizeof(__pyx_k_query_name), 0, 1, 0, 1},
  {&__pyx_n_u_query_start, __pyx_k_query_start, sizeof(__pyx_k_query_start), 0, 1, 0, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1},
  {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1},
  {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1},
  {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1},
  {&__pyx_n_u_rep_matches, __pyx_k_rep_matches, sizeof(__pyx_k_rep_matches), 0, 1, 0, 1},
  {&__pyx_n_s_reverse_complement, __pyx_k_reverse_complement, sizeof(__pyx_k_reverse_complement), 0, 0, 1, 1},
  {&__pyx_n_s_rna_type, __pyx_k_rna_type, sizeof(__pyx_k_rna_type), 0, 0, 1, 1},
  {&__pyx_n_s_roi_order, __pyx_k_roi_order, sizeof(__pyx_k_roi_order), 0, 0, 1, 1},
  {&__pyx_n_s_round, __pyx_k_round, sizeof(__pyx_k_round), 0, 0, 1, 1},
  {&__pyx_kp_u_s_3UTR, __pyx_k_s_3UTR, sizeof(__pyx_k_s_3UTR), 0, 1, 0, 0},
  {&__pyx_kp_u_s_5UTR, __pyx_k_s_5UTR, sizeof(__pyx_k_s_5UTR), 0, 1, 0, 0},
  {&__pyx_kp_u_s_CDS, __pyx_k_s_CDS, sizeof(__pyx_k_s_CDS), 0, 1, 0, 0},
  {&__pyx_n_s_s_end, __pyx_k_s_end, sizeof(__pyx_k_s_end), 0, 0, 1, 1},
  {&__pyx_kp_u_s_is_a_zero_length_SegmentChain, __pyx_k_s_is_a_zero_length_SegmentChain, sizeof(__pyx_k_s_is_a_zero_length_SegmentChain), 0, 1, 0, 0},
  {&__pyx_kp_u_s_is_a_zero_length_SegmentChain_2, __pyx_k_s_is_a_zero_length_SegmentChain_2, sizeof(__pyx_k_s_is_a_zero_length_SegmentChain_2), 0, 1, 0, 0},
  {&__pyx_kp_u_s_s_s, __pyx_k_s_s_s, sizeof(__pyx_k_s_s_s), 0, 1, 0, 0},
  {&__pyx_n_s_s_start, __pyx_k_s_start, sizeof(__pyx_k_s_start), 0, 0, 1, 1},
  {&__pyx_kp_u_s_subchain, __pyx_k_s_subchain, sizeof(__pyx_k_s_subchain), 0, 1, 0, 0},
  {&__pyx_n_s_sb, __pyx_k_sb, sizeof(__pyx_k_sb), 0, 0, 1, 1},
  {&__pyx_n_u_score, __pyx_k_score, sizeof(__pyx_k_score), 0, 1, 0, 1},
  {&__pyx_n_s_search, __pyx_k_search, sizeof(__pyx_k_search), 0, 0, 1, 1},
  {&__pyx_n_s_seg, __pyx_k_seg, sizeof(__pyx_k_seg), 0, 0, 1, 1},
  {&__pyx_n_s_segchain, __pyx_k_segchain, sizeof(__pyx_k_segchain), 0, 0, 1, 1},
  {&__pyx_n_s_segment, __pyx_k_segment, sizeof(__pyx_k_segment), 0, 0, 1, 1},
  {&__pyx_kp_u_segments, __pyx_k_segments, sizeof(__pyx_k_segments), 0, 1, 0, 0},
  {&__pyx_n_s_segments_2, __pyx_k_segments_2, sizeof(__pyx_k_segments_2), 0, 0, 1, 1},
  {&__pyx_n_s_segpat, __pyx_k_segpat, sizeof(__pyx_k_segpat), 0, 0, 1, 1},
  {&__pyx_n_s_segs, __pyx_k_segs, sizeof(__pyx_k_segs), 0, 0, 1, 1},
  {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1},
  {&__pyx_n_s_seq, __pyx_k_seq, sizeof(__pyx_k_seq), 0, 0, 1, 1},
  {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1},
  {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1},
  {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1},
  {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1},
  {&__pyx_n_u_source, __pyx_k_source, sizeof(__pyx_k_source), 0, 1, 0, 1},
  {&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1},
  {&__pyx_n_s_sq, __pyx_k_sq, sizeof(__pyx_k_sq), 0, 0, 1, 1},
  {&__pyx_n_s_sq_starts, __pyx_k_sq_starts, sizeof(__pyx_k_sq_starts), 0, 0, 1, 1},
  {&__pyx_n_s_sstart, __pyx_k_sstart, sizeof(__pyx_k_sstart), 0, 0, 1, 1},
  {&__pyx_n_s_st, __pyx_k_st, sizeof(__pyx_k_st), 0, 0, 1, 1},
  {&__pyx_n_s_st_starts, __pyx_k_st_starts, sizeof(__pyx_k_st_starts), 0, 0, 1, 1},
  {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
  {&__pyx_n_u_start_codon, __pyx_k_start_codon, sizeof(__pyx_k_start_codon), 0, 1, 0, 1},
  {&__pyx_kp_u_start_coordinate_supplied_is_Non, __pyx_k_start_coordinate_supplied_is_Non, sizeof(__pyx_k_start_coordinate_supplied_is_Non), 0, 1, 0, 0},
  {&__pyx_n_s_staticmethod, __pyx_k_staticmethod, sizeof(__pyx_k_staticmethod), 0, 0, 1, 1},
  {&__pyx_n_s_step, __pyx_k_step, sizeof(__pyx_k_step), 0, 0, 1, 1},
  {&__pyx_n_s_stmp, __pyx_k_stmp, sizeof(__pyx_k_stmp), 0, 0, 1, 1},
  {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1},
  {&__pyx_n_u_stop_codon, __pyx_k_stop_codon, sizeof(__pyx_k_stop_codon), 0, 1, 0, 1},
  {&__pyx_n_s_strand, __pyx_k_strand, sizeof(__pyx_k_strand), 0, 0, 1, 1},
  {&__pyx_n_u_strand, __pyx_k_strand, sizeof(__pyx_k_strand), 0, 1, 0, 1},
  {&__pyx_kp_u_strand_2, __pyx_k_strand_2, sizeof(__pyx_k_strand_2), 0, 1, 0, 0},
  {&__pyx_n_s_stranded, __pyx_k_stranded, sizeof(__pyx_k_stranded), 0, 0, 1, 1},
  {&__pyx_kp_s_strided_and_direct, __pyx_k_strided_and_direct, sizeof(__pyx_k_strided_and_direct), 0, 0, 1, 0},
  {&__pyx_kp_s_strided_and_direct_or_indirect, __pyx_k_strided_and_direct_or_indirect, sizeof(__pyx_k_strided_and_direct_or_indirect), 0, 0, 1, 0},
  {&__pyx_kp_s_strided_and_indirect, __pyx_k_strided_and_indirect, sizeof(__pyx_k_strided_and_indirect), 0, 0, 1, 0},
  {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0},
  {&__pyx_n_s_strip, __pyx_k_strip, sizeof(__pyx_k_strip), 0, 0, 1, 1},
  {&__pyx_n_s_struct, __pyx_k_struct, sizeof(__pyx_k_struct), 0, 0, 1, 1},
  {&__pyx_n_s_sum, __pyx_k_sum, sizeof(__pyx_k_sum), 0, 0, 1, 1},
  {&__pyx_n_s_t_start, __pyx_k_t_start, sizeof(__pyx_k_t_start), 0, 0, 1, 1},
  {&__pyx_n_s_t_starts, __pyx_k_t_starts, sizeof(__pyx_k_t_starts), 0, 0, 1, 1},
  {&__pyx_n_u_t_starts, __pyx_k_t_starts, sizeof(__pyx_k_t_starts), 0, 1, 0, 1},
  {&__pyx_n_u_target_end, __pyx_k_target_end, sizeof(__pyx_k_target_end), 0, 1, 0, 1},
  {&__pyx_n_u_target_gap_bases, __pyx_k_target_gap_bases, sizeof(__pyx_k_target_gap_bases), 0, 1, 0, 1},
  {&__pyx_n_u_target_gap_count, __pyx_k_target_gap_count, sizeof(__pyx_k_target_gap_count), 0, 1, 0, 1},
  {&__pyx_n_u_target_length, __pyx_k_target_length, sizeof(__pyx_k_target_length), 0, 1, 0, 1},
  {&__pyx_n_u_target_name, __pyx_k_target_name, sizeof(__pyx_k_target_name), 0, 1, 0, 1},
  {&__pyx_n_u_target_start, __pyx_k_target_start, sizeof(__pyx_k_target_start), 0, 1, 0, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_thickend, __pyx_k_thickend, sizeof(__pyx_k_thickend), 0, 0, 1, 1},
  {&__pyx_n_u_thickend, __pyx_k_thickend, sizeof(__pyx_k_thickend), 0, 1, 0, 1},
  {&__pyx_n_s_thickstart, __pyx_k_thickstart, sizeof(__pyx_k_thickstart), 0, 0, 1, 1},
  {&__pyx_n_u_thickstart, __pyx_k_thickstart, sizeof(__pyx_k_thickstart), 0, 1, 0, 1},
  {&__pyx_n_u_three_prime_UTR, __pyx_k_three_prime_UTR, sizeof(__pyx_k_three_prime_UTR), 0, 1, 0, 1},
  {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1},
  {&__pyx_n_s_tolist, __pyx_k_tolist, sizeof(__pyx_k_tolist), 0, 0, 1, 1},
  {&__pyx_n_s_transcript, __pyx_k_transcript, sizeof(__pyx_k_transcript), 0, 0, 1, 1},
  {&__pyx_n_u_transcript_id, __pyx_k_transcript_id, sizeof(__pyx_k_transcript_id), 0, 1, 0, 1},
  {&__pyx_n_s_tx, __pyx_k_tx, sizeof(__pyx_k_tx), 0, 0, 1, 1},
  {&__pyx_n_s_type, __pyx_k_type, sizeof(__pyx_k_type), 0, 0, 1, 1},
  {&__pyx_n_u_type, __pyx_k_type, sizeof(__pyx_k_type), 0, 1, 0, 1},
  {&__pyx_kp_s_unable_to_allocate_array_data, __pyx_k_unable_to_allocate_array_data, sizeof(__pyx_k_unable_to_allocate_array_data), 0, 0, 1, 0},
  {&__pyx_kp_s_unable_to_allocate_shape_and_str, __pyx_k_unable_to_allocate_shape_and_str, sizeof(__pyx_k_unable_to_allocate_shape_and_str), 0, 0, 1, 0},
  {&__pyx_n_s_unpack, __pyx_k_unpack, sizeof(__pyx_k_unpack), 0, 0, 1, 1},
  {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1},
  {&__pyx_n_s_v, __pyx_k_v, sizeof(__pyx_k_v), 0, 0, 1, 1},
  {&__pyx_kp_u_value_of, __pyx_k_value_of, sizeof(__pyx_k_value_of), 0, 1, 0, 0},
  {&__pyx_n_s_values, __pyx_k_values, sizeof(__pyx_k_values), 0, 0, 1, 1},
  {&__pyx_n_s_warn, __pyx_k_warn, sizeof(__pyx_k_warn), 0, 0, 1, 1},
  {&__pyx_kp_u_with, __pyx_k_with, sizeof(__pyx_k_with), 0, 1, 0, 0},
  {&__pyx_kp_u_wrong_and_or_multiple_chromosom, __pyx_k_wrong_and_or_multiple_chromosom, sizeof(__pyx_k_wrong_and_or_multiple_chromosom), 0, 1, 0, 0},
  {&__pyx_kp_u_wrong_and_or_multiple_strands, __pyx_k_wrong_and_or_multiple_strands, sizeof(__pyx_k_wrong_and_or_multiple_strands), 0, 1, 0, 0},
  {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1},
  {&__pyx_n_s_zeros_like, __pyx_k_zeros_like, sizeof(__pyx_k_zeros_like), 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 CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_staticmethod = __Pyx_GetBuiltinName(__pyx_n_s_staticmethod); if (!__pyx_builtin_staticmethod) __PYX_ERR(0, 1046, __pyx_L1_error)
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 442, __pyx_L1_error)
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 487, __pyx_L1_error)
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 547, __pyx_L1_error)
  __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(0, 587, __pyx_L1_error)
  __pyx_builtin_all = __Pyx_GetBuiltinName(__pyx_n_s_all); if (!__pyx_builtin_all) __PYX_ERR(0, 685, __pyx_L1_error)
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 696, __pyx_L1_error)
  __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 1131, __pyx_L1_error)
  __pyx_builtin_sum = __Pyx_GetBuiltinName(__pyx_n_s_sum); if (!__pyx_builtin_sum) __PYX_ERR(0, 1430, __pyx_L1_error)
  __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(0, 1685, __pyx_L1_error)
  __pyx_builtin_UserWarning = __Pyx_GetBuiltinName(__pyx_n_s_UserWarning); if (!__pyx_builtin_UserWarning) __PYX_ERR(0, 2209, __pyx_L1_error)
  __pyx_builtin_round = __Pyx_GetBuiltinName(__pyx_n_s_round); if (!__pyx_builtin_round) __PYX_ERR(0, 2758, __pyx_L1_error)
  __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 2894, __pyx_L1_error)
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 3535, __pyx_L1_error)
  __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(2, 109, __pyx_L1_error)
  __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(3, 945, __pyx_L1_error)
  __pyx_builtin_Ellipsis = __Pyx_GetBuiltinName(__pyx_n_s_Ellipsis); if (!__pyx_builtin_Ellipsis) __PYX_ERR(4, 404, __pyx_L1_error)
  __pyx_builtin_id = __Pyx_GetBuiltinName(__pyx_n_s_id); if (!__pyx_builtin_id) __PYX_ERR(4, 613, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

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

  /* "plastid/genomics/roitools.pyx":576
 *     attr = { KEY : DEFAULT for KEY, DEFAULT,_ in _default_bed_columns.values() }
 * 
 *     for i in (3, 4, 6, 7, 8, 9, 10, 11):             # <<<<<<<<<<<<<<
 *         # populate attr with real values from BED columns that are present
 *         if i >= num_bed_columns:
 */
  __pyx_tuple__16 = PyTuple_Pack(8, __pyx_int_3, __pyx_int_4, __pyx_int_6, __pyx_int_7, __pyx_int_8, __pyx_int_9, __pyx_int_10, __pyx_int_11); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);

  /* "plastid/genomics/roitools.pyx":679
 * 
 *             if len(types) > 1:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "get_attr_from_bed: List of `extra_columns` contains mixed types. All items need to be the same type, either str or tuple."
 *                 )
 */
  __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_u_get_attr_from_bed_List_of_extra); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);

  /* "plastid/genomics/roitools.pyx":686
 *             elif types == { tuple }:
 *                 if all([len(X) == 2 for X in extra_columns]) == False:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "get_attr_from_bed: Cannot make SegmentChain from BED input: if a list, extra_columns must be a list of tuples of (column_name,formatter_func)"
 *                     )
 */
  __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_u_get_attr_from_bed_Cannot_make_Se); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 686, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "plastid/genomics/roitools.pyx":733
 * 
 *     # clean up attr
 *     for key in ("blocks", "blocksizes", "blockstarts", "chrom_start", "strand", "chrom"):             # <<<<<<<<<<<<<<
 *         attr.pop(key)
 * 
 */
  __pyx_tuple__22 = PyTuple_Pack(6, __pyx_n_u_blocks, __pyx_n_u_blocksizes, __pyx_n_u_blockstarts, __pyx_n_u_chrom_start, __pyx_n_u_strand, __pyx_n_u_chrom); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 733, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "plastid/genomics/roitools.pyx":865
 *                     else false
 *     else:
 *         raise ValueError("This operation is not defined for SegmentChains.")             # <<<<<<<<<<<<<<
 * 
 * cdef ExBool transcript_richcmp(Transcript chain1, Transcript chain2, int cmpval) except bool_exception:
 */
  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_u_This_operation_is_not_defined_fo); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 865, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "plastid/genomics/roitools.pyx":933
 *                     else false
 *     else:
 *         raise ValueError("This operation is not defined for Transcripts.")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_u_This_operation_is_not_defined_fo_2); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 933, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "plastid/genomics/roitools.pyx":1131
 *             return other._cmp_helper(self, LT) or self._cmp_helper(other, EQ)
 *         else:
 *             raise AttributeError("Comparison operation not defined")             # <<<<<<<<<<<<<<
 * 
 *     def __contains__(self, other):
 */
  __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_u_Comparison_operation_not_defined); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 1131, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__27);
  __Pyx_GIVEREF(__pyx_tuple__27);

  /* "plastid/genomics/roitools.pyx":1582
 *             return chain_richcmp(self, SegmentChain(other), cmpval) == true
 *         else:
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChain eq/ineq/et c is only defined for other SegmentChains or GenomicSegments."
 *             )
 */
  __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_u_SegmentChain_eq_ineq_et_c_is_onl); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 1582, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);

  /* "plastid/genomics/roitools.pyx":1688
 *             return retval == true
 *         else:
 *             raise TypeError("The 'in'/containment operator is only defined for GenomicSegments and SegmentChains")             # <<<<<<<<<<<<<<
 * 
 *     cdef ExBool c_contains(self, SegmentChain other) except bool_exception:
 */
  __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_u_The_in_containment_operator_is_o); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 1688, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);

  /* "plastid/genomics/roitools.pyx":2895
 *             return "\t".join(str(X) for X in ltmp) + "\n"
 *         except KeyError:
 *             raise AttributeError(             # <<<<<<<<<<<<<<
 *                 "SegmentChains only support PSL output if all PSL attributes are defined in self.attr: match_length, mismatches, rep_matches, N, query_gap_count, query_gap_bases, strand, query_length, query_start, query_end, target_name, target_length, target_start, target_end"
 *             )
 */
  __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_u_SegmentChains_only_support_PSL_o); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 2895, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);

  /* "plastid/genomics/roitools.pyx":3206
 * 
 *         if start is None:
 *             raise TypeError('start coordinate supplied is None. Expected int')             # <<<<<<<<<<<<<<
 *         elif end is None:
 *             raise TypeError('end coordinate supplied is None. Expected int')
 */
  __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_u_start_coordinate_supplied_is_Non); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 3206, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);

  /* "plastid/genomics/roitools.pyx":3208
 *             raise TypeError('start coordinate supplied is None. Expected int')
 *         elif end is None:
 *             raise TypeError('end coordinate supplied is None. Expected int')             # <<<<<<<<<<<<<<
 * 
 *         if stranded == True and self.c_strand == reverse_strand:
 */
  __pyx_tuple__37 = PyTuple_Pack(1, __pyx_kp_u_end_coordinate_supplied_is_None); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 3208, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);

  /* "plastid/genomics/roitools.pyx":3271
 * 
 *         if self.c_strand == reverse_strand and stranded is True:
 *             count_array = count_array[..., ::-1]             # <<<<<<<<<<<<<<
 * 
 *         return count_array
 */
  __pyx_slice__38 = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_slice__38)) __PYX_ERR(0, 3271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__38);
  __Pyx_GIVEREF(__pyx_slice__38);
  __pyx_tuple__39 = PyTuple_Pack(2, Py_Ellipsis, __pyx_slice__38); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 3271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);

  /* "plastid/genomics/roitools.pyx":3313
 * 
 *             mask = numpy.empty_like(counts)
 *             mask[..., :] = m             # <<<<<<<<<<<<<<
 * 
 *         return MaskedArray(counts, mask=mask.astype(bool), copy=copy)
 */
  __pyx_slice__40 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__40)) __PYX_ERR(0, 3313, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__40);
  __Pyx_GIVEREF(__pyx_slice__40);
  __pyx_tuple__41 = PyTuple_Pack(2, Py_Ellipsis, __pyx_slice__40); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 3313, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);

  /* "plastid/genomics/roitools.pyx":4229
 *             stmp += cds_chain.as_gtf(feature_type="CDS", escape=escape, excludes=excludes)
 * 
 *             start_codon_chain = cds_chain_temp.get_subchain(0, 3)             # <<<<<<<<<<<<<<
 *             start_codon_chain.attr.update(child_chain_attr)
 *             stmp += start_codon_chain.as_gtf(
 */
  __pyx_tuple__43 = PyTuple_Pack(2, __pyx_int_0, __pyx_int_3); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 4229, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__43);
  __Pyx_GIVEREF(__pyx_tuple__43);

  /* "plastid/genomics/roitools.pyx":4343
 *         excludes = [] if excludes is None else excludes
 * 
 *         keys_to_pop = ("ID",)             # <<<<<<<<<<<<<<
 *         for k in keys_to_pop:
 *             if k in child_attr:
 */
  __pyx_tuple__44 = PyTuple_Pack(1, __pyx_n_u_ID_2); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 4343, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":945
 *         __pyx_import_array()
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_umath() except -1:
 */
  __pyx_tuple__45 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(3, 945, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__45);
  __Pyx_GIVEREF(__pyx_tuple__45);

  /* "../_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/lib/python3.7/site-packages/numpy/__init__.pxd":951
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_ufunc() except -1:
 */
  __pyx_tuple__46 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(3, 951, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__46);
  __Pyx_GIVEREF(__pyx_tuple__46);

  /* "View.MemoryView":133
 * 
 *         if not self.ndim:
 *             raise ValueError("Empty shape tuple for cython.array")             # <<<<<<<<<<<<<<
 * 
 *         if itemsize <= 0:
 */
  __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_s_Empty_shape_tuple_for_cython_arr); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(4, 133, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__47);
  __Pyx_GIVEREF(__pyx_tuple__47);

  /* "View.MemoryView":136
 * 
 *         if itemsize <= 0:
 *             raise ValueError("itemsize <= 0 for cython.array")             # <<<<<<<<<<<<<<
 * 
 *         if not isinstance(format, bytes):
 */
  __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_s_itemsize_0_for_cython_array); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(4, 136, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);

  /* "View.MemoryView":148
 * 
 *         if not self._shape:
 *             raise MemoryError("unable to allocate shape and strides.")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__49 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_shape_and_str); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(4, 148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__49);
  __Pyx_GIVEREF(__pyx_tuple__49);

  /* "View.MemoryView":176
 *             self.data = <char *>malloc(self.len)
 *             if not self.data:
 *                 raise MemoryError("unable to allocate array data.")             # <<<<<<<<<<<<<<
 * 
 *             if self.dtype_is_object:
 */
  __pyx_tuple__50 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_array_data); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(4, 176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__50);
  __Pyx_GIVEREF(__pyx_tuple__50);

  /* "View.MemoryView":192
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         if not (flags & bufmode):
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")             # <<<<<<<<<<<<<<
 *         info.buf = self.data
 *         info.len = self.len
 */
  __pyx_tuple__51 = PyTuple_Pack(1, __pyx_kp_s_Can_only_create_a_buffer_that_is); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(4, 192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__52 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(4, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__52);
  __Pyx_GIVEREF(__pyx_tuple__52);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__53 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(4, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);

  /* "View.MemoryView":418
 *     def __setitem__(memoryview self, object index, object value):
 *         if self.view.readonly:
 *             raise TypeError("Cannot assign to read-only memoryview")             # <<<<<<<<<<<<<<
 * 
 *         have_slices, index = _unellipsify(index, self.view.ndim)
 */
  __pyx_tuple__54 = PyTuple_Pack(1, __pyx_kp_s_Cannot_assign_to_read_only_memor); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(4, 418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__54);
  __Pyx_GIVEREF(__pyx_tuple__54);

  /* "View.MemoryView":495
 *             result = struct.unpack(self.view.format, bytesitem)
 *         except struct.error:
 *             raise ValueError("Unable to convert item to object")             # <<<<<<<<<<<<<<
 *         else:
 *             if len(self.view.format) == 1:
 */
  __pyx_tuple__55 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_convert_item_to_object); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(4, 495, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);

  /* "View.MemoryView":520
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         if flags & PyBUF_WRITABLE and self.view.readonly:
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_ND:
 */
  __pyx_tuple__56 = PyTuple_Pack(1, __pyx_kp_s_Cannot_create_writable_memory_vi); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(4, 520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__56);
  __Pyx_GIVEREF(__pyx_tuple__56);

  /* "View.MemoryView":570
 *         if self.view.strides == NULL:
 * 
 *             raise ValueError("Buffer view does not expose strides")             # <<<<<<<<<<<<<<
 * 
 *         return tuple([stride for stride in self.view.strides[:self.view.ndim]])
 */
  __pyx_tuple__57 = PyTuple_Pack(1, __pyx_kp_s_Buffer_view_does_not_expose_stri); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(4, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__57);
  __Pyx_GIVEREF(__pyx_tuple__57);

  /* "View.MemoryView":577
 *     def suboffsets(self):
 *         if self.view.suboffsets == NULL:
 *             return (-1,) * self.view.ndim             # <<<<<<<<<<<<<<
 * 
 *         return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]])
 */
  __pyx_tuple__58 = PyTuple_New(1); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(4, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__58);
  __Pyx_INCREF(__pyx_int_neg_1);
  __Pyx_GIVEREF(__pyx_int_neg_1);
  PyTuple_SET_ITEM(__pyx_tuple__58, 0, __pyx_int_neg_1);
  __Pyx_GIVEREF(__pyx_tuple__58);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__59 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(4, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__60 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(4, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__60);
  __Pyx_GIVEREF(__pyx_tuple__60);

  /* "View.MemoryView":703
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:
 *             raise ValueError("Indirect dimensions not supported")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__61 = PyTuple_Pack(1, __pyx_kp_s_Indirect_dimensions_not_supporte); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(4, 703, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__61);
  __Pyx_GIVEREF(__pyx_tuple__61);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__62 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(4, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__62);
  __Pyx_GIVEREF(__pyx_tuple__62);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__63 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(4, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__63);
  __Pyx_GIVEREF(__pyx_tuple__63);

  /* "plastid/genomics/roitools.pyx":164
 * 
 * # to/from str
 * igvpat = re.compile(r"([^:]*):([0-9]+)-([0-9]+)")             # <<<<<<<<<<<<<<
 * segpat = re.compile(r"([^:]*):([0-9]+)-([0-9]+)\(([+-.])\)")
 * ivcpat = re.compile(r"([^:]*):([^(]+)\(([+-.])\)")
 */
  __pyx_tuple__64 = PyTuple_Pack(1, __pyx_kp_u_0_9_0_9); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__64);
  __Pyx_GIVEREF(__pyx_tuple__64);

  /* "plastid/genomics/roitools.pyx":165
 * # to/from str
 * igvpat = re.compile(r"([^:]*):([0-9]+)-([0-9]+)")
 * segpat = re.compile(r"([^:]*):([0-9]+)-([0-9]+)\(([+-.])\)")             # <<<<<<<<<<<<<<
 * ivcpat = re.compile(r"([^:]*):([^(]+)\(([+-.])\)")
 * 
 */
  __pyx_tuple__65 = PyTuple_Pack(1, __pyx_kp_u_0_9_0_9_2); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__65);
  __Pyx_GIVEREF(__pyx_tuple__65);

  /* "plastid/genomics/roitools.pyx":166
 * igvpat = re.compile(r"([^:]*):([0-9]+)-([0-9]+)")
 * segpat = re.compile(r"([^:]*):([0-9]+)-([0-9]+)\(([+-.])\)")
 * ivcpat = re.compile(r"([^:]*):([^(]+)\(([+-.])\)")             # <<<<<<<<<<<<<<
 * 
 * # compile time constants - __richcmp__ test
 */
  __pyx_tuple__67 = PyTuple_Pack(1, __pyx_kp_u__66); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__67);
  __Pyx_GIVEREF(__pyx_tuple__67);

  /* "plastid/genomics/roitools.pyx":194
 * #==============================================================================
 * 
 * NullSegment = GenomicSegment("NullChromosome", 0, 0, "\x00")             # <<<<<<<<<<<<<<
 * """Placeholder |GenomicSegment| for undefined objects"""
 * 
 */
  __pyx_tuple__69 = PyTuple_Pack(4, __pyx_n_u_NullChromosome, __pyx_int_0, __pyx_int_0, __pyx_kp_u__68); if (unlikely(!__pyx_tuple__69)) __PYX_ERR(0, 194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__69);
  __Pyx_GIVEREF(__pyx_tuple__69);

  /* "plastid/genomics/roitools.pyx":201
 * #===============================================================================
 * 
 * def _get_attr(dict dtmp):             # <<<<<<<<<<<<<<
 *     ltmp=[]
 *     for k, v in sorted(dtmp.items()):
 */
  __pyx_tuple__70 = PyTuple_Pack(4, __pyx_n_s_dtmp, __pyx_n_s_ltmp, __pyx_n_s_k, __pyx_n_s_v); if (unlikely(!__pyx_tuple__70)) __PYX_ERR(0, 201, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__70);
  __Pyx_GIVEREF(__pyx_tuple__70);
  __pyx_codeobj__71 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__70, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plastid_genomics_roitools_pyx, __pyx_n_s_get_attr, 201, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__71)) __PYX_ERR(0, 201, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":208
 *     return ",".join(ltmp)
 * 
 * def _format_segmentchain(SegmentChain segchain):             # <<<<<<<<<<<<<<
 *     """Formats a |SegmentChain| as a string, which when ``eval`` ed, should
 *     reconstruct the |SegmentChain|.  Used for creating test datasets.
 */
  __pyx_tuple__72 = PyTuple_Pack(4, __pyx_n_s_segchain, __pyx_n_s_iv_ltmp, __pyx_n_s_iv, __pyx_n_s_stmp); if (unlikely(!__pyx_tuple__72)) __PYX_ERR(0, 208, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__72);
  __Pyx_GIVEREF(__pyx_tuple__72);
  __pyx_codeobj__73 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__72, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plastid_genomics_roitools_pyx, __pyx_n_s_format_segmentchain, 208, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__73)) __PYX_ERR(0, 208, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":230
 *     return stmp
 * 
 * def _format_transcript(Transcript tx):             # <<<<<<<<<<<<<<
 *     """Formats a |Transcript| as a string, which when ``eval`` ed, should
 *     reconstruct the |Transcript|.  Used for creating test datasets.
 */
  __pyx_tuple__74 = PyTuple_Pack(4, __pyx_n_s_tx, __pyx_n_s_iv_ltmp, __pyx_n_s_iv, __pyx_n_s_stmp); if (unlikely(!__pyx_tuple__74)) __PYX_ERR(0, 230, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__74);
  __Pyx_GIVEREF(__pyx_tuple__74);
  __pyx_codeobj__75 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__74, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plastid_genomics_roitools_pyx, __pyx_n_s_format_transcript, 230, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__75)) __PYX_ERR(0, 230, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":1047
 * 
 *     @staticmethod
 *     def from_str(str inp):             # <<<<<<<<<<<<<<
 *         """Construct a |GenomicSegment| from its ``str()`` representation
 * 
 */
  __pyx_tuple__76 = PyTuple_Pack(7, __pyx_n_s_inp, __pyx_n_s_start, __pyx_n_s_end, __pyx_n_s_chrom, __pyx_n_s_strand, __pyx_n_s_s_start, __pyx_n_s_s_end); if (unlikely(!__pyx_tuple__76)) __PYX_ERR(0, 1047, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__76);
  __Pyx_GIVEREF(__pyx_tuple__76);
  __pyx_codeobj__77 = (PyObject*)__Pyx_PyCode_New(1, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__76, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plastid_genomics_roitools_pyx, __pyx_n_s_from_str, 1047, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__77)) __PYX_ERR(0, 1047, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":1197
 * 
 *     @staticmethod
 *     def from_igv_str(str loc_str, str strand="."):             # <<<<<<<<<<<<<<
 *         """Construct |GenomicSegment| from IGV location string
 * 
 */
  __pyx_tuple__78 = PyTuple_Pack(7, __pyx_n_s_loc_str, __pyx_n_s_strand, __pyx_n_s_chrom, __pyx_n_s_s_start, __pyx_n_s_s_end, __pyx_n_s_start, __pyx_n_s_end); if (unlikely(!__pyx_tuple__78)) __PYX_ERR(0, 1197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__78);
  __Pyx_GIVEREF(__pyx_tuple__78);
  __pyx_codeobj__79 = (PyObject*)__Pyx_PyCode_New(2, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__78, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plastid_genomics_roitools_pyx, __pyx_n_s_from_igv_str, 1197, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__79)) __PYX_ERR(0, 1197, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":3379
 * 
 *     @staticmethod
 *     def from_str(str inp):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| from a string formatted by :py:meth:`SegmentChain.__str__`:
 * 
 */
  __pyx_tuple__80 = PyTuple_Pack(10, __pyx_n_s_inp, __pyx_n_s_chrom, __pyx_n_s_middle, __pyx_n_s_strand, __pyx_n_s_sstart, __pyx_n_s_send, __pyx_n_s_piece, __pyx_n_s_segs, __pyx_n_s_start, __pyx_n_s_end); if (unlikely(!__pyx_tuple__80)) __PYX_ERR(0, 3379, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__80);
  __Pyx_GIVEREF(__pyx_tuple__80);
  __pyx_codeobj__81 = (PyObject*)__Pyx_PyCode_New(1, 0, 10, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__80, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plastid_genomics_roitools_pyx, __pyx_n_s_from_str, 3379, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__81)) __PYX_ERR(0, 3379, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":3421
 *     # at each call to from_bed (e.g. from a BigBedReader)
 *     @staticmethod
 *     def from_bed(str line, object extra_columns=0):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| from a line from a `BED`_ file.  The `BED`_
 *         line may contain 4 to 12 columns, per the specification.  These will be
 */
  __pyx_tuple__82 = PyTuple_Pack(5, __pyx_n_s_line, __pyx_n_s_extra_columns, __pyx_n_s_attr, __pyx_n_s_segments_2, __pyx_n_s_chain); if (unlikely(!__pyx_tuple__82)) __PYX_ERR(0, 3421, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__82);
  __Pyx_GIVEREF(__pyx_tuple__82);
  __pyx_codeobj__83 = (PyObject*)__Pyx_PyCode_New(2, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__82, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plastid_genomics_roitools_pyx, __pyx_n_s_from_bed, 3421, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__83)) __PYX_ERR(0, 3421, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":3473
 * 
 *     @staticmethod
 *     def from_psl(psl_line):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| from a line from a `PSL`_ (BLAT) file
 * 
 */
  __pyx_tuple__84 = PyTuple_Pack(16, __pyx_n_s_psl_line, __pyx_n_s_items, __pyx_n_s_segs, __pyx_n_s_attr, __pyx_n_s_t_start, __pyx_n_s_block_size, __pyx_n_s_st, __pyx_n_s_sb, __pyx_n_s_strand, __pyx_n_s_seg, __pyx_n_s_block_sizes, __pyx_n_s_sq_starts, __pyx_n_s_st_starts, __pyx_n_s_t_starts, __pyx_n_s_q_starts, __pyx_n_s_sq); if (unlikely(!__pyx_tuple__84)) __PYX_ERR(0, 3473, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__84);
  __Pyx_GIVEREF(__pyx_tuple__84);
  __pyx_codeobj__85 = (PyObject*)__Pyx_PyCode_New(1, 0, 16, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__84, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plastid_genomics_roitools_pyx, __pyx_n_s_from_psl, 3473, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__85)) __PYX_ERR(0, 3473, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4459
 * 
 *     @staticmethod
 *     def from_bed(str line, extra_columns=0):             # <<<<<<<<<<<<<<
 *         """Create a |Transcript| from a BED line with 4 or more columns.
 *         `thickstart` and `thickend` columns, if present, are assumed to specify
 */
  __pyx_tuple__86 = PyTuple_Pack(7, __pyx_n_s_line, __pyx_n_s_extra_columns, __pyx_n_s_attr, __pyx_n_s_segments_2, __pyx_n_s_chain, __pyx_n_s_cds_genome_start_2, __pyx_n_s_cds_genome_end_2); if (unlikely(!__pyx_tuple__86)) __PYX_ERR(0, 4459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__86);
  __Pyx_GIVEREF(__pyx_tuple__86);
  __pyx_codeobj__87 = (PyObject*)__Pyx_PyCode_New(2, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__86, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plastid_genomics_roitools_pyx, __pyx_n_s_from_bed, 4459, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__87)) __PYX_ERR(0, 4459, __pyx_L1_error)

  /* "plastid/genomics/roitools.pyx":4528
 * 
 *     @staticmethod
 *     def from_psl(str psl_line):             # <<<<<<<<<<<<<<
 *         cdef:
 *             Transcript transcript = Transcript()
 */
  __pyx_tuple__88 = PyTuple_Pack(4, __pyx_n_s_psl_line, __pyx_n_s_transcript, __pyx_n_s_segchain, __pyx_n_s_attr); if (unlikely(!__pyx_tuple__88)) __PYX_ERR(0, 4528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__88);
  __Pyx_GIVEREF(__pyx_tuple__88);
  __pyx_codeobj__89 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__88, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plastid_genomics_roitools_pyx, __pyx_n_s_from_psl, 4528, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__89)) __PYX_ERR(0, 4528, __pyx_L1_error)

  /* "View.MemoryView":286
 *         return self.name
 * 
 * cdef generic = Enum("<strided and direct or indirect>")             # <<<<<<<<<<<<<<
 * cdef strided = Enum("<strided and direct>") # default
 * cdef indirect = Enum("<strided and indirect>")
 */
  __pyx_tuple__90 = PyTuple_Pack(1, __pyx_kp_s_strided_and_direct_or_indirect); if (unlikely(!__pyx_tuple__90)) __PYX_ERR(4, 286, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__90);
  __Pyx_GIVEREF(__pyx_tuple__90);

  /* "View.MemoryView":287
 * 
 * cdef generic = Enum("<strided and direct or indirect>")
 * cdef strided = Enum("<strided and direct>") # default             # <<<<<<<<<<<<<<
 * cdef indirect = Enum("<strided and indirect>")
 * 
 */
  __pyx_tuple__91 = PyTuple_Pack(1, __pyx_kp_s_strided_and_direct); if (unlikely(!__pyx_tuple__91)) __PYX_ERR(4, 287, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__91);
  __Pyx_GIVEREF(__pyx_tuple__91);

  /* "View.MemoryView":288
 * cdef generic = Enum("<strided and direct or indirect>")
 * cdef strided = Enum("<strided and direct>") # default
 * cdef indirect = Enum("<strided and indirect>")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__92 = PyTuple_Pack(1, __pyx_kp_s_strided_and_indirect); if (unlikely(!__pyx_tuple__92)) __PYX_ERR(4, 288, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__92);
  __Pyx_GIVEREF(__pyx_tuple__92);

  /* "View.MemoryView":291
 * 
 * 
 * cdef contiguous = Enum("<contiguous and direct>")             # <<<<<<<<<<<<<<
 * cdef indirect_contiguous = Enum("<contiguous and indirect>")
 * 
 */
  __pyx_tuple__93 = PyTuple_Pack(1, __pyx_kp_s_contiguous_and_direct); if (unlikely(!__pyx_tuple__93)) __PYX_ERR(4, 291, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__93);
  __Pyx_GIVEREF(__pyx_tuple__93);

  /* "View.MemoryView":292
 * 
 * cdef contiguous = Enum("<contiguous and direct>")
 * cdef indirect_contiguous = Enum("<contiguous and indirect>")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__94 = PyTuple_Pack(1, __pyx_kp_s_contiguous_and_indirect); if (unlikely(!__pyx_tuple__94)) __PYX_ERR(4, 292, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__94);
  __Pyx_GIVEREF(__pyx_tuple__94);

  /* "(tree fragment)":1
 * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */
  __pyx_tuple__95 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__95)) __PYX_ERR(4, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__95);
  __Pyx_GIVEREF(__pyx_tuple__95);
  __pyx_codeobj__96 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__95, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_Enum, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__96)) __PYX_ERR(4, 1, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
  __pyx_umethod_PyDict_Type_get.type = (PyObject*)&PyDict_Type;
  __pyx_umethod_PyDict_Type_items.type = (PyObject*)&PyDict_Type;
  __pyx_umethod_PyDict_Type_pop.type = (PyObject*)&PyDict_Type;
  __pyx_umethod_PyDict_Type_update.type = (PyObject*)&PyDict_Type;
  __pyx_umethod_PyUnicode_Type_strip.type = (PyObject*)&PyUnicode_Type;
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_6 = PyInt_FromLong(6); if (unlikely(!__pyx_int_6)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_7 = PyInt_FromLong(7); if (unlikely(!__pyx_int_7)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_9 = PyInt_FromLong(9); if (unlikely(!__pyx_int_9)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_10 = PyInt_FromLong(10); if (unlikely(!__pyx_int_10)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_11 = PyInt_FromLong(11); if (unlikely(!__pyx_int_11)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_255 = PyInt_FromLong(255); if (unlikely(!__pyx_int_255)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_184977713 = PyInt_FromLong(184977713L); if (unlikely(!__pyx_int_184977713)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/

static int __Pyx_modinit_global_init_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  /*--- Global init code ---*/
  __pyx_v_7plastid_8genomics_8roitools_NullSegment = ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)Py_None); Py_INCREF(Py_None);
  __pyx_v_7plastid_8genomics_8roitools_hash_template = Py_None; Py_INCREF(Py_None);
  __pyx_v_7plastid_8genomics_8roitools_mask_template = Py_None; Py_INCREF(Py_None);
  generic = Py_None; Py_INCREF(Py_None);
  strided = Py_None; Py_INCREF(Py_None);
  indirect = Py_None; Py_INCREF(Py_None);
  contiguous = Py_None; Py_INCREF(Py_None);
  indirect_contiguous = Py_None; Py_INCREF(Py_None);
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_variable_export_code(void) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  /*--- Variable export code ---*/
  if (__Pyx_ExportVoidPtr(__pyx_n_s_NullSegment, (void *)&__pyx_v_7plastid_8genomics_8roitools_NullSegment, "struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_function_export_code(void) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  /*--- Function export code ---*/
  if (__Pyx_ExportFunction("positions_to_segments", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_positions_to_segments, "PyObject *(PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("positionlist_to_segments", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_positionlist_to_segments, "PyObject *(PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("add_three_for_stop_codon", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_add_three_for_stop_codon, "struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("merge_segments", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_merge_segments, "PyObject *(PyObject *, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("nonecheck", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_nonecheck, "void (PyObject *, PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("check_segments", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_check_segments, "int (struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("chain_richcmp", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_chain_richcmp, "enum __pyx_t_7plastid_8genomics_8c_common_ExBool (struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("transcript_richcmp", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_transcript_richcmp, "enum __pyx_t_7plastid_8genomics_8c_common_ExBool (struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *, struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("get_attr_from_bed_column_tuples", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed_column_tuples, "PyObject *(PyObject *, int, int, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("get_attr_from_bed_column_names", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed_column_names, "PyObject *(PyObject *, int, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("get_attr_from_bed_column_number", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed_column_number, "PyObject *(PyObject *, int, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("get_standard_bed_attr", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_get_standard_bed_attr, "PyObject *(PyObject *, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("get_attr_from_bed", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_get_attr_from_bed, "PyObject *(PyObject *, struct __pyx_opt_args_7plastid_8genomics_8roitools_get_attr_from_bed *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("get_segments_from_bed", (void (*)(void))__pyx_f_7plastid_8genomics_8roitools_get_segments_from_bed, "PyObject *(PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_type_init_code(void) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  /*--- Type init code ---*/
  __pyx_vtabptr_7plastid_8genomics_8roitools_GenomicSegment = &__pyx_vtable_7plastid_8genomics_8roitools_GenomicSegment;
  __pyx_vtable_7plastid_8genomics_8roitools_GenomicSegment.contains = (int (*)(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, int __pyx_skip_dispatch))__pyx_f_7plastid_8genomics_8roitools_14GenomicSegment_contains;
  __pyx_vtable_7plastid_8genomics_8roitools_GenomicSegment.overlaps = (int (*)(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, int __pyx_skip_dispatch))__pyx_f_7plastid_8genomics_8roitools_14GenomicSegment_overlaps;
  __pyx_vtable_7plastid_8genomics_8roitools_GenomicSegment._cmp_helper = (int (*)(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, int, int __pyx_skip_dispatch))__pyx_f_7plastid_8genomics_8roitools_14GenomicSegment__cmp_helper;
  __pyx_vtable_7plastid_8genomics_8roitools_GenomicSegment.as_igv_str = (PyObject *(*)(struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *, int __pyx_skip_dispatch))__pyx_f_7plastid_8genomics_8roitools_14GenomicSegment_as_igv_str;
  if (PyType_Ready(&__pyx_type_7plastid_8genomics_8roitools_GenomicSegment) < 0) __PYX_ERR(0, 941, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_7plastid_8genomics_8roitools_GenomicSegment.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7plastid_8genomics_8roitools_GenomicSegment.tp_dictoffset && __pyx_type_7plastid_8genomics_8roitools_GenomicSegment.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_7plastid_8genomics_8roitools_GenomicSegment.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_7plastid_8genomics_8roitools_GenomicSegment, "__len__"); if (unlikely(!wrapper)) __PYX_ERR(0, 941, __pyx_L1_error)
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_7plastid_8genomics_8roitools_14GenomicSegment_16__len__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_7plastid_8genomics_8roitools_14GenomicSegment_16__len__.doc = __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_16__len__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_7plastid_8genomics_8roitools_14GenomicSegment_16__len__;
    }
  }
  #endif
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_7plastid_8genomics_8roitools_GenomicSegment, "__contains__"); if (unlikely(!wrapper)) __PYX_ERR(0, 941, __pyx_L1_error)
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_7plastid_8genomics_8roitools_14GenomicSegment_22__contains__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_7plastid_8genomics_8roitools_14GenomicSegment_22__contains__.doc = __pyx_doc_7plastid_8genomics_8roitools_14GenomicSegment_22__contains__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_7plastid_8genomics_8roitools_14GenomicSegment_22__contains__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_7plastid_8genomics_8roitools_GenomicSegment.tp_dict, __pyx_vtabptr_7plastid_8genomics_8roitools_GenomicSegment) < 0) __PYX_ERR(0, 941, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_GenomicSegment_3, (PyObject *)&__pyx_type_7plastid_8genomics_8roitools_GenomicSegment) < 0) __PYX_ERR(0, 941, __pyx_L1_error)
  __pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment = &__pyx_type_7plastid_8genomics_8roitools_GenomicSegment;
  __pyx_vtabptr_7plastid_8genomics_8roitools_SegmentChain = &__pyx_vtable_7plastid_8genomics_8roitools_SegmentChain;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_add_segments = (int (*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, PyObject *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_add_segments;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain._set_segments = (int (*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, PyObject *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain__set_segments;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain._get_position_hash = (arrayobject *(*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain__get_position_hash;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain._set_masks = (int (*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, PyObject *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain__set_masks;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_reset_masks = (void (*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_reset_masks;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_shares_segments_with = (PyObject *(*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_shares_segments_with;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_covers = (enum __pyx_t_7plastid_8genomics_8c_common_ExBool (*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_covers;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_antisense_overlaps = (enum __pyx_t_7plastid_8genomics_8c_common_ExBool (*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_antisense_overlaps;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_unstranded_overlaps = (enum __pyx_t_7plastid_8genomics_8c_common_ExBool (*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_unstranded_overlaps;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_overlaps = (enum __pyx_t_7plastid_8genomics_8c_common_ExBool (*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_overlaps;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_contains = (enum __pyx_t_7plastid_8genomics_8c_common_ExBool (*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_contains;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_get_position_list = (PyObject *(*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_position_list;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_get_position_set = (PyObject *(*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_position_set;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_get_position_array = (PyArrayObject *(*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, int))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_position_array;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.get_masked_position_set = (PyObject *(*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, int __pyx_skip_dispatch))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_get_masked_position_set;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_get_genomic_coordinate = (long (*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, long, int))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_genomic_coordinate;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_get_segmentchain_coordinate = (long (*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, long, int))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_segmentchain_coordinate;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.c_get_subchain = (struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *(*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, long, long, int))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_c_get_subchain;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain._restrand = (struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *(*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, enum __pyx_t_7plastid_8genomics_8c_common_Strand))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain__restrand;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.get_unstranded = (struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *(*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, int __pyx_skip_dispatch))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_get_unstranded;
  __pyx_vtable_7plastid_8genomics_8roitools_SegmentChain.get_antisense = (struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *(*)(struct __pyx_obj_7plastid_8genomics_8roitools_SegmentChain *, int __pyx_skip_dispatch))__pyx_f_7plastid_8genomics_8roitools_12SegmentChain_get_antisense;
  if (PyType_Ready(&__pyx_type_7plastid_8genomics_8roitools_SegmentChain) < 0) __PYX_ERR(0, 1251, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_7plastid_8genomics_8roitools_SegmentChain.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7plastid_8genomics_8roitools_SegmentChain.tp_dictoffset && __pyx_type_7plastid_8genomics_8roitools_SegmentChain.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_7plastid_8genomics_8roitools_SegmentChain.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_7plastid_8genomics_8roitools_SegmentChain, "__str__"); if (unlikely(!wrapper)) __PYX_ERR(0, 1251, __pyx_L1_error)
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_18__str__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_18__str__.doc = __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_18__str__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_18__str__;
    }
  }
  #endif
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_7plastid_8genomics_8roitools_SegmentChain, "__getitem__"); if (unlikely(!wrapper)) __PYX_ERR(0, 1251, __pyx_L1_error)
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_20__getitem__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_20__getitem__.doc = __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_20__getitem__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_20__getitem__;
    }
  }
  #endif
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_7plastid_8genomics_8roitools_SegmentChain, "__iter__"); if (unlikely(!wrapper)) __PYX_ERR(0, 1251, __pyx_L1_error)
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_22__iter__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_22__iter__.doc = __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_22__iter__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_22__iter__;
    }
  }
  #endif
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_7plastid_8genomics_8roitools_SegmentChain, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 1251, __pyx_L1_error)
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_24__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_24__next__.doc = __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_24__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_24__next__;
    }
  }
  #endif
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_7plastid_8genomics_8roitools_SegmentChain, "__len__"); if (unlikely(!wrapper)) __PYX_ERR(0, 1251, __pyx_L1_error)
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_28__len__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_28__len__.doc = __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_28__len__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_28__len__;
    }
  }
  #endif
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_7plastid_8genomics_8roitools_SegmentChain, "__contains__"); if (unlikely(!wrapper)) __PYX_ERR(0, 1251, __pyx_L1_error)
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_30__contains__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_30__contains__.doc = __pyx_doc_7plastid_8genomics_8roitools_12SegmentChain_30__contains__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_7plastid_8genomics_8roitools_12SegmentChain_30__contains__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_7plastid_8genomics_8roitools_SegmentChain.tp_dict, __pyx_vtabptr_7plastid_8genomics_8roitools_SegmentChain) < 0) __PYX_ERR(0, 1251, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_SegmentChain_2, (PyObject *)&__pyx_type_7plastid_8genomics_8roitools_SegmentChain) < 0) __PYX_ERR(0, 1251, __pyx_L1_error)
  __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain = &__pyx_type_7plastid_8genomics_8roitools_SegmentChain;
  __pyx_vtabptr_7plastid_8genomics_8roitools_Transcript = &__pyx_vtable_7plastid_8genomics_8roitools_Transcript;
  __pyx_vtable_7plastid_8genomics_8roitools_Transcript.__pyx_base = *__pyx_vtabptr_7plastid_8genomics_8roitools_SegmentChain;
  __pyx_vtable_7plastid_8genomics_8roitools_Transcript._update_cds = (int (*)(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *))__pyx_f_7plastid_8genomics_8roitools_10Transcript__update_cds;
  __pyx_vtable_7plastid_8genomics_8roitools_Transcript._update_from_cds_start = (int (*)(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *))__pyx_f_7plastid_8genomics_8roitools_10Transcript__update_from_cds_start;
  __pyx_vtable_7plastid_8genomics_8roitools_Transcript._update_from_cds_end = (int (*)(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *))__pyx_f_7plastid_8genomics_8roitools_10Transcript__update_from_cds_end;
  __pyx_vtable_7plastid_8genomics_8roitools_Transcript._update_from_cds_genome_start = (int (*)(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *))__pyx_f_7plastid_8genomics_8roitools_10Transcript__update_from_cds_genome_start;
  __pyx_vtable_7plastid_8genomics_8roitools_Transcript._update_from_cds_genome_end = (int (*)(struct __pyx_obj_7plastid_8genomics_8roitools_Transcript *))__pyx_f_7plastid_8genomics_8roitools_10Transcript__update_from_cds_genome_end;
  __pyx_type_7plastid_8genomics_8roitools_Transcript.tp_base = __pyx_ptype_7plastid_8genomics_8roitools_SegmentChain;
  if (PyType_Ready(&__pyx_type_7plastid_8genomics_8roitools_Transcript) < 0) __PYX_ERR(0, 3555, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_7plastid_8genomics_8roitools_Transcript.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7plastid_8genomics_8roitools_Transcript.tp_dictoffset && __pyx_type_7plastid_8genomics_8roitools_Transcript.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_7plastid_8genomics_8roitools_Transcript.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_7plastid_8genomics_8roitools_Transcript.tp_dict, __pyx_vtabptr_7plastid_8genomics_8roitools_Transcript) < 0) __PYX_ERR(0, 3555, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_Transcript_3, (PyObject *)&__pyx_type_7plastid_8genomics_8roitools_Transcript) < 0) __PYX_ERR(0, 3555, __pyx_L1_error)
  __pyx_ptype_7plastid_8genomics_8roitools_Transcript = &__pyx_type_7plastid_8genomics_8roitools_Transcript;
  if (PyType_Ready(&__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed) < 0) __PYX_ERR(0, 2669, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed.tp_dictoffset && __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed = &__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct__as_bed;
  if (PyType_Ready(&__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr) < 0) __PYX_ERR(0, 2770, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr.tp_dictoffset && __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr = &__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_1_genexpr;
  if (PyType_Ready(&__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr) < 0) __PYX_ERR(0, 2771, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr.tp_dictoffset && __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr = &__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_2_genexpr;
  if (PyType_Ready(&__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr) < 0) __PYX_ERR(0, 2772, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr.tp_dictoffset && __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr = &__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_3_genexpr;
  if (PyType_Ready(&__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr) < 0) __PYX_ERR(0, 2773, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr.tp_dictoffset && __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr = &__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_4_genexpr;
  if (PyType_Ready(&__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl) < 0) __PYX_ERR(0, 2809, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl.tp_dictoffset && __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl = &__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_5_as_psl;
  if (PyType_Ready(&__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr) < 0) __PYX_ERR(0, 2893, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr.tp_dictoffset && __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr = &__pyx_type_7plastid_8genomics_8roitools___pyx_scope_struct_6_genexpr;
  __pyx_vtabptr_array = &__pyx_vtable_array;
  __pyx_vtable_array.get_memview = (PyObject *(*)(struct __pyx_array_obj *))__pyx_array_get_memview;
  if (PyType_Ready(&__pyx_type___pyx_array) < 0) __PYX_ERR(4, 105, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type___pyx_array.tp_print = 0;
  #endif
  if (__Pyx_SetVtable(__pyx_type___pyx_array.tp_dict, __pyx_vtabptr_array) < 0) __PYX_ERR(4, 105, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_array) < 0) __PYX_ERR(4, 105, __pyx_L1_error)
  __pyx_array_type = &__pyx_type___pyx_array;
  if (PyType_Ready(&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(4, 279, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type___pyx_MemviewEnum.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_MemviewEnum.tp_dictoffset && __pyx_type___pyx_MemviewEnum.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type___pyx_MemviewEnum.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(4, 279, __pyx_L1_error)
  __pyx_MemviewEnum_type = &__pyx_type___pyx_MemviewEnum;
  __pyx_vtabptr_memoryview = &__pyx_vtable_memoryview;
  __pyx_vtable_memoryview.get_item_pointer = (char *(*)(struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_get_item_pointer;
  __pyx_vtable_memoryview.is_slice = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_is_slice;
  __pyx_vtable_memoryview.setitem_slice_assignment = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *, PyObject *))__pyx_memoryview_setitem_slice_assignment;
  __pyx_vtable_memoryview.setitem_slice_assign_scalar = (PyObject *(*)(struct __pyx_memoryview_obj *, struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_setitem_slice_assign_scalar;
  __pyx_vtable_memoryview.setitem_indexed = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *, PyObject *))__pyx_memoryview_setitem_indexed;
  __pyx_vtable_memoryview.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryview_convert_item_to_object;
  __pyx_vtable_memoryview.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryview_assign_item_from_object;
  if (PyType_Ready(&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(4, 330, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type___pyx_memoryview.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryview.tp_dictoffset && __pyx_type___pyx_memoryview.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type___pyx_memoryview.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type___pyx_memoryview.tp_dict, __pyx_vtabptr_memoryview) < 0) __PYX_ERR(4, 330, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(4, 330, __pyx_L1_error)
  __pyx_memoryview_type = &__pyx_type___pyx_memoryview;
  __pyx_vtabptr__memoryviewslice = &__pyx_vtable__memoryviewslice;
  __pyx_vtable__memoryviewslice.__pyx_base = *__pyx_vtabptr_memoryview;
  __pyx_vtable__memoryviewslice.__pyx_base.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryviewslice_convert_item_to_object;
  __pyx_vtable__memoryviewslice.__pyx_base.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryviewslice_assign_item_from_object;
  __pyx_type___pyx_memoryviewslice.tp_base = __pyx_memoryview_type;
  if (PyType_Ready(&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(4, 965, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type___pyx_memoryviewslice.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryviewslice.tp_dictoffset && __pyx_type___pyx_memoryviewslice.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type___pyx_memoryviewslice.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type___pyx_memoryviewslice.tp_dict, __pyx_vtabptr__memoryviewslice) < 0) __PYX_ERR(4, 965, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(4, 965, __pyx_L1_error)
  __pyx_memoryviewslice_type = &__pyx_type___pyx_memoryviewslice;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_type_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  /*--- Type import code ---*/
  __pyx_t_1 = PyImport_ImportModule("plastid.genomics.c_common"); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7plastid_8genomics_8c_common__GeneratorWrapper = __Pyx_ImportType(__pyx_t_1, "plastid.genomics.c_common", "_GeneratorWrapper", sizeof(struct __pyx_obj_7plastid_8genomics_8c_common__GeneratorWrapper), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_7plastid_8genomics_8c_common__GeneratorWrapper) __PYX_ERR(5, 16, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", 
  #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(6, 9, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(7, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(7, 8, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 15, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(8, 15, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("array"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 58, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_5array_array = __Pyx_ImportType(__pyx_t_1, "array", "array", sizeof(arrayobject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_7cpython_5array_array) __PYX_ERR(2, 58, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("numpy"); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 200, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_5numpy_dtype = __Pyx_ImportType(__pyx_t_1, "numpy", "dtype", sizeof(PyArray_Descr), __Pyx_ImportType_CheckSize_Ignore);
   if (!__pyx_ptype_5numpy_dtype) __PYX_ERR(3, 200, __pyx_L1_error)
  __pyx_ptype_5numpy_flatiter = __Pyx_ImportType(__pyx_t_1, "numpy", "flatiter", sizeof(PyArrayIterObject), __Pyx_ImportType_CheckSize_Ignore);
   if (!__pyx_ptype_5numpy_flatiter) __PYX_ERR(3, 223, __pyx_L1_error)
  __pyx_ptype_5numpy_broadcast = __Pyx_ImportType(__pyx_t_1, "numpy", "broadcast", sizeof(PyArrayMultiIterObject), __Pyx_ImportType_CheckSize_Ignore);
   if (!__pyx_ptype_5numpy_broadcast) __PYX_ERR(3, 227, __pyx_L1_error)
  __pyx_ptype_5numpy_ndarray = __Pyx_ImportType(__pyx_t_1, "numpy", "ndarray", sizeof(PyArrayObject), __Pyx_ImportType_CheckSize_Ignore);
   if (!__pyx_ptype_5numpy_ndarray) __PYX_ERR(3, 239, __pyx_L1_error)
  __pyx_ptype_5numpy_generic = __Pyx_ImportType(__pyx_t_1, "numpy", "generic", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5numpy_generic) __PYX_ERR(3, 771, __pyx_L1_error)
  __pyx_ptype_5numpy_number = __Pyx_ImportType(__pyx_t_1, "numpy", "number", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5numpy_number) __PYX_ERR(3, 773, __pyx_L1_error)
  __pyx_ptype_5numpy_integer = __Pyx_ImportType(__pyx_t_1, "numpy", "integer", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5numpy_integer) __PYX_ERR(3, 775, __pyx_L1_error)
  __pyx_ptype_5numpy_signedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "signedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5numpy_signedinteger) __PYX_ERR(3, 777, __pyx_L1_error)
  __pyx_ptype_5numpy_unsignedinteger = __Pyx_ImportType(__pyx_t_1, "numpy", "unsignedinteger", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5numpy_unsignedinteger) __PYX_ERR(3, 779, __pyx_L1_error)
  __pyx_ptype_5numpy_inexact = __Pyx_ImportType(__pyx_t_1, "numpy", "inexact", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5numpy_inexact) __PYX_ERR(3, 781, __pyx_L1_error)
  __pyx_ptype_5numpy_floating = __Pyx_ImportType(__pyx_t_1, "numpy", "floating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5numpy_floating) __PYX_ERR(3, 783, __pyx_L1_error)
  __pyx_ptype_5numpy_complexfloating = __Pyx_ImportType(__pyx_t_1, "numpy", "complexfloating", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5numpy_complexfloating) __PYX_ERR(3, 785, __pyx_L1_error)
  __pyx_ptype_5numpy_flexible = __Pyx_ImportType(__pyx_t_1, "numpy", "flexible", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5numpy_flexible) __PYX_ERR(3, 787, __pyx_L1_error)
  __pyx_ptype_5numpy_character = __Pyx_ImportType(__pyx_t_1, "numpy", "character", sizeof(PyObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5numpy_character) __PYX_ERR(3, 789, __pyx_L1_error)
  __pyx_ptype_5numpy_ufunc = __Pyx_ImportType(__pyx_t_1, "numpy", "ufunc", sizeof(PyUFuncObject), __Pyx_ImportType_CheckSize_Ignore);
   if (!__pyx_ptype_5numpy_ufunc) __PYX_ERR(3, 827, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_variable_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  /*--- Variable import code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  /*--- Function import code ---*/
  __pyx_t_1 = PyImport_ImportModule("plastid.genomics.c_common"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportFunction(__pyx_t_1, "strand_to_str", (void (**)(void))&__pyx_f_7plastid_8genomics_8c_common_strand_to_str, "PyObject *(enum __pyx_t_7plastid_8genomics_8c_common_Strand)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_1, "str_to_strand", (void (**)(void))&__pyx_f_7plastid_8genomics_8c_common_str_to_strand, "enum __pyx_t_7plastid_8genomics_8c_common_Strand (PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}


#ifndef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#elif PY_MAJOR_VERSION < 3
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" void
#else
#define __Pyx_PyMODINIT_FUNC void
#endif
#else
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
#else
#define __Pyx_PyMODINIT_FUNC PyObject *
#endif
#endif


#if PY_MAJOR_VERSION < 3
__Pyx_PyMODINIT_FUNC initroitools(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC initroitools(void)
#else
__Pyx_PyMODINIT_FUNC PyInit_roitools(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC PyInit_roitools(void)
#if CYTHON_PEP489_MULTI_PHASE_INIT
{
  return PyModuleDef_Init(&__pyx_moduledef);
}
static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
    #if PY_VERSION_HEX >= 0x030700A1
    static PY_INT64_T main_interpreter_id = -1;
    PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
    if (main_interpreter_id == -1) {
        main_interpreter_id = current_id;
        return (unlikely(current_id == -1)) ? -1 : 0;
    } else if (unlikely(main_interpreter_id != current_id))
    #else
    static PyInterpreterState *main_interpreter = NULL;
    PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
    if (!main_interpreter) {
        main_interpreter = current_interpreter;
    } else if (unlikely(main_interpreter != current_interpreter))
    #endif
    {
        PyErr_SetString(
            PyExc_ImportError,
            "Interpreter change detected - this module can only be loaded into one interpreter per process.");
        return -1;
    }
    return 0;
}
static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) {
    PyObject *value = PyObject_GetAttrString(spec, from_name);
    int result = 0;
    if (likely(value)) {
        if (allow_none || value != Py_None) {
            result = PyDict_SetItemString(moddict, to_name, value);
        }
        Py_DECREF(value);
    } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Clear();
    } else {
        result = -1;
    }
    return result;
}
static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
    PyObject *module = NULL, *moddict, *modname;
    if (__Pyx_check_single_interpreter())
        return NULL;
    if (__pyx_m)
        return __Pyx_NewRef(__pyx_m);
    modname = PyObject_GetAttrString(spec, "name");
    if (unlikely(!modname)) goto bad;
    module = PyModule_NewObject(modname);
    Py_DECREF(modname);
    if (unlikely(!module)) goto bad;
    moddict = PyModule_GetDict(module);
    if (unlikely(!moddict)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
    return module;
bad:
    Py_XDECREF(module);
    return NULL;
}


static CYTHON_SMALL_CODE int __pyx_pymod_exec_roitools(PyObject *__pyx_pyinit_module)
#endif
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  static PyThread_type_lock __pyx_t_3[8];
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  if (__pyx_m) {
    if (__pyx_m == __pyx_pyinit_module) return 0;
    PyErr_SetString(PyExc_RuntimeError, "Module 'roitools' has already been imported. Re-initialisation is not supported.");
    return -1;
  }
  #elif PY_MAJOR_VERSION >= 3
  if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  #endif
  #if CYTHON_REFNANNY
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
if (!__Pyx_RefNanny) {
  PyErr_Clear();
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  if (!__Pyx_RefNanny)
      Py_FatalError("failed to import 'refnanny' module");
}
#endif
  __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_roitools(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pxy_PyFrame_Initialize_Offsets
  __Pxy_PyFrame_Initialize_Offsets();
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_AsyncGen_USED
  if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  PyEval_InitThreads();
  #endif
  /*--- Module creation code ---*/
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  __pyx_m = __pyx_pyinit_module;
  Py_INCREF(__pyx_m);
  #else
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("roitools", __pyx_methods, __pyx_k_This_module_contains_classes_for, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_b);
  __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_cython_runtime);
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main_plastid__genomics__roitools) {
    if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "plastid.genomics.roitools")) {
      if (unlikely(PyDict_SetItemString(modules, "plastid.genomics.roitools", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global type/function init code ---*/
  (void)__Pyx_modinit_global_init_code();
  if (unlikely(__Pyx_modinit_variable_export_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely(__Pyx_modinit_function_export_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely(__Pyx_modinit_type_init_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  (void)__Pyx_modinit_variable_import_code();
  if (unlikely(__Pyx_modinit_function_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif

  /* "plastid/genomics/roitools.pyx":128
 * 
 * 
 * import re             # <<<<<<<<<<<<<<
 * import copy
 * import array
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_re, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_1) < 0) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":129
 * 
 * import re
 * import copy             # <<<<<<<<<<<<<<
 * import array
 * import numpy
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_copy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_copy, __pyx_t_1) < 0) __PYX_ERR(0, 129, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":130
 * import re
 * import copy
 * import array             # <<<<<<<<<<<<<<
 * import numpy
 * 
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_array, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_array, __pyx_t_1) < 0) __PYX_ERR(0, 130, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":131
 * import copy
 * import array
 * import numpy             # <<<<<<<<<<<<<<
 * 
 * cimport numpy
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 131, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_numpy, __pyx_t_1) < 0) __PYX_ERR(0, 131, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":135
 * cimport numpy
 * 
 * from numpy.ma import MaskedArray as MaskedArray             # <<<<<<<<<<<<<<
 * from Bio.SeqRecord import SeqRecord
 * from Bio.Seq import Seq
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_MaskedArray);
  __Pyx_GIVEREF(__pyx_n_s_MaskedArray);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_MaskedArray);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_numpy_ma, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_MaskedArray); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_MaskedArray, __pyx_t_1) < 0) __PYX_ERR(0, 135, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":136
 * 
 * from numpy.ma import MaskedArray as MaskedArray
 * from Bio.SeqRecord import SeqRecord             # <<<<<<<<<<<<<<
 * from Bio.Seq import Seq
 * 
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_SeqRecord);
  __Pyx_GIVEREF(__pyx_n_s_SeqRecord);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_SeqRecord);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_Bio_SeqRecord, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_SeqRecord); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SeqRecord, __pyx_t_2) < 0) __PYX_ERR(0, 136, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":137
 * from numpy.ma import MaskedArray as MaskedArray
 * from Bio.SeqRecord import SeqRecord
 * from Bio.Seq import Seq             # <<<<<<<<<<<<<<
 * 
 * from plastid.util.services.exceptions import DataWarning, warn
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_Seq);
  __Pyx_GIVEREF(__pyx_n_s_Seq);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_Seq);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_Bio_Seq, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 137, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_Seq); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Seq, __pyx_t_1) < 0) __PYX_ERR(0, 137, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":139
 * from Bio.Seq import Seq
 * 
 * from plastid.util.services.exceptions import DataWarning, warn             # <<<<<<<<<<<<<<
 * from plastid.plotting.colors import get_str_from_rgb255, get_str_from_rgb, get_rgb255
 * from plastid.readers.gff_tokens import make_GFF3_tokens, make_GTF2_tokens
 */
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 139, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_DataWarning);
  __Pyx_GIVEREF(__pyx_n_s_DataWarning);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_DataWarning);
  __Pyx_INCREF(__pyx_n_s_warn);
  __Pyx_GIVEREF(__pyx_n_s_warn);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_warn);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_plastid_util_services_exceptions, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_DataWarning); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 139, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_DataWarning, __pyx_t_2) < 0) __PYX_ERR(0, 139, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_warn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 139, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_warn, __pyx_t_2) < 0) __PYX_ERR(0, 139, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":140
 * 
 * from plastid.util.services.exceptions import DataWarning, warn
 * from plastid.plotting.colors import get_str_from_rgb255, get_str_from_rgb, get_rgb255             # <<<<<<<<<<<<<<
 * from plastid.readers.gff_tokens import make_GFF3_tokens, make_GTF2_tokens
 * 
 */
  __pyx_t_1 = PyList_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_get_str_from_rgb255);
  __Pyx_GIVEREF(__pyx_n_s_get_str_from_rgb255);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_get_str_from_rgb255);
  __Pyx_INCREF(__pyx_n_s_get_str_from_rgb);
  __Pyx_GIVEREF(__pyx_n_s_get_str_from_rgb);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_get_str_from_rgb);
  __Pyx_INCREF(__pyx_n_s_get_rgb255);
  __Pyx_GIVEREF(__pyx_n_s_get_rgb255);
  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_get_rgb255);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_plastid_plotting_colors, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_get_str_from_rgb255); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_str_from_rgb255, __pyx_t_1) < 0) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_get_str_from_rgb); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_str_from_rgb, __pyx_t_1) < 0) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_get_rgb255); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_rgb255, __pyx_t_1) < 0) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":141
 * from plastid.util.services.exceptions import DataWarning, warn
 * from plastid.plotting.colors import get_str_from_rgb255, get_str_from_rgb, get_rgb255
 * from plastid.readers.gff_tokens import make_GFF3_tokens, make_GTF2_tokens             # <<<<<<<<<<<<<<
 * 
 * from plastid.genomics.c_common cimport (
 */
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 141, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_make_GFF3_tokens);
  __Pyx_GIVEREF(__pyx_n_s_make_GFF3_tokens);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_make_GFF3_tokens);
  __Pyx_INCREF(__pyx_n_s_make_GTF2_tokens);
  __Pyx_GIVEREF(__pyx_n_s_make_GTF2_tokens);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_make_GTF2_tokens);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_plastid_readers_gff_tokens, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 141, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_make_GFF3_tokens); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 141, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_make_GFF3_tokens, __pyx_t_2) < 0) __PYX_ERR(0, 141, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_make_GTF2_tokens); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 141, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_make_GTF2_tokens, __pyx_t_2) < 0) __PYX_ERR(0, 141, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":159
 * #===============================================================================
 * 
 * cdef hash_template = array.array('l', []) # c signed long / python int             # <<<<<<<<<<<<<<
 * cdef mask_template = array.array('i', []) # TODO: change to c unsigned char / python int
 * 
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 159, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_u_l);
  __Pyx_GIVEREF(__pyx_n_u_l);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_l);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 159, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_XGOTREF(__pyx_v_7plastid_8genomics_8roitools_hash_template);
  __Pyx_DECREF_SET(__pyx_v_7plastid_8genomics_8roitools_hash_template, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":160
 * 
 * cdef hash_template = array.array('l', []) # c signed long / python int
 * cdef mask_template = array.array('i', []) # TODO: change to c unsigned char / python int             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_u_i);
  __Pyx_GIVEREF(__pyx_n_u_i);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_i);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_XGOTREF(__pyx_v_7plastid_8genomics_8roitools_mask_template);
  __Pyx_DECREF_SET(__pyx_v_7plastid_8genomics_8roitools_mask_template, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":164
 * 
 * # to/from str
 * igvpat = re.compile(r"([^:]*):([0-9]+)-([0-9]+)")             # <<<<<<<<<<<<<<
 * segpat = re.compile(r"([^:]*):([0-9]+)-([0-9]+)\(([+-.])\)")
 * ivcpat = re.compile(r"([^:]*):([^(]+)\(([+-.])\)")
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_re); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_compile); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_igvpat, __pyx_t_1) < 0) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":165
 * # to/from str
 * igvpat = re.compile(r"([^:]*):([0-9]+)-([0-9]+)")
 * segpat = re.compile(r"([^:]*):([0-9]+)-([0-9]+)\(([+-.])\)")             # <<<<<<<<<<<<<<
 * ivcpat = re.compile(r"([^:]*):([^(]+)\(([+-.])\)")
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_re); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_compile); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__65, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_segpat, __pyx_t_1) < 0) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":166
 * igvpat = re.compile(r"([^:]*):([0-9]+)-([0-9]+)")
 * segpat = re.compile(r"([^:]*):([0-9]+)-([0-9]+)\(([+-.])\)")
 * ivcpat = re.compile(r"([^:]*):([^(]+)\(([+-.])\)")             # <<<<<<<<<<<<<<
 * 
 * # compile time constants - __richcmp__ test
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_re); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_compile); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__67, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ivcpat, __pyx_t_1) < 0) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":177
 * 
 * # numeric types
 * INT    = numpy.int             # <<<<<<<<<<<<<<
 * FLOAT  = numpy.float
 * DOUBLE = numpy.double
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 177, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 177, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_INT, __pyx_t_2) < 0) __PYX_ERR(0, 177, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":178
 * # numeric types
 * INT    = numpy.int
 * FLOAT  = numpy.float             # <<<<<<<<<<<<<<
 * DOUBLE = numpy.double
 * LONG   = numpy.long
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_FLOAT, __pyx_t_1) < 0) __PYX_ERR(0, 178, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":179
 * INT    = numpy.int
 * FLOAT  = numpy.float
 * DOUBLE = numpy.double             # <<<<<<<<<<<<<<
 * LONG   = numpy.long
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_double); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_DOUBLE, __pyx_t_2) < 0) __PYX_ERR(0, 179, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "plastid/genomics/roitools.pyx":180
 * FLOAT  = numpy.float
 * DOUBLE = numpy.double
 * LONG   = numpy.long             # <<<<<<<<<<<<<<
 * 
 * ctypedef numpy.int_t    INT_t
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_long); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_LONG, __pyx_t_1) < 0) __PYX_ERR(0, 180, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":194
 * #==============================================================================
 * 
 * NullSegment = GenomicSegment("NullChromosome", 0, 0, "\x00")             # <<<<<<<<<<<<<<
 * """Placeholder |GenomicSegment| for undefined objects"""
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment), __pyx_tuple__69, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_XGOTREF(((PyObject *)__pyx_v_7plastid_8genomics_8roitools_NullSegment));
  __Pyx_DECREF_SET(__pyx_v_7plastid_8genomics_8roitools_NullSegment, ((struct __pyx_obj_7plastid_8genomics_8roitools_GenomicSegment *)__pyx_t_1));
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":201
 * #===============================================================================
 * 
 * def _get_attr(dict dtmp):             # <<<<<<<<<<<<<<
 *     ltmp=[]
 *     for k, v in sorted(dtmp.items()):
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7plastid_8genomics_8roitools_1_get_attr, NULL, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 201, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_attr, __pyx_t_1) < 0) __PYX_ERR(0, 201, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":208
 *     return ",".join(ltmp)
 * 
 * def _format_segmentchain(SegmentChain segchain):             # <<<<<<<<<<<<<<
 *     """Formats a |SegmentChain| as a string, which when ``eval`` ed, should
 *     reconstruct the |SegmentChain|.  Used for creating test datasets.
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7plastid_8genomics_8roitools_3_format_segmentchain, NULL, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 208, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_format_segmentchain, __pyx_t_1) < 0) __PYX_ERR(0, 208, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":230
 *     return stmp
 * 
 * def _format_transcript(Transcript tx):             # <<<<<<<<<<<<<<
 *     """Formats a |Transcript| as a string, which when ``eval`` ed, should
 *     reconstruct the |Transcript|.  Used for creating test datasets.
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7plastid_8genomics_8roitools_5_format_transcript, NULL, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 230, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_format_transcript, __pyx_t_1) < 0) __PYX_ERR(0, 230, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "plastid/genomics/roitools.pyx":1047
 * 
 *     @staticmethod
 *     def from_str(str inp):             # <<<<<<<<<<<<<<
 *         """Construct a |GenomicSegment| from its ``str()`` representation
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7plastid_8genomics_8roitools_14GenomicSegment_11from_str, NULL, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1047, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment->tp_dict, __pyx_n_s_from_str, __pyx_t_1) < 0) __PYX_ERR(0, 1047, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment);

  /* "plastid/genomics/roitools.pyx":1046
 *         return hash((self.__class__.__name__, self.chrom, self.start, self.end, self.strand))
 * 
 *     @staticmethod             # <<<<<<<<<<<<<<
 *     def from_str(str inp):
 *         """Construct a |GenomicSegment| from its ``str()`` representation
 */
  __Pyx_GetNameInClass(__pyx_t_1, (PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment, __pyx_n_s_from_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1047, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1046, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment->tp_dict, __pyx_n_s_from_str, __pyx_t_2) < 0) __PYX_ERR(0, 1047, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment);

  /* "plastid/genomics/roitools.pyx":1197
 * 
 *     @staticmethod
 *     def from_igv_str(str loc_str, str strand="."):             # <<<<<<<<<<<<<<
 *         """Construct |GenomicSegment| from IGV location string
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7plastid_8genomics_8roitools_14GenomicSegment_31from_igv_str, NULL, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment->tp_dict, __pyx_n_s_from_igv_str, __pyx_t_2) < 0) __PYX_ERR(0, 1197, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment);

  /* "plastid/genomics/roitools.pyx":1196
 *         return "%s:%s-%s" % (self.chrom, self.start + 1, self.end+1)
 * 
 *     @staticmethod             # <<<<<<<<<<<<<<
 *     def from_igv_str(str loc_str, str strand="."):
 *         """Construct |GenomicSegment| from IGV location string
 */
  __Pyx_GetNameInClass(__pyx_t_2, (PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment, __pyx_n_s_from_igv_str); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1196, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment->tp_dict, __pyx_n_s_from_igv_str, __pyx_t_1) < 0) __PYX_ERR(0, 1197, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_GenomicSegment);

  /* "plastid/genomics/roitools.pyx":3379
 * 
 *     @staticmethod
 *     def from_str(str inp):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| from a string formatted by :py:meth:`SegmentChain.__str__`:
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7plastid_8genomics_8roitools_12SegmentChain_93from_str, NULL, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3379, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain->tp_dict, __pyx_n_s_from_str, __pyx_t_1) < 0) __PYX_ERR(0, 3379, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain);

  /* "plastid/genomics/roitools.pyx":3378
 *         return ">%s\n%s\n" % (self.get_name(), self.get_sequence(genome, stranded=stranded))
 * 
 *     @staticmethod             # <<<<<<<<<<<<<<
 *     def from_str(str inp):
 *         """Create a |SegmentChain| from a string formatted by :py:meth:`SegmentChain.__str__`:
 */
  __Pyx_GetNameInClass(__pyx_t_1, (PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain, __pyx_n_s_from_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3379, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3378, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain->tp_dict, __pyx_n_s_from_str, __pyx_t_2) < 0) __PYX_ERR(0, 3379, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain);

  /* "plastid/genomics/roitools.pyx":3421
 *     # at each call to from_bed (e.g. from a BigBedReader)
 *     @staticmethod
 *     def from_bed(str line, object extra_columns=0):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| from a line from a `BED`_ file.  The `BED`_
 *         line may contain 4 to 12 columns, per the specification.  These will be
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7plastid_8genomics_8roitools_12SegmentChain_95from_bed, NULL, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3421, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain->tp_dict, __pyx_n_s_from_bed, __pyx_t_2) < 0) __PYX_ERR(0, 3421, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain);

  /* "plastid/genomics/roitools.pyx":3420
 * 
 *     # at each call to from_bed (e.g. from a BigBedReader)
 *     @staticmethod             # <<<<<<<<<<<<<<
 *     def from_bed(str line, object extra_columns=0):
 *         """Create a |SegmentChain| from a line from a `BED`_ file.  The `BED`_
 */
  __Pyx_GetNameInClass(__pyx_t_2, (PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain, __pyx_n_s_from_bed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3421, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3420, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain->tp_dict, __pyx_n_s_from_bed, __pyx_t_1) < 0) __PYX_ERR(0, 3421, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain);

  /* "plastid/genomics/roitools.pyx":3473
 * 
 *     @staticmethod
 *     def from_psl(psl_line):             # <<<<<<<<<<<<<<
 *         """Create a |SegmentChain| from a line from a `PSL`_ (BLAT) file
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7plastid_8genomics_8roitools_12SegmentChain_97from_psl, NULL, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3473, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain->tp_dict, __pyx_n_s_from_psl, __pyx_t_1) < 0) __PYX_ERR(0, 3473, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain);

  /* "plastid/genomics/roitools.pyx":3472
 * 
 * 
 *     @staticmethod             # <<<<<<<<<<<<<<
 *     def from_psl(psl_line):
 *         """Create a |SegmentChain| from a line from a `PSL`_ (BLAT) file
 */
  __Pyx_GetNameInClass(__pyx_t_1, (PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain, __pyx_n_s_from_psl); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3473, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain->tp_dict, __pyx_n_s_from_psl, __pyx_t_2) < 0) __PYX_ERR(0, 3473, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_SegmentChain);

  /* "plastid/genomics/roitools.pyx":4459
 * 
 *     @staticmethod
 *     def from_bed(str line, extra_columns=0):             # <<<<<<<<<<<<<<
 *         """Create a |Transcript| from a BED line with 4 or more columns.
 *         `thickstart` and `thickend` columns, if present, are assumed to specify
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7plastid_8genomics_8roitools_10Transcript_29from_bed, NULL, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript->tp_dict, __pyx_n_s_from_bed, __pyx_t_2) < 0) __PYX_ERR(0, 4459, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_Transcript);

  /* "plastid/genomics/roitools.pyx":4458
 *         )
 * 
 *     @staticmethod             # <<<<<<<<<<<<<<
 *     def from_bed(str line, extra_columns=0):
 *         """Create a |Transcript| from a BED line with 4 or more columns.
 */
  __Pyx_GetNameInClass(__pyx_t_2, (PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript, __pyx_n_s_from_bed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript->tp_dict, __pyx_n_s_from_bed, __pyx_t_1) < 0) __PYX_ERR(0, 4459, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_Transcript);

  /* "plastid/genomics/roitools.pyx":4528
 * 
 *     @staticmethod
 *     def from_psl(str psl_line):             # <<<<<<<<<<<<<<
 *         cdef:
 *             Transcript transcript = Transcript()
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7plastid_8genomics_8roitools_10Transcript_31from_psl, NULL, __pyx_n_s_plastid_genomics_roitools); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript->tp_dict, __pyx_n_s_from_psl, __pyx_t_1) < 0) __PYX_ERR(0, 4528, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_Transcript);

  /* "plastid/genomics/roitools.pyx":4527
 *         return chain
 * 
 *     @staticmethod             # <<<<<<<<<<<<<<
 *     def from_psl(str psl_line):
 *         cdef:
 */
  __Pyx_GetNameInClass(__pyx_t_1, (PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript, __pyx_n_s_from_psl); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4527, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7plastid_8genomics_8roitools_Transcript->tp_dict, __pyx_n_s_from_psl, __pyx_t_2) < 0) __PYX_ERR(0, 4528, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_7plastid_8genomics_8roitools_Transcript);

  /* "plastid/genomics/roitools.pyx":1
 * #!/usr/bin/env python             # <<<<<<<<<<<<<<
 * """This module contains classes for representing and manipulating genomic
 * features.
 */
  __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "View.MemoryView":209
 *         info.obj = self
 * 
 *     __pyx_getbuffer = capsule(<void *> &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(array self):
 */
  __pyx_t_2 = __pyx_capsule_create(((void *)(&__pyx_array_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 209, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem((PyObject *)__pyx_array_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_2) < 0) __PYX_ERR(4, 209, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_array_type);

  /* "View.MemoryView":286
 *         return self.name
 * 
 * cdef generic = Enum("<strided and direct or indirect>")             # <<<<<<<<<<<<<<
 * cdef strided = Enum("<strided and direct>") # default
 * cdef indirect = Enum("<strided and indirect>")
 */
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__90, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 286, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_XGOTREF(generic);
  __Pyx_DECREF_SET(generic, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":287
 * 
 * cdef generic = Enum("<strided and direct or indirect>")
 * cdef strided = Enum("<strided and direct>") # default             # <<<<<<<<<<<<<<
 * cdef indirect = Enum("<strided and indirect>")
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__91, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 287, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_XGOTREF(strided);
  __Pyx_DECREF_SET(strided, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":288
 * cdef generic = Enum("<strided and direct or indirect>")
 * cdef strided = Enum("<strided and direct>") # default
 * cdef indirect = Enum("<strided and indirect>")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__92, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 288, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_XGOTREF(indirect);
  __Pyx_DECREF_SET(indirect, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":291
 * 
 * 
 * cdef contiguous = Enum("<contiguous and direct>")             # <<<<<<<<<<<<<<
 * cdef indirect_contiguous = Enum("<contiguous and indirect>")
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__93, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 291, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_XGOTREF(contiguous);
  __Pyx_DECREF_SET(contiguous, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":292
 * 
 * cdef contiguous = Enum("<contiguous and direct>")
 * cdef indirect_contiguous = Enum("<contiguous and indirect>")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__94, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 292, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_XGOTREF(indirect_contiguous);
  __Pyx_DECREF_SET(indirect_contiguous, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":316
 * 
 * DEF THREAD_LOCKS_PREALLOCATED = 8
 * cdef int __pyx_memoryview_thread_locks_used = 0             # <<<<<<<<<<<<<<
 * cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [
 *     PyThread_allocate_lock(),
 */
  __pyx_memoryview_thread_locks_used = 0;

  /* "View.MemoryView":317
 * DEF THREAD_LOCKS_PREALLOCATED = 8
 * cdef int __pyx_memoryview_thread_locks_used = 0
 * cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [             # <<<<<<<<<<<<<<
 *     PyThread_allocate_lock(),
 *     PyThread_allocate_lock(),
 */
  __pyx_t_3[0] = PyThread_allocate_lock();
  __pyx_t_3[1] = PyThread_allocate_lock();
  __pyx_t_3[2] = PyThread_allocate_lock();
  __pyx_t_3[3] = PyThread_allocate_lock();
  __pyx_t_3[4] = PyThread_allocate_lock();
  __pyx_t_3[5] = PyThread_allocate_lock();
  __pyx_t_3[6] = PyThread_allocate_lock();
  __pyx_t_3[7] = PyThread_allocate_lock();
  memcpy(&(__pyx_memoryview_thread_locks[0]), __pyx_t_3, sizeof(__pyx_memoryview_thread_locks[0]) * (8));

  /* "View.MemoryView":549
 *         info.obj = self
 * 
 *     __pyx_getbuffer = capsule(<void *> &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 549, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem((PyObject *)__pyx_memoryview_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_2) < 0) __PYX_ERR(4, 549, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_memoryview_type);

  /* "View.MemoryView":995
 *         return self.from_object
 * 
 *     __pyx_getbuffer = capsule(<void *> &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem((PyObject *)__pyx_memoryviewslice_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_2) < 0) __PYX_ERR(4, 995, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_memoryviewslice_type);

  /* "(tree fragment)":1
 * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15View_dot_MemoryView_1__pyx_unpickle_Enum, NULL, __pyx_n_s_View_MemoryView); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_Enum, __pyx_t_2) < 0) __PYX_ERR(4, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":11
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result.name = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 */

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

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init plastid.genomics.roitools", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_CLEAR(__pyx_m);
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init plastid.genomics.roitools");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  return (__pyx_m != NULL) ? 0 : -1;
  #elif PY_MAJOR_VERSION >= 3
  return __pyx_m;
  #else
  return;
  #endif
}

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

/* PyObjectGetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#endif

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

/* ArgTypeTest */
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    else if (exact) {
        #if PY_MAJOR_VERSION == 2
        if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(__Pyx_TypeCheck(obj, type))) return 1;
    }
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
    return 0;
}

/* PyObjectCall */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = Py_TYPE(func)->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* UnpackUnboundCMethod */
static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
    PyObject *method;
    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
    if (unlikely(!method))
        return -1;
    target->method = method;
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION >= 3
    if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type)))
    #endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
        target->func = descr->d_method->ml_meth;
        target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
    }
#endif
    return 0;
}

/* CallUnboundCMethod0 */
static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_ASSUME_SAFE_MACROS
    args = PyTuple_New(1);
    if (unlikely(!args)) goto bad;
    Py_INCREF(self);
    PyTuple_SET_ITEM(args, 0, self);
#else
    args = PyTuple_Pack(1, self);
    if (unlikely(!args)) goto bad;
#endif
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    Py_DECREF(args);
bad:
    return result;
}

/* py_dict_items */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) {
    if (PY_MAJOR_VERSION >= 3)
        return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_items, d);
    else
        return PyDict_Items(d);
}

/* RaiseTooManyValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

/* RaiseNeedMoreValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

/* IterFinish */
static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_FAST_THREAD_STATE
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

/* UnpackItemEndCheck */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    } else {
        return __Pyx_IterFinish();
    }
    return 0;
}

/* PyObjectFormatAndDecref */
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f) {
    if (unlikely(!s)) return NULL;
    if (likely(PyUnicode_CheckExact(s))) return s;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyString_CheckExact(s))) {
        PyObject *result = PyUnicode_FromEncodedObject(s, NULL, "strict");
        Py_DECREF(s);
        return result;
    }
    #endif
    return __Pyx_PyObject_FormatAndDecref(s, f);
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f) {
    PyObject *result = PyObject_Format(s, f);
    Py_DECREF(s);
    return result;
}

/* JoinPyUnicode */
static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
                                      CYTHON_UNUSED Py_UCS4 max_char) {
#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    PyObject *result_uval;
    int result_ukind;
    Py_ssize_t i, char_pos;
    void *result_udata;
#if CYTHON_PEP393_ENABLED
    result_uval = PyUnicode_New(result_ulength, max_char);
    if (unlikely(!result_uval)) return NULL;
    result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND;
    result_udata = PyUnicode_DATA(result_uval);
#else
    result_uval = PyUnicode_FromUnicode(NULL, result_ulength);
    if (unlikely(!result_uval)) return NULL;
    result_ukind = sizeof(Py_UNICODE);
    result_udata = PyUnicode_AS_UNICODE(result_uval);
#endif
    char_pos = 0;
    for (i=0; i < value_count; i++) {
        int ukind;
        Py_ssize_t ulength;
        void *udata;
        PyObject *uval = PyTuple_GET_ITEM(value_tuple, i);
        if (unlikely(__Pyx_PyUnicode_READY(uval)))
            goto bad;
        ulength = __Pyx_PyUnicode_GET_LENGTH(uval);
        if (unlikely(!ulength))
            continue;
        if (unlikely(char_pos + ulength < 0))
            goto overflow;
        ukind = __Pyx_PyUnicode_KIND(uval);
        udata = __Pyx_PyUnicode_DATA(uval);
        if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) {
            memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind));
        } else {
            #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters)
            _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength);
            #else
            Py_ssize_t j;
            for (j=0; j < ulength; j++) {
                Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j);
                __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar);
            }
            #endif
        }
        char_pos += ulength;
    }
    return result_uval;
overflow:
    PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string");
bad:
    Py_DECREF(result_uval);
    return NULL;
#else
    result_ulength++;
    value_count++;
    return PyUnicode_Join(__pyx_empty_unicode, value_tuple);
#endif
}

/* PyDictVersioning */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
    PyObject **dictptr = NULL;
    Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
    if (offset) {
#if CYTHON_COMPILING_IN_CPYTHON
        dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
#else
        dictptr = _PyObject_GetDictPtr(obj);
#endif
    }
    return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
}
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
        return 0;
    return obj_dict_version == __Pyx_get_object_dict_version(obj);
}
#endif

/* GetModuleGlobalName */
#if CYTHON_USE_DICT_VERSIONS
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
#else
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
#endif
{
    PyObject *result;
#if !CYTHON_AVOID_BORROWED_REFS
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
    result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    } else if (unlikely(PyErr_Occurred())) {
        return NULL;
    }
#else
    result = PyDict_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
#endif
#else
    result = PyObject_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
    PyErr_Clear();
#endif
    return __Pyx_GetBuiltinName(name);
}

/* PyCFunctionFastCall */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
    PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    PyObject *self = PyCFunction_GET_SELF(func);
    int flags = PyCFunction_GET_FLAGS(func);
    assert(PyCFunction_Check(func));
    assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)));
    assert(nargs >= 0);
    assert(nargs == 0 || args != NULL);
    /* _PyCFunction_FastCallDict() must not be called with an exception set,
       because it may clear it (directly or indirectly) and so the
       caller loses its exception */
    assert(!PyErr_Occurred());
    if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
        return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL);
    } else {
        return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs);
    }
}
#endif

/* PyFunctionFastCall */
#if CYTHON_FAST_PYCALL
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
                                               PyObject *globals) {
    PyFrameObject *f;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject **fastlocals;
    Py_ssize_t i;
    PyObject *result;
    assert(globals != NULL);
    /* XXX Perhaps we should create a specialized
       PyFrame_New() that doesn't take locals, but does
       take builtins without sanity checking them.
       */
    assert(tstate != NULL);
    f = PyFrame_New(tstate, co, globals, NULL);
    if (f == NULL) {
        return NULL;
    }
    fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
    for (i = 0; i < na; i++) {
        Py_INCREF(*args);
        fastlocals[i] = *args++;
    }
    result = PyEval_EvalFrameEx(f,0);
    ++tstate->recursion_depth;
    Py_DECREF(f);
    --tstate->recursion_depth;
    return result;
}
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) {
    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
    PyObject *globals = PyFunction_GET_GLOBALS(func);
    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
    PyObject *closure;
#if PY_MAJOR_VERSION >= 3
    PyObject *kwdefs;
#endif
    PyObject *kwtuple, **k;
    PyObject **d;
    Py_ssize_t nd;
    Py_ssize_t nk;
    PyObject *result;
    assert(kwargs == NULL || PyDict_Check(kwargs));
    nk = kwargs ? PyDict_Size(kwargs) : 0;
    if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
        return NULL;
    }
    if (
#if PY_MAJOR_VERSION >= 3
            co->co_kwonlyargcount == 0 &&
#endif
            likely(kwargs == NULL || nk == 0) &&
            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
        if (argdefs == NULL && co->co_argcount == nargs) {
            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
            goto done;
        }
        else if (nargs == 0 && argdefs != NULL
                 && co->co_argcount == Py_SIZE(argdefs)) {
            /* function called with no arguments, but all parameters have
               a default value: use default values as arguments .*/
            args = &PyTuple_GET_ITEM(argdefs, 0);
            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
            goto done;
        }
    }
    if (kwargs != NULL) {
        Py_ssize_t pos, i;
        kwtuple = PyTuple_New(2 * nk);
        if (kwtuple == NULL) {
            result = NULL;
            goto done;
        }
        k = &PyTuple_GET_ITEM(kwtuple, 0);
        pos = i = 0;
        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i / 2;
    }
    else {
        kwtuple = NULL;
        k = NULL;
    }
    closure = PyFunction_GET_CLOSURE(func);
#if PY_MAJOR_VERSION >= 3
    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
#endif
    if (argdefs != NULL) {
        d = &PyTuple_GET_ITEM(argdefs, 0);
        nd = Py_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }
#if PY_MAJOR_VERSION >= 3
    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
#else
    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, closure);
#endif
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif
#endif

/* PyObjectCall2Args */
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
    PyObject *args, *result = NULL;
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(function)) {
        PyObject *args[2] = {arg1, arg2};
        return __Pyx_PyFunction_FastCall(function, args, 2);
    }
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(function)) {
        PyObject *args[2] = {arg1, arg2};
        return __Pyx_PyCFunction_FastCall(function, args, 2);
    }
    #endif
    args = PyTuple_New(2);
    if (unlikely(!args)) goto done;
    Py_INCREF(arg1);
    PyTuple_SET_ITEM(args, 0, arg1);
    Py_INCREF(arg2);
    PyTuple_SET_ITEM(args, 1, arg2);
    Py_INCREF(function);
    result = __Pyx_PyObject_Call(function, args, NULL);
    Py_DECREF(args);
    Py_DECREF(function);
done:
    return result;
}

/* PyObjectCallMethO */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallOneArg */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, &arg, 1);
    }
#endif
    if (likely(PyCFunction_Check(func))) {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
#if CYTHON_FAST_PYCCALL
        } else if (__Pyx_PyFastCFunction_Check(func)) {
            return __Pyx_PyCFunction_FastCall(func, &arg, 1);
#endif
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

/* PyObjectCallNoArg */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, NULL, 0);
    }
#endif
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func)))
#else
    if (likely(PyCFunction_Check(func)))
#endif
    {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

/* GetItemInt */
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyList_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyTuple_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return NULL;
                    PyErr_Clear();
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

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

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

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

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

/* SetItemInt */
static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
    int r;
    if (!j) return -1;
    r = PyObject_SetItem(o, j, v);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list,
                                               CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = (!wraparound) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o));
        if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o)))) {
            PyObject* old = PyList_GET_ITEM(o, n);
            Py_INCREF(v);
            PyList_SET_ITEM(o, n, v);
            Py_DECREF(old);
            return 1;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_ass_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return -1;
                    PyErr_Clear();
                }
            }
            return m->sq_ass_item(o, i, v);
        }
    }
#else
#if CYTHON_COMPILING_IN_PYPY
    if (is_list || (PySequence_Check(o) && !PyDict_Check(o)))
#else
    if (is_list || PySequence_Check(o))
#endif
    {
        return PySequence_SetItem(o, i, v);
    }
#endif
    return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v);
}

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a - b);
            if (likely((x^a) >= 0 || (x^~b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
            }
        }
                x = a - b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla - llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("subtract", return NULL)
            result = ((double)a) - (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
}
#endif

/* GetTopmostException */
#if CYTHON_USE_EXC_INFO_STACK
static _PyErr_StackItem *
__Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
{
    _PyErr_StackItem *exc_info = tstate->exc_info;
    while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
           exc_info->previous_item != NULL)
    {
        exc_info = exc_info->previous_item;
    }
    return exc_info;
}
#endif

/* SaveResetException */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
    *type = exc_info->exc_type;
    *value = exc_info->exc_value;
    *tb = exc_info->exc_traceback;
    #else
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    #endif
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = tstate->exc_info;
    tmp_type = exc_info->exc_type;
    tmp_value = exc_info->exc_value;
    tmp_tb = exc_info->exc_traceback;
    exc_info->exc_type = type;
    exc_info->exc_value = value;
    exc_info->exc_traceback = tb;
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
#endif

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

/* CIntToDigits */
static const char DIGIT_PAIRS_10[2*10*10+1] = {
    "00010203040506070809"
    "10111213141516171819"
    "20212223242526272829"
    "30313233343536373839"
    "40414243444546474849"
    "50515253545556575859"
    "60616263646566676869"
    "70717273747576777879"
    "80818283848586878889"
    "90919293949596979899"
};
static const char DIGIT_PAIRS_8[2*8*8+1] = {
    "0001020304050607"
    "1011121314151617"
    "2021222324252627"
    "3031323334353637"
    "4041424344454647"
    "5051525354555657"
    "6061626364656667"
    "7071727374757677"
};
static const char DIGITS_HEX[2*16+1] = {
    "0123456789abcdef"
    "0123456789ABCDEF"
};

/* BuildPyUnicode */
static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength,
                                                int prepend_sign, char padding_char) {
    PyObject *uval;
    Py_ssize_t uoffset = ulength - clength;
#if CYTHON_USE_UNICODE_INTERNALS
    Py_ssize_t i;
#if CYTHON_PEP393_ENABLED
    void *udata;
    uval = PyUnicode_New(ulength, 127);
    if (unlikely(!uval)) return NULL;
    udata = PyUnicode_DATA(uval);
#else
    Py_UNICODE *udata;
    uval = PyUnicode_FromUnicode(NULL, ulength);
    if (unlikely(!uval)) return NULL;
    udata = PyUnicode_AS_UNICODE(uval);
#endif
    if (uoffset > 0) {
        i = 0;
        if (prepend_sign) {
            __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-');
            i++;
        }
        for (; i < uoffset; i++) {
            __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char);
        }
    }
    for (i=0; i < clength; i++) {
        __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]);
    }
#else
    {
        PyObject *sign = NULL, *padding = NULL;
        uval = NULL;
        if (uoffset > 0) {
            prepend_sign = !!prepend_sign;
            if (uoffset > prepend_sign) {
                padding = PyUnicode_FromOrdinal(padding_char);
                if (likely(padding) && uoffset > prepend_sign + 1) {
                    PyObject *tmp;
                    PyObject *repeat = PyInt_FromSize_t(uoffset - prepend_sign);
                    if (unlikely(!repeat)) goto done_or_error;
                    tmp = PyNumber_Multiply(padding, repeat);
                    Py_DECREF(repeat);
                    Py_DECREF(padding);
                    padding = tmp;
                }
                if (unlikely(!padding)) goto done_or_error;
            }
            if (prepend_sign) {
                sign = PyUnicode_FromOrdinal('-');
                if (unlikely(!sign)) goto done_or_error;
            }
        }
        uval = PyUnicode_DecodeASCII(chars, clength, NULL);
        if (likely(uval) && padding) {
            PyObject *tmp = PyNumber_Add(padding, uval);
            Py_DECREF(uval);
            uval = tmp;
        }
        if (likely(uval) && sign) {
            PyObject *tmp = PyNumber_Add(sign, uval);
            Py_DECREF(uval);
            uval = tmp;
        }
done_or_error:
        Py_XDECREF(padding);
        Py_XDECREF(sign);
    }
#endif
    return uval;
}

/* CIntToPyUnicode */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_int(int value, Py_ssize_t width, char padding_char, char format_char) {
    char digits[sizeof(int)*3+2];
    char *dpos, *end = digits + sizeof(int)*3+2;
    const char *hex_digits = DIGITS_HEX;
    Py_ssize_t length, ulength;
    int prepend_sign, last_one_off;
    int remaining;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (format_char == 'X') {
        hex_digits += 16;
        format_char = 'x';
    }
    remaining = value;
    last_one_off = 0;
    dpos = end;
    do {
        int digit_pos;
        switch (format_char) {
        case 'o':
            digit_pos = abs((int)(remaining % (8*8)));
            remaining = (int) (remaining / (8*8));
            dpos -= 2;
            memcpy(dpos, DIGIT_PAIRS_8 + digit_pos * 2, 2);
            last_one_off = (digit_pos < 8);
            break;
        case 'd':
            digit_pos = abs((int)(remaining % (10*10)));
            remaining = (int) (remaining / (10*10));
            dpos -= 2;
            memcpy(dpos, DIGIT_PAIRS_10 + digit_pos * 2, 2);
            last_one_off = (digit_pos < 10);
            break;
        case 'x':
            *(--dpos) = hex_digits[abs((int)(remaining % 16))];
            remaining = (int) (remaining / 16);
            break;
        default:
            assert(0);
            break;
        }
    } while (unlikely(remaining != 0));
    if (last_one_off) {
        assert(*dpos == '0');
        dpos++;
    }
    length = end - dpos;
    ulength = length;
    prepend_sign = 0;
    if (!is_unsigned && value <= neg_one) {
        if (padding_char == ' ' || width <= length + 1) {
            *(--dpos) = '-';
            ++length;
        } else {
            prepend_sign = 1;
        }
        ++ulength;
    }
    if (width > ulength) {
        ulength = width;
    }
    if (ulength == 1) {
        return PyUnicode_FromOrdinal(*dpos);
    }
    return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char);
}

/* PyErrFetchRestore */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}
#endif

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

/* PyUnicode_Unicode */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Unicode(PyObject *obj) {
    if (unlikely(obj == Py_None))
        obj = __pyx_kp_u_None;
    return __Pyx_NewRef(obj);
}

/* CIntToPyUnicode */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_long(long value, Py_ssize_t width, char padding_char, char format_char) {
    char digits[sizeof(long)*3+2];
    char *dpos, *end = digits + sizeof(long)*3+2;
    const char *hex_digits = DIGITS_HEX;
    Py_ssize_t length, ulength;
    int prepend_sign, last_one_off;
    long remaining;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (format_char == 'X') {
        hex_digits += 16;
        format_char = 'x';
    }
    remaining = value;
    last_one_off = 0;
    dpos = end;
    do {
        int digit_pos;
        switch (format_char) {
        case 'o':
            digit_pos = abs((int)(remaining % (8*8)));
            remaining = (long) (remaining / (8*8));
            dpos -= 2;
            memcpy(dpos, DIGIT_PAIRS_8 + digit_pos * 2, 2);
            last_one_off = (digit_pos < 8);
            break;
        case 'd':
            digit_pos = abs((int)(remaining % (10*10)));
            remaining = (long) (remaining / (10*10));
            dpos -= 2;
            memcpy(dpos, DIGIT_PAIRS_10 + digit_pos * 2, 2);
            last_one_off = (digit_pos < 10);
            break;
        case 'x':
            *(--dpos) = hex_digits[abs((int)(remaining % 16))];
            remaining = (long) (remaining / 16);
            break;
        default:
            assert(0);
            break;
        }
    } while (unlikely(remaining != 0));
    if (last_one_off) {
        assert(*dpos == '0');
        dpos++;
    }
    length = end - dpos;
    ulength = length;
    prepend_sign = 0;
    if (!is_unsigned && value <= neg_one) {
        if (padding_char == ' ' || width <= length + 1) {
            *(--dpos) = '-';
            ++length;
        } else {
            prepend_sign = 1;
        }
        ++ulength;
    }
    if (width > ulength) {
        ulength = width;
    }
    if (ulength == 1) {
        return PyUnicode_FromOrdinal(*dpos);
    }
    return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char);
}

/* PyObjectGetMethod */
static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) {
    PyObject *attr;
#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP
    PyTypeObject *tp = Py_TYPE(obj);
    PyObject *descr;
    descrgetfunc f = NULL;
    PyObject **dictptr, *dict;
    int meth_found = 0;
    assert (*method == NULL);
    if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) {
        attr = __Pyx_PyObject_GetAttrStr(obj, name);
        goto try_unpack;
    }
    if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) {
        return 0;
    }
    descr = _PyType_Lookup(tp, name);
    if (likely(descr != NULL)) {
        Py_INCREF(descr);
#if PY_MAJOR_VERSION >= 3
        #ifdef __Pyx_CyFunction_USED
        if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr)))
        #else
        if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type)))
        #endif
#else
        #ifdef __Pyx_CyFunction_USED
        if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr)))
        #else
        if (likely(PyFunction_Check(descr)))
        #endif
#endif
        {
            meth_found = 1;
        } else {
            f = Py_TYPE(descr)->tp_descr_get;
            if (f != NULL && PyDescr_IsData(descr)) {
                attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
                Py_DECREF(descr);
                goto try_unpack;
            }
        }
    }
    dictptr = _PyObject_GetDictPtr(obj);
    if (dictptr != NULL && (dict = *dictptr) != NULL) {
        Py_INCREF(dict);
        attr = __Pyx_PyDict_GetItemStr(dict, name);
        if (attr != NULL) {
            Py_INCREF(attr);
            Py_DECREF(dict);
            Py_XDECREF(descr);
            goto try_unpack;
        }
        Py_DECREF(dict);
    }
    if (meth_found) {
        *method = descr;
        return 1;
    }
    if (f != NULL) {
        attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
        Py_DECREF(descr);
        goto try_unpack;
    }
    if (descr != NULL) {
        *method = descr;
        return 0;
    }
    PyErr_Format(PyExc_AttributeError,
#if PY_MAJOR_VERSION >= 3
                 "'%.50s' object has no attribute '%U'",
                 tp->tp_name, name);
#else
                 "'%.50s' object has no attribute '%.400s'",
                 tp->tp_name, PyString_AS_STRING(name));
#endif
    return 0;
#else
    attr = __Pyx_PyObject_GetAttrStr(obj, name);
    goto try_unpack;
#endif
try_unpack:
#if CYTHON_UNPACK_METHODS
    if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) {
        PyObject *function = PyMethod_GET_FUNCTION(attr);
        Py_INCREF(function);
        Py_DECREF(attr);
        *method = function;
        return 1;
    }
#endif
    *method = attr;
    return 0;
}

/* PyObjectCallMethod0 */
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
    PyObject *method = NULL, *result = NULL;
    int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
    if (likely(is_method)) {
        result = __Pyx_PyObject_CallOneArg(method, obj);
        Py_DECREF(method);
        return result;
    }
    if (unlikely(!method)) goto bad;
    result = __Pyx_PyObject_CallNoArg(method);
    Py_DECREF(method);
bad:
    return result;
}

/* RaiseNoneIterError */
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

/* UnpackTupleError */
static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
    if (t == Py_None) {
      __Pyx_RaiseNoneNotIterableError();
    } else if (PyTuple_GET_SIZE(t) < index) {
      __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
    } else {
      __Pyx_RaiseTooManyValuesError(index);
    }
}

/* UnpackTuple2 */
static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
        PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) {
    PyObject *value1 = NULL, *value2 = NULL;
#if CYTHON_COMPILING_IN_PYPY
    value1 = PySequence_ITEM(tuple, 0);  if (unlikely(!value1)) goto bad;
    value2 = PySequence_ITEM(tuple, 1);  if (unlikely(!value2)) goto bad;
#else
    value1 = PyTuple_GET_ITEM(tuple, 0);  Py_INCREF(value1);
    value2 = PyTuple_GET_ITEM(tuple, 1);  Py_INCREF(value2);
#endif
    if (decref_tuple) {
        Py_DECREF(tuple);
    }
    *pvalue1 = value1;
    *pvalue2 = value2;
    return 0;
#if CYTHON_COMPILING_IN_PYPY
bad:
    Py_XDECREF(value1);
    Py_XDECREF(value2);
    if (decref_tuple) { Py_XDECREF(tuple); }
    return -1;
#endif
}
static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2,
                                       int has_known_size, int decref_tuple) {
    Py_ssize_t index;
    PyObject *value1 = NULL, *value2 = NULL, *iter = NULL;
    iternextfunc iternext;
    iter = PyObject_GetIter(tuple);
    if (unlikely(!iter)) goto bad;
    if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; }
    iternext = Py_TYPE(iter)->tp_iternext;
    value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; }
    value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; }
    if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad;
    Py_DECREF(iter);
    *pvalue1 = value1;
    *pvalue2 = value2;
    return 0;
unpacking_failed:
    if (!has_known_size && __Pyx_IterFinish() == 0)
        __Pyx_RaiseNeedMoreValuesError(index);
bad:
    Py_XDECREF(iter);
    Py_XDECREF(value1);
    Py_XDECREF(value2);
    if (decref_tuple) { Py_XDECREF(tuple); }
    return -1;
}

/* dict_iter */
static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name,
                                                   Py_ssize_t* p_orig_length, int* p_source_is_dict) {
    is_dict = is_dict || likely(PyDict_CheckExact(iterable));
    *p_source_is_dict = is_dict;
    if (is_dict) {
#if !CYTHON_COMPILING_IN_PYPY
        *p_orig_length = PyDict_Size(iterable);
        Py_INCREF(iterable);
        return iterable;
#elif PY_MAJOR_VERSION >= 3
        static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL;
        PyObject **pp = NULL;
        if (method_name) {
            const char *name = PyUnicode_AsUTF8(method_name);
            if (strcmp(name, "iteritems") == 0) pp = &py_items;
            else if (strcmp(name, "iterkeys") == 0) pp = &py_keys;
            else if (strcmp(name, "itervalues") == 0) pp = &py_values;
            if (pp) {
                if (!*pp) {
                    *pp = PyUnicode_FromString(name + 4);
                    if (!*pp)
                        return NULL;
                }
                method_name = *pp;
            }
        }
#endif
    }
    *p_orig_length = 0;
    if (method_name) {
        PyObject* iter;
        iterable = __Pyx_PyObject_CallMethod0(iterable, method_name);
        if (!iterable)
            return NULL;
#if !CYTHON_COMPILING_IN_PYPY
        if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable))
            return iterable;
#endif
        iter = PyObject_GetIter(iterable);
        Py_DECREF(iterable);
        return iter;
    }
    return PyObject_GetIter(iterable);
}
static CYTHON_INLINE int __Pyx_dict_iter_next(
        PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos,
        PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) {
    PyObject* next_item;
#if !CYTHON_COMPILING_IN_PYPY
    if (source_is_dict) {
        PyObject *key, *value;
        if (unlikely(orig_length != PyDict_Size(iter_obj))) {
            PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration");
            return -1;
        }
        if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) {
            return 0;
        }
        if (pitem) {
            PyObject* tuple = PyTuple_New(2);
            if (unlikely(!tuple)) {
                return -1;
            }
            Py_INCREF(key);
            Py_INCREF(value);
            PyTuple_SET_ITEM(tuple, 0, key);
            PyTuple_SET_ITEM(tuple, 1, value);
            *pitem = tuple;
        } else {
            if (pkey) {
                Py_INCREF(key);
                *pkey = key;
            }
            if (pvalue) {
                Py_INCREF(value);
                *pvalue = value;
            }
        }
        return 1;
    } else if (PyTuple_CheckExact(iter_obj)) {
        Py_ssize_t pos = *ppos;
        if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0;
        *ppos = pos + 1;
        next_item = PyTuple_GET_ITEM(iter_obj, pos);
        Py_INCREF(next_item);
    } else if (PyList_CheckExact(iter_obj)) {
        Py_ssize_t pos = *ppos;
        if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0;
        *ppos = pos + 1;
        next_item = PyList_GET_ITEM(iter_obj, pos);
        Py_INCREF(next_item);
    } else
#endif
    {
        next_item = PyIter_Next(iter_obj);
        if (unlikely(!next_item)) {
            return __Pyx_IterFinish();
        }
    }
    if (pitem) {
        *pitem = next_item;
    } else if (pkey && pvalue) {
        if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1))
            return -1;
    } else if (pkey) {
        *pkey = next_item;
    } else {
        *pvalue = next_item;
    }
    return 1;
}

/* DictGetItem */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
    PyObject *value;
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (!PyErr_Occurred()) {
            if (unlikely(PyTuple_Check(key))) {
                PyObject* args = PyTuple_Pack(1, key);
                if (likely(args)) {
                    PyErr_SetObject(PyExc_KeyError, args);
                    Py_DECREF(args);
                }
            } else {
                PyErr_SetObject(PyExc_KeyError, key);
            }
        }
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#endif

/* PyErrExceptionMatches */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
    PyObject *exc_type = tstate->curexc_type;
    if (exc_type == err) return 1;
    if (unlikely(!exc_type)) return 0;
    if (unlikely(PyTuple_Check(err)))
        return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
    return __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
}
#endif

/* CallUnboundCMethod1 */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) {
    if (likely(cfunc->func)) {
        int flag = cfunc->flag;
        if (flag == METH_O) {
            return (*(cfunc->func))(self, arg);
        } else if (PY_VERSION_HEX >= 0x030600B1 && flag == METH_FASTCALL) {
            if (PY_VERSION_HEX >= 0x030700A0) {
                return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, &arg, 1);
            } else {
                return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
            }
        } else if (PY_VERSION_HEX >= 0x030700A0 && flag == (METH_FASTCALL | METH_KEYWORDS)) {
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
        }
    }
    return __Pyx__CallUnboundCMethod1(cfunc, self, arg);
}
#endif
static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_COMPILING_IN_CPYTHON
    if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
        args = PyTuple_New(1);
        if (unlikely(!args)) goto bad;
        Py_INCREF(arg);
        PyTuple_SET_ITEM(args, 0, arg);
        if (cfunc->flag & METH_KEYWORDS)
            result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
        else
            result = (*cfunc->func)(self, args);
    } else {
        args = PyTuple_New(2);
        if (unlikely(!args)) goto bad;
        Py_INCREF(self);
        PyTuple_SET_ITEM(args, 0, self);
        Py_INCREF(arg);
        PyTuple_SET_ITEM(args, 1, arg);
        result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    }
#else
    args = PyTuple_Pack(2, self, arg);
    if (unlikely(!args)) goto bad;
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
#endif
bad:
    Py_XDECREF(args);
    return result;
}

/* PyIntCompare */
static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) {
    if (op1 == op2) {
        Py_RETURN_TRUE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a == b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        int unequal;
        unsigned long uintval;
        Py_ssize_t size = Py_SIZE(op1);
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        if (intval == 0) {
            if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
        } else if (intval < 0) {
            if (size >= 0)
                Py_RETURN_FALSE;
            intval = -intval;
            size = -size;
        } else {
            if (size <= 0)
                Py_RETURN_FALSE;
        }
        uintval = (unsigned long) intval;
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 4)) {
            unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 3)) {
            unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 2)) {
            unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 1)) {
            unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
            unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
        if (unequal == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
        if ((double)a == (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    return (
        PyObject_RichCompare(op1, op2, Py_EQ));
}

/* ObjectGetItem */
#if CYTHON_USE_TYPE_SLOTS
static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) {
    PyObject *runerr;
    Py_ssize_t key_value;
    PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence;
    if (unlikely(!(m && m->sq_item))) {
        PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name);
        return NULL;
    }
    key_value = __Pyx_PyIndex_AsSsize_t(index);
    if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
        return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
    }
    if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
        PyErr_Clear();
        PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name);
    }
    return NULL;
}
static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) {
    PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping;
    if (likely(m && m->mp_subscript)) {
        return m->mp_subscript(obj, key);
    }
    return __Pyx_PyObject_GetIndex(obj, key);
}
#endif

/* CallUnboundCMethod2 */
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2) {
    if (likely(cfunc->func)) {
        PyObject *args[2] = {arg1, arg2};
        if (cfunc->flag == METH_FASTCALL) {
            #if PY_VERSION_HEX >= 0x030700A0
            return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, args, 2);
            #else
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
            #endif
        }
        #if PY_VERSION_HEX >= 0x030700A0
        if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS))
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
        #endif
    }
    return __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2);
}
#endif
static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2){
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_COMPILING_IN_CPYTHON
    if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
        args = PyTuple_New(2);
        if (unlikely(!args)) goto bad;
        Py_INCREF(arg1);
        PyTuple_SET_ITEM(args, 0, arg1);
        Py_INCREF(arg2);
        PyTuple_SET_ITEM(args, 1, arg2);
        if (cfunc->flag & METH_KEYWORDS)
            result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
        else
            result = (*cfunc->func)(self, args);
    } else {
        args = PyTuple_New(3);
        if (unlikely(!args)) goto bad;
        Py_INCREF(self);
        PyTuple_SET_ITEM(args, 0, self);
        Py_INCREF(arg1);
        PyTuple_SET_ITEM(args, 1, arg1);
        Py_INCREF(arg2);
        PyTuple_SET_ITEM(args, 2, arg2);
        result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    }
#else
    args = PyTuple_Pack(3, self, arg1, arg2);
    if (unlikely(!args)) goto bad;
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
#endif
bad:
    Py_XDECREF(args);
    return result;
}

/* py_dict_pop */
static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX > 0x030600B3
    if ((1)) {
        return _PyDict_Pop(d, key, default_value);
    } else
#endif
    if (default_value) {
        return __Pyx_CallUnboundCMethod2(&__pyx_umethod_PyDict_Type_pop, d, key, default_value);
    } else {
        return __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_pop, d, key);
    }
}

/* WriteUnraisableException */
static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_PyThreadState_declare
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
#ifdef _MSC_VER
    else state = (PyGILState_STATE)-1;
#endif
#endif
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

/* BytesEquals */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result;
#if CYTHON_USE_UNICODE_INTERNALS
            Py_hash_t hash1, hash2;
            hash1 = ((PyBytesObject*)s1)->ob_shash;
            hash2 = ((PyBytesObject*)s2)->ob_shash;
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                return (equals == Py_NE);
            }
#endif
            result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

/* UnicodeEquals */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
#if PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
#if CYTHON_USE_UNICODE_INTERNALS
        {
            Py_hash_t hash1, hash2;
        #if CYTHON_PEP393_ENABLED
            hash1 = ((PyASCIIObject*)s1)->hash;
            hash2 = ((PyASCIIObject*)s2)->hash;
        #else
            hash1 = ((PyUnicodeObject*)s1)->hash;
            hash2 = ((PyUnicodeObject*)s2)->hash;
        #endif
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                goto return_ne;
            }
        }
#endif
        kind = __Pyx_PyUnicode_KIND(s1);
        if (kind != __Pyx_PyUnicode_KIND(s2)) {
            goto return_ne;
        }
        data1 = __Pyx_PyUnicode_DATA(s1);
        data2 = __Pyx_PyUnicode_DATA(s2);
        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
            goto return_ne;
        } else if (length == 1) {
            goto return_eq;
        } else {
            int result = memcmp(data1, data2, (size_t)(length * kind));
            #if PY_MAJOR_VERSION < 3
            Py_XDECREF(owned_ref);
            #endif
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & s2_is_unicode) {
        goto return_ne;
    } else if ((s2 == Py_None) & s1_is_unicode) {
        goto return_ne;
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        #if PY_MAJOR_VERSION < 3
        Py_XDECREF(owned_ref);
        #endif
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
return_eq:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_EQ);
return_ne:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_NE);
#endif
}

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

/* BufferIndexError */
static void __Pyx_RaiseBufferIndexError(int axis) {
  PyErr_Format(PyExc_IndexError,
     "Out of bounds on buffer access (axis %d)", axis);
}

/* MemviewSliceInit */
static int
__Pyx_init_memviewslice(struct __pyx_memoryview_obj *memview,
                        int ndim,
                        __Pyx_memviewslice *memviewslice,
                        int memview_is_new_reference)
{
    __Pyx_RefNannyDeclarations
    int i, retval=-1;
    Py_buffer *buf = &memview->view;
    __Pyx_RefNannySetupContext("init_memviewslice", 0);
    if (unlikely(memviewslice->memview || memviewslice->data)) {
        PyErr_SetString(PyExc_ValueError,
            "memviewslice is already initialized!");
        goto fail;
    }
    if (buf->strides) {
        for (i = 0; i < ndim; i++) {
            memviewslice->strides[i] = buf->strides[i];
        }
    } else {
        Py_ssize_t stride = buf->itemsize;
        for (i = ndim - 1; i >= 0; i--) {
            memviewslice->strides[i] = stride;
            stride *= buf->shape[i];
        }
    }
    for (i = 0; i < ndim; i++) {
        memviewslice->shape[i]   = buf->shape[i];
        if (buf->suboffsets) {
            memviewslice->suboffsets[i] = buf->suboffsets[i];
        } else {
            memviewslice->suboffsets[i] = -1;
        }
    }
    memviewslice->memview = memview;
    memviewslice->data = (char *)buf->buf;
    if (__pyx_add_acquisition_count(memview) == 0 && !memview_is_new_reference) {
        Py_INCREF(memview);
    }
    retval = 0;
    goto no_fail;
fail:
    memviewslice->memview = 0;
    memviewslice->data = 0;
    retval = -1;
no_fail:
    __Pyx_RefNannyFinishContext();
    return retval;
}
#ifndef Py_NO_RETURN
#define Py_NO_RETURN
#endif
static void __pyx_fatalerror(const char *fmt, ...) Py_NO_RETURN {
    va_list vargs;
    char msg[200];
#ifdef HAVE_STDARG_PROTOTYPES
    va_start(vargs, fmt);
#else
    va_start(vargs);
#endif
    vsnprintf(msg, 200, fmt, vargs);
    va_end(vargs);
    Py_FatalError(msg);
}
static CYTHON_INLINE int
__pyx_add_acquisition_count_locked(__pyx_atomic_int *acquisition_count,
                                   PyThread_type_lock lock)
{
    int result;
    PyThread_acquire_lock(lock, 1);
    result = (*acquisition_count)++;
    PyThread_release_lock(lock);
    return result;
}
static CYTHON_INLINE int
__pyx_sub_acquisition_count_locked(__pyx_atomic_int *acquisition_count,
                                   PyThread_type_lock lock)
{
    int result;
    PyThread_acquire_lock(lock, 1);
    result = (*acquisition_count)--;
    PyThread_release_lock(lock);
    return result;
}
static CYTHON_INLINE void
__Pyx_INC_MEMVIEW(__Pyx_memviewslice *memslice, int have_gil, int lineno)
{
    int first_time;
    struct __pyx_memoryview_obj *memview = memslice->memview;
    if (unlikely(!memview || (PyObject *) memview == Py_None))
        return;
    if (unlikely(__pyx_get_slice_count(memview) < 0))
        __pyx_fatalerror("Acquisition count is %d (line %d)",
                         __pyx_get_slice_count(memview), lineno);
    first_time = __pyx_add_acquisition_count(memview) == 0;
    if (unlikely(first_time)) {
        if (have_gil) {
            Py_INCREF((PyObject *) memview);
        } else {
            PyGILState_STATE _gilstate = PyGILState_Ensure();
            Py_INCREF((PyObject *) memview);
            PyGILState_Release(_gilstate);
        }
    }
}
static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *memslice,
                                             int have_gil, int lineno) {
    int last_time;
    struct __pyx_memoryview_obj *memview = memslice->memview;
    if (unlikely(!memview || (PyObject *) memview == Py_None)) {
        memslice->memview = NULL;
        return;
    }
    if (unlikely(__pyx_get_slice_count(memview) <= 0))
        __pyx_fatalerror("Acquisition count is %d (line %d)",
                         __pyx_get_slice_count(memview), lineno);
    last_time = __pyx_sub_acquisition_count(memview) == 1;
    memslice->data = NULL;
    if (unlikely(last_time)) {
        if (have_gil) {
            Py_CLEAR(memslice->memview);
        } else {
            PyGILState_STATE _gilstate = PyGILState_Ensure();
            Py_CLEAR(memslice->memview);
            PyGILState_Release(_gilstate);
        }
    } else {
        memslice->memview = NULL;
    }
}

/* CIntToPyUnicode */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_Py_ssize_t(Py_ssize_t value, Py_ssize_t width, char padding_char, char format_char) {
    char digits[sizeof(Py_ssize_t)*3+2];
    char *dpos, *end = digits + sizeof(Py_ssize_t)*3+2;
    const char *hex_digits = DIGITS_HEX;
    Py_ssize_t length, ulength;
    int prepend_sign, last_one_off;
    Py_ssize_t remaining;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const Py_ssize_t neg_one = (Py_ssize_t) -1, const_zero = (Py_ssize_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (format_char == 'X') {
        hex_digits += 16;
        format_char = 'x';
    }
    remaining = value;
    last_one_off = 0;
    dpos = end;
    do {
        int digit_pos;
        switch (format_char) {
        case 'o':
            digit_pos = abs((int)(remaining % (8*8)));
            remaining = (Py_ssize_t) (remaining / (8*8));
            dpos -= 2;
            memcpy(dpos, DIGIT_PAIRS_8 + digit_pos * 2, 2);
            last_one_off = (digit_pos < 8);
            break;
        case 'd':
            digit_pos = abs((int)(remaining % (10*10)));
            remaining = (Py_ssize_t) (remaining / (10*10));
            dpos -= 2;
            memcpy(dpos, DIGIT_PAIRS_10 + digit_pos * 2, 2);
            last_one_off = (digit_pos < 10);
            break;
        case 'x':
            *(--dpos) = hex_digits[abs((int)(remaining % 16))];
            remaining = (Py_ssize_t) (remaining / 16);
            break;
        default:
            assert(0);
            break;
        }
    } while (unlikely(remaining != 0));
    if (last_one_off) {
        assert(*dpos == '0');
        dpos++;
    }
    length = end - dpos;
    ulength = length;
    prepend_sign = 0;
    if (!is_unsigned && value <= neg_one) {
        if (padding_char == ' ' || width <= length + 1) {
            *(--dpos) = '-';
            ++length;
        } else {
            prepend_sign = 1;
        }
        ++ulength;
    }
    if (width > ulength) {
        ulength = width;
    }
    if (ulength == 1) {
        return PyUnicode_FromOrdinal(*dpos);
    }
    return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char);
}

/* IterNext */
static PyObject *__Pyx_PyIter_Next2Default(PyObject* defval) {
    PyObject* exc_type;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    exc_type = __Pyx_PyErr_Occurred();
    if (unlikely(exc_type)) {
        if (!defval || unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))
            return NULL;
        __Pyx_PyErr_Clear();
        Py_INCREF(defval);
        return defval;
    }
    if (defval) {
        Py_INCREF(defval);
        return defval;
    }
    __Pyx_PyErr_SetNone(PyExc_StopIteration);
    return NULL;
}
static void __Pyx_PyIter_Next_ErrorNoIterator(PyObject *iterator) {
    PyErr_Format(PyExc_TypeError,
        "%.200s object is not an iterator", Py_TYPE(iterator)->tp_name);
}
static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject* defval) {
    PyObject* next;
    iternextfunc iternext = Py_TYPE(iterator)->tp_iternext;
    if (likely(iternext)) {
#if CYTHON_USE_TYPE_SLOTS
        next = iternext(iterator);
        if (likely(next))
            return next;
        #if PY_VERSION_HEX >= 0x02070000
        if (unlikely(iternext == &_PyObject_NextNotImplemented))
            return NULL;
        #endif
#else
        next = PyIter_Next(iterator);
        if (likely(next))
            return next;
#endif
    } else if (CYTHON_USE_TYPE_SLOTS || unlikely(!PyIter_Check(iterator))) {
        __Pyx_PyIter_Next_ErrorNoIterator(iterator);
        return NULL;
    }
#if !CYTHON_USE_TYPE_SLOTS
    else {
        next = PyIter_Next(iterator);
        if (likely(next))
            return next;
    }
#endif
    return __Pyx_PyIter_Next2Default(defval);
}

/* SliceTupleAndList */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop, Py_ssize_t* _length) {
    Py_ssize_t start = *_start, stop = *_stop, length = *_length;
    if (start < 0) {
        start += length;
        if (start < 0)
            start = 0;
    }
    if (stop < 0)
        stop += length;
    else if (stop > length)
        stop = length;
    *_length = stop - start;
    *_start = start;
    *_stop = stop;
}
static CYTHON_INLINE void __Pyx_copy_object_array(PyObject** CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) {
    PyObject *v;
    Py_ssize_t i;
    for (i = 0; i < length; i++) {
        v = dest[i] = src[i];
        Py_INCREF(v);
    }
}
static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(
            PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
    PyObject* dest;
    Py_ssize_t length = PyList_GET_SIZE(src);
    __Pyx_crop_slice(&start, &stop, &length);
    if (unlikely(length <= 0))
        return PyList_New(0);
    dest = PyList_New(length);
    if (unlikely(!dest))
        return NULL;
    __Pyx_copy_object_array(
        ((PyListObject*)src)->ob_item + start,
        ((PyListObject*)dest)->ob_item,
        length);
    return dest;
}
static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(
            PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
    PyObject* dest;
    Py_ssize_t length = PyTuple_GET_SIZE(src);
    __Pyx_crop_slice(&start, &stop, &length);
    if (unlikely(length <= 0))
        return PyTuple_New(0);
    dest = PyTuple_New(length);
    if (unlikely(!dest))
        return NULL;
    __Pyx_copy_object_array(
        ((PyTupleObject*)src)->ob_item + start,
        ((PyTupleObject*)dest)->ob_item,
        length);
    return dest;
}
#endif

/* IsLittleEndian */
static CYTHON_INLINE int __Pyx_Is_Little_Endian(void)
{
  union {
    uint32_t u32;
    uint8_t u8[4];
  } S;
  S.u32 = 0x01020304;
  return S.u8[0] == 4;
}

/* BufferFormatCheck */
static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
                              __Pyx_BufFmt_StackElem* stack,
                              __Pyx_TypeInfo* type) {
  stack[0].field = &ctx->root;
  stack[0].parent_offset = 0;
  ctx->root.type = type;
  ctx->root.name = "buffer dtype";
  ctx->root.offset = 0;
  ctx->head = stack;
  ctx->head->field = &ctx->root;
  ctx->fmt_offset = 0;
  ctx->head->parent_offset = 0;
  ctx->new_packmode = '@';
  ctx->enc_packmode = '@';
  ctx->new_count = 1;
  ctx->enc_count = 0;
  ctx->enc_type = 0;
  ctx->is_complex = 0;
  ctx->is_valid_array = 0;
  ctx->struct_alignment = 0;
  while (type->typegroup == 'S') {
    ++ctx->head;
    ctx->head->field = type->fields;
    ctx->head->parent_offset = 0;
    type = type->fields->type;
  }
}
static int __Pyx_BufFmt_ParseNumber(const char** ts) {
    int count;
    const char* t = *ts;
    if (*t < '0' || *t > '9') {
      return -1;
    } else {
        count = *t++ - '0';
        while (*t >= '0' && *t <= '9') {
            count *= 10;
            count += *t++ - '0';
        }
    }
    *ts = t;
    return count;
}
static int __Pyx_BufFmt_ExpectNumber(const char **ts) {
    int number = __Pyx_BufFmt_ParseNumber(ts);
    if (number == -1)
        PyErr_Format(PyExc_ValueError,\
                     "Does not understand character buffer dtype format string ('%c')", **ts);
    return number;
}
static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) {
  PyErr_Format(PyExc_ValueError,
               "Unexpected format string character: '%c'", ch);
}
static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) {
  switch (ch) {
    case '?': return "'bool'";
    case 'c': return "'char'";
    case 'b': return "'signed char'";
    case 'B': return "'unsigned char'";
    case 'h': return "'short'";
    case 'H': return "'unsigned short'";
    case 'i': return "'int'";
    case 'I': return "'unsigned int'";
    case 'l': return "'long'";
    case 'L': return "'unsigned long'";
    case 'q': return "'long long'";
    case 'Q': return "'unsigned long long'";
    case 'f': return (is_complex ? "'complex float'" : "'float'");
    case 'd': return (is_complex ? "'complex double'" : "'double'");
    case 'g': return (is_complex ? "'complex long double'" : "'long double'");
    case 'T': return "a struct";
    case 'O': return "Python object";
    case 'P': return "a pointer";
    case 's': case 'p': return "a string";
    case 0: return "end";
    default: return "unparseable format string";
  }
}
static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return 2;
    case 'i': case 'I': case 'l': case 'L': return 4;
    case 'q': case 'Q': return 8;
    case 'f': return (is_complex ? 8 : 4);
    case 'd': return (is_complex ? 16 : 8);
    case 'g': {
      PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g')..");
      return 0;
    }
    case 'O': case 'P': return sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(short);
    case 'i': case 'I': return sizeof(int);
    case 'l': case 'L': return sizeof(long);
    #ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(PY_LONG_LONG);
    #endif
    case 'f': return sizeof(float) * (is_complex ? 2 : 1);
    case 'd': return sizeof(double) * (is_complex ? 2 : 1);
    case 'g': return sizeof(long double) * (is_complex ? 2 : 1);
    case 'O': case 'P': return sizeof(void*);
    default: {
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
  }
}
typedef struct { char c; short x; } __Pyx_st_short;
typedef struct { char c; int x; } __Pyx_st_int;
typedef struct { char c; long x; } __Pyx_st_long;
typedef struct { char c; float x; } __Pyx_st_float;
typedef struct { char c; double x; } __Pyx_st_double;
typedef struct { char c; long double x; } __Pyx_st_longdouble;
typedef struct { char c; void *x; } __Pyx_st_void_p;
#ifdef HAVE_LONG_LONG
typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong;
#endif
static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, CYTHON_UNUSED int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short);
    case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int);
    case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long);
#ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG);
#endif
    case 'f': return sizeof(__Pyx_st_float) - sizeof(float);
    case 'd': return sizeof(__Pyx_st_double) - sizeof(double);
    case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double);
    case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
/* These are for computing the padding at the end of the struct to align
   on the first member of the struct. This will probably the same as above,
   but we don't have any guarantees.
 */
typedef struct { short x; char c; } __Pyx_pad_short;
typedef struct { int x; char c; } __Pyx_pad_int;
typedef struct { long x; char c; } __Pyx_pad_long;
typedef struct { float x; char c; } __Pyx_pad_float;
typedef struct { double x; char c; } __Pyx_pad_double;
typedef struct { long double x; char c; } __Pyx_pad_longdouble;
typedef struct { void *x; char c; } __Pyx_pad_void_p;
#ifdef HAVE_LONG_LONG
typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong;
#endif
static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, CYTHON_UNUSED int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(__Pyx_pad_short) - sizeof(short);
    case 'i': case 'I': return sizeof(__Pyx_pad_int) - sizeof(int);
    case 'l': case 'L': return sizeof(__Pyx_pad_long) - sizeof(long);
#ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(__Pyx_pad_longlong) - sizeof(PY_LONG_LONG);
#endif
    case 'f': return sizeof(__Pyx_pad_float) - sizeof(float);
    case 'd': return sizeof(__Pyx_pad_double) - sizeof(double);
    case 'g': return sizeof(__Pyx_pad_longdouble) - sizeof(long double);
    case 'P': case 'O': return sizeof(__Pyx_pad_void_p) - sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) {
  switch (ch) {
    case 'c':
        return 'H';
    case 'b': case 'h': case 'i':
    case 'l': case 'q': case 's': case 'p':
        return 'I';
    case '?': case 'B': case 'H': case 'I': case 'L': case 'Q':
        return 'U';
    case 'f': case 'd': case 'g':
        return (is_complex ? 'C' : 'R');
    case 'O':
        return 'O';
    case 'P':
        return 'P';
    default: {
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
  }
}
static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) {
  if (ctx->head == NULL || ctx->head->field == &ctx->root) {
    const char* expected;
    const char* quote;
    if (ctx->head == NULL) {
      expected = "end";
      quote = "";
    } else {
      expected = ctx->head->field->type->name;
      quote = "'";
    }
    PyErr_Format(PyExc_ValueError,
                 "Buffer dtype mismatch, expected %s%s%s but got %s",
                 quote, expected, quote,
                 __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex));
  } else {
    __Pyx_StructField* field = ctx->head->field;
    __Pyx_StructField* parent = (ctx->head - 1)->field;
    PyErr_Format(PyExc_ValueError,
                 "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'",
                 field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex),
                 parent->type->name, field->name);
  }
}
static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) {
  char group;
  size_t size, offset, arraysize = 1;
  if (ctx->enc_type == 0) return 0;
  if (ctx->head->field->type->arraysize[0]) {
    int i, ndim = 0;
    if (ctx->enc_type == 's' || ctx->enc_type == 'p') {
        ctx->is_valid_array = ctx->head->field->type->ndim == 1;
        ndim = 1;
        if (ctx->enc_count != ctx->head->field->type->arraysize[0]) {
            PyErr_Format(PyExc_ValueError,
                         "Expected a dimension of size %zu, got %zu",
                         ctx->head->field->type->arraysize[0], ctx->enc_count);
            return -1;
        }
    }
    if (!ctx->is_valid_array) {
      PyErr_Format(PyExc_ValueError, "Expected %d dimensions, got %d",
                   ctx->head->field->type->ndim, ndim);
      return -1;
    }
    for (i = 0; i < ctx->head->field->type->ndim; i++) {
      arraysize *= ctx->head->field->type->arraysize[i];
    }
    ctx->is_valid_array = 0;
    ctx->enc_count = 1;
  }
  group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex);
  do {
    __Pyx_StructField* field = ctx->head->field;
    __Pyx_TypeInfo* type = field->type;
    if (ctx->enc_packmode == '@' || ctx->enc_packmode == '^') {
      size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex);
    } else {
      size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex);
    }
    if (ctx->enc_packmode == '@') {
      size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex);
      size_t align_mod_offset;
      if (align_at == 0) return -1;
      align_mod_offset = ctx->fmt_offset % align_at;
      if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset;
      if (ctx->struct_alignment == 0)
          ctx->struct_alignment = __Pyx_BufFmt_TypeCharToPadding(ctx->enc_type,
                                                                 ctx->is_complex);
    }
    if (type->size != size || type->typegroup != group) {
      if (type->typegroup == 'C' && type->fields != NULL) {
        size_t parent_offset = ctx->head->parent_offset + field->offset;
        ++ctx->head;
        ctx->head->field = type->fields;
        ctx->head->parent_offset = parent_offset;
        continue;
      }
      if ((type->typegroup == 'H' || group == 'H') && type->size == size) {
      } else {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return -1;
      }
    }
    offset = ctx->head->parent_offset + field->offset;
    if (ctx->fmt_offset != offset) {
      PyErr_Format(PyExc_ValueError,
                   "Buffer dtype mismatch; next field is at offset %" CYTHON_FORMAT_SSIZE_T "d but %" CYTHON_FORMAT_SSIZE_T "d expected",
                   (Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset);
      return -1;
    }
    ctx->fmt_offset += size;
    if (arraysize)
      ctx->fmt_offset += (arraysize - 1) * size;
    --ctx->enc_count;
    while (1) {
      if (field == &ctx->root) {
        ctx->head = NULL;
        if (ctx->enc_count != 0) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return -1;
        }
        break;
      }
      ctx->head->field = ++field;
      if (field->type == NULL) {
        --ctx->head;
        field = ctx->head->field;
        continue;
      } else if (field->type->typegroup == 'S') {
        size_t parent_offset = ctx->head->parent_offset + field->offset;
        if (field->type->fields->type == NULL) continue;
        field = field->type->fields;
        ++ctx->head;
        ctx->head->field = field;
        ctx->head->parent_offset = parent_offset;
        break;
      } else {
        break;
      }
    }
  } while (ctx->enc_count);
  ctx->enc_type = 0;
  ctx->is_complex = 0;
  return 0;
}
static PyObject *
__pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp)
{
    const char *ts = *tsp;
    int i = 0, number, ndim;
    ++ts;
    if (ctx->new_count != 1) {
        PyErr_SetString(PyExc_ValueError,
                        "Cannot handle repeated arrays in format string");
        return NULL;
    }
    if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
    ndim = ctx->head->field->type->ndim;
    while (*ts && *ts != ')') {
        switch (*ts) {
            case ' ': case '\f': case '\r': case '\n': case '\t': case '\v':  continue;
            default:  break;
        }
        number = __Pyx_BufFmt_ExpectNumber(&ts);
        if (number == -1) return NULL;
        if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i])
            return PyErr_Format(PyExc_ValueError,
                        "Expected a dimension of size %zu, got %d",
                        ctx->head->field->type->arraysize[i], number);
        if (*ts != ',' && *ts != ')')
            return PyErr_Format(PyExc_ValueError,
                                "Expected a comma in format string, got '%c'", *ts);
        if (*ts == ',') ts++;
        i++;
    }
    if (i != ndim)
        return PyErr_Format(PyExc_ValueError, "Expected %d dimension(s), got %d",
                            ctx->head->field->type->ndim, i);
    if (!*ts) {
        PyErr_SetString(PyExc_ValueError,
                        "Unexpected end of format string, expected ')'");
        return NULL;
    }
    ctx->is_valid_array = 1;
    ctx->new_count = 1;
    *tsp = ++ts;
    return Py_None;
}
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) {
  int got_Z = 0;
  while (1) {
    switch(*ts) {
      case 0:
        if (ctx->enc_type != 0 && ctx->head == NULL) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return NULL;
        }
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        if (ctx->head != NULL) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return NULL;
        }
        return ts;
      case ' ':
      case '\r':
      case '\n':
        ++ts;
        break;
      case '<':
        if (!__Pyx_Is_Little_Endian()) {
          PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '>':
      case '!':
        if (__Pyx_Is_Little_Endian()) {
          PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '=':
      case '@':
      case '^':
        ctx->new_packmode = *ts++;
        break;
      case 'T':
        {
          const char* ts_after_sub;
          size_t i, struct_count = ctx->new_count;
          size_t struct_alignment = ctx->struct_alignment;
          ctx->new_count = 1;
          ++ts;
          if (*ts != '{') {
            PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'");
            return NULL;
          }
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0;
          ctx->enc_count = 0;
          ctx->struct_alignment = 0;
          ++ts;
          ts_after_sub = ts;
          for (i = 0; i != struct_count; ++i) {
            ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts);
            if (!ts_after_sub) return NULL;
          }
          ts = ts_after_sub;
          if (struct_alignment) ctx->struct_alignment = struct_alignment;
        }
        break;
      case '}':
        {
          size_t alignment = ctx->struct_alignment;
          ++ts;
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0;
          if (alignment && ctx->fmt_offset % alignment) {
            ctx->fmt_offset += alignment - (ctx->fmt_offset % alignment);
          }
        }
        return ts;
      case 'x':
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        ctx->fmt_offset += ctx->new_count;
        ctx->new_count = 1;
        ctx->enc_count = 0;
        ctx->enc_type = 0;
        ctx->enc_packmode = ctx->new_packmode;
        ++ts;
        break;
      case 'Z':
        got_Z = 1;
        ++ts;
        if (*ts != 'f' && *ts != 'd' && *ts != 'g') {
          __Pyx_BufFmt_RaiseUnexpectedChar('Z');
          return NULL;
        }
        CYTHON_FALLTHROUGH;
      case '?': case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I':
      case 'l': case 'L': case 'q': case 'Q':
      case 'f': case 'd': case 'g':
      case 'O': case 'p':
        if ((ctx->enc_type == *ts) && (got_Z == ctx->is_complex) &&
            (ctx->enc_packmode == ctx->new_packmode) && (!ctx->is_valid_array)) {
          ctx->enc_count += ctx->new_count;
          ctx->new_count = 1;
          got_Z = 0;
          ++ts;
          break;
        }
        CYTHON_FALLTHROUGH;
      case 's':
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        ctx->enc_count = ctx->new_count;
        ctx->enc_packmode = ctx->new_packmode;
        ctx->enc_type = *ts;
        ctx->is_complex = got_Z;
        ++ts;
        ctx->new_count = 1;
        got_Z = 0;
        break;
      case ':':
        ++ts;
        while(*ts != ':') ++ts;
        ++ts;
        break;
      case '(':
        if (!__pyx_buffmt_parse_array(ctx, &ts)) return NULL;
        break;
      default:
        {
          int number = __Pyx_BufFmt_ExpectNumber(&ts);
          if (number == -1) return NULL;
          ctx->new_count = (size_t)number;
        }
    }
  }
}

/* BufferGetAndValidate */
  static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
  if (unlikely(info->buf == NULL)) return;
  if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL;
  __Pyx_ReleaseBuffer(info);
}
static void __Pyx_ZeroBuffer(Py_buffer* buf) {
  buf->buf = NULL;
  buf->obj = NULL;
  buf->strides = __Pyx_zeros;
  buf->shape = __Pyx_zeros;
  buf->suboffsets = __Pyx_minusones;
}
static int __Pyx__GetBufferAndValidate(
        Py_buffer* buf, PyObject* obj,  __Pyx_TypeInfo* dtype, int flags,
        int nd, int cast, __Pyx_BufFmt_StackElem* stack)
{
  buf->buf = NULL;
  if (unlikely(__Pyx_GetBuffer(obj, buf, flags) == -1)) {
    __Pyx_ZeroBuffer(buf);
    return -1;
  }
  if (unlikely(buf->ndim != nd)) {
    PyErr_Format(PyExc_ValueError,
                 "Buffer has wrong number of dimensions (expected %d, got %d)",
                 nd, buf->ndim);
    goto fail;
  }
  if (!cast) {
    __Pyx_BufFmt_Context ctx;
    __Pyx_BufFmt_Init(&ctx, stack, dtype);
    if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail;
  }
  if (unlikely((size_t)buf->itemsize != dtype->size)) {
    PyErr_Format(PyExc_ValueError,
      "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)",
      buf->itemsize, (buf->itemsize > 1) ? "s" : "",
      dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : "");
    goto fail;
  }
  if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones;
  return 0;
fail:;
  __Pyx_SafeReleaseBuffer(buf);
  return -1;
}

/* BufferFallbackError */
  static void __Pyx_RaiseBufferFallbackError(void) {
  PyErr_SetString(PyExc_ValueError,
     "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!");
}

/* dict_getitem_default */
  static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
    PyObject* value;
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (unlikely(PyErr_Occurred()))
            return NULL;
        value = default_value;
    }
    Py_INCREF(value);
    if ((1));
#else
    if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) {
        value = PyDict_GetItem(d, key);
        if (unlikely(!value)) {
            value = default_value;
        }
        Py_INCREF(value);
    }
#endif
    else {
        if (default_value == Py_None)
            value = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_get, d, key);
        else
            value = __Pyx_CallUnboundCMethod2(&__pyx_umethod_PyDict_Type_get, d, key, default_value);
    }
    return value;
}

/* None */
  static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

/* ModInt[long] */
  static CYTHON_INLINE long __Pyx_mod_long(long a, long b) {
    long r = a % b;
    r += ((r != 0) & ((r ^ b) < 0)) * b;
    return r;
}

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

/* SliceObject */
  static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
        Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
#if CYTHON_USE_TYPE_SLOTS
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                    goto bad;
                PyErr_Clear();
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#endif
    {
        PyObject* result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_USE_TYPE_SLOTS
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
bad:
    return NULL;
}

/* GetItemIntUnicode */
  static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Fast(PyObject* ustring, Py_ssize_t i,
                                                           int wraparound, int boundscheck) {
    Py_ssize_t length;
    if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return (Py_UCS4)-1;
    if (wraparound | boundscheck) {
        length = __Pyx_PyUnicode_GET_LENGTH(ustring);
        if (wraparound & unlikely(i < 0)) i += length;
        if ((!boundscheck) || likely(__Pyx_is_valid_index(i, length))) {
            return __Pyx_PyUnicode_READ_CHAR(ustring, i);
        } else {
            PyErr_SetString(PyExc_IndexError, "string index out of range");
            return (Py_UCS4)-1;
        }
    } else {
        return __Pyx_PyUnicode_READ_CHAR(ustring, i);
    }
}

/* PyUnicode_Substring */
  static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Substring(
            PyObject* text, Py_ssize_t start, Py_ssize_t stop) {
    Py_ssize_t length;
    if (unlikely(__Pyx_PyUnicode_READY(text) == -1)) return NULL;
    length = __Pyx_PyUnicode_GET_LENGTH(text);
    if (start < 0) {
        start += length;
        if (start < 0)
            start = 0;
    }
    if (stop < 0)
        stop += length;
    else if (stop > length)
        stop = length;
    if (stop <= start)
        return __Pyx_NewRef(__pyx_empty_unicode);
#if CYTHON_PEP393_ENABLED
    return PyUnicode_FromKindAndData(PyUnicode_KIND(text),
        PyUnicode_1BYTE_DATA(text) + start*PyUnicode_KIND(text), stop-start);
#else
    return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(text)+start, stop-start);
#endif
}

/* MergeKeywords */
  static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping) {
    PyObject *iter, *key = NULL, *value = NULL;
    int source_is_dict, result;
    Py_ssize_t orig_length, ppos = 0;
    iter = __Pyx_dict_iterator(source_mapping, 0, __pyx_n_s_items, &orig_length, &source_is_dict);
    if (unlikely(!iter)) {
        PyObject *args;
        if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
        PyErr_Clear();
        args = PyTuple_Pack(1, source_mapping);
        if (likely(args)) {
            PyObject *fallback = PyObject_Call((PyObject*)&PyDict_Type, args, NULL);
            Py_DECREF(args);
            if (likely(fallback)) {
                iter = __Pyx_dict_iterator(fallback, 1, __pyx_n_s_items, &orig_length, &source_is_dict);
                Py_DECREF(fallback);
            }
        }
        if (unlikely(!iter)) goto bad;
    }
    while (1) {
        result = __Pyx_dict_iter_next(iter, orig_length, &ppos, &key, &value, NULL, source_is_dict);
        if (unlikely(result < 0)) goto bad;
        if (!result) break;
        if (unlikely(PyDict_Contains(kwdict, key))) {
            __Pyx_RaiseDoubleKeywordsError("function", key);
            result = -1;
        } else {
            result = PyDict_SetItem(kwdict, key, value);
        }
        Py_DECREF(key);
        Py_DECREF(value);
        if (unlikely(result < 0)) goto bad;
    }
    Py_XDECREF(iter);
    return 0;
bad:
    Py_XDECREF(iter);
    return -1;
}

/* DivInt[Py_ssize_t] */
  static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t a, Py_ssize_t b) {
    Py_ssize_t q = a / b;
    Py_ssize_t r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

/* GetAttr */
  static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
#if CYTHON_USE_TYPE_SLOTS
#if PY_MAJOR_VERSION >= 3
    if (likely(PyUnicode_Check(n)))
#else
    if (likely(PyString_Check(n)))
#endif
        return __Pyx_PyObject_GetAttrStr(o, n);
#endif
    return PyObject_GetAttr(o, n);
}

/* decode_c_string */
  static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
         const char* cstring, Py_ssize_t start, Py_ssize_t stop,
         const char* encoding, const char* errors,
         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
    Py_ssize_t length;
    if (unlikely((start < 0) | (stop < 0))) {
        size_t slen = strlen(cstring);
        if (unlikely(slen > (size_t) PY_SSIZE_T_MAX)) {
            PyErr_SetString(PyExc_OverflowError,
                            "c-string too long to convert to Python");
            return NULL;
        }
        length = (Py_ssize_t) slen;
        if (start < 0) {
            start += length;
            if (start < 0)
                start = 0;
        }
        if (stop < 0)
            stop += length;
    }
    if (unlikely(stop <= start))
        return __Pyx_NewRef(__pyx_empty_unicode);
    length = stop - start;
    cstring += start;
    if (decode_func) {
        return decode_func(cstring, length, errors);
    } else {
        return PyUnicode_Decode(cstring, length, encoding, errors);
    }
}

/* GetAttr3 */
  static PyObject *__Pyx_GetAttr3Default(PyObject *d) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        return NULL;
    __Pyx_PyErr_Clear();
    Py_INCREF(d);
    return d;
}
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) {
    PyObject *r = __Pyx_GetAttr(o, n);
    return (likely(r)) ? r : __Pyx_GetAttr3Default(d);
}

/* SwapException */
  #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = tstate->exc_info;
    tmp_type = exc_info->exc_type;
    tmp_value = exc_info->exc_value;
    tmp_tb = exc_info->exc_traceback;
    exc_info->exc_type = *type;
    exc_info->exc_value = *value;
    exc_info->exc_traceback = *tb;
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = *type;
    tstate->exc_value = *value;
    tstate->exc_traceback = *tb;
    #endif
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
    PyErr_SetExcInfo(*type, *value, *tb);
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}
#endif

/* Import */
  static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) {
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_MAJOR_VERSION < 3
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

/* FastTypeChecks */
  #if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
    while (a) {
        a = a->tp_base;
        if (a == b)
            return 1;
    }
    return b == &PyBaseObject_Type;
}
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
    PyObject *mro;
    if (a == b) return 1;
    mro = a->tp_mro;
    if (likely(mro)) {
        Py_ssize_t i, n;
        n = PyTuple_GET_SIZE(mro);
        for (i = 0; i < n; i++) {
            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
                return 1;
        }
        return 0;
    }
    return __Pyx_InBases(a, b);
}
#if PY_MAJOR_VERSION == 2
static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
    PyObject *exception, *value, *tb;
    int res;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&exception, &value, &tb);
    res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
    if (unlikely(res == -1)) {
        PyErr_WriteUnraisable(err);
        res = 0;
    }
    if (!res) {
        res = PyObject_IsSubclass(err, exc_type2);
        if (unlikely(res == -1)) {
            PyErr_WriteUnraisable(err);
            res = 0;
        }
    }
    __Pyx_ErrRestore(exception, value, tb);
    return res;
}
#else
static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
    int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
    if (!res) {
        res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
    }
    return res;
}
#endif
static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    assert(PyExceptionClass_Check(exc_type));
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        PyObject *t = PyTuple_GET_ITEM(tuple, i);
        #if PY_MAJOR_VERSION < 3
        if (likely(exc_type == t)) return 1;
        #endif
        if (likely(PyExceptionClass_Check(t))) {
            if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
        } else {
        }
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
    if (likely(err == exc_type)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        if (likely(PyExceptionClass_Check(exc_type))) {
            return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
        } else if (likely(PyTuple_Check(exc_type))) {
            return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
        } else {
        }
    }
    return PyErr_GivenExceptionMatches(err, exc_type);
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
    assert(PyExceptionClass_Check(exc_type1));
    assert(PyExceptionClass_Check(exc_type2));
    if (likely(err == exc_type1 || err == exc_type2)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
    }
    return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
}
#endif

/* DivInt[long] */
  static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
    long q = a / b;
    long r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

/* ImportFrom */
  static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

/* HasAttr */
  static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
    PyObject *r;
    if (unlikely(!__Pyx_PyBaseString_Check(n))) {
        PyErr_SetString(PyExc_TypeError,
                        "hasattr(): attribute name must be string");
        return -1;
    }
    r = __Pyx_GetAttr(o, n);
    if (unlikely(!r)) {
        PyErr_Clear();
        return 0;
    } else {
        Py_DECREF(r);
        return 1;
    }
}

/* PyObject_GenericGetAttrNoDict */
  #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) {
    PyErr_Format(PyExc_AttributeError,
#if PY_MAJOR_VERSION >= 3
                 "'%.50s' object has no attribute '%U'",
                 tp->tp_name, attr_name);
#else
                 "'%.50s' object has no attribute '%.400s'",
                 tp->tp_name, PyString_AS_STRING(attr_name));
#endif
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
    PyObject *descr;
    PyTypeObject *tp = Py_TYPE(obj);
    if (unlikely(!PyString_Check(attr_name))) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    assert(!tp->tp_dictoffset);
    descr = _PyType_Lookup(tp, attr_name);
    if (unlikely(!descr)) {
        return __Pyx_RaiseGenericGetAttributeError(tp, attr_name);
    }
    Py_INCREF(descr);
    #if PY_MAJOR_VERSION < 3
    if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
    #endif
    {
        descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
        if (unlikely(f)) {
            PyObject *res = f(descr, obj, (PyObject *)tp);
            Py_DECREF(descr);
            return res;
        }
    }
    return descr;
}
#endif

/* PyObject_GenericGetAttr */
  #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) {
    if (unlikely(Py_TYPE(obj)->tp_dictoffset)) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name);
}
#endif

/* SetVTable */
  static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

/* PyObjectGetAttrStrNoError */
  static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        __Pyx_PyErr_Clear();
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) {
        return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1);
    }
#endif
    result = __Pyx_PyObject_GetAttrStr(obj, attr_name);
    if (unlikely(!result)) {
        __Pyx_PyObject_GetAttrStr_ClearAttributeError();
    }
    return result;
}

/* SetupReduce */
  static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
  int ret;
  PyObject *name_attr;
  name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name);
  if (likely(name_attr)) {
      ret = PyObject_RichCompareBool(name_attr, name, Py_EQ);
  } else {
      ret = -1;
  }
  if (unlikely(ret < 0)) {
      PyErr_Clear();
      ret = 0;
  }
  Py_XDECREF(name_attr);
  return ret;
}
static int __Pyx_setup_reduce(PyObject* type_obj) {
    int ret = 0;
    PyObject *object_reduce = NULL;
    PyObject *object_reduce_ex = NULL;
    PyObject *reduce = NULL;
    PyObject *reduce_ex = NULL;
    PyObject *reduce_cython = NULL;
    PyObject *setstate = NULL;
    PyObject *setstate_cython = NULL;
#if CYTHON_USE_PYTYPE_LOOKUP
    if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD;
#else
    if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD;
#endif
#if CYTHON_USE_PYTYPE_LOOKUP
    object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD;
#else
    object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD;
#endif
    reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD;
    if (reduce_ex == object_reduce_ex) {
#if CYTHON_USE_PYTYPE_LOOKUP
        object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD;
#else
        object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD;
#endif
        reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD;
        if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) {
            reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython);
            if (likely(reduce_cython)) {
                ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
            } else if (reduce == object_reduce || PyErr_Occurred()) {
                goto __PYX_BAD;
            }
            setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate);
            if (!setstate) PyErr_Clear();
            if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) {
                setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython);
                if (likely(setstate_cython)) {
                    ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                    ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                } else if (!setstate || PyErr_Occurred()) {
                    goto __PYX_BAD;
                }
            }
            PyType_Modified((PyTypeObject*)type_obj);
        }
    }
    goto __PYX_GOOD;
__PYX_BAD:
    if (!PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name);
    ret = -1;
__PYX_GOOD:
#if !CYTHON_USE_PYTYPE_LOOKUP
    Py_XDECREF(object_reduce);
    Py_XDECREF(object_reduce_ex);
#endif
    Py_XDECREF(reduce);
    Py_XDECREF(reduce_ex);
    Py_XDECREF(reduce_cython);
    Py_XDECREF(setstate);
    Py_XDECREF(setstate_cython);
    return ret;
}

/* TypeImport */
  #ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name,
    size_t size, enum __Pyx_ImportType_CheckSize check_size)
{
    PyObject *result = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    result = PyObject_GetAttrString(module, class_name);
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if ((size_t)basicsize < size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        goto bad;
    }
    if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        goto bad;
    }
    else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(result);
    return NULL;
}
#endif

/* GetNameInClass */
  static PyObject *__Pyx_GetGlobalNameAfterAttributeLookup(PyObject *name) {
    PyObject *result;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        return NULL;
    __Pyx_PyErr_Clear();
    __Pyx_GetModuleGlobalNameUncached(result, name);
    return result;
}
static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name) {
    PyObject *result;
    result = __Pyx_PyObject_GetAttrStr(nmspace, name);
    if (!result) {
        result = __Pyx_GetGlobalNameAfterAttributeLookup(name);
    }
    return result;
}

/* CLineInTraceback */
  #ifndef CYTHON_CLINE_IN_TRACEBACK
static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) {
    PyObject *use_cline;
    PyObject *ptype, *pvalue, *ptraceback;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject **cython_runtime_dict;
#endif
    if (unlikely(!__pyx_cython_runtime)) {
        return c_line;
    }
    __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
#if CYTHON_COMPILING_IN_CPYTHON
    cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
    if (likely(cython_runtime_dict)) {
        __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
            use_cline, *cython_runtime_dict,
            __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
    } else
#endif
    {
      PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
      if (use_cline_obj) {
        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
        Py_DECREF(use_cline_obj);
      } else {
        PyErr_Clear();
        use_cline = NULL;
      }
    }
    if (!use_cline) {
        c_line = 0;
        (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
    }
    else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
        c_line = 0;
    }
    __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
    return c_line;
}
#endif

/* CodeObjectCache */
  static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = start + (end - start) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

/* AddTraceback */
  #include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = NULL;
    PyObject *py_funcname = NULL;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_srcfile = NULL;
    py_srcfile = PyString_FromString(filename);
    if (!py_srcfile) goto bad;
    #endif
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        funcname = PyUnicode_AsUTF8(py_funcname);
        if (!funcname) goto bad;
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        if (!py_funcname) goto bad;
        #endif
    }
    #if PY_MAJOR_VERSION < 3
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    #else
    py_code = PyCode_NewEmpty(filename, funcname, py_line);
    #endif
    Py_XDECREF(py_funcname);  // XDECREF since it's only set on Py3 if cline
    return py_code;
bad:
    Py_XDECREF(py_funcname);
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_srcfile);
    #endif
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    if (c_line) {
        c_line = __Pyx_CLineForTraceback(tstate, c_line);
    }
    py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        tstate,            /*PyThreadState *tstate,*/
        py_code,           /*PyCodeObject *code,*/
        __pyx_d,    /*PyObject *globals,*/
        0                  /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

#if PY_MAJOR_VERSION < 3
static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
    if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags);
        if (__Pyx_TypeCheck(obj, __pyx_ptype_7cpython_5array_array)) return __pyx_pw_7cpython_5array_5array_1__getbuffer__(obj, view, flags);
        if (__Pyx_TypeCheck(obj, __pyx_array_type)) return __pyx_array_getbuffer(obj, view, flags);
        if (__Pyx_TypeCheck(obj, __pyx_memoryview_type)) return __pyx_memoryview_getbuffer(obj, view, flags);
    PyErr_Format(PyExc_TypeError, "'%.200s' does not have the buffer interface", Py_TYPE(obj)->tp_name);
    return -1;
}
static void __Pyx_ReleaseBuffer(Py_buffer *view) {
    PyObject *obj = view->obj;
    if (!obj) return;
    if (PyObject_CheckBuffer(obj)) {
        PyBuffer_Release(view);
        return;
    }
    if ((0)) {}
        else if (__Pyx_TypeCheck(obj, __pyx_ptype_7cpython_5array_array)) __pyx_pw_7cpython_5array_5array_3__releasebuffer__(obj, view);
    view->obj = NULL;
    Py_DECREF(obj);
}
#endif


  /* MemviewSliceIsContig */
  static int
__pyx_memviewslice_is_contig(const __Pyx_memviewslice mvs, char order, int ndim)
{
    int i, index, step, start;
    Py_ssize_t itemsize = mvs.memview->view.itemsize;
    if (order == 'F') {
        step = 1;
        start = 0;
    } else {
        step = -1;
        start = ndim - 1;
    }
    for (i = 0; i < ndim; i++) {
        index = start + step * i;
        if (mvs.suboffsets[index] >= 0 || mvs.strides[index] != itemsize)
            return 0;
        itemsize *= mvs.shape[index];
    }
    return 1;
}

/* OverlappingSlices */
  static void
__pyx_get_array_memory_extents(__Pyx_memviewslice *slice,
                               void **out_start, void **out_end,
                               int ndim, size_t itemsize)
{
    char *start, *end;
    int i;
    start = end = slice->data;
    for (i = 0; i < ndim; i++) {
        Py_ssize_t stride = slice->strides[i];
        Py_ssize_t extent = slice->shape[i];
        if (extent == 0) {
            *out_start = *out_end = start;
            return;
        } else {
            if (stride > 0)
                end += stride * (extent - 1);
            else
                start += stride * (extent - 1);
        }
    }
    *out_start = start;
    *out_end = end + itemsize;
}
static int
__pyx_slices_overlap(__Pyx_memviewslice *slice1,
                     __Pyx_memviewslice *slice2,
                     int ndim, size_t itemsize)
{
    void *start1, *end1, *start2, *end2;
    __pyx_get_array_memory_extents(slice1, &start1, &end1, ndim, itemsize);
    __pyx_get_array_memory_extents(slice2, &start2, &end2, ndim, itemsize);
    return (start1 < end2) && (start2 < end1);
}

/* Capsule */
  static CYTHON_INLINE PyObject *
__pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig)
{
    PyObject *cobj;
#if PY_VERSION_HEX >= 0x02070000
    cobj = PyCapsule_New(p, sig, NULL);
#else
    cobj = PyCObject_FromVoidPtr(p, NULL);
#endif
    return cobj;
}

/* CIntFromPyVerify */
  #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

/* TypeInfoCompare */
  static int
__pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b)
{
    int i;
    if (!a || !b)
        return 0;
    if (a == b)
        return 1;
    if (a->size != b->size || a->typegroup != b->typegroup ||
            a->is_unsigned != b->is_unsigned || a->ndim != b->ndim) {
        if (a->typegroup == 'H' || b->typegroup == 'H') {
            return a->size == b->size;
        } else {
            return 0;
        }
    }
    if (a->ndim) {
        for (i = 0; i < a->ndim; i++)
            if (a->arraysize[i] != b->arraysize[i])
                return 0;
    }
    if (a->typegroup == 'S') {
        if (a->flags != b->flags)
            return 0;
        if (a->fields || b->fields) {
            if (!(a->fields && b->fields))
                return 0;
            for (i = 0; a->fields[i].type && b->fields[i].type; i++) {
                __Pyx_StructField *field_a = a->fields + i;
                __Pyx_StructField *field_b = b->fields + i;
                if (field_a->offset != field_b->offset ||
                    !__pyx_typeinfo_cmp(field_a->type, field_b->type))
                    return 0;
            }
            return !a->fields[i].type && !b->fields[i].type;
        }
    }
    return 1;
}

/* MemviewSliceValidateAndInit */
  static int
__pyx_check_strides(Py_buffer *buf, int dim, int ndim, int spec)
{
    if (buf->shape[dim] <= 1)
        return 1;
    if (buf->strides) {
        if (spec & __Pyx_MEMVIEW_CONTIG) {
            if (spec & (__Pyx_MEMVIEW_PTR|__Pyx_MEMVIEW_FULL)) {
                if (unlikely(buf->strides[dim] != sizeof(void *))) {
                    PyErr_Format(PyExc_ValueError,
                                 "Buffer is not indirectly contiguous "
                                 "in dimension %d.", dim);
                    goto fail;
                }
            } else if (unlikely(buf->strides[dim] != buf->itemsize)) {
                PyErr_SetString(PyExc_ValueError,
                                "Buffer and memoryview are not contiguous "
                                "in the same dimension.");
                goto fail;
            }
        }
        if (spec & __Pyx_MEMVIEW_FOLLOW) {
            Py_ssize_t stride = buf->strides[dim];
            if (stride < 0)
                stride = -stride;
            if (unlikely(stride < buf->itemsize)) {
                PyErr_SetString(PyExc_ValueError,
                                "Buffer and memoryview are not contiguous "
                                "in the same dimension.");
                goto fail;
            }
        }
    } else {
        if (unlikely(spec & __Pyx_MEMVIEW_CONTIG && dim != ndim - 1)) {
            PyErr_Format(PyExc_ValueError,
                         "C-contiguous buffer is not contiguous in "
                         "dimension %d", dim);
            goto fail;
        } else if (unlikely(spec & (__Pyx_MEMVIEW_PTR))) {
            PyErr_Format(PyExc_ValueError,
                         "C-contiguous buffer is not indirect in "
                         "dimension %d", dim);
            goto fail;
        } else if (unlikely(buf->suboffsets)) {
            PyErr_SetString(PyExc_ValueError,
                            "Buffer exposes suboffsets but no strides");
            goto fail;
        }
    }
    return 1;
fail:
    return 0;
}
static int
__pyx_check_suboffsets(Py_buffer *buf, int dim, CYTHON_UNUSED int ndim, int spec)
{
    if (spec & __Pyx_MEMVIEW_DIRECT) {
        if (unlikely(buf->suboffsets && buf->suboffsets[dim] >= 0)) {
            PyErr_Format(PyExc_ValueError,
                         "Buffer not compatible with direct access "
                         "in dimension %d.", dim);
            goto fail;
        }
    }
    if (spec & __Pyx_MEMVIEW_PTR) {
        if (unlikely(!buf->suboffsets || (buf->suboffsets[dim] < 0))) {
            PyErr_Format(PyExc_ValueError,
                         "Buffer is not indirectly accessible "
                         "in dimension %d.", dim);
            goto fail;
        }
    }
    return 1;
fail:
    return 0;
}
static int
__pyx_verify_contig(Py_buffer *buf, int ndim, int c_or_f_flag)
{
    int i;
    if (c_or_f_flag & __Pyx_IS_F_CONTIG) {
        Py_ssize_t stride = 1;
        for (i = 0; i < ndim; i++) {
            if (unlikely(stride * buf->itemsize != buf->strides[i]  &&  buf->shape[i] > 1)) {
                PyErr_SetString(PyExc_ValueError,
                    "Buffer not fortran contiguous.");
                goto fail;
            }
            stride = stride * buf->shape[i];
        }
    } else if (c_or_f_flag & __Pyx_IS_C_CONTIG) {
        Py_ssize_t stride = 1;
        for (i = ndim - 1; i >- 1; i--) {
            if (unlikely(stride * buf->itemsize != buf->strides[i]  &&  buf->shape[i] > 1)) {
                PyErr_SetString(PyExc_ValueError,
                    "Buffer not C contiguous.");
                goto fail;
            }
            stride = stride * buf->shape[i];
        }
    }
    return 1;
fail:
    return 0;
}
static int __Pyx_ValidateAndInit_memviewslice(
                int *axes_specs,
                int c_or_f_flag,
                int buf_flags,
                int ndim,
                __Pyx_TypeInfo *dtype,
                __Pyx_BufFmt_StackElem stack[],
                __Pyx_memviewslice *memviewslice,
                PyObject *original_obj)
{
    struct __pyx_memoryview_obj *memview, *new_memview;
    __Pyx_RefNannyDeclarations
    Py_buffer *buf;
    int i, spec = 0, retval = -1;
    __Pyx_BufFmt_Context ctx;
    int from_memoryview = __pyx_memoryview_check(original_obj);
    __Pyx_RefNannySetupContext("ValidateAndInit_memviewslice", 0);
    if (from_memoryview && __pyx_typeinfo_cmp(dtype, ((struct __pyx_memoryview_obj *)
                                                            original_obj)->typeinfo)) {
        memview = (struct __pyx_memoryview_obj *) original_obj;
        new_memview = NULL;
    } else {
        memview = (struct __pyx_memoryview_obj *) __pyx_memoryview_new(
                                            original_obj, buf_flags, 0, dtype);
        new_memview = memview;
        if (unlikely(!memview))
            goto fail;
    }
    buf = &memview->view;
    if (unlikely(buf->ndim != ndim)) {
        PyErr_Format(PyExc_ValueError,
                "Buffer has wrong number of dimensions (expected %d, got %d)",
                ndim, buf->ndim);
        goto fail;
    }
    if (new_memview) {
        __Pyx_BufFmt_Init(&ctx, stack, dtype);
        if (unlikely(!__Pyx_BufFmt_CheckString(&ctx, buf->format))) goto fail;
    }
    if (unlikely((unsigned) buf->itemsize != dtype->size)) {
        PyErr_Format(PyExc_ValueError,
                     "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "u byte%s) "
                     "does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "u byte%s)",
                     buf->itemsize,
                     (buf->itemsize > 1) ? "s" : "",
                     dtype->name,
                     dtype->size,
                     (dtype->size > 1) ? "s" : "");
        goto fail;
    }
    if (buf->len > 0) {
        for (i = 0; i < ndim; i++) {
            spec = axes_specs[i];
            if (unlikely(!__pyx_check_strides(buf, i, ndim, spec)))
                goto fail;
            if (unlikely(!__pyx_check_suboffsets(buf, i, ndim, spec)))
                goto fail;
        }
        if (unlikely(buf->strides && !__pyx_verify_contig(buf, ndim, c_or_f_flag)))
            goto fail;
    }
    if (unlikely(__Pyx_init_memviewslice(memview, ndim, memviewslice,
                                         new_memview != NULL) == -1)) {
        goto fail;
    }
    retval = 0;
    goto no_fail;
fail:
    Py_XDECREF(new_memview);
    retval = -1;
no_fail:
    __Pyx_RefNannyFinishContext();
    return retval;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_long(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0,
                                                 PyBUF_RECORDS_RO | writable_flag, 1,
                                                 &__Pyx_TypeInfo_long, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_int(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0,
                                                 PyBUF_RECORDS_RO | writable_flag, 1,
                                                 &__Pyx_TypeInfo_int, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* Declarations */
  #if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return ::std::complex< float >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return x + y*(__pyx_t_float_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      __pyx_t_float_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

/* Arithmetic */
  #if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sum_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_diff_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prod_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    #if 1
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quot_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        if (b.imag == 0) {
            return __pyx_t_float_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else if (fabsf(b.real) >= fabsf(b.imag)) {
            if (b.real == 0 && b.imag == 0) {
                return __pyx_t_float_complex_from_parts(a.real / b.real, a.imag / b.imag);
            } else {
                float r = b.imag / b.real;
                float s = (float)(1.0) / (b.real + b.imag * r);
                return __pyx_t_float_complex_from_parts(
                    (a.real + a.imag * r) * s, (a.imag - a.real * r) * s);
            }
        } else {
            float r = b.real / b.imag;
            float s = (float)(1.0) / (b.imag + b.real * r);
            return __pyx_t_float_complex_from_parts(
                (a.real * r + a.imag) * s, (a.imag * r - a.real) * s);
        }
    }
    #else
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quot_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        if (b.imag == 0) {
            return __pyx_t_float_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else {
            float denom = b.real * b.real + b.imag * b.imag;
            return __pyx_t_float_complex_from_parts(
                (a.real * b.real + a.imag * b.imag) / denom,
                (a.imag * b.real - a.real * b.imag) / denom);
        }
    }
    #endif
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_neg_float(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero_float(__pyx_t_float_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conj_float(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE float __Pyx_c_abs_float(__pyx_t_float_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrtf(z.real*z.real + z.imag*z.imag);
          #else
            return hypotf(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_pow_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
            __pyx_t_float_complex z;
            float r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    float denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        return __Pyx_c_prod_float(a, a);
                    case 3:
                        z = __Pyx_c_prod_float(a, a);
                        return __Pyx_c_prod_float(z, a);
                    case 4:
                        z = __Pyx_c_prod_float(a, a);
                        return __Pyx_c_prod_float(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                } else if (b.imag == 0) {
                    z.real = powf(a.real, b.real);
                    z.imag = 0;
                    return z;
                } else if (a.real > 0) {
                    r = a.real;
                    theta = 0;
                } else {
                    r = -a.real;
                    theta = atan2f(0.0, -1.0);
                }
            } else {
                r = __Pyx_c_abs_float(a);
                theta = atan2f(a.imag, a.real);
            }
            lnr = logf(r);
            z_r = expf(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cosf(z_theta);
            z.imag = z_r * sinf(z_theta);
            return z;
        }
    #endif
#endif

/* Declarations */
  #if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return ::std::complex< double >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return x + y*(__pyx_t_double_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      __pyx_t_double_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

/* Arithmetic */
  #if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    #if 1
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        if (b.imag == 0) {
            return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else if (fabs(b.real) >= fabs(b.imag)) {
            if (b.real == 0 && b.imag == 0) {
                return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.imag);
            } else {
                double r = b.imag / b.real;
                double s = (double)(1.0) / (b.real + b.imag * r);
                return __pyx_t_double_complex_from_parts(
                    (a.real + a.imag * r) * s, (a.imag - a.real * r) * s);
            }
        } else {
            double r = b.real / b.imag;
            double s = (double)(1.0) / (b.imag + b.real * r);
            return __pyx_t_double_complex_from_parts(
                (a.real * r + a.imag) * s, (a.imag * r - a.real) * s);
        }
    }
    #else
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        if (b.imag == 0) {
            return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else {
            double denom = b.real * b.real + b.imag * b.imag;
            return __pyx_t_double_complex_from_parts(
                (a.real * b.real + a.imag * b.imag) / denom,
                (a.imag * b.real - a.real * b.imag) / denom);
        }
    }
    #endif
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg_double(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero_double(__pyx_t_double_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj_double(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs_double(__pyx_t_double_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrt(z.real*z.real + z.imag*z.imag);
          #else
            return hypot(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
            __pyx_t_double_complex z;
            double r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    double denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        return __Pyx_c_prod_double(a, a);
                    case 3:
                        z = __Pyx_c_prod_double(a, a);
                        return __Pyx_c_prod_double(z, a);
                    case 4:
                        z = __Pyx_c_prod_double(a, a);
                        return __Pyx_c_prod_double(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                } else if (b.imag == 0) {
                    z.real = pow(a.real, b.real);
                    z.imag = 0;
                    return z;
                } else if (a.real > 0) {
                    r = a.real;
                    theta = 0;
                } else {
                    r = -a.real;
                    theta = atan2(0.0, -1.0);
                }
            } else {
                r = __Pyx_c_abs_double(a);
                theta = atan2(a.imag, a.real);
            }
            lnr = log(r);
            z_r = exp(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cos(z_theta);
            z.imag = z_r * sin(z_theta);
            return z;
        }
    #endif
#endif

/* MemviewSliceCopyTemplate */
  static __Pyx_memviewslice
__pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs,
                                 const char *mode, int ndim,
                                 size_t sizeof_dtype, int contig_flag,
                                 int dtype_is_object)
{
    __Pyx_RefNannyDeclarations
    int i;
    __Pyx_memviewslice new_mvs = { 0, 0, { 0 }, { 0 }, { 0 } };
    struct __pyx_memoryview_obj *from_memview = from_mvs->memview;
    Py_buffer *buf = &from_memview->view;
    PyObject *shape_tuple = NULL;
    PyObject *temp_int = NULL;
    struct __pyx_array_obj *array_obj = NULL;
    struct __pyx_memoryview_obj *memview_obj = NULL;
    __Pyx_RefNannySetupContext("__pyx_memoryview_copy_new_contig", 0);
    for (i = 0; i < ndim; i++) {
        if (unlikely(from_mvs->suboffsets[i] >= 0)) {
            PyErr_Format(PyExc_ValueError, "Cannot copy memoryview slice with "
                                           "indirect dimensions (axis %d)", i);
            goto fail;
        }
    }
    shape_tuple = PyTuple_New(ndim);
    if (unlikely(!shape_tuple)) {
        goto fail;
    }
    __Pyx_GOTREF(shape_tuple);
    for(i = 0; i < ndim; i++) {
        temp_int = PyInt_FromSsize_t(from_mvs->shape[i]);
        if(unlikely(!temp_int)) {
            goto fail;
        } else {
            PyTuple_SET_ITEM(shape_tuple, i, temp_int);
            temp_int = NULL;
        }
    }
    array_obj = __pyx_array_new(shape_tuple, sizeof_dtype, buf->format, (char *) mode, NULL);
    if (unlikely(!array_obj)) {
        goto fail;
    }
    __Pyx_GOTREF(array_obj);
    memview_obj = (struct __pyx_memoryview_obj *) __pyx_memoryview_new(
                                    (PyObject *) array_obj, contig_flag,
                                    dtype_is_object,
                                    from_mvs->memview->typeinfo);
    if (unlikely(!memview_obj))
        goto fail;
    if (unlikely(__Pyx_init_memviewslice(memview_obj, ndim, &new_mvs, 1) < 0))
        goto fail;
    if (unlikely(__pyx_memoryview_copy_contents(*from_mvs, new_mvs, ndim, ndim,
                                                dtype_is_object) < 0))
        goto fail;
    goto no_fail;
fail:
    __Pyx_XDECREF(new_mvs.memview);
    new_mvs.memview = NULL;
    new_mvs.data = NULL;
no_fail:
    __Pyx_XDECREF(shape_tuple);
    __Pyx_XDECREF(temp_int);
    __Pyx_XDECREF(array_obj);
    __Pyx_RefNannyFinishContext();
    return new_mvs;
}

/* CIntFromPy */
  static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

/* CIntFromPy */
  static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* CIntToPy */
  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7plastid_8genomics_8c_common_Strand(enum __pyx_t_7plastid_8genomics_8c_common_Strand value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const enum __pyx_t_7plastid_8genomics_8c_common_Strand neg_one = (enum __pyx_t_7plastid_8genomics_8c_common_Strand) -1, const_zero = (enum __pyx_t_7plastid_8genomics_8c_common_Strand) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
  static CYTHON_INLINE enum __pyx_t_7plastid_8genomics_8c_common_Strand __Pyx_PyInt_As_enum____pyx_t_7plastid_8genomics_8c_common_Strand(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const enum __pyx_t_7plastid_8genomics_8c_common_Strand neg_one = (enum __pyx_t_7plastid_8genomics_8c_common_Strand) -1, const_zero = (enum __pyx_t_7plastid_8genomics_8c_common_Strand) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) 0;
                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand, digit, digits[0])
                case 2:
                    if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) >= 2 * PyLong_SHIFT) {
                            return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) (((((enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) >= 3 * PyLong_SHIFT) {
                            return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) (((((((enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) >= 4 * PyLong_SHIFT) {
                            return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) (((((((((enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7plastid_8genomics_8c_common_Strand, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7plastid_8genomics_8c_common_Strand, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) 0;
                case -1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) - 1 > 2 * PyLong_SHIFT) {
                            return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) (((enum __pyx_t_7plastid_8genomics_8c_common_Strand)-1)*(((((enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) - 1 > 2 * PyLong_SHIFT) {
                            return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) ((((((enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) - 1 > 3 * PyLong_SHIFT) {
                            return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) (((enum __pyx_t_7plastid_8genomics_8c_common_Strand)-1)*(((((((enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) - 1 > 3 * PyLong_SHIFT) {
                            return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) ((((((((enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) - 1 > 4 * PyLong_SHIFT) {
                            return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) (((enum __pyx_t_7plastid_8genomics_8c_common_Strand)-1)*(((((((((enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7plastid_8genomics_8c_common_Strand, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) - 1 > 4 * PyLong_SHIFT) {
                            return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) ((((((((((enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7plastid_8genomics_8c_common_Strand)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7plastid_8genomics_8c_common_Strand, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_Strand) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7plastid_8genomics_8c_common_Strand, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            enum __pyx_t_7plastid_8genomics_8c_common_Strand val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) -1;
        }
    } else {
        enum __pyx_t_7plastid_8genomics_8c_common_Strand val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) -1;
        val = __Pyx_PyInt_As_enum____pyx_t_7plastid_8genomics_8c_common_Strand(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to enum __pyx_t_7plastid_8genomics_8c_common_Strand");
    return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to enum __pyx_t_7plastid_8genomics_8c_common_Strand");
    return (enum __pyx_t_7plastid_8genomics_8c_common_Strand) -1;
}

/* CIntToPy */
  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7plastid_8genomics_8c_common_ExBool(enum __pyx_t_7plastid_8genomics_8c_common_ExBool value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const enum __pyx_t_7plastid_8genomics_8c_common_ExBool neg_one = (enum __pyx_t_7plastid_8genomics_8c_common_ExBool) -1, const_zero = (enum __pyx_t_7plastid_8genomics_8c_common_ExBool) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_ExBool) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_ExBool) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_ExBool) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_ExBool) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(enum __pyx_t_7plastid_8genomics_8c_common_ExBool) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(enum __pyx_t_7plastid_8genomics_8c_common_ExBool),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
  static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const char neg_one = (char) -1, const_zero = (char) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(char) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(char, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (char) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (char) 0;
                case  1: __PYX_VERIFY_RETURN_INT(char, digit, digits[0])
                case 2:
                    if (8 * sizeof(char) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 2 * PyLong_SHIFT) {
                            return (char) (((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(char) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 3 * PyLong_SHIFT) {
                            return (char) (((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(char) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 4 * PyLong_SHIFT) {
                            return (char) (((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (char) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(char) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (char) 0;
                case -1: __PYX_VERIFY_RETURN_INT(char, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(char,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(char) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(char) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                            return (char) ((((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(char) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                            return (char) ((((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(char) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) {
                            return (char) ((((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(char) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            char val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (char) -1;
        }
    } else {
        char val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (char) -1;
        val = __Pyx_PyInt_As_char(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to char");
    return (char) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to char");
    return (char) -1;
}

/* FetchCommonType */
  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;
}

/* PyObjectCallMethod1 */
  static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) {
    PyObject *result = __Pyx_PyObject_CallOneArg(method, arg);
    Py_DECREF(method);
    return result;
}
static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
    PyObject *method = NULL, *result;
    int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
    if (likely(is_method)) {
        result = __Pyx_PyObject_Call2Args(method, obj, arg);
        Py_DECREF(method);
        return result;
    }
    if (unlikely(!method)) return NULL;
    return __Pyx__PyObject_CallMethod1(method, arg);
}

/* CoroutineBase */
  #include <structmember.h>
#include <frameobject.h>
#define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom)
static int __Pyx_PyGen__FetchStopIterationValue(CYTHON_UNUSED PyThreadState *__pyx_tstate, 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 (likely(et == PyExc_StopIteration)) {
        if (!ev) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#if PY_VERSION_HEX >= 0x030300A0
        else if (Py_TYPE(ev) == (PyTypeObject*)PyExc_StopIteration) {
            value = ((PyStopIterationObject *)ev)->value;
            Py_INCREF(value);
            Py_DECREF(ev);
        }
#endif
        else if (unlikely(PyTuple_Check(ev))) {
            if (PyTuple_GET_SIZE(ev) >= 1) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                value = PyTuple_GET_ITEM(ev, 0);
                Py_INCREF(value);
#else
                value = PySequence_ITEM(ev, 0);
#endif
            } else {
                Py_INCREF(Py_None);
                value = Py_None;
            }
            Py_DECREF(ev);
        }
        else if (!__Pyx_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) {
            value = ev;
        }
        if (likely(value)) {
            Py_XDECREF(tb);
            Py_DECREF(et);
            *pvalue = value;
            return 0;
        }
    } else if (!__Pyx_PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    PyErr_NormalizeException(&et, &ev, &tb);
    if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)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 = __Pyx_PyObject_GetAttrStr(ev, __pyx_n_s_args);
        Py_DECREF(ev);
        if (likely(args)) {
            value = PySequence_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;
}
static CYTHON_INLINE
void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *exc_state) {
    PyObject *t, *v, *tb;
    t = exc_state->exc_type;
    v = exc_state->exc_value;
    tb = exc_state->exc_traceback;
    exc_state->exc_type = NULL;
    exc_state->exc_value = NULL;
    exc_state->exc_traceback = NULL;
    Py_XDECREF(t);
    Py_XDECREF(v);
    Py_XDECREF(tb);
}
#define __Pyx_Coroutine_AlreadyRunningError(gen)  (__Pyx__Coroutine_AlreadyRunningError(gen), (PyObject*)NULL)
static void __Pyx__Coroutine_AlreadyRunningError(CYTHON_UNUSED __pyx_CoroutineObject *gen) {
    const char *msg;
    if ((0)) {
    #ifdef __Pyx_Coroutine_USED
    } else if (__Pyx_Coroutine_Check((PyObject*)gen)) {
        msg = "coroutine already executing";
    #endif
    #ifdef __Pyx_AsyncGen_USED
    } else if (__Pyx_AsyncGen_CheckExact((PyObject*)gen)) {
        msg = "async generator already executing";
    #endif
    } else {
        msg = "generator already executing";
    }
    PyErr_SetString(PyExc_ValueError, msg);
}
#define __Pyx_Coroutine_NotStartedError(gen)  (__Pyx__Coroutine_NotStartedError(gen), (PyObject*)NULL)
static void __Pyx__Coroutine_NotStartedError(CYTHON_UNUSED PyObject *gen) {
    const char *msg;
    if ((0)) {
    #ifdef __Pyx_Coroutine_USED
    } else if (__Pyx_Coroutine_Check(gen)) {
        msg = "can't send non-None value to a just-started coroutine";
    #endif
    #ifdef __Pyx_AsyncGen_USED
    } else if (__Pyx_AsyncGen_CheckExact(gen)) {
        msg = "can't send non-None value to a just-started async generator";
    #endif
    } else {
        msg = "can't send non-None value to a just-started generator";
    }
    PyErr_SetString(PyExc_TypeError, msg);
}
#define __Pyx_Coroutine_AlreadyTerminatedError(gen, value, closing)  (__Pyx__Coroutine_AlreadyTerminatedError(gen, value, closing), (PyObject*)NULL)
static void __Pyx__Coroutine_AlreadyTerminatedError(CYTHON_UNUSED PyObject *gen, PyObject *value, CYTHON_UNUSED int closing) {
    #ifdef __Pyx_Coroutine_USED
    if (!closing && __Pyx_Coroutine_Check(gen)) {
        PyErr_SetString(PyExc_RuntimeError, "cannot reuse already awaited coroutine");
    } else
    #endif
    if (value) {
        #ifdef __Pyx_AsyncGen_USED
        if (__Pyx_AsyncGen_CheckExact(gen))
            PyErr_SetNone(__Pyx_PyExc_StopAsyncIteration);
        else
        #endif
        PyErr_SetNone(PyExc_StopIteration);
    }
}
static
PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value, int closing) {
    __Pyx_PyThreadState_declare
    PyThreadState *tstate;
    __Pyx_ExcInfoStruct *exc_state;
    PyObject *retval;
    assert(!self->is_running);
    if (unlikely(self->resume_label == 0)) {
        if (unlikely(value && value != Py_None)) {
            return __Pyx_Coroutine_NotStartedError((PyObject*)self);
        }
    }
    if (unlikely(self->resume_label == -1)) {
        return __Pyx_Coroutine_AlreadyTerminatedError((PyObject*)self, value, closing);
    }
#if CYTHON_FAST_THREAD_STATE
    __Pyx_PyThreadState_assign
    tstate = __pyx_tstate;
#else
    tstate = __Pyx_PyThreadState_Current;
#endif
    exc_state = &self->gi_exc_state;
    if (exc_state->exc_type) {
        #if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
        #else
        if (exc_state->exc_traceback) {
            PyTracebackObject *tb = (PyTracebackObject *) exc_state->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            assert(f->f_back == NULL);
            #if PY_VERSION_HEX >= 0x030B00A1
            f->f_back = PyThreadState_GetFrame(tstate);
            #else
            Py_XINCREF(tstate->frame);
            f->f_back = tstate->frame;
            #endif
        }
        #endif
    }
#if CYTHON_USE_EXC_INFO_STACK
    exc_state->previous_item = tstate->exc_info;
    tstate->exc_info = exc_state;
#else
    if (exc_state->exc_type) {
        __Pyx_ExceptionSwap(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback);
    } else {
        __Pyx_Coroutine_ExceptionClear(exc_state);
        __Pyx_ExceptionSave(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback);
    }
#endif
    self->is_running = 1;
    retval = self->body((PyObject *) self, tstate, value);
    self->is_running = 0;
#if CYTHON_USE_EXC_INFO_STACK
    exc_state = &self->gi_exc_state;
    tstate->exc_info = exc_state->previous_item;
    exc_state->previous_item = NULL;
    __Pyx_Coroutine_ResetFrameBackpointer(exc_state);
#endif
    return retval;
}
static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state) {
    PyObject *exc_tb = exc_state->exc_traceback;
    if (likely(exc_tb)) {
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
#else
        PyTracebackObject *tb = (PyTracebackObject *) exc_tb;
        PyFrameObject *f = tb->tb_frame;
        Py_CLEAR(f->f_back);
#endif
    }
}
static CYTHON_INLINE
PyObject *__Pyx_Coroutine_MethodReturn(CYTHON_UNUSED PyObject* gen, PyObject *retval) {
    if (unlikely(!retval)) {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        if (!__Pyx_PyErr_Occurred()) {
            PyObject *exc = PyExc_StopIteration;
            #ifdef __Pyx_AsyncGen_USED
            if (__Pyx_AsyncGen_CheckExact(gen))
                exc = __Pyx_PyExc_StopAsyncIteration;
            #endif
            __Pyx_PyErr_SetNone(exc);
        }
    }
    return retval;
}
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
static CYTHON_INLINE
PyObject *__Pyx_PyGen_Send(PyGenObject *gen, PyObject *arg) {
#if PY_VERSION_HEX <= 0x030A00A1
    return _PyGen_Send(gen, arg);
#else
    PyObject *result;
    if (PyIter_Send((PyObject*)gen, arg ? arg : Py_None, &result) == PYGEN_RETURN) {
        if (PyAsyncGen_CheckExact(gen)) {
            assert(result == Py_None);
            PyErr_SetNone(PyExc_StopAsyncIteration);
        }
        else if (result == Py_None) {
            PyErr_SetNone(PyExc_StopIteration);
        }
        else {
            _PyGen_SetStopIterationValue(result);
        }
        Py_CLEAR(result);
    }
    return result;
#endif
}
#endif
static CYTHON_INLINE
PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) {
    PyObject *ret;
    PyObject *val = NULL;
    __Pyx_Coroutine_Undelegate(gen);
    __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, &val);
    ret = __Pyx_Coroutine_SendEx(gen, val, 0);
    Py_XDECREF(val);
    return ret;
}
static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) {
    PyObject *retval;
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(gen->is_running))
        return __Pyx_Coroutine_AlreadyRunningError(gen);
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        #ifdef __Pyx_Generator_USED
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Coroutine_Send(yf, value);
        } else
        #endif
        #ifdef __Pyx_Coroutine_USED
        if (__Pyx_Coroutine_Check(yf)) {
            ret = __Pyx_Coroutine_Send(yf, value);
        } else
        #endif
        #ifdef __Pyx_AsyncGen_USED
        if (__pyx_PyAsyncGenASend_CheckExact(yf)) {
            ret = __Pyx_async_gen_asend_send(yf, value);
        } else
        #endif
        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
        if (PyGen_CheckExact(yf)) {
            ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value);
        } else
        #endif
        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03050000 && defined(PyCoro_CheckExact) && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
        if (PyCoro_CheckExact(yf)) {
            ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value);
        } else
        #endif
        {
            if (value == Py_None)
                ret = Py_TYPE(yf)->tp_iternext(yf);
            else
                ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value);
        }
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        retval = __Pyx_Coroutine_FinishDelegation(gen);
    } else {
        retval = __Pyx_Coroutine_SendEx(gen, value, 0);
    }
    return __Pyx_Coroutine_MethodReturn(self, retval);
}
static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) {
    PyObject *retval = NULL;
    int err = 0;
    #ifdef __Pyx_Generator_USED
    if (__Pyx_Generator_CheckExact(yf)) {
        retval = __Pyx_Coroutine_Close(yf);
        if (!retval)
            return -1;
    } else
    #endif
    #ifdef __Pyx_Coroutine_USED
    if (__Pyx_Coroutine_Check(yf)) {
        retval = __Pyx_Coroutine_Close(yf);
        if (!retval)
            return -1;
    } else
    if (__Pyx_CoroutineAwait_CheckExact(yf)) {
        retval = __Pyx_CoroutineAwait_Close((__pyx_CoroutineAwaitObject*)yf, NULL);
        if (!retval)
            return -1;
    } else
    #endif
    #ifdef __Pyx_AsyncGen_USED
    if (__pyx_PyAsyncGenASend_CheckExact(yf)) {
        retval = __Pyx_async_gen_asend_close(yf, NULL);
    } else
    if (__pyx_PyAsyncGenAThrow_CheckExact(yf)) {
        retval = __Pyx_async_gen_athrow_close(yf, NULL);
    } else
    #endif
    {
        PyObject *meth;
        gen->is_running = 1;
        meth = __Pyx_PyObject_GetAttrStr(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_Next(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(gen->is_running))
        return __Pyx_Coroutine_AlreadyRunningError(gen);
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        #ifdef __Pyx_Generator_USED
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Generator_Next(yf);
        } else
        #endif
        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
        if (PyGen_CheckExact(yf)) {
            ret = __Pyx_PyGen_Send((PyGenObject*)yf, NULL);
        } else
        #endif
        #ifdef __Pyx_Coroutine_USED
        if (__Pyx_Coroutine_Check(yf)) {
            ret = __Pyx_Coroutine_Send(yf, Py_None);
        } else
        #endif
            ret = Py_TYPE(yf)->tp_iternext(yf);
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        return __Pyx_Coroutine_FinishDelegation(gen);
    }
    return __Pyx_Coroutine_SendEx(gen, Py_None, 0);
}
static PyObject *__Pyx_Coroutine_Close_Method(PyObject *self, CYTHON_UNUSED PyObject *arg) {
    return __Pyx_Coroutine_Close(self);
}
static PyObject *__Pyx_Coroutine_Close(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    PyObject *retval, *raised_exception;
    PyObject *yf = gen->yieldfrom;
    int err = 0;
    if (unlikely(gen->is_running))
        return __Pyx_Coroutine_AlreadyRunningError(gen);
    if (yf) {
        Py_INCREF(yf);
        err = __Pyx_Coroutine_CloseIter(gen, yf);
        __Pyx_Coroutine_Undelegate(gen);
        Py_DECREF(yf);
    }
    if (err == 0)
        PyErr_SetNone(PyExc_GeneratorExit);
    retval = __Pyx_Coroutine_SendEx(gen, NULL, 1);
    if (unlikely(retval)) {
        const char *msg;
        Py_DECREF(retval);
        if ((0)) {
        #ifdef __Pyx_Coroutine_USED
        } else if (__Pyx_Coroutine_Check(self)) {
            msg = "coroutine ignored GeneratorExit";
        #endif
        #ifdef __Pyx_AsyncGen_USED
        } else if (__Pyx_AsyncGen_CheckExact(self)) {
#if PY_VERSION_HEX < 0x03060000
            msg = "async generator ignored GeneratorExit - might require Python 3.6+ finalisation (PEP 525)";
#else
            msg = "async generator ignored GeneratorExit";
#endif
        #endif
        } else {
            msg = "generator ignored GeneratorExit";
        }
        PyErr_SetString(PyExc_RuntimeError, msg);
        return NULL;
    }
    raised_exception = PyErr_Occurred();
    if (likely(!raised_exception || __Pyx_PyErr_GivenExceptionMatches2(raised_exception, PyExc_GeneratorExit, PyExc_StopIteration))) {
        if (raised_exception) PyErr_Clear();
        Py_INCREF(Py_None);
        return Py_None;
    }
    return NULL;
}
static PyObject *__Pyx__Coroutine_Throw(PyObject *self, PyObject *typ, PyObject *val, PyObject *tb,
                                        PyObject *args, int close_on_genexit) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(gen->is_running))
        return __Pyx_Coroutine_AlreadyRunningError(gen);
    if (yf) {
        PyObject *ret;
        Py_INCREF(yf);
        if (__Pyx_PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && close_on_genexit) {
            int err = __Pyx_Coroutine_CloseIter(gen, yf);
            Py_DECREF(yf);
            __Pyx_Coroutine_Undelegate(gen);
            if (err < 0)
                return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0));
            goto throw_here;
        }
        gen->is_running = 1;
        if (0
        #ifdef __Pyx_Generator_USED
            || __Pyx_Generator_CheckExact(yf)
        #endif
        #ifdef __Pyx_Coroutine_USED
            || __Pyx_Coroutine_Check(yf)
        #endif
            ) {
            ret = __Pyx__Coroutine_Throw(yf, typ, val, tb, args, close_on_genexit);
        #ifdef __Pyx_Coroutine_USED
        } else if (__Pyx_CoroutineAwait_CheckExact(yf)) {
            ret = __Pyx__Coroutine_Throw(((__pyx_CoroutineAwaitObject*)yf)->coroutine, typ, val, tb, args, close_on_genexit);
        #endif
        } else {
            PyObject *meth = __Pyx_PyObject_GetAttrStr(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_Coroutine_Undelegate(gen);
                gen->is_running = 0;
                goto throw_here;
            }
            if (likely(args)) {
                ret = PyObject_CallObject(meth, args);
            } else {
                ret = PyObject_CallFunctionObjArgs(meth, typ, val, tb, NULL);
            }
            Py_DECREF(meth);
        }
        gen->is_running = 0;
        Py_DECREF(yf);
        if (!ret) {
            ret = __Pyx_Coroutine_FinishDelegation(gen);
        }
        return __Pyx_Coroutine_MethodReturn(self, ret);
    }
throw_here:
    __Pyx_Raise(typ, val, tb, NULL);
    return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0));
}
static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) {
    PyObject *typ;
    PyObject *val = NULL;
    PyObject *tb = NULL;
    if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
        return NULL;
    return __Pyx__Coroutine_Throw(self, typ, val, tb, args, 1);
}
static CYTHON_INLINE int __Pyx_Coroutine_traverse_excstate(__Pyx_ExcInfoStruct *exc_state, visitproc visit, void *arg) {
    Py_VISIT(exc_state->exc_type);
    Py_VISIT(exc_state->exc_value);
    Py_VISIT(exc_state->exc_traceback);
    return 0;
}
static int __Pyx_Coroutine_traverse(__pyx_CoroutineObject *gen, visitproc visit, void *arg) {
    Py_VISIT(gen->closure);
    Py_VISIT(gen->classobj);
    Py_VISIT(gen->yieldfrom);
    return __Pyx_Coroutine_traverse_excstate(&gen->gi_exc_state, visit, arg);
}
static int __Pyx_Coroutine_clear(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    Py_CLEAR(gen->closure);
    Py_CLEAR(gen->classobj);
    Py_CLEAR(gen->yieldfrom);
    __Pyx_Coroutine_ExceptionClear(&gen->gi_exc_state);
#ifdef __Pyx_AsyncGen_USED
    if (__Pyx_AsyncGen_CheckExact(self)) {
        Py_CLEAR(((__pyx_PyAsyncGenObject*)gen)->ag_finalizer);
    }
#endif
    Py_CLEAR(gen->gi_code);
    Py_CLEAR(gen->gi_frame);
    Py_CLEAR(gen->gi_name);
    Py_CLEAR(gen->gi_qualname);
    Py_CLEAR(gen->gi_modulename);
    return 0;
}
static void __Pyx_Coroutine_dealloc(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) 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 && CYTHON_USE_TP_FINALIZE
        if (PyObject_CallFinalizerFromDealloc(self))
#else
        Py_TYPE(gen)->tp_del(self);
        if (Py_REFCNT(self) > 0)
#endif
        {
            return;
        }
        PyObject_GC_UnTrack(self);
    }
#ifdef __Pyx_AsyncGen_USED
    if (__Pyx_AsyncGen_CheckExact(self)) {
        /* We have to handle this case for asynchronous generators
           right here, because this code has to be between UNTRACK
           and GC_Del. */
        Py_CLEAR(((__pyx_PyAsyncGenObject*)self)->ag_finalizer);
    }
#endif
    __Pyx_Coroutine_clear(self);
    PyObject_GC_Del(gen);
}
static void __Pyx_Coroutine_del(PyObject *self) {
    PyObject *error_type, *error_value, *error_traceback;
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    __Pyx_PyThreadState_declare
    if (gen->resume_label < 0) {
        return;
    }
#if !CYTHON_USE_TP_FINALIZE
    assert(self->ob_refcnt == 0);
    __Pyx_SET_REFCNT(self, 1);
#endif
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&error_type, &error_value, &error_traceback);
#ifdef __Pyx_AsyncGen_USED
    if (__Pyx_AsyncGen_CheckExact(self)) {
        __pyx_PyAsyncGenObject *agen = (__pyx_PyAsyncGenObject*)self;
        PyObject *finalizer = agen->ag_finalizer;
        if (finalizer && !agen->ag_closed) {
            PyObject *res = __Pyx_PyObject_CallOneArg(finalizer, self);
            if (unlikely(!res)) {
                PyErr_WriteUnraisable(self);
            } else {
                Py_DECREF(res);
            }
            __Pyx_ErrRestore(error_type, error_value, error_traceback);
            return;
        }
    }
#endif
    if (unlikely(gen->resume_label == 0 && !error_value)) {
#ifdef __Pyx_Coroutine_USED
#ifdef __Pyx_Generator_USED
    if (!__Pyx_Generator_CheckExact(self))
#endif
        {
        PyObject_GC_UnTrack(self);
#if PY_MAJOR_VERSION >= 3  || defined(PyErr_WarnFormat)
        if (unlikely(PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "coroutine '%.50S' was never awaited", gen->gi_qualname) < 0))
            PyErr_WriteUnraisable(self);
#else
        {PyObject *msg;
        char *cmsg;
        #if CYTHON_COMPILING_IN_PYPY
        msg = NULL;
        cmsg = (char*) "coroutine was never awaited";
        #else
        char *cname;
        PyObject *qualname;
        qualname = gen->gi_qualname;
        cname = PyString_AS_STRING(qualname);
        msg = PyString_FromFormat("coroutine '%.50s' was never awaited", cname);
        if (unlikely(!msg)) {
            PyErr_Clear();
            cmsg = (char*) "coroutine was never awaited";
        } else {
            cmsg = PyString_AS_STRING(msg);
        }
        #endif
        if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, cmsg, 1) < 0))
            PyErr_WriteUnraisable(self);
        Py_XDECREF(msg);}
#endif
        PyObject_GC_Track(self);
        }
#endif
    } else {
        PyObject *res = __Pyx_Coroutine_Close(self);
        if (unlikely(!res)) {
            if (PyErr_Occurred())
                PyErr_WriteUnraisable(self);
        } else {
            Py_DECREF(res);
        }
    }
    __Pyx_ErrRestore(error_type, error_value, error_traceback);
#if !CYTHON_USE_TP_FINALIZE
    assert(Py_REFCNT(self) > 0);
    if (--self->ob_refcnt == 0) {
        return;
    }
    {
        Py_ssize_t refcnt = Py_REFCNT(self);
        _Py_NewReference(self);
        __Pyx_SET_REFCNT(self, refcnt);
    }
#if CYTHON_COMPILING_IN_CPYTHON
    assert(PyType_IS_GC(Py_TYPE(self)) &&
           _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_Coroutine_get_name(__pyx_CoroutineObject *self, CYTHON_UNUSED void *context)
{
    PyObject *name = self->gi_name;
    if (unlikely(!name)) name = Py_None;
    Py_INCREF(name);
    return name;
}
static int
__Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value, CYTHON_UNUSED void *context)
{
    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_Coroutine_get_qualname(__pyx_CoroutineObject *self, CYTHON_UNUSED void *context)
{
    PyObject *name = self->gi_qualname;
    if (unlikely(!name)) name = Py_None;
    Py_INCREF(name);
    return name;
}
static int
__Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value, CYTHON_UNUSED void *context)
{
    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 PyObject *
__Pyx_Coroutine_get_frame(__pyx_CoroutineObject *self, CYTHON_UNUSED void *context)
{
    PyObject *frame = self->gi_frame;
    if (!frame) {
        if (unlikely(!self->gi_code)) {
            Py_RETURN_NONE;
        }
        frame = (PyObject *) PyFrame_New(
            PyThreadState_Get(),            /*PyThreadState *tstate,*/
            (PyCodeObject*) self->gi_code,  /*PyCodeObject *code,*/
            __pyx_d,                 /*PyObject *globals,*/
            0                               /*PyObject *locals*/
        );
        if (unlikely(!frame))
            return NULL;
        self->gi_frame = frame;
    }
    Py_INCREF(frame);
    return frame;
}
static __pyx_CoroutineObject *__Pyx__Coroutine_New(
            PyTypeObject* type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
            PyObject *name, PyObject *qualname, PyObject *module_name) {
    __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type);
    if (unlikely(!gen))
        return NULL;
    return __Pyx__Coroutine_NewInit(gen, body, code, closure, name, qualname, module_name);
}
static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit(
            __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
            PyObject *name, PyObject *qualname, PyObject *module_name) {
    gen->body = body;
    gen->closure = closure;
    Py_XINCREF(closure);
    gen->is_running = 0;
    gen->resume_label = 0;
    gen->classobj = NULL;
    gen->yieldfrom = NULL;
    gen->gi_exc_state.exc_type = NULL;
    gen->gi_exc_state.exc_value = NULL;
    gen->gi_exc_state.exc_traceback = NULL;
#if CYTHON_USE_EXC_INFO_STACK
    gen->gi_exc_state.previous_item = NULL;
#endif
    gen->gi_weakreflist = NULL;
    Py_XINCREF(qualname);
    gen->gi_qualname = qualname;
    Py_XINCREF(name);
    gen->gi_name = name;
    Py_XINCREF(module_name);
    gen->gi_modulename = module_name;
    Py_XINCREF(code);
    gen->gi_code = code;
    gen->gi_frame = NULL;
    PyObject_GC_Track(gen);
    return gen;
}

/* PatchModuleWithCoroutine */
  static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) {
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
    int result;
    PyObject *globals, *result_obj;
    globals = PyDict_New();  if (unlikely(!globals)) goto ignore;
    result = PyDict_SetItemString(globals, "_cython_coroutine_type",
    #ifdef __Pyx_Coroutine_USED
        (PyObject*)__pyx_CoroutineType);
    #else
        Py_None);
    #endif
    if (unlikely(result < 0)) goto ignore;
    result = PyDict_SetItemString(globals, "_cython_generator_type",
    #ifdef __Pyx_Generator_USED
        (PyObject*)__pyx_GeneratorType);
    #else
        Py_None);
    #endif
    if (unlikely(result < 0)) goto ignore;
    if (unlikely(PyDict_SetItemString(globals, "_module", module) < 0)) goto ignore;
    if (unlikely(PyDict_SetItemString(globals, "__builtins__", __pyx_b) < 0)) goto ignore;
    result_obj = PyRun_String(py_code, Py_file_input, globals, globals);
    if (unlikely(!result_obj)) goto ignore;
    Py_DECREF(result_obj);
    Py_DECREF(globals);
    return module;
ignore:
    Py_XDECREF(globals);
    PyErr_WriteUnraisable(module);
    if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch module with custom type", 1) < 0)) {
        Py_DECREF(module);
        module = NULL;
    }
#else
    py_code++;
#endif
    return module;
}

/* PatchGeneratorABC */
  #ifndef CYTHON_REGISTER_ABCS
#define CYTHON_REGISTER_ABCS 1
#endif
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
static PyObject* __Pyx_patch_abc_module(PyObject *module);
static PyObject* __Pyx_patch_abc_module(PyObject *module) {
    module = __Pyx_Coroutine_patch_module(
        module, ""
"if _cython_generator_type is not None:\n"
"    try: Generator = _module.Generator\n"
"    except AttributeError: pass\n"
"    else: Generator.register(_cython_generator_type)\n"
"if _cython_coroutine_type is not None:\n"
"    try: Coroutine = _module.Coroutine\n"
"    except AttributeError: pass\n"
"    else: Coroutine.register(_cython_coroutine_type)\n"
    );
    return module;
}
#endif
static int __Pyx_patch_abc(void) {
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
    static int abc_patched = 0;
    if (CYTHON_REGISTER_ABCS && !abc_patched) {
        PyObject *module;
        module = PyImport_ImportModule((PY_MAJOR_VERSION >= 3) ? "collections.abc" : "collections");
        if (!module) {
            PyErr_WriteUnraisable(NULL);
            if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning,
                    ((PY_MAJOR_VERSION >= 3) ?
                        "Cython module failed to register with collections.abc module" :
                        "Cython module failed to register with collections module"), 1) < 0)) {
                return -1;
            }
        } else {
            module = __Pyx_patch_abc_module(module);
            abc_patched = 1;
            if (unlikely(!module))
                return -1;
            Py_DECREF(module);
        }
        module = PyImport_ImportModule("backports_abc");
        if (module) {
            module = __Pyx_patch_abc_module(module);
            Py_XDECREF(module);
        }
        if (!module) {
            PyErr_Clear();
        }
    }
#else
    if ((0)) __Pyx_Coroutine_patch_module(NULL, NULL);
#endif
    return 0;
}

/* Generator */
  static PyMethodDef __pyx_Generator_methods[] = {
    {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O,
     (char*) PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")},
    {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS,
     (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in generator,\nreturn next yielded value or raise StopIteration.")},
    {"close", (PyCFunction) __Pyx_Coroutine_Close_Method, METH_NOARGS,
     (char*) PyDoc_STR("close() -> raise GeneratorExit inside generator.")},
    {0, 0, 0, 0}
};
static PyMemberDef __pyx_Generator_memberlist[] = {
    {(char *) "gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
    {(char*) "gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
     (char*) PyDoc_STR("object being iterated by 'yield from', or None")},
    {(char*) "gi_code", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_code), READONLY, NULL},
    {0, 0, 0, 0, 0}
};
static PyGetSetDef __pyx_Generator_getsets[] = {
    {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name,
     (char*) PyDoc_STR("name of the generator"), 0},
    {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname,
     (char*) PyDoc_STR("qualified name of the generator"), 0},
    {(char *) "gi_frame", (getter)__Pyx_Coroutine_get_frame, NULL,
     (char*) PyDoc_STR("Frame of the generator"), 0},
    {0, 0, 0, 0, 0}
};
static PyTypeObject __pyx_GeneratorType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    "generator",
    sizeof(__pyx_CoroutineObject),
    0,
    (destructor) __Pyx_Coroutine_dealloc,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE,
    0,
    (traverseproc) __Pyx_Coroutine_traverse,
    0,
    0,
    offsetof(__pyx_CoroutineObject, 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 CYTHON_USE_TP_FINALIZE
    0,
#else
    __Pyx_Coroutine_del,
#endif
    0,
#if CYTHON_USE_TP_FINALIZE
    __Pyx_Coroutine_del,
#elif PY_VERSION_HEX >= 0x030400a1
    0,
#endif
#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
    0,
#endif
#if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
    0,
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
    0,
#endif
};
static int __pyx_Generator_init(void) {
    __pyx_GeneratorType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
    __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter;
    __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type);
    if (unlikely(!__pyx_GeneratorType)) {
        return -1;
    }
    return 0;
}

/* CheckBinaryVersion */
  static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

/* PyObjectSetAttrStr */
  #if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_setattro))
        return tp->tp_setattro(obj, attr_name, value);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_setattr))
        return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
#endif
    return PyObject_SetAttr(obj, attr_name, value);
}
#endif

/* VoidPtrExport */
  static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig) {
    PyObject *d;
    PyObject *cobj = 0;
    d = PyDict_GetItem(__pyx_d, __pyx_n_s_pyx_capi);
    Py_XINCREF(d);
    if (!d) {
        d = PyDict_New();
        if (!d)
            goto bad;
        if (__Pyx_PyObject_SetAttrStr(__pyx_m, __pyx_n_s_pyx_capi, d) < 0)
            goto bad;
    }
#if PY_VERSION_HEX >= 0x02070000
    cobj = PyCapsule_New(p, sig, 0);
#else
    cobj = PyCObject_FromVoidPtrAndDesc(p, (void *)sig, 0);
#endif
    if (!cobj)
        goto bad;
    if (PyDict_SetItem(d, name, cobj) < 0)
        goto bad;
    Py_DECREF(cobj);
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(cobj);
    Py_XDECREF(d);
    return -1;
}

/* FunctionExport */
  static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    union {
        void (*fp)(void);
        void *p;
    } tmp;
    d = PyObject_GetAttrString(__pyx_m, (char *)"__pyx_capi__");
    if (!d) {
        PyErr_Clear();
        d = PyDict_New();
        if (!d)
            goto bad;
        Py_INCREF(d);
        if (PyModule_AddObject(__pyx_m, (char *)"__pyx_capi__", d) < 0)
            goto bad;
    }
    tmp.fp = f;
#if PY_VERSION_HEX >= 0x02070000
    cobj = PyCapsule_New(tmp.p, sig, 0);
#else
    cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
#endif
    if (!cobj)
        goto bad;
    if (PyDict_SetItemString(d, name, cobj) < 0)
        goto bad;
    Py_DECREF(cobj);
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(cobj);
    Py_XDECREF(d);
    return -1;
}

/* FunctionImport */
  #ifndef __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    union {
        void (*fp)(void);
        void *p;
    } tmp;
    d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
    if (!d)
        goto bad;
    cobj = PyDict_GetItemString(d, funcname);
    if (!cobj) {
        PyErr_Format(PyExc_ImportError,
            "%.200s does not export expected C function %.200s",
                PyModule_GetName(module), funcname);
        goto bad;
    }
#if PY_VERSION_HEX >= 0x02070000
    if (!PyCapsule_IsValid(cobj, sig)) {
        PyErr_Format(PyExc_TypeError,
            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
        goto bad;
    }
    tmp.p = PyCapsule_GetPointer(cobj, sig);
#else
    {const char *desc, *s1, *s2;
    desc = (const char *)PyCObject_GetDesc(cobj);
    if (!desc)
        goto bad;
    s1 = desc; s2 = sig;
    while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
    if (*s1 != *s2) {
        PyErr_Format(PyExc_TypeError,
            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, desc);
        goto bad;
    }
    tmp.p = PyCObject_AsVoidPtr(cobj);}
#endif
    *f = tmp.fp;
    if (!(*f))
        goto bad;
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(d);
    return -1;
}
#endif

/* InitStrings */
  static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        if (PyObject_Hash(*t->p) == -1)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
#if !CYTHON_PEP393_ENABLED
static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    char* defenc_c;
    PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
    if (!defenc) return NULL;
    defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    {
        char* end = defenc_c + PyBytes_GET_SIZE(defenc);
        char* c;
        for (c = defenc_c; c < end; c++) {
            if ((unsigned char) (*c) >= 128) {
                PyUnicode_AsASCIIString(o);
                return NULL;
            }
        }
    }
#endif
    *length = PyBytes_GET_SIZE(defenc);
    return defenc_c;
}
#else
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    if (likely(PyUnicode_IS_ASCII(o))) {
        *length = PyUnicode_GET_LENGTH(o);
        return PyUnicode_AsUTF8(o);
    } else {
        PyUnicode_AsASCIIString(o);
        return NULL;
    }
#else
    return PyUnicode_AsUTF8AndSize(o, length);
#endif
}
#endif
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
        return __Pyx_PyUnicode_AsStringAndSize(o, length);
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
    int retval;
    if (unlikely(!x)) return -1;
    retval = __Pyx_PyObject_IsTrue(x);
    Py_DECREF(x);
    return retval;
}
static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
#if PY_MAJOR_VERSION >= 3
    if (PyLong_Check(result)) {
        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                "__int__ returned non-int (type %.200s).  "
                "The ability to return an instance of a strict subclass of int "
                "is deprecated, and may be removed in a future version of Python.",
                Py_TYPE(result)->tp_name)) {
            Py_DECREF(result);
            return NULL;
        }
        return result;
    }
#endif
    PyErr_Format(PyExc_TypeError,
                 "__%.4s__ returned non-%.4s (type %.200s)",
                 type_name, type_name, Py_TYPE(result)->tp_name);
    Py_DECREF(result);
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
  PyNumberMethods *m;
#endif
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_Check(x) || PyLong_Check(x)))
#else
  if (likely(PyLong_Check(x)))
#endif
    return __Pyx_NewRef(x);
#if CYTHON_USE_TYPE_SLOTS
  m = Py_TYPE(x)->tp_as_number;
  #if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = m->nb_int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = m->nb_long(x);
  }
  #else
  if (likely(m && m->nb_int)) {
    name = "int";
    res = m->nb_int(x);
  }
  #endif
#else
  if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
    res = PyNumber_Int(x);
  }
#endif
  if (likely(res)) {
#if PY_MAJOR_VERSION < 3
    if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
#else
    if (unlikely(!PyLong_CheckExact(res))) {
#endif
        return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(b);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) {
  if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) {
    return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o);
#if PY_MAJOR_VERSION < 3
  } else if (likely(PyInt_CheckExact(o))) {
    return PyInt_AS_LONG(o);
#endif
  } else {
    Py_ssize_t ival;
    PyObject *x;
    x = PyNumber_Index(o);
    if (!x) return -1;
    ival = PyInt_AsLong(x);
    Py_DECREF(x);
    return ival;
  }
}
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
