/* Generated by Cython 0.13 on Thu Feb  3 22:15:44 2011 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#else

#include <stddef.h> /* For offsetof */
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif

#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif

#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif

#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif

#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
  #define PyDict_Contains(d,o)   PySequence_Contains(d,o)
#endif

#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
#endif

#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)

  typedef struct {
     void *buf;
     PyObject *obj;
     Py_ssize_t len;
     Py_ssize_t itemsize;
     int readonly;
     int ndim;
     char *format;
     Py_ssize_t *shape;
     Py_ssize_t *strides;
     Py_ssize_t *suboffsets;
     void *internal;
  } Py_buffer;

  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)

#endif

#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif

#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif

#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif

#if PY_VERSION_HEX < 0x02060000
  #define PyBytesObject                PyStringObject
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_Check                PyString_Check
  #define PyBytes_CheckExact           PyString_CheckExact
  #define PyBytes_FromString           PyString_FromString
  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
  #define PyBytes_FromFormat           PyString_FromFormat
  #define PyBytes_DecodeEscape         PyString_DecodeEscape
  #define PyBytes_AsString             PyString_AsString
  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
  #define PyBytes_Size                 PyString_Size
  #define PyBytes_AS_STRING            PyString_AS_STRING
  #define PyBytes_GET_SIZE             PyString_GET_SIZE
  #define PyBytes_Repr                 PyString_Repr
  #define PyBytes_Concat               PyString_Concat
  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
  #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
  #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
#endif

#ifndef PySet_CheckExact
#  define PySet_CheckExact(obj)          (Py_TYPE(obj) == &PySet_Type)
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject PyLongObject
#endif


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

#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif

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

#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE_API__chimerascan__bx__intersection
#include "stdlib.h"

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

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

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


/* Type Conversion Predeclarations */

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

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))


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


static const char *__pyx_f[] = {
  "intersection.pyx",
};

/* Type declarations */

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":232
 * 
 * 
 *     cpdef left(self, position, int n=1, int max_dist=2500):             # <<<<<<<<<<<<<<
 *         """
 *         find n features with a start > than `position`
 */

struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_left {
  int __pyx_n;
  int n;
  int max_dist;
};

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":247
 *         return r[:n]
 * 
 *     cpdef right(self, position, int n=1, int max_dist=2500):             # <<<<<<<<<<<<<<
 *         """
 *         find n features with a end < than position
 */

struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_right {
  int __pyx_n;
  int n;
  int max_dist;
};

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":61
 * cdef float nlog = -1.0 / log(0.5)
 * 
 * cdef class IntervalNode:             # <<<<<<<<<<<<<<
 *     """
 *     A single node of an `IntervalTree`.
 */

struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode {
  PyObject_HEAD
  struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *__pyx_vtab;
  float priority;
  PyObject *interval;
  int start;
  int end;
  int minend;
  int maxend;
  int minstart;
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *cleft;
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *cright;
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *croot;
};

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":309
 *         return cmp( self.start, other.start ) or cmp( self.end, other.end )
 * 
 * cdef class IntervalTree:             # <<<<<<<<<<<<<<
 *     """
 *     Data structure for performing window intersect queries on a set of
 */

struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree {
  PyObject_HEAD
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *root;
};

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":274
 * ## ---- Wrappers that retain the old interface -------------------------------
 * 
 * cdef class Interval:             # <<<<<<<<<<<<<<
 *     """
 *     Basic feature, with required integer start and end properties.
 */

struct __pyx_obj_11chimerascan_2bx_12intersection_Interval {
  PyObject_HEAD
  int start;
  int end;
  PyObject *value;
  PyObject *chrom;
  PyObject *strand;
};


/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":61
 * cdef float nlog = -1.0 / log(0.5)
 * 
 * cdef class IntervalNode:             # <<<<<<<<<<<<<<
 *     """
 *     A single node of an `IntervalTree`.
 */

struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode {
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *(*insert)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, int, int, PyObject *, int __pyx_skip_dispatch);
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *(*rotate_right)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *);
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *(*rotate_left)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *);
  void (*set_ends)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *);
  void (*_intersect)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, int, int, PyObject *);
  void (*_seek_left)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, int, PyObject *, int, int);
  void (*_seek_right)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, int, PyObject *, int, int);
  PyObject *(*left)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_left *__pyx_optional_args);
  PyObject *(*right)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_right *__pyx_optional_args);
  void (*_traverse)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, PyObject *);
};
static struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *__pyx_vtabptr_11chimerascan_2bx_12intersection_IntervalNode;

#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) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
  end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
  }
  #define __Pyx_RefNannySetupContext(name)           void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  #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_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
#else
  #define __Pyx_RefNannySetupContext(name)
  #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_XDECREF(r) Py_XDECREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)

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

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

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

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

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

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

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

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

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

static void __Pyx_WriteUnraisable(const char *name); /*proto*/

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

static void __Pyx_AddTraceback(const char *funcname); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
/* Module declarations from chimerascan.bx.intersection */

static PyTypeObject *__pyx_ptype_11chimerascan_2bx_12intersection_IntervalNode = 0;
static PyTypeObject *__pyx_ptype_11chimerascan_2bx_12intersection_Interval = 0;
static PyTypeObject *__pyx_ptype_11chimerascan_2bx_12intersection_IntervalTree = 0;
static float __pyx_v_11chimerascan_2bx_12intersection_nlog;
static struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_11chimerascan_2bx_12intersection_EmptyNode = 0;
static CYTHON_INLINE int __pyx_f_11chimerascan_2bx_12intersection_imax2(int, int); /*proto*/
static CYTHON_INLINE int __pyx_f_11chimerascan_2bx_12intersection_imax3(int, int, int); /*proto*/
static CYTHON_INLINE int __pyx_f_11chimerascan_2bx_12intersection_imin3(int, int, int); /*proto*/
static CYTHON_INLINE int __pyx_f_11chimerascan_2bx_12intersection_imin2(int, int); /*proto*/
#define __Pyx_MODULE_NAME "chimerascan.bx.intersection"
int __pyx_module_is_main_chimerascan__bx__intersection = 0;

/* Implementation of chimerascan.bx.intersection */
static PyObject *__pyx_builtin_cmp;
static char __pyx_k_1[] = "IntervalNode(%i, %i)";
static char __pyx_k_3[] = "start must be less than end";
static char __pyx_k_4[] = "Interval(%d, %d";
static char __pyx_k_5[] = ", value=";
static char __pyx_k_6[] = ")";
static char __pyx_k_7[] = "-";
static char __pyx_k_8[] = "\nDownloaded from:\nhttps://bitbucket.org/james_taylor/bx-python/wiki/Home\n\nData structure for performing intersect queries on a set of intervals which\npreserves all information about the intervals (unlike bitset projection methods).\n\n:Authors: James Taylor (james@jamestaylor.org),\n          Ian Schenk (ian.schenck@gmail.com),\n          Brent Pedersen (bpederse@gmail.com)\n";
static char __pyx_k_9[] = "IntervalNode.insert (line 103)";
static char __pyx_k_10[] = "IntervalNode.intersect (line 169)";
static char __pyx_k_11[] = "IntervalNode.left (line 232)";
static char __pyx_k_12[] = "IntervalNode.right (line 247)";
static char __pyx_k_13[] = "IntervalTree.insert (line 372)";
static char __pyx_k_14[] = "IntervalTree.find (line 384)";
static char __pyx_k_15[] = "IntervalTree.before (line 392)";
static char __pyx_k_16[] = "IntervalTree.after (line 401)";
static char __pyx_k_17[] = "IntervalTree.insert_interval (line 412)";
static char __pyx_k_18[] = "IntervalTree.before_interval (line 421)";
static char __pyx_k_19[] = "IntervalTree.after_interval (line 430)";
static char __pyx_k_20[] = "IntervalTree.upstream_of_interval (line 439)";
static char __pyx_k_21[] = "upstream_of_interval";
static char __pyx_k_22[] = "IntervalTree.downstream_of_interval (line 451)";
static char __pyx_k_23[] = "downstream_of_interval";
static char __pyx_k_24[] = "IntervalTree.traverse (line 463)";
static char __pyx_k__n[] = "n";
static char __pyx_k__add[] = "add";
static char __pyx_k__cmp[] = "cmp";
static char __pyx_k__end[] = "end";
static char __pyx_k__key[] = "key";
static char __pyx_k__find[] = "find";
static char __pyx_k__left[] = "left";
static char __pyx_k__root[] = "root";
static char __pyx_k__sort[] = "sort";
static char __pyx_k__after[] = "after";
static char __pyx_k__chrom[] = "chrom";
static char __pyx_k__cleft[] = "cleft";
static char __pyx_k__croot[] = "croot";
static char __pyx_k__right[] = "right";
static char __pyx_k__start[] = "start";
static char __pyx_k__value[] = "value";
static char __pyx_k__before[] = "before";
static char __pyx_k__cright[] = "cright";
static char __pyx_k__insert[] = "insert";
static char __pyx_k__maxend[] = "maxend";
static char __pyx_k__minend[] = "minend";
static char __pyx_k__strand[] = "strand";
static char __pyx_k__reverse[] = "reverse";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k__interval[] = "interval";
static char __pyx_k__max_dist[] = "max_dist";
static char __pyx_k__minstart[] = "minstart";
static char __pyx_k__operator[] = "operator";
static char __pyx_k__position[] = "position";
static char __pyx_k__priority[] = "priority";
static char __pyx_k__set_ends[] = "set_ends";
static char __pyx_k__traverse[] = "traverse";
static char __pyx_k___traverse[] = "_traverse";
static char __pyx_k__intersect[] = "intersect";
static char __pyx_k___intersect[] = "_intersect";
static char __pyx_k___seek_left[] = "_seek_left";
static char __pyx_k__attrgetter[] = "attrgetter";
static char __pyx_k__Intersecter[] = "Intersecter";
static char __pyx_k___seek_right[] = "_seek_right";
static char __pyx_k__rotate_left[] = "rotate_left";
static char __pyx_k__IntervalNode[] = "IntervalNode";
static char __pyx_k__IntervalTree[] = "IntervalTree";
static char __pyx_k__add_interval[] = "add_interval";
static char __pyx_k__rotate_right[] = "rotate_right";
static char __pyx_k__num_intervals[] = "num_intervals";
static char __pyx_k__after_interval[] = "after_interval";
static char __pyx_k__before_interval[] = "before_interval";
static char __pyx_k__insert_interval[] = "insert_interval";
static PyObject *__pyx_kp_s_1;
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_16;
static PyObject *__pyx_kp_u_17;
static PyObject *__pyx_kp_u_18;
static PyObject *__pyx_kp_u_19;
static PyObject *__pyx_kp_u_20;
static PyObject *__pyx_n_s_21;
static PyObject *__pyx_kp_u_22;
static PyObject *__pyx_n_s_23;
static PyObject *__pyx_kp_u_24;
static PyObject *__pyx_kp_s_3;
static PyObject *__pyx_kp_s_4;
static PyObject *__pyx_kp_s_5;
static PyObject *__pyx_kp_s_6;
static PyObject *__pyx_kp_s_7;
static PyObject *__pyx_kp_u_9;
static PyObject *__pyx_n_s__Intersecter;
static PyObject *__pyx_n_s__IntervalNode;
static PyObject *__pyx_n_s__IntervalTree;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s___intersect;
static PyObject *__pyx_n_s___seek_left;
static PyObject *__pyx_n_s___seek_right;
static PyObject *__pyx_n_s___traverse;
static PyObject *__pyx_n_s__add;
static PyObject *__pyx_n_s__add_interval;
static PyObject *__pyx_n_s__after;
static PyObject *__pyx_n_s__after_interval;
static PyObject *__pyx_n_s__attrgetter;
static PyObject *__pyx_n_s__before;
static PyObject *__pyx_n_s__before_interval;
static PyObject *__pyx_n_s__chrom;
static PyObject *__pyx_n_s__cleft;
static PyObject *__pyx_n_s__cmp;
static PyObject *__pyx_n_s__cright;
static PyObject *__pyx_n_s__croot;
static PyObject *__pyx_n_s__end;
static PyObject *__pyx_n_s__find;
static PyObject *__pyx_n_s__insert;
static PyObject *__pyx_n_s__insert_interval;
static PyObject *__pyx_n_s__intersect;
static PyObject *__pyx_n_s__interval;
static PyObject *__pyx_n_s__key;
static PyObject *__pyx_n_s__left;
static PyObject *__pyx_n_s__max_dist;
static PyObject *__pyx_n_s__maxend;
static PyObject *__pyx_n_s__minend;
static PyObject *__pyx_n_s__minstart;
static PyObject *__pyx_n_s__n;
static PyObject *__pyx_n_s__num_intervals;
static PyObject *__pyx_n_s__operator;
static PyObject *__pyx_n_s__position;
static PyObject *__pyx_n_s__priority;
static PyObject *__pyx_n_s__reverse;
static PyObject *__pyx_n_s__right;
static PyObject *__pyx_n_s__root;
static PyObject *__pyx_n_s__rotate_left;
static PyObject *__pyx_n_s__rotate_right;
static PyObject *__pyx_n_s__set_ends;
static PyObject *__pyx_n_s__sort;
static PyObject *__pyx_n_s__start;
static PyObject *__pyx_n_s__strand;
static PyObject *__pyx_n_s__traverse;
static PyObject *__pyx_n_s__value;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_int_2500;
static PyObject *__pyx_k_2;

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":33
 *     int iabs(int)
 * 
 * cdef inline int imax2(int a, int b):             # <<<<<<<<<<<<<<
 *     if b > a: return b
 *     return a
 */

static CYTHON_INLINE int __pyx_f_11chimerascan_2bx_12intersection_imax2(int __pyx_v_a, int __pyx_v_b) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("imax2");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":34
 * 
 * cdef inline int imax2(int a, int b):
 *     if b > a: return b             # <<<<<<<<<<<<<<
 *     return a
 * 
 */
  __pyx_t_1 = (__pyx_v_b > __pyx_v_a);
  if (__pyx_t_1) {
    __pyx_r = __pyx_v_b;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":35
 * cdef inline int imax2(int a, int b):
 *     if b > a: return b
 *     return a             # <<<<<<<<<<<<<<
 * 
 * cdef inline int imax3(int a, int b, int c):
 */
  __pyx_r = __pyx_v_a;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":37
 *     return a
 * 
 * cdef inline int imax3(int a, int b, int c):             # <<<<<<<<<<<<<<
 *     if b > a:
 *         if c > b:
 */

static CYTHON_INLINE int __pyx_f_11chimerascan_2bx_12intersection_imax3(int __pyx_v_a, int __pyx_v_b, int __pyx_v_c) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("imax3");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":38
 * 
 * cdef inline int imax3(int a, int b, int c):
 *     if b > a:             # <<<<<<<<<<<<<<
 *         if c > b:
 *             return c
 */
  __pyx_t_1 = (__pyx_v_b > __pyx_v_a);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":39
 * cdef inline int imax3(int a, int b, int c):
 *     if b > a:
 *         if c > b:             # <<<<<<<<<<<<<<
 *             return c
 *         return b
 */
    __pyx_t_1 = (__pyx_v_c > __pyx_v_b);
    if (__pyx_t_1) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":40
 *     if b > a:
 *         if c > b:
 *             return c             # <<<<<<<<<<<<<<
 *         return b
 *     if a > c:
 */
      __pyx_r = __pyx_v_c;
      goto __pyx_L0;
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":41
 *         if c > b:
 *             return c
 *         return b             # <<<<<<<<<<<<<<
 *     if a > c:
 *         return a
 */
    __pyx_r = __pyx_v_b;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":42
 *             return c
 *         return b
 *     if a > c:             # <<<<<<<<<<<<<<
 *         return a
 *     return c
 */
  __pyx_t_1 = (__pyx_v_a > __pyx_v_c);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":43
 *         return b
 *     if a > c:
 *         return a             # <<<<<<<<<<<<<<
 *     return c
 * 
 */
    __pyx_r = __pyx_v_a;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":44
 *     if a > c:
 *         return a
 *     return c             # <<<<<<<<<<<<<<
 * 
 * cdef inline int imin3(int a, int b, int c):
 */
  __pyx_r = __pyx_v_c;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":46
 *     return c
 * 
 * cdef inline int imin3(int a, int b, int c):             # <<<<<<<<<<<<<<
 *     if b < a:
 *         if c < b:
 */

static CYTHON_INLINE int __pyx_f_11chimerascan_2bx_12intersection_imin3(int __pyx_v_a, int __pyx_v_b, int __pyx_v_c) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("imin3");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":47
 * 
 * cdef inline int imin3(int a, int b, int c):
 *     if b < a:             # <<<<<<<<<<<<<<
 *         if c < b:
 *             return c
 */
  __pyx_t_1 = (__pyx_v_b < __pyx_v_a);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":48
 * cdef inline int imin3(int a, int b, int c):
 *     if b < a:
 *         if c < b:             # <<<<<<<<<<<<<<
 *             return c
 *         return b
 */
    __pyx_t_1 = (__pyx_v_c < __pyx_v_b);
    if (__pyx_t_1) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":49
 *     if b < a:
 *         if c < b:
 *             return c             # <<<<<<<<<<<<<<
 *         return b
 *     if a < c:
 */
      __pyx_r = __pyx_v_c;
      goto __pyx_L0;
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":50
 *         if c < b:
 *             return c
 *         return b             # <<<<<<<<<<<<<<
 *     if a < c:
 *         return a
 */
    __pyx_r = __pyx_v_b;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":51
 *             return c
 *         return b
 *     if a < c:             # <<<<<<<<<<<<<<
 *         return a
 *     return c
 */
  __pyx_t_1 = (__pyx_v_a < __pyx_v_c);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":52
 *         return b
 *     if a < c:
 *         return a             # <<<<<<<<<<<<<<
 *     return c
 * 
 */
    __pyx_r = __pyx_v_a;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":53
 *     if a < c:
 *         return a
 *     return c             # <<<<<<<<<<<<<<
 * 
 * cdef inline int imin2(int a, int b):
 */
  __pyx_r = __pyx_v_c;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":55
 *     return c
 * 
 * cdef inline int imin2(int a, int b):             # <<<<<<<<<<<<<<
 *     if b < a: return b
 *     return a
 */

static CYTHON_INLINE int __pyx_f_11chimerascan_2bx_12intersection_imin2(int __pyx_v_a, int __pyx_v_b) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("imin2");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":56
 * 
 * cdef inline int imin2(int a, int b):
 *     if b < a: return b             # <<<<<<<<<<<<<<
 *     return a
 * 
 */
  __pyx_t_1 = (__pyx_v_b < __pyx_v_a);
  if (__pyx_t_1) {
    __pyx_r = __pyx_v_b;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":57
 * cdef inline int imin2(int a, int b):
 *     if b < a: return b
 *     return a             # <<<<<<<<<<<<<<
 * 
 * cdef float nlog = -1.0 / log(0.5)
 */
  __pyx_r = __pyx_v_a;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":69
 *     """
 *     cdef float priority
 *     cdef public object interval             # <<<<<<<<<<<<<<
 *     cdef public int start, end
 *     cdef int minend, maxend, minstart
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_8interval___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_8interval___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->interval);
  __pyx_r = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->interval;
  goto __pyx_L0;

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

static int __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_8interval___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_8interval___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->interval);
  __Pyx_DECREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->interval);
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->interval = __pyx_v_value;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_8interval___del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_8interval___del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__del__");
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->interval);
  __Pyx_DECREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->interval);
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->interval = Py_None;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":70
 *     cdef float priority
 *     cdef public object interval
 *     cdef public int start, end             # <<<<<<<<<<<<<<
 *     cdef int minend, maxend, minstart
 *     cdef IntervalNode cleft, cright, croot
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_5start___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_5start___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.start.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_5start___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_5start___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__set__");
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->start = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.start.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_3end___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_3end___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.end.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_3end___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_3end___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__set__");
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->end = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.end.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":75
 * 
 *     property left_node:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.cleft if self.cleft is not EmptyNode else None
 *     property right_node:
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_9left_node___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_9left_node___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("__get__");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":76
 *     property left_node:
 *         def __get__(self):
 *             return self.cleft if self.cleft is not EmptyNode else None             # <<<<<<<<<<<<<<
 *     property right_node:
 *         def __get__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = (((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->cleft != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_2) {
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->cleft));
    __pyx_t_1 = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->cleft;
  } else {
    __Pyx_INCREF(Py_None);
    __pyx_t_1 = Py_None;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":78
 *             return self.cleft if self.cleft is not EmptyNode else None
 *     property right_node:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.cright if self.cright is not EmptyNode else None
 *     property root_node:
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_10right_node___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_10right_node___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("__get__");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":79
 *     property right_node:
 *         def __get__(self):
 *             return self.cright if self.cright is not EmptyNode else None             # <<<<<<<<<<<<<<
 *     property root_node:
 *         def __get__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = (((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->cright != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_2) {
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->cright));
    __pyx_t_1 = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->cright;
  } else {
    __Pyx_INCREF(Py_None);
    __pyx_t_1 = Py_None;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":81
 *             return self.cright if self.cright is not EmptyNode else None
 *     property root_node:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.croot if self.croot is not EmptyNode else None
 * 
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_9root_node___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_9root_node___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("__get__");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":82
 *     property root_node:
 *         def __get__(self):
 *             return self.croot if self.croot is not EmptyNode else None             # <<<<<<<<<<<<<<
 * 
 *     def __repr__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = (((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->croot != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_2) {
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->croot));
    __pyx_t_1 = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->croot;
  } else {
    __Pyx_INCREF(Py_None);
    __pyx_t_1 = Py_None;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":84
 *             return self.croot if self.croot is not EmptyNode else None
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return "IntervalNode(%i, %i)" % (self.start, self.end)
 * 
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode___repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode___repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("__repr__");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":85
 * 
 *     def __repr__(self):
 *         return "IntervalNode(%i, %i)" % (self.start, self.end)             # <<<<<<<<<<<<<<
 * 
 *     def __cinit__(IntervalNode self, int start, int end, object interval):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->end); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.__repr__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":87
 *         return "IntervalNode(%i, %i)" % (self.start, self.end)
 * 
 *     def __cinit__(IntervalNode self, int start, int end, object interval):             # <<<<<<<<<<<<<<
 *         # Python lacks the binomial distribution, so we convert a
 *         # uniform into a binomial because it naturally scales with
 */

static int __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_start;
  int __pyx_v_end;
  PyObject *__pyx_v_interval = 0;
  int __pyx_r;
  double __pyx_t_1;
  double __pyx_t_2;
  double __pyx_t_3;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__interval,0};
  __Pyx_RefNannySetupContext("__cinit__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__interval);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_start = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_interval = values[2];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_start = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_interval = PyTuple_GET_ITEM(__pyx_args, 2);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.__cinit__");
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":92
 *         # tree size.  Also, python's uniform is perfect since the
 *         # upper limit is not inclusive, which gives us undefined here.
 *         self.priority = ceil(nlog * log(-1.0/(1.0 * rand()/RAND_MAX - 1)))             # <<<<<<<<<<<<<<
 *         self.start    = start
 *         self.end      = end
 */
  __pyx_t_1 = (-1.0);
  __pyx_t_2 = (1.0 * rand());
  if (unlikely(RAND_MAX == 0)) {
    PyErr_Format(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_3 = ((__pyx_t_2 / RAND_MAX) - 1.0);
  if (unlikely(__pyx_t_3 == 0)) {
    PyErr_Format(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->priority = ceil((__pyx_v_11chimerascan_2bx_12intersection_nlog * log((__pyx_t_1 / __pyx_t_3))));

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":93
 *         # upper limit is not inclusive, which gives us undefined here.
 *         self.priority = ceil(nlog * log(-1.0/(1.0 * rand()/RAND_MAX - 1)))
 *         self.start    = start             # <<<<<<<<<<<<<<
 *         self.end      = end
 *         self.interval = interval
 */
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->start = __pyx_v_start;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":94
 *         self.priority = ceil(nlog * log(-1.0/(1.0 * rand()/RAND_MAX - 1)))
 *         self.start    = start
 *         self.end      = end             # <<<<<<<<<<<<<<
 *         self.interval = interval
 *         self.maxend   = end
 */
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->end = __pyx_v_end;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":95
 *         self.start    = start
 *         self.end      = end
 *         self.interval = interval             # <<<<<<<<<<<<<<
 *         self.maxend   = end
 *         self.minstart = start
 */
  __Pyx_INCREF(__pyx_v_interval);
  __Pyx_GIVEREF(__pyx_v_interval);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->interval);
  __Pyx_DECREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->interval);
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->interval = __pyx_v_interval;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":96
 *         self.end      = end
 *         self.interval = interval
 *         self.maxend   = end             # <<<<<<<<<<<<<<
 *         self.minstart = start
 *         self.minend   = end
 */
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->maxend = __pyx_v_end;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":97
 *         self.interval = interval
 *         self.maxend   = end
 *         self.minstart = start             # <<<<<<<<<<<<<<
 *         self.minend   = end
 *         self.cleft    = EmptyNode
 */
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->minstart = __pyx_v_start;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":98
 *         self.maxend   = end
 *         self.minstart = start
 *         self.minend   = end             # <<<<<<<<<<<<<<
 *         self.cleft    = EmptyNode
 *         self.cright   = EmptyNode
 */
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->minend = __pyx_v_end;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":99
 *         self.minstart = start
 *         self.minend   = end
 *         self.cleft    = EmptyNode             # <<<<<<<<<<<<<<
 *         self.cright   = EmptyNode
 *         self.croot    = EmptyNode
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_11chimerascan_2bx_12intersection_EmptyNode));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_11chimerascan_2bx_12intersection_EmptyNode));
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->cleft);
  __Pyx_DECREF(((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->cleft));
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->cleft = __pyx_v_11chimerascan_2bx_12intersection_EmptyNode;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":100
 *         self.minend   = end
 *         self.cleft    = EmptyNode
 *         self.cright   = EmptyNode             # <<<<<<<<<<<<<<
 *         self.croot    = EmptyNode
 * 
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_11chimerascan_2bx_12intersection_EmptyNode));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_11chimerascan_2bx_12intersection_EmptyNode));
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->cright);
  __Pyx_DECREF(((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->cright));
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->cright = __pyx_v_11chimerascan_2bx_12intersection_EmptyNode;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":101
 *         self.cleft    = EmptyNode
 *         self.cright   = EmptyNode
 *         self.croot    = EmptyNode             # <<<<<<<<<<<<<<
 * 
 *     cpdef IntervalNode insert(IntervalNode self, int start, int end, object interval):
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_11chimerascan_2bx_12intersection_EmptyNode));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_11chimerascan_2bx_12intersection_EmptyNode));
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->croot);
  __Pyx_DECREF(((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->croot));
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->croot = __pyx_v_11chimerascan_2bx_12intersection_EmptyNode;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.__cinit__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":103
 *         self.croot    = EmptyNode
 * 
 *     cpdef IntervalNode insert(IntervalNode self, int start, int end, object interval):             # <<<<<<<<<<<<<<
 *         """
 *         Insert a new IntervalNode into the tree of which this node is
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_insert(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_self, int __pyx_v_start, int __pyx_v_end, PyObject *__pyx_v_interval, int __pyx_skip_dispatch) {
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_croot = 0;
  int __pyx_v_decision_endpoint;
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("insert");
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__insert); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (void *)&__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_insert)) {
      __Pyx_XDECREF(((PyObject *)__pyx_r));
      __pyx_t_2 = PyInt_FromLong(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_v_interval);
      PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_interval);
      __Pyx_GIVEREF(__pyx_v_interval);
      __pyx_t_2 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_11chimerascan_2bx_12intersection_IntervalNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_r = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":109
 *         may or may not be this node!)
 *         """
 *         cdef IntervalNode croot = self             # <<<<<<<<<<<<<<
 *         # If starts are the same, decide which to add interval to based on
 *         # end, thus maintaining sortedness relative to start/end
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_v_croot = __pyx_v_self;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":112
 *         # If starts are the same, decide which to add interval to based on
 *         # end, thus maintaining sortedness relative to start/end
 *         cdef int decision_endpoint = start             # <<<<<<<<<<<<<<
 *         if start == self.start:
 *             decision_endpoint = end
 */
  __pyx_v_decision_endpoint = __pyx_v_start;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":113
 *         # end, thus maintaining sortedness relative to start/end
 *         cdef int decision_endpoint = start
 *         if start == self.start:             # <<<<<<<<<<<<<<
 *             decision_endpoint = end
 * 
 */
  __pyx_t_5 = (__pyx_v_start == __pyx_v_self->start);
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":114
 *         cdef int decision_endpoint = start
 *         if start == self.start:
 *             decision_endpoint = end             # <<<<<<<<<<<<<<
 * 
 *         if decision_endpoint > self.start:
 */
    __pyx_v_decision_endpoint = __pyx_v_end;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":116
 *             decision_endpoint = end
 * 
 *         if decision_endpoint > self.start:             # <<<<<<<<<<<<<<
 *             # insert to cright tree
 *             if self.cright is not EmptyNode:
 */
  __pyx_t_5 = (__pyx_v_decision_endpoint > __pyx_v_self->start);
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":118
 *         if decision_endpoint > self.start:
 *             # insert to cright tree
 *             if self.cright is not EmptyNode:             # <<<<<<<<<<<<<<
 *                 self.cright = self.cright.insert( start, end, interval )
 *             else:
 */
    __pyx_t_5 = (__pyx_v_self->cright != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
    if (__pyx_t_5) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":119
 *             # insert to cright tree
 *             if self.cright is not EmptyNode:
 *                 self.cright = self.cright.insert( start, end, interval )             # <<<<<<<<<<<<<<
 *             else:
 *                 self.cright = IntervalNode( start, end, interval )
 */
      __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->cright->__pyx_vtab)->insert(__pyx_v_self->cright, __pyx_v_start, __pyx_v_end, __pyx_v_interval, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_v_self->cright);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->cright));
      __pyx_v_self->cright = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_t_1);
      __pyx_t_1 = 0;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":121
 *                 self.cright = self.cright.insert( start, end, interval )
 *             else:
 *                 self.cright = IntervalNode( start, end, interval )             # <<<<<<<<<<<<<<
 *             # rebalance tree
 *             if self.priority < self.cright.priority:
 */
      __pyx_t_1 = PyInt_FromLong(__pyx_v_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_v_interval);
      PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_interval);
      __Pyx_GIVEREF(__pyx_v_interval);
      __pyx_t_1 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_2bx_12intersection_IntervalNode)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GIVEREF(__pyx_t_3);
      __Pyx_GOTREF(__pyx_v_self->cright);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->cright));
      __pyx_v_self->cright = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_t_3);
      __pyx_t_3 = 0;
    }
    __pyx_L5:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":123
 *                 self.cright = IntervalNode( start, end, interval )
 *             # rebalance tree
 *             if self.priority < self.cright.priority:             # <<<<<<<<<<<<<<
 *                 croot = self.rotate_left()
 *         else:
 */
    __pyx_t_5 = (__pyx_v_self->priority < __pyx_v_self->cright->priority);
    if (__pyx_t_5) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":124
 *             # rebalance tree
 *             if self.priority < self.cright.priority:
 *                 croot = self.rotate_left()             # <<<<<<<<<<<<<<
 *         else:
 *             # insert to cleft tree
 */
      __pyx_t_3 = ((PyObject *)((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->__pyx_vtab)->rotate_left(__pyx_v_self)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_v_croot));
      __pyx_v_croot = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_t_3);
      __pyx_t_3 = 0;
      goto __pyx_L6;
    }
    __pyx_L6:;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":127
 *         else:
 *             # insert to cleft tree
 *             if self.cleft is not EmptyNode:             # <<<<<<<<<<<<<<
 *                 self.cleft = self.cleft.insert( start, end, interval)
 *             else:
 */
    __pyx_t_5 = (__pyx_v_self->cleft != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
    if (__pyx_t_5) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":128
 *             # insert to cleft tree
 *             if self.cleft is not EmptyNode:
 *                 self.cleft = self.cleft.insert( start, end, interval)             # <<<<<<<<<<<<<<
 *             else:
 *                 self.cleft = IntervalNode( start, end, interval)
 */
      __pyx_t_3 = ((PyObject *)((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->cleft->__pyx_vtab)->insert(__pyx_v_self->cleft, __pyx_v_start, __pyx_v_end, __pyx_v_interval, 0)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __Pyx_GOTREF(__pyx_v_self->cleft);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->cleft));
      __pyx_v_self->cleft = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_t_3);
      __pyx_t_3 = 0;
      goto __pyx_L7;
    }
    /*else*/ {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":130
 *                 self.cleft = self.cleft.insert( start, end, interval)
 *             else:
 *                 self.cleft = IntervalNode( start, end, interval)             # <<<<<<<<<<<<<<
 *             # rebalance tree
 *             if self.priority < self.cleft.priority:
 */
      __pyx_t_3 = PyInt_FromLong(__pyx_v_start); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyInt_FromLong(__pyx_v_end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_v_interval);
      PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_interval);
      __Pyx_GIVEREF(__pyx_v_interval);
      __pyx_t_3 = 0;
      __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_2bx_12intersection_IntervalNode)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GIVEREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_v_self->cleft);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->cleft));
      __pyx_v_self->cleft = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_t_4);
      __pyx_t_4 = 0;
    }
    __pyx_L7:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":132
 *                 self.cleft = IntervalNode( start, end, interval)
 *             # rebalance tree
 *             if self.priority < self.cleft.priority:             # <<<<<<<<<<<<<<
 *                 croot = self.rotate_right()
 * 
 */
    __pyx_t_5 = (__pyx_v_self->priority < __pyx_v_self->cleft->priority);
    if (__pyx_t_5) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":133
 *             # rebalance tree
 *             if self.priority < self.cleft.priority:
 *                 croot = self.rotate_right()             # <<<<<<<<<<<<<<
 * 
 *         croot.set_ends()
 */
      __pyx_t_4 = ((PyObject *)((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->__pyx_vtab)->rotate_right(__pyx_v_self)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(((PyObject *)__pyx_v_croot));
      __pyx_v_croot = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_t_4);
      __pyx_t_4 = 0;
      goto __pyx_L8;
    }
    __pyx_L8:;
  }
  __pyx_L4:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":135
 *                 croot = self.rotate_right()
 * 
 *         croot.set_ends()             # <<<<<<<<<<<<<<
 *         self.cleft.croot  = croot
 *         self.cright.croot = croot
 */
  ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_croot->__pyx_vtab)->set_ends(__pyx_v_croot);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":136
 * 
 *         croot.set_ends()
 *         self.cleft.croot  = croot             # <<<<<<<<<<<<<<
 *         self.cright.croot = croot
 *         return croot
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_croot));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_croot));
  __Pyx_GOTREF(__pyx_v_self->cleft->croot);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->cleft->croot));
  __pyx_v_self->cleft->croot = __pyx_v_croot;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":137
 *         croot.set_ends()
 *         self.cleft.croot  = croot
 *         self.cright.croot = croot             # <<<<<<<<<<<<<<
 *         return croot
 * 
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_croot));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_croot));
  __Pyx_GOTREF(__pyx_v_self->cright->croot);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->cright->croot));
  __pyx_v_self->cright->croot = __pyx_v_croot;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":138
 *         self.cleft.croot  = croot
 *         self.cright.croot = croot
 *         return croot             # <<<<<<<<<<<<<<
 * 
 *     cdef IntervalNode rotate_right(IntervalNode self):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_croot));
  __pyx_r = __pyx_v_croot;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)Py_None); __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.insert");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_croot);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":103
 *         self.croot    = EmptyNode
 * 
 *     cpdef IntervalNode insert(IntervalNode self, int start, int end, object interval):             # <<<<<<<<<<<<<<
 *         """
 *         Insert a new IntervalNode into the tree of which this node is
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalNode_insert[] = "\n        Insert a new IntervalNode into the tree of which this node is\n        currently the root. The return value is the new root of the tree (which\n        may or may not be this node!)\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_start;
  int __pyx_v_end;
  PyObject *__pyx_v_interval = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__interval,0};
  __Pyx_RefNannySetupContext("insert");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("insert", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__interval);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("insert", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "insert") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_start = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_interval = values[2];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_start = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_interval = PyTuple_GET_ITEM(__pyx_args, 2);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("insert", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.insert");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->__pyx_vtab)->insert(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self), __pyx_v_start, __pyx_v_end, __pyx_v_interval, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.insert");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":140
 *         return croot
 * 
 *     cdef IntervalNode rotate_right(IntervalNode self):             # <<<<<<<<<<<<<<
 *         cdef IntervalNode croot = self.cleft
 *         self.cleft  = self.cleft.cright
 */

static  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_rotate_right(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_self) {
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_croot = 0;
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("rotate_right");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":141
 * 
 *     cdef IntervalNode rotate_right(IntervalNode self):
 *         cdef IntervalNode croot = self.cleft             # <<<<<<<<<<<<<<
 *         self.cleft  = self.cleft.cright
 *         croot.cright = self
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self->cleft));
  __pyx_v_croot = __pyx_v_self->cleft;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":142
 *     cdef IntervalNode rotate_right(IntervalNode self):
 *         cdef IntervalNode croot = self.cleft
 *         self.cleft  = self.cleft.cright             # <<<<<<<<<<<<<<
 *         croot.cright = self
 *         self.set_ends()
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self->cleft->cright));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->cleft->cright));
  __Pyx_GOTREF(__pyx_v_self->cleft);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->cleft));
  __pyx_v_self->cleft = __pyx_v_self->cleft->cright;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":143
 *         cdef IntervalNode croot = self.cleft
 *         self.cleft  = self.cleft.cright
 *         croot.cright = self             # <<<<<<<<<<<<<<
 *         self.set_ends()
 *         return croot
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_GOTREF(__pyx_v_croot->cright);
  __Pyx_DECREF(((PyObject *)__pyx_v_croot->cright));
  __pyx_v_croot->cright = __pyx_v_self;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":144
 *         self.cleft  = self.cleft.cright
 *         croot.cright = self
 *         self.set_ends()             # <<<<<<<<<<<<<<
 *         return croot
 * 
 */
  ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->__pyx_vtab)->set_ends(__pyx_v_self);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":145
 *         croot.cright = self
 *         self.set_ends()
 *         return croot             # <<<<<<<<<<<<<<
 * 
 *     cdef IntervalNode rotate_left(IntervalNode self):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_croot));
  __pyx_r = __pyx_v_croot;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_croot);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":147
 *         return croot
 * 
 *     cdef IntervalNode rotate_left(IntervalNode self):             # <<<<<<<<<<<<<<
 *         cdef IntervalNode croot = self.cright
 *         self.cright = self.cright.cleft
 */

static  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_rotate_left(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_self) {
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_croot = 0;
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("rotate_left");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":148
 * 
 *     cdef IntervalNode rotate_left(IntervalNode self):
 *         cdef IntervalNode croot = self.cright             # <<<<<<<<<<<<<<
 *         self.cright = self.cright.cleft
 *         croot.cleft  = self
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self->cright));
  __pyx_v_croot = __pyx_v_self->cright;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":149
 *     cdef IntervalNode rotate_left(IntervalNode self):
 *         cdef IntervalNode croot = self.cright
 *         self.cright = self.cright.cleft             # <<<<<<<<<<<<<<
 *         croot.cleft  = self
 *         self.set_ends()
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self->cright->cleft));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->cright->cleft));
  __Pyx_GOTREF(__pyx_v_self->cright);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->cright));
  __pyx_v_self->cright = __pyx_v_self->cright->cleft;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":150
 *         cdef IntervalNode croot = self.cright
 *         self.cright = self.cright.cleft
 *         croot.cleft  = self             # <<<<<<<<<<<<<<
 *         self.set_ends()
 *         return croot
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_GOTREF(__pyx_v_croot->cleft);
  __Pyx_DECREF(((PyObject *)__pyx_v_croot->cleft));
  __pyx_v_croot->cleft = __pyx_v_self;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":151
 *         self.cright = self.cright.cleft
 *         croot.cleft  = self
 *         self.set_ends()             # <<<<<<<<<<<<<<
 *         return croot
 * 
 */
  ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->__pyx_vtab)->set_ends(__pyx_v_self);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":152
 *         croot.cleft  = self
 *         self.set_ends()
 *         return croot             # <<<<<<<<<<<<<<
 * 
 *     cdef inline void set_ends(IntervalNode self):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_croot));
  __pyx_r = __pyx_v_croot;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_croot);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":154
 *         return croot
 * 
 *     cdef inline void set_ends(IntervalNode self):             # <<<<<<<<<<<<<<
 *         if self.cright is not EmptyNode and self.cleft is not EmptyNode:
 *             self.maxend = imax3(self.end, self.cright.maxend, self.cleft.maxend)
 */

static CYTHON_INLINE void __pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_set_ends(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_self) {
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("set_ends");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":155
 * 
 *     cdef inline void set_ends(IntervalNode self):
 *         if self.cright is not EmptyNode and self.cleft is not EmptyNode:             # <<<<<<<<<<<<<<
 *             self.maxend = imax3(self.end, self.cright.maxend, self.cleft.maxend)
 *             self.minend = imin3(self.end, self.cright.minend, self.cleft.minend)
 */
  __pyx_t_1 = (__pyx_v_self->cright != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_1) {
    __pyx_t_2 = (__pyx_v_self->cleft != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_1;
  }
  if (__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":156
 *     cdef inline void set_ends(IntervalNode self):
 *         if self.cright is not EmptyNode and self.cleft is not EmptyNode:
 *             self.maxend = imax3(self.end, self.cright.maxend, self.cleft.maxend)             # <<<<<<<<<<<<<<
 *             self.minend = imin3(self.end, self.cright.minend, self.cleft.minend)
 *             self.minstart = imin3(self.start, self.cright.minstart, self.cleft.minstart)
 */
    __pyx_v_self->maxend = __pyx_f_11chimerascan_2bx_12intersection_imax3(__pyx_v_self->end, __pyx_v_self->cright->maxend, __pyx_v_self->cleft->maxend);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":157
 *         if self.cright is not EmptyNode and self.cleft is not EmptyNode:
 *             self.maxend = imax3(self.end, self.cright.maxend, self.cleft.maxend)
 *             self.minend = imin3(self.end, self.cright.minend, self.cleft.minend)             # <<<<<<<<<<<<<<
 *             self.minstart = imin3(self.start, self.cright.minstart, self.cleft.minstart)
 *         elif self.cright is not EmptyNode:
 */
    __pyx_v_self->minend = __pyx_f_11chimerascan_2bx_12intersection_imin3(__pyx_v_self->end, __pyx_v_self->cright->minend, __pyx_v_self->cleft->minend);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":158
 *             self.maxend = imax3(self.end, self.cright.maxend, self.cleft.maxend)
 *             self.minend = imin3(self.end, self.cright.minend, self.cleft.minend)
 *             self.minstart = imin3(self.start, self.cright.minstart, self.cleft.minstart)             # <<<<<<<<<<<<<<
 *         elif self.cright is not EmptyNode:
 *             self.maxend = imax2(self.end, self.cright.maxend)
 */
    __pyx_v_self->minstart = __pyx_f_11chimerascan_2bx_12intersection_imin3(__pyx_v_self->start, __pyx_v_self->cright->minstart, __pyx_v_self->cleft->minstart);
    goto __pyx_L3;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":159
 *             self.minend = imin3(self.end, self.cright.minend, self.cleft.minend)
 *             self.minstart = imin3(self.start, self.cright.minstart, self.cleft.minstart)
 *         elif self.cright is not EmptyNode:             # <<<<<<<<<<<<<<
 *             self.maxend = imax2(self.end, self.cright.maxend)
 *             self.minend = imin2(self.end, self.cright.minend)
 */
  __pyx_t_3 = (__pyx_v_self->cright != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":160
 *             self.minstart = imin3(self.start, self.cright.minstart, self.cleft.minstart)
 *         elif self.cright is not EmptyNode:
 *             self.maxend = imax2(self.end, self.cright.maxend)             # <<<<<<<<<<<<<<
 *             self.minend = imin2(self.end, self.cright.minend)
 *             self.minstart = imin2(self.start, self.cright.minstart)
 */
    __pyx_v_self->maxend = __pyx_f_11chimerascan_2bx_12intersection_imax2(__pyx_v_self->end, __pyx_v_self->cright->maxend);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":161
 *         elif self.cright is not EmptyNode:
 *             self.maxend = imax2(self.end, self.cright.maxend)
 *             self.minend = imin2(self.end, self.cright.minend)             # <<<<<<<<<<<<<<
 *             self.minstart = imin2(self.start, self.cright.minstart)
 *         elif self.cleft is not EmptyNode:
 */
    __pyx_v_self->minend = __pyx_f_11chimerascan_2bx_12intersection_imin2(__pyx_v_self->end, __pyx_v_self->cright->minend);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":162
 *             self.maxend = imax2(self.end, self.cright.maxend)
 *             self.minend = imin2(self.end, self.cright.minend)
 *             self.minstart = imin2(self.start, self.cright.minstart)             # <<<<<<<<<<<<<<
 *         elif self.cleft is not EmptyNode:
 *             self.maxend = imax2(self.end, self.cleft.maxend)
 */
    __pyx_v_self->minstart = __pyx_f_11chimerascan_2bx_12intersection_imin2(__pyx_v_self->start, __pyx_v_self->cright->minstart);
    goto __pyx_L3;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":163
 *             self.minend = imin2(self.end, self.cright.minend)
 *             self.minstart = imin2(self.start, self.cright.minstart)
 *         elif self.cleft is not EmptyNode:             # <<<<<<<<<<<<<<
 *             self.maxend = imax2(self.end, self.cleft.maxend)
 *             self.minend = imin2(self.end, self.cleft.minend)
 */
  __pyx_t_3 = (__pyx_v_self->cleft != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":164
 *             self.minstart = imin2(self.start, self.cright.minstart)
 *         elif self.cleft is not EmptyNode:
 *             self.maxend = imax2(self.end, self.cleft.maxend)             # <<<<<<<<<<<<<<
 *             self.minend = imin2(self.end, self.cleft.minend)
 *             self.minstart = imin2(self.start, self.cleft.minstart)
 */
    __pyx_v_self->maxend = __pyx_f_11chimerascan_2bx_12intersection_imax2(__pyx_v_self->end, __pyx_v_self->cleft->maxend);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":165
 *         elif self.cleft is not EmptyNode:
 *             self.maxend = imax2(self.end, self.cleft.maxend)
 *             self.minend = imin2(self.end, self.cleft.minend)             # <<<<<<<<<<<<<<
 *             self.minstart = imin2(self.start, self.cleft.minstart)
 * 
 */
    __pyx_v_self->minend = __pyx_f_11chimerascan_2bx_12intersection_imin2(__pyx_v_self->end, __pyx_v_self->cleft->minend);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":166
 *             self.maxend = imax2(self.end, self.cleft.maxend)
 *             self.minend = imin2(self.end, self.cleft.minend)
 *             self.minstart = imin2(self.start, self.cleft.minstart)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_v_self->minstart = __pyx_f_11chimerascan_2bx_12intersection_imin2(__pyx_v_self->start, __pyx_v_self->cleft->minstart);
    goto __pyx_L3;
  }
  __pyx_L3:;

  __Pyx_RefNannyFinishContext();
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":169
 * 
 * 
 *     def intersect( self, int start, int end, sort=True ):             # <<<<<<<<<<<<<<
 *         """
 *         given a start and a end, return a list of features
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_intersect(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalNode_intersect[] = "\n        given a start and a end, return a list of features\n        falling within that range\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_intersect(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_start;
  int __pyx_v_end;
  PyObject *__pyx_v_sort = 0;
  PyObject *__pyx_v_results = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__sort,0};
  __Pyx_RefNannySetupContext("intersect");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[2] = __pyx_k_2;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("intersect", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sort);
        if (value) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "intersect") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_start = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_sort = values[2];
  } else {
    __pyx_v_sort = __pyx_k_2;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3:
      __pyx_v_sort = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2:
      __pyx_v_end = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __pyx_v_start = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("intersect", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.intersect");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":174
 *         falling within that range
 *         """
 *         cdef list results = []             # <<<<<<<<<<<<<<
 *         self._intersect( start, end, results )
 *         return results
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_v_results = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":175
 *         """
 *         cdef list results = []
 *         self._intersect( start, end, results )             # <<<<<<<<<<<<<<
 *         return results
 * 
 */
  ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->__pyx_vtab)->_intersect(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self), __pyx_v_start, __pyx_v_end, __pyx_v_results);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":176
 *         cdef list results = []
 *         self._intersect( start, end, results )
 *         return results             # <<<<<<<<<<<<<<
 * 
 *     find = intersect
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_results));
  __pyx_r = ((PyObject *)__pyx_v_results);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.intersect");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_results);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":180
 *     find = intersect
 * 
 *     cdef void _intersect( IntervalNode self, int start, int end, list results ):             # <<<<<<<<<<<<<<
 *         # Left subtree
 *         if self.cleft is not EmptyNode and self.cleft.maxend > start:
 */

static  void __pyx_f_11chimerascan_2bx_12intersection_12IntervalNode__intersect(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_self, int __pyx_v_start, int __pyx_v_end, PyObject *__pyx_v_results) {
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  __Pyx_RefNannySetupContext("_intersect");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":182
 *     cdef void _intersect( IntervalNode self, int start, int end, list results ):
 *         # Left subtree
 *         if self.cleft is not EmptyNode and self.cleft.maxend > start:             # <<<<<<<<<<<<<<
 *             self.cleft._intersect( start, end, results )
 *         # This interval
 */
  __pyx_t_1 = (__pyx_v_self->cleft != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_1) {
    __pyx_t_2 = (__pyx_v_self->cleft->maxend > __pyx_v_start);
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_1;
  }
  if (__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":183
 *         # Left subtree
 *         if self.cleft is not EmptyNode and self.cleft.maxend > start:
 *             self.cleft._intersect( start, end, results )             # <<<<<<<<<<<<<<
 *         # This interval
 *         if ( self.end > start ) and ( self.start < end ):
 */
    ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->cleft->__pyx_vtab)->_intersect(__pyx_v_self->cleft, __pyx_v_start, __pyx_v_end, __pyx_v_results);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":185
 *             self.cleft._intersect( start, end, results )
 *         # This interval
 *         if ( self.end > start ) and ( self.start < end ):             # <<<<<<<<<<<<<<
 *             results.append( self.interval )
 *         # Right subtree
 */
  __pyx_t_3 = (__pyx_v_self->end > __pyx_v_start);
  if (__pyx_t_3) {
    __pyx_t_1 = (__pyx_v_self->start < __pyx_v_end);
    __pyx_t_2 = __pyx_t_1;
  } else {
    __pyx_t_2 = __pyx_t_3;
  }
  if (__pyx_t_2) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":186
 *         # This interval
 *         if ( self.end > start ) and ( self.start < end ):
 *             results.append( self.interval )             # <<<<<<<<<<<<<<
 *         # Right subtree
 *         if self.cright is not EmptyNode and self.start < end:
 */
    if (unlikely(__pyx_v_results == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_4 = PyList_Append(((PyObject *)__pyx_v_results), __pyx_v_self->interval); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":188
 *             results.append( self.interval )
 *         # Right subtree
 *         if self.cright is not EmptyNode and self.start < end:             # <<<<<<<<<<<<<<
 *             self.cright._intersect( start, end, results )
 * 
 */
  __pyx_t_2 = (__pyx_v_self->cright != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_2) {
    __pyx_t_3 = (__pyx_v_self->start < __pyx_v_end);
    __pyx_t_1 = __pyx_t_3;
  } else {
    __pyx_t_1 = __pyx_t_2;
  }
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":189
 *         # Right subtree
 *         if self.cright is not EmptyNode and self.start < end:
 *             self.cright._intersect( start, end, results )             # <<<<<<<<<<<<<<
 * 
 * 
 */
    ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->cright->__pyx_vtab)->_intersect(__pyx_v_self->cright, __pyx_v_start, __pyx_v_end, __pyx_v_results);
    goto __pyx_L5;
  }
  __pyx_L5:;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("chimerascan.bx.intersection.IntervalNode._intersect");
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":192
 * 
 * 
 *     cdef void _seek_left(IntervalNode self, int position, list results, int n, int max_dist):             # <<<<<<<<<<<<<<
 *         # we know we can bail in these 2 cases.
 *         if self.maxend + max_dist < position:
 */

static  void __pyx_f_11chimerascan_2bx_12intersection_12IntervalNode__seek_left(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_self, int __pyx_v_position, PyObject *__pyx_v_results, int __pyx_v_n, int __pyx_v_max_dist) {
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("_seek_left");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":194
 *     cdef void _seek_left(IntervalNode self, int position, list results, int n, int max_dist):
 *         # we know we can bail in these 2 cases.
 *         if self.maxend + max_dist < position:             # <<<<<<<<<<<<<<
 *             return
 *         if self.minstart > position:
 */
  __pyx_t_1 = ((__pyx_v_self->maxend + __pyx_v_max_dist) < __pyx_v_position);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":195
 *         # we know we can bail in these 2 cases.
 *         if self.maxend + max_dist < position:
 *             return             # <<<<<<<<<<<<<<
 *         if self.minstart > position:
 *             return
 */
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":196
 *         if self.maxend + max_dist < position:
 *             return
 *         if self.minstart > position:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  __pyx_t_1 = (__pyx_v_self->minstart > __pyx_v_position);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":197
 *             return
 *         if self.minstart > position:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         # the ordering of these 3 blocks makes it so the results are
 */
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":201
 *         # the ordering of these 3 blocks makes it so the results are
 *         # ordered nearest to farest from the query position
 *         if self.cright is not EmptyNode:             # <<<<<<<<<<<<<<
 *             self.cright._seek_left(position, results, n, max_dist)
 * 
 */
  __pyx_t_1 = (__pyx_v_self->cright != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":202
 *         # ordered nearest to farest from the query position
 *         if self.cright is not EmptyNode:
 *             self.cright._seek_left(position, results, n, max_dist)             # <<<<<<<<<<<<<<
 * 
 *         if -1 < position - self.end < max_dist:
 */
    ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->cright->__pyx_vtab)->_seek_left(__pyx_v_self->cright, __pyx_v_position, __pyx_v_results, __pyx_v_n, __pyx_v_max_dist);
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":204
 *             self.cright._seek_left(position, results, n, max_dist)
 * 
 *         if -1 < position - self.end < max_dist:             # <<<<<<<<<<<<<<
 *             results.append(self.interval)
 * 
 */
  __pyx_t_2 = (__pyx_v_position - __pyx_v_self->end);
  __pyx_t_1 = (-1 < __pyx_t_2);
  if (__pyx_t_1) {
    __pyx_t_1 = (__pyx_t_2 < __pyx_v_max_dist);
  }
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":205
 * 
 *         if -1 < position - self.end < max_dist:
 *             results.append(self.interval)             # <<<<<<<<<<<<<<
 * 
 *         # TODO: can these conditionals be more stringent?
 */
    if (unlikely(__pyx_v_results == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_2 = PyList_Append(((PyObject *)__pyx_v_results), __pyx_v_self->interval); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":208
 * 
 *         # TODO: can these conditionals be more stringent?
 *         if self.cleft is not EmptyNode:             # <<<<<<<<<<<<<<
 *                 self.cleft._seek_left(position, results, n, max_dist)
 * 
 */
  __pyx_t_1 = (__pyx_v_self->cleft != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":209
 *         # TODO: can these conditionals be more stringent?
 *         if self.cleft is not EmptyNode:
 *                 self.cleft._seek_left(position, results, n, max_dist)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->cleft->__pyx_vtab)->_seek_left(__pyx_v_self->cleft, __pyx_v_position, __pyx_v_results, __pyx_v_n, __pyx_v_max_dist);
    goto __pyx_L7;
  }
  __pyx_L7:;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("chimerascan.bx.intersection.IntervalNode._seek_left");
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":213
 * 
 * 
 *     cdef void _seek_right(IntervalNode self, int position, list results, int n, int max_dist):             # <<<<<<<<<<<<<<
 *         # we know we can bail in these 2 cases.
 *         if self.maxend < position: return
 */

static  void __pyx_f_11chimerascan_2bx_12intersection_12IntervalNode__seek_right(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_self, int __pyx_v_position, PyObject *__pyx_v_results, int __pyx_v_n, int __pyx_v_max_dist) {
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("_seek_right");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":215
 *     cdef void _seek_right(IntervalNode self, int position, list results, int n, int max_dist):
 *         # we know we can bail in these 2 cases.
 *         if self.maxend < position: return             # <<<<<<<<<<<<<<
 *         if self.minstart - max_dist > position: return
 * 
 */
  __pyx_t_1 = (__pyx_v_self->maxend < __pyx_v_position);
  if (__pyx_t_1) {
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":216
 *         # we know we can bail in these 2 cases.
 *         if self.maxend < position: return
 *         if self.minstart - max_dist > position: return             # <<<<<<<<<<<<<<
 * 
 *         #print "SEEK_RIGHT:",self, self.cleft, self.maxend, self.minstart, position
 */
  __pyx_t_1 = ((__pyx_v_self->minstart - __pyx_v_max_dist) > __pyx_v_position);
  if (__pyx_t_1) {
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":222
 *         # the ordering of these 3 blocks makes it so the results are
 *         # ordered nearest to farest from the query position
 *         if self.cleft is not EmptyNode:             # <<<<<<<<<<<<<<
 *                 self.cleft._seek_right(position, results, n, max_dist)
 * 
 */
  __pyx_t_1 = (__pyx_v_self->cleft != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":223
 *         # ordered nearest to farest from the query position
 *         if self.cleft is not EmptyNode:
 *                 self.cleft._seek_right(position, results, n, max_dist)             # <<<<<<<<<<<<<<
 * 
 *         if -1 < self.start - position < max_dist:
 */
    ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->cleft->__pyx_vtab)->_seek_right(__pyx_v_self->cleft, __pyx_v_position, __pyx_v_results, __pyx_v_n, __pyx_v_max_dist);
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":225
 *                 self.cleft._seek_right(position, results, n, max_dist)
 * 
 *         if -1 < self.start - position < max_dist:             # <<<<<<<<<<<<<<
 *             results.append(self.interval)
 * 
 */
  __pyx_t_2 = (__pyx_v_self->start - __pyx_v_position);
  __pyx_t_1 = (-1 < __pyx_t_2);
  if (__pyx_t_1) {
    __pyx_t_1 = (__pyx_t_2 < __pyx_v_max_dist);
  }
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":226
 * 
 *         if -1 < self.start - position < max_dist:
 *             results.append(self.interval)             # <<<<<<<<<<<<<<
 * 
 *         if self.cright is not EmptyNode:
 */
    if (unlikely(__pyx_v_results == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_2 = PyList_Append(((PyObject *)__pyx_v_results), __pyx_v_self->interval); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":228
 *             results.append(self.interval)
 * 
 *         if self.cright is not EmptyNode:             # <<<<<<<<<<<<<<
 *                 self.cright._seek_right(position, results, n, max_dist)
 * 
 */
  __pyx_t_1 = (__pyx_v_self->cright != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":229
 * 
 *         if self.cright is not EmptyNode:
 *                 self.cright._seek_right(position, results, n, max_dist)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->cright->__pyx_vtab)->_seek_right(__pyx_v_self->cright, __pyx_v_position, __pyx_v_results, __pyx_v_n, __pyx_v_max_dist);
    goto __pyx_L7;
  }
  __pyx_L7:;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("chimerascan.bx.intersection.IntervalNode._seek_right");
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":232
 * 
 * 
 *     cpdef left(self, position, int n=1, int max_dist=2500):             # <<<<<<<<<<<<<<
 *         """
 *         find n features with a start > than `position`
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_left(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static  PyObject *__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_left(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_self, PyObject *__pyx_v_position, int __pyx_skip_dispatch, struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_left *__pyx_optional_args) {
  int __pyx_v_n = ((int)1);
  int __pyx_v_max_dist = ((int)2500);
  PyObject *__pyx_v_results = 0;
  PyObject *__pyx_v_r;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("left");
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_n = __pyx_optional_args->n;
      if (__pyx_optional_args->__pyx_n > 1) {
        __pyx_v_max_dist = __pyx_optional_args->max_dist;
      }
    }
  }
  __pyx_v_r = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__left); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (void *)&__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_left)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_max_dist); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_v_position);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_position);
      __Pyx_GIVEREF(__pyx_v_position);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_2 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":239
 *         max_dist: the maximum distance to look before giving up.
 *         """
 *         cdef list results = []             # <<<<<<<<<<<<<<
 *         # use start - 1 becuase .left() assumes strictly left-of
 *         self._seek_left( position - 1, results, n, max_dist )
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_v_results = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":241
 *         cdef list results = []
 *         # use start - 1 becuase .left() assumes strictly left-of
 *         self._seek_left( position - 1, results, n, max_dist )             # <<<<<<<<<<<<<<
 *         if len(results) == n: return results
 *         r = results
 */
  __pyx_t_1 = PyNumber_Subtract(__pyx_v_position, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->__pyx_vtab)->_seek_left(__pyx_v_self, __pyx_t_5, __pyx_v_results, __pyx_v_n, __pyx_v_max_dist);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":242
 *         # use start - 1 becuase .left() assumes strictly left-of
 *         self._seek_left( position - 1, results, n, max_dist )
 *         if len(results) == n: return results             # <<<<<<<<<<<<<<
 *         r = results
 *         r.sort(key=operator.attrgetter('end'), reverse=True)
 */
  if (unlikely(__pyx_v_results == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
  }
  __pyx_t_6 = PyList_GET_SIZE(((PyObject *)__pyx_v_results)); 
  __pyx_t_7 = (__pyx_t_6 == __pyx_v_n);
  if (__pyx_t_7) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_results));
    __pyx_r = ((PyObject *)__pyx_v_results);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":243
 *         self._seek_left( position - 1, results, n, max_dist )
 *         if len(results) == n: return results
 *         r = results             # <<<<<<<<<<<<<<
 *         r.sort(key=operator.attrgetter('end'), reverse=True)
 *         return r[:n]
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_results));
  __Pyx_DECREF(((PyObject *)__pyx_v_r));
  __pyx_v_r = __pyx_v_results;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":244
 *         if len(results) == n: return results
 *         r = results
 *         r.sort(key=operator.attrgetter('end'), reverse=True)             # <<<<<<<<<<<<<<
 *         return r[:n]
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_r), __pyx_n_s__sort); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__operator); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__attrgetter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __pyx_t_8 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__key), __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__reverse), __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyEval_CallObjectWithKeywords(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":245
 *         r = results
 *         r.sort(key=operator.attrgetter('end'), reverse=True)
 *         return r[:n]             # <<<<<<<<<<<<<<
 * 
 *     cpdef right(self, position, int n=1, int max_dist=2500):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_8 = PySequence_GetSlice(((PyObject *)__pyx_v_r), 0, __pyx_v_n); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_8));
  __pyx_r = ((PyObject *)__pyx_t_8);
  __pyx_t_8 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.left");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_results);
  __Pyx_DECREF(__pyx_v_r);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":232
 * 
 * 
 *     cpdef left(self, position, int n=1, int max_dist=2500):             # <<<<<<<<<<<<<<
 *         """
 *         find n features with a start > than `position`
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_left(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalNode_left[] = "\n        find n features with a start > than `position`\n        f: a Interval object (or anything with an `end` attribute)\n        n: the number of features to return\n        max_dist: the maximum distance to look before giving up.\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_left(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_position = 0;
  int __pyx_v_n;
  int __pyx_v_max_dist;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_left __pyx_t_2;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__position,&__pyx_n_s__n,&__pyx_n_s__max_dist,0};
  __Pyx_RefNannySetupContext("left");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__position);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__n);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_dist);
        if (value) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "left") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_position = values[0];
    if (values[1]) {
      __pyx_v_n = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_n = ((int)1);
    }
    if (values[2]) {
      __pyx_v_max_dist = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_max_dist == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_max_dist = ((int)2500);
    }
  } else {
    __pyx_v_n = ((int)1);
    __pyx_v_max_dist = ((int)2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: __pyx_v_max_dist = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_max_dist == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      case  2: __pyx_v_n = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      case  1: __pyx_v_position = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("left", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.left");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 2;
  __pyx_t_2.n = __pyx_v_n;
  __pyx_t_2.max_dist = __pyx_v_max_dist;
  __pyx_t_1 = ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->__pyx_vtab)->left(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self), __pyx_v_position, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.left");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":247
 *         return r[:n]
 * 
 *     cpdef right(self, position, int n=1, int max_dist=2500):             # <<<<<<<<<<<<<<
 *         """
 *         find n features with a end < than position
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_right(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static  PyObject *__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_right(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_self, PyObject *__pyx_v_position, int __pyx_skip_dispatch, struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_right *__pyx_optional_args) {
  int __pyx_v_n = ((int)1);
  int __pyx_v_max_dist = ((int)2500);
  PyObject *__pyx_v_results = 0;
  PyObject *__pyx_v_r;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("right");
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_n = __pyx_optional_args->n;
      if (__pyx_optional_args->__pyx_n > 1) {
        __pyx_v_max_dist = __pyx_optional_args->max_dist;
      }
    }
  }
  __pyx_v_r = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__right); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (void *)&__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_right)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_max_dist); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_v_position);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_position);
      __Pyx_GIVEREF(__pyx_v_position);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_2 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":254
 *         max_dist: the maximum distance to look before giving up.
 *         """
 *         cdef list results = []             # <<<<<<<<<<<<<<
 *         # use end + 1 becuase .right() assumes strictly right-of
 *         self._seek_right(position + 1, results, n, max_dist)
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_v_results = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":256
 *         cdef list results = []
 *         # use end + 1 becuase .right() assumes strictly right-of
 *         self._seek_right(position + 1, results, n, max_dist)             # <<<<<<<<<<<<<<
 *         if len(results) == n: return results
 *         r = results
 */
  __pyx_t_1 = PyNumber_Add(__pyx_v_position, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->__pyx_vtab)->_seek_right(__pyx_v_self, __pyx_t_5, __pyx_v_results, __pyx_v_n, __pyx_v_max_dist);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":257
 *         # use end + 1 becuase .right() assumes strictly right-of
 *         self._seek_right(position + 1, results, n, max_dist)
 *         if len(results) == n: return results             # <<<<<<<<<<<<<<
 *         r = results
 *         r.sort(key=operator.attrgetter('start'))
 */
  if (unlikely(__pyx_v_results == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
  }
  __pyx_t_6 = PyList_GET_SIZE(((PyObject *)__pyx_v_results)); 
  __pyx_t_7 = (__pyx_t_6 == __pyx_v_n);
  if (__pyx_t_7) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_results));
    __pyx_r = ((PyObject *)__pyx_v_results);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":258
 *         self._seek_right(position + 1, results, n, max_dist)
 *         if len(results) == n: return results
 *         r = results             # <<<<<<<<<<<<<<
 *         r.sort(key=operator.attrgetter('start'))
 *         return r[:n]
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_results));
  __Pyx_DECREF(((PyObject *)__pyx_v_r));
  __pyx_v_r = __pyx_v_results;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":259
 *         if len(results) == n: return results
 *         r = results
 *         r.sort(key=operator.attrgetter('start'))             # <<<<<<<<<<<<<<
 *         return r[:n]
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_r), __pyx_n_s__sort); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__operator); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__attrgetter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __pyx_t_8 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__key), __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyEval_CallObjectWithKeywords(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":260
 *         r = results
 *         r.sort(key=operator.attrgetter('start'))
 *         return r[:n]             # <<<<<<<<<<<<<<
 * 
 *     def traverse(self, func):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_8 = PySequence_GetSlice(((PyObject *)__pyx_v_r), 0, __pyx_v_n); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_8));
  __pyx_r = ((PyObject *)__pyx_t_8);
  __pyx_t_8 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.right");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_results);
  __Pyx_DECREF(__pyx_v_r);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":247
 *         return r[:n]
 * 
 *     cpdef right(self, position, int n=1, int max_dist=2500):             # <<<<<<<<<<<<<<
 *         """
 *         find n features with a end < than position
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_right(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalNode_right[] = "\n        find n features with a end < than position\n        f: a Interval object (or anything with a `start` attribute)\n        n: the number of features to return\n        max_dist: the maximum distance to look before giving up.\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_right(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_position = 0;
  int __pyx_v_n;
  int __pyx_v_max_dist;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_right __pyx_t_2;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__position,&__pyx_n_s__n,&__pyx_n_s__max_dist,0};
  __Pyx_RefNannySetupContext("right");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__position);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__n);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_dist);
        if (value) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "right") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_position = values[0];
    if (values[1]) {
      __pyx_v_n = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_n = ((int)1);
    }
    if (values[2]) {
      __pyx_v_max_dist = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_max_dist == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_max_dist = ((int)2500);
    }
  } else {
    __pyx_v_n = ((int)1);
    __pyx_v_max_dist = ((int)2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: __pyx_v_max_dist = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_max_dist == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      case  2: __pyx_v_n = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      case  1: __pyx_v_position = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("right", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.right");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 2;
  __pyx_t_2.n = __pyx_v_n;
  __pyx_t_2.max_dist = __pyx_v_max_dist;
  __pyx_t_1 = ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->__pyx_vtab)->right(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self), __pyx_v_position, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalNode.right");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":262
 *         return r[:n]
 * 
 *     def traverse(self, func):             # <<<<<<<<<<<<<<
 *         self._traverse(func)
 * 
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_traverse(PyObject *__pyx_v_self, PyObject *__pyx_v_func); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_traverse(PyObject *__pyx_v_self, PyObject *__pyx_v_func) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("traverse");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":263
 * 
 *     def traverse(self, func):
 *         self._traverse(func)             # <<<<<<<<<<<<<<
 * 
 *     cdef void _traverse(IntervalNode self, object func):
 */
  ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self)->__pyx_vtab)->_traverse(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self), __pyx_v_func);

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

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":265
 *         self._traverse(func)
 * 
 *     cdef void _traverse(IntervalNode self, object func):             # <<<<<<<<<<<<<<
 *         if self.cleft is not EmptyNode: self.cleft._traverse(func)
 *         func(self)
 */

static  void __pyx_f_11chimerascan_2bx_12intersection_12IntervalNode__traverse(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *__pyx_v_self, PyObject *__pyx_v_func) {
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("_traverse");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":266
 * 
 *     cdef void _traverse(IntervalNode self, object func):
 *         if self.cleft is not EmptyNode: self.cleft._traverse(func)             # <<<<<<<<<<<<<<
 *         func(self)
 *         if self.cright is not EmptyNode: self.cright._traverse(func)
 */
  __pyx_t_1 = (__pyx_v_self->cleft != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_1) {
    ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->cleft->__pyx_vtab)->_traverse(__pyx_v_self->cleft, __pyx_v_func);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":267
 *     cdef void _traverse(IntervalNode self, object func):
 *         if self.cleft is not EmptyNode: self.cleft._traverse(func)
 *         func(self)             # <<<<<<<<<<<<<<
 *         if self.cright is not EmptyNode: self.cright._traverse(func)
 * 
 */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __pyx_t_3 = PyObject_Call(__pyx_v_func, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":268
 *         if self.cleft is not EmptyNode: self.cleft._traverse(func)
 *         func(self)
 *         if self.cright is not EmptyNode: self.cright._traverse(func)             # <<<<<<<<<<<<<<
 * 
 * cdef IntervalNode EmptyNode = IntervalNode( 0, 0, Interval(0, 0))
 */
  __pyx_t_1 = (__pyx_v_self->cright != __pyx_v_11chimerascan_2bx_12intersection_EmptyNode);
  if (__pyx_t_1) {
    ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_v_self->cright->__pyx_vtab)->_traverse(__pyx_v_self->cright, __pyx_v_func);
    goto __pyx_L4;
  }
  __pyx_L4:;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("chimerascan.bx.intersection.IntervalNode._traverse");
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":288
 * 
 *     """
 *     cdef public int start, end             # <<<<<<<<<<<<<<
 *     cdef public object value, chrom, strand
 * 
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_8Interval_5start___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_8Interval_5start___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.bx.intersection.Interval.start.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5start___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5start___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__set__");
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->start = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.Interval.start.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_8Interval_3end___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_8Interval_3end___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.bx.intersection.Interval.end.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_3end___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_3end___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__set__");
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->end = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.Interval.end.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":289
 *     """
 *     cdef public int start, end
 *     cdef public object value, chrom, strand             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, int start, int end, object value=None, object chrom=None, object strand=None ):
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_8Interval_5value___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_8Interval_5value___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value);
  __pyx_r = ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value;
  goto __pyx_L0;

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

static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5value___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5value___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value);
  __Pyx_DECREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value);
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value = __pyx_v_value;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5value___del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5value___del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__del__");
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value);
  __Pyx_DECREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value);
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value = Py_None;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_8Interval_5chrom___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_8Interval_5chrom___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->chrom);
  __pyx_r = ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->chrom;
  goto __pyx_L0;

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

static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5chrom___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5chrom___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->chrom);
  __Pyx_DECREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->chrom);
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->chrom = __pyx_v_value;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5chrom___del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5chrom___del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__del__");
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->chrom);
  __Pyx_DECREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->chrom);
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->chrom = Py_None;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_8Interval_6strand___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_8Interval_6strand___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->strand);
  __pyx_r = ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->strand;
  goto __pyx_L0;

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

static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_6strand___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_6strand___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->strand);
  __Pyx_DECREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->strand);
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->strand = __pyx_v_value;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_6strand___del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval_6strand___del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__del__");
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->strand);
  __Pyx_DECREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->strand);
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->strand = Py_None;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":291
 *     cdef public object value, chrom, strand
 * 
 *     def __init__(self, int start, int end, object value=None, object chrom=None, object strand=None ):             # <<<<<<<<<<<<<<
 *         assert start <= end, "start must be less than end"
 *         self.start  = start
 */

static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_start;
  int __pyx_v_end;
  PyObject *__pyx_v_value = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_strand = 0;
  int __pyx_r;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__value,&__pyx_n_s__chrom,&__pyx_n_s__strand,0};
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[5] = {0,0,0,0,0};
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__value);
        if (value) { values[2] = value; kw_args--; }
      }
      case  3:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__chrom);
        if (value) { values[3] = value; kw_args--; }
      }
      case  4:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__strand);
        if (value) { values[4] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_start = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_value = values[2];
    __pyx_v_chrom = values[3];
    __pyx_v_strand = values[4];
  } else {
    __pyx_v_value = ((PyObject *)Py_None);
    __pyx_v_chrom = ((PyObject *)Py_None);
    __pyx_v_strand = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  5:
      __pyx_v_strand = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4:
      __pyx_v_chrom = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3:
      __pyx_v_value = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2:
      __pyx_v_end = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __pyx_v_start = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.Interval.__init__");
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":292
 * 
 *     def __init__(self, int start, int end, object value=None, object chrom=None, object strand=None ):
 *         assert start <= end, "start must be less than end"             # <<<<<<<<<<<<<<
 *         self.start  = start
 *         self.end   = end
 */
  #ifndef PYREX_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_start <= __pyx_v_end))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_3));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":293
 *     def __init__(self, int start, int end, object value=None, object chrom=None, object strand=None ):
 *         assert start <= end, "start must be less than end"
 *         self.start  = start             # <<<<<<<<<<<<<<
 *         self.end   = end
 *         self.value = value
 */
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->start = __pyx_v_start;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":294
 *         assert start <= end, "start must be less than end"
 *         self.start  = start
 *         self.end   = end             # <<<<<<<<<<<<<<
 *         self.value = value
 *         self.chrom = chrom
 */
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->end = __pyx_v_end;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":295
 *         self.start  = start
 *         self.end   = end
 *         self.value = value             # <<<<<<<<<<<<<<
 *         self.chrom = chrom
 *         self.strand = strand
 */
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value);
  __Pyx_DECREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value);
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value = __pyx_v_value;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":296
 *         self.end   = end
 *         self.value = value
 *         self.chrom = chrom             # <<<<<<<<<<<<<<
 *         self.strand = strand
 * 
 */
  __Pyx_INCREF(__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_v_chrom);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->chrom);
  __Pyx_DECREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->chrom);
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->chrom = __pyx_v_chrom;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":297
 *         self.value = value
 *         self.chrom = chrom
 *         self.strand = strand             # <<<<<<<<<<<<<<
 * 
 *     def __repr__(self):
 */
  __Pyx_INCREF(__pyx_v_strand);
  __Pyx_GIVEREF(__pyx_v_strand);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->strand);
  __Pyx_DECREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->strand);
  ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->strand = __pyx_v_strand;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.Interval.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":299
 *         self.strand = strand
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         fstr = "Interval(%d, %d" % (self.start, self.end)
 *         if not self.value is None:
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_8Interval___repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_8Interval___repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_v_fstr;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("__repr__");
  __pyx_v_fstr = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":300
 * 
 *     def __repr__(self):
 *         fstr = "Interval(%d, %d" % (self.start, self.end)             # <<<<<<<<<<<<<<
 *         if not self.value is None:
 *             fstr += ", value=" + str(self.value)
 */
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->end); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_4), __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_v_fstr);
  __pyx_v_fstr = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":301
 *     def __repr__(self):
 *         fstr = "Interval(%d, %d" % (self.start, self.end)
 *         if not self.value is None:             # <<<<<<<<<<<<<<
 *             fstr += ", value=" + str(self.value)
 *         fstr += ")"
 */
  __pyx_t_4 = (((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value == Py_None);
  __pyx_t_5 = (!__pyx_t_4);
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":302
 *         fstr = "Interval(%d, %d" % (self.start, self.end)
 *         if not self.value is None:
 *             fstr += ", value=" + str(self.value)             # <<<<<<<<<<<<<<
 *         fstr += ")"
 *         return fstr
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value);
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value);
    __Pyx_GIVEREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->value);
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)&PyString_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Add(((PyObject *)__pyx_kp_s_5), __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_fstr, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_v_fstr);
    __pyx_v_fstr = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":303
 *         if not self.value is None:
 *             fstr += ", value=" + str(self.value)
 *         fstr += ")"             # <<<<<<<<<<<<<<
 *         return fstr
 * 
 */
  __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_fstr, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_fstr);
  __pyx_v_fstr = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":304
 *             fstr += ", value=" + str(self.value)
 *         fstr += ")"
 *         return fstr             # <<<<<<<<<<<<<<
 * 
 *     def __cmp__(self, other):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_fstr);
  __pyx_r = __pyx_v_fstr;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.bx.intersection.Interval.__repr__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_fstr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":306
 *         return fstr
 * 
 *     def __cmp__(self, other):             # <<<<<<<<<<<<<<
 *         return cmp( self.start, other.start ) or cmp( self.end, other.end )
 * 
 */

#if PY_MAJOR_VERSION < 3
static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval___cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_8Interval___cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  __Pyx_RefNannySetupContext("__cmp__");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":307
 * 
 *     def __cmp__(self, other):
 *         return cmp( self.start, other.start ) or cmp( self.end, other.end )             # <<<<<<<<<<<<<<
 * 
 * cdef class IntervalTree:
 */
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_other, __pyx_n_s__start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_builtin_cmp, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_4) {
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_3 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)__pyx_v_self)->end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_other, __pyx_n_s__end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_3 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_builtin_cmp, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __pyx_t_1;
    __pyx_t_1 = 0;
  } else {
    __pyx_t_5 = __pyx_t_2;
    __pyx_t_2 = 0;
  }
  __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = __pyx_t_6;
  goto __pyx_L0;

  __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_5);
  __Pyx_AddTraceback("chimerascan.bx.intersection.Interval.__cmp__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
#endif /*!(#if PY_MAJOR_VERSION < 3)*/

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":367
 *     cdef IntervalNode root
 * 
 *     def __cinit__( self ):             # <<<<<<<<<<<<<<
 *         root = None
 * 
 */

static int __pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_root;
  int __pyx_r;
  __Pyx_RefNannySetupContext("__cinit__");
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;
  __pyx_v_root = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":368
 * 
 *     def __cinit__( self ):
 *         root = None             # <<<<<<<<<<<<<<
 * 
 *     # ---- Position based interfaces -----------------------------------------
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF(__pyx_v_root);
  __pyx_v_root = Py_None;

  __pyx_r = 0;
  __Pyx_DECREF(__pyx_v_root);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":372
 *     # ---- Position based interfaces -----------------------------------------
 * 
 *     def insert( self, int start, int end, object value=None ):             # <<<<<<<<<<<<<<
 *         """
 *         Insert the interval [start,end) associated with value `value`.
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_insert[] = "\n        Insert the interval [start,end) associated with value `value`.\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_start;
  int __pyx_v_end;
  PyObject *__pyx_v_value = 0;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__value,0};
  __Pyx_RefNannySetupContext("insert");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[2] = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("insert", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__value);
        if (value) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "insert") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_start = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_value = values[2];
  } else {
    __pyx_v_value = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3:
      __pyx_v_value = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2:
      __pyx_v_end = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __pyx_v_start = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("insert", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.insert");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":376
 *         Insert the interval [start,end) associated with value `value`.
 *         """
 *         if self.root is None:             # <<<<<<<<<<<<<<
 *             self.root = IntervalNode( start, end, value )
 *         else:
 */
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root) == Py_None);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":377
 *         """
 *         if self.root is None:
 *             self.root = IntervalNode( start, end, value )             # <<<<<<<<<<<<<<
 *         else:
 *             self.root = self.root.insert( start, end, value )
 */
    __pyx_t_2 = PyInt_FromLong(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyInt_FromLong(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_2bx_12intersection_IntervalNode)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root);
    __Pyx_DECREF(((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root));
    ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":379
 *             self.root = IntervalNode( start, end, value )
 *         else:
 *             self.root = self.root.insert( start, end, value )             # <<<<<<<<<<<<<<
 * 
 *     add = insert
 */
    __pyx_t_3 = ((PyObject *)((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root->__pyx_vtab)->insert(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root, __pyx_v_start, __pyx_v_end, __pyx_v_value, 0)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root);
    __Pyx_DECREF(((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root));
    ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_t_3);
    __pyx_t_3 = 0;
  }
  __pyx_L6:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.insert");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":384
 * 
 * 
 *     def find( self, start, end ):             # <<<<<<<<<<<<<<
 *         """
 *         Return a sorted list of all intervals overlapping [start,end).
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_find(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_find[] = "\n        Return a sorted list of all intervals overlapping [start,end).\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_find(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0};
  __Pyx_RefNannySetupContext("find");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("find", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "find") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_start = values[0];
    __pyx_v_end = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_start = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_end = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("find", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.find");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":388
 *         Return a sorted list of all intervals overlapping [start,end).
 *         """
 *         if self.root is None:             # <<<<<<<<<<<<<<
 *             return []
 *         return self.root.find( start, end )
 */
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root) == Py_None);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":389
 *         """
 *         if self.root is None:
 *             return []             # <<<<<<<<<<<<<<
 *         return self.root.find( start, end )
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_r = ((PyObject *)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":390
 *         if self.root is None:
 *             return []
 *         return self.root.find( start, end )             # <<<<<<<<<<<<<<
 * 
 *     def before( self, position, num_intervals=1, max_dist=2500 ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyObject_GetAttr(((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root), __pyx_n_s__find); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_end);
  __Pyx_GIVEREF(__pyx_v_end);
  __pyx_t_4 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __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;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.find");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":392
 *         return self.root.find( start, end )
 * 
 *     def before( self, position, num_intervals=1, max_dist=2500 ):             # <<<<<<<<<<<<<<
 *         """
 *         Find `num_intervals` intervals that lie before `position` and are no
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_before(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_before[] = "\n        Find `num_intervals` intervals that lie before `position` and are no\n        further than `max_dist` positions away\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_before(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_position = 0;
  PyObject *__pyx_v_num_intervals = 0;
  PyObject *__pyx_v_max_dist = 0;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_left __pyx_t_5;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__position,&__pyx_n_s__num_intervals,&__pyx_n_s__max_dist,0};
  __Pyx_RefNannySetupContext("before");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)__pyx_int_1);
    values[2] = ((PyObject *)__pyx_int_2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__position);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__num_intervals);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_dist);
        if (value) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "before") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_position = values[0];
    __pyx_v_num_intervals = values[1];
    __pyx_v_max_dist = values[2];
  } else {
    __pyx_v_num_intervals = ((PyObject *)__pyx_int_1);
    __pyx_v_max_dist = ((PyObject *)__pyx_int_2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: __pyx_v_max_dist = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_num_intervals = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_position = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("before", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.before");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":397
 *         further than `max_dist` positions away
 *         """
 *         if self.root is None:             # <<<<<<<<<<<<<<
 *             return []
 *         return self.root.left( position, num_intervals, max_dist )
 */
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root) == Py_None);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":398
 *         """
 *         if self.root is None:
 *             return []             # <<<<<<<<<<<<<<
 *         return self.root.left( position, num_intervals, max_dist )
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_r = ((PyObject *)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":399
 *         if self.root is None:
 *             return []
 *         return self.root.left( position, num_intervals, max_dist )             # <<<<<<<<<<<<<<
 * 
 *     def after( self, position, num_intervals=1, max_dist=2500 ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_num_intervals); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_max_dist); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5.__pyx_n = 2;
  __pyx_t_5.n = __pyx_t_3;
  __pyx_t_5.max_dist = __pyx_t_4;
  __pyx_t_2 = ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root->__pyx_vtab)->left(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root, __pyx_v_position, 0, &__pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.before");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":401
 *         return self.root.left( position, num_intervals, max_dist )
 * 
 *     def after( self, position, num_intervals=1, max_dist=2500 ):             # <<<<<<<<<<<<<<
 *         """
 *         Find `num_intervals` intervals that lie after `position` and are no
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_after(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_after[] = "\n        Find `num_intervals` intervals that lie after `position` and are no\n        further than `max_dist` positions away\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_after(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_position = 0;
  PyObject *__pyx_v_num_intervals = 0;
  PyObject *__pyx_v_max_dist = 0;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_right __pyx_t_5;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__position,&__pyx_n_s__num_intervals,&__pyx_n_s__max_dist,0};
  __Pyx_RefNannySetupContext("after");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)__pyx_int_1);
    values[2] = ((PyObject *)__pyx_int_2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__position);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__num_intervals);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_dist);
        if (value) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "after") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_position = values[0];
    __pyx_v_num_intervals = values[1];
    __pyx_v_max_dist = values[2];
  } else {
    __pyx_v_num_intervals = ((PyObject *)__pyx_int_1);
    __pyx_v_max_dist = ((PyObject *)__pyx_int_2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: __pyx_v_max_dist = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_num_intervals = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_position = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("after", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.after");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":406
 *         further than `max_dist` positions away
 *         """
 *         if self.root is None:             # <<<<<<<<<<<<<<
 *             return []
 *         return self.root.right( position, num_intervals, max_dist )
 */
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root) == Py_None);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":407
 *         """
 *         if self.root is None:
 *             return []             # <<<<<<<<<<<<<<
 *         return self.root.right( position, num_intervals, max_dist )
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_r = ((PyObject *)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":408
 *         if self.root is None:
 *             return []
 *         return self.root.right( position, num_intervals, max_dist )             # <<<<<<<<<<<<<<
 * 
 *     # ---- Interval-like object based interfaces -----------------------------
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_num_intervals); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_max_dist); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5.__pyx_n = 2;
  __pyx_t_5.n = __pyx_t_3;
  __pyx_t_5.max_dist = __pyx_t_4;
  __pyx_t_2 = ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root->__pyx_vtab)->right(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root, __pyx_v_position, 0, &__pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.after");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":412
 *     # ---- Interval-like object based interfaces -----------------------------
 * 
 *     def insert_interval( self, interval ):             # <<<<<<<<<<<<<<
 *         """
 *         Insert an "interval" like object (one with at least start and end
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_insert_interval(PyObject *__pyx_v_self, PyObject *__pyx_v_interval); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_insert_interval[] = "\n        Insert an \"interval\" like object (one with at least start and end\n        attributes)\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_insert_interval(PyObject *__pyx_v_self, PyObject *__pyx_v_interval) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("insert_interval");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":417
 *         attributes)
 *         """
 *         self.insert( interval.start, interval.end, interval )             # <<<<<<<<<<<<<<
 * 
 *     add_interval = insert_interval
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__insert); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_interval, __pyx_n_s__start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_interval, __pyx_n_s__end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_interval);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_interval);
  __Pyx_GIVEREF(__pyx_v_interval);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.insert_interval");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":421
 *     add_interval = insert_interval
 * 
 *     def before_interval( self, interval, num_intervals=1, max_dist=2500 ):             # <<<<<<<<<<<<<<
 *         """
 *         Find `num_intervals` intervals that lie completely before `interval`
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_before_interval(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_before_interval[] = "\n        Find `num_intervals` intervals that lie completely before `interval`\n        and are no further than `max_dist` positions away\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_before_interval(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_interval = 0;
  PyObject *__pyx_v_num_intervals = 0;
  PyObject *__pyx_v_max_dist = 0;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_left __pyx_t_6;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__interval,&__pyx_n_s__num_intervals,&__pyx_n_s__max_dist,0};
  __Pyx_RefNannySetupContext("before_interval");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)__pyx_int_1);
    values[2] = ((PyObject *)__pyx_int_2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__interval);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__num_intervals);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_dist);
        if (value) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "before_interval") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_interval = values[0];
    __pyx_v_num_intervals = values[1];
    __pyx_v_max_dist = values[2];
  } else {
    __pyx_v_num_intervals = ((PyObject *)__pyx_int_1);
    __pyx_v_max_dist = ((PyObject *)__pyx_int_2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: __pyx_v_max_dist = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_num_intervals = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_interval = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("before_interval", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.before_interval");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":426
 *         and are no further than `max_dist` positions away
 *         """
 *         if self.root is None:             # <<<<<<<<<<<<<<
 *             return []
 *         return self.root.left( interval.start, num_intervals, max_dist )
 */
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root) == Py_None);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":427
 *         """
 *         if self.root is None:
 *             return []             # <<<<<<<<<<<<<<
 *         return self.root.left( interval.start, num_intervals, max_dist )
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_r = ((PyObject *)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":428
 *         if self.root is None:
 *             return []
 *         return self.root.left( interval.start, num_intervals, max_dist )             # <<<<<<<<<<<<<<
 * 
 *     def after_interval( self, interval, num_intervals=1, max_dist=2500 ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_interval, __pyx_n_s__start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_num_intervals); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_max_dist); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6.__pyx_n = 2;
  __pyx_t_6.n = __pyx_t_3;
  __pyx_t_6.max_dist = __pyx_t_4;
  __pyx_t_5 = ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root->__pyx_vtab)->left(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root, __pyx_t_2, 0, &__pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.before_interval");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":430
 *         return self.root.left( interval.start, num_intervals, max_dist )
 * 
 *     def after_interval( self, interval, num_intervals=1, max_dist=2500 ):             # <<<<<<<<<<<<<<
 *         """
 *         Find `num_intervals` intervals that lie completely after `interval` and
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_after_interval(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_after_interval[] = "\n        Find `num_intervals` intervals that lie completely after `interval` and\n        are no further than `max_dist` positions away\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_after_interval(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_interval = 0;
  PyObject *__pyx_v_num_intervals = 0;
  PyObject *__pyx_v_max_dist = 0;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_right __pyx_t_6;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__interval,&__pyx_n_s__num_intervals,&__pyx_n_s__max_dist,0};
  __Pyx_RefNannySetupContext("after_interval");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)__pyx_int_1);
    values[2] = ((PyObject *)__pyx_int_2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__interval);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__num_intervals);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_dist);
        if (value) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "after_interval") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_interval = values[0];
    __pyx_v_num_intervals = values[1];
    __pyx_v_max_dist = values[2];
  } else {
    __pyx_v_num_intervals = ((PyObject *)__pyx_int_1);
    __pyx_v_max_dist = ((PyObject *)__pyx_int_2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: __pyx_v_max_dist = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_num_intervals = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_interval = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("after_interval", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.after_interval");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":435
 *         are no further than `max_dist` positions away
 *         """
 *         if self.root is None:             # <<<<<<<<<<<<<<
 *             return []
 *         return self.root.right( interval.end, num_intervals, max_dist )
 */
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root) == Py_None);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":436
 *         """
 *         if self.root is None:
 *             return []             # <<<<<<<<<<<<<<
 *         return self.root.right( interval.end, num_intervals, max_dist )
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_r = ((PyObject *)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":437
 *         if self.root is None:
 *             return []
 *         return self.root.right( interval.end, num_intervals, max_dist )             # <<<<<<<<<<<<<<
 * 
 *     def upstream_of_interval( self, interval, num_intervals=1, max_dist=2500 ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_interval, __pyx_n_s__end); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_num_intervals); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_max_dist); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6.__pyx_n = 2;
  __pyx_t_6.n = __pyx_t_3;
  __pyx_t_6.max_dist = __pyx_t_4;
  __pyx_t_5 = ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root->__pyx_vtab)->right(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root, __pyx_t_2, 0, &__pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.after_interval");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":439
 *         return self.root.right( interval.end, num_intervals, max_dist )
 * 
 *     def upstream_of_interval( self, interval, num_intervals=1, max_dist=2500 ):             # <<<<<<<<<<<<<<
 *         """
 *         Find `num_intervals` intervals that lie completely upstream of
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_upstream_of_interval(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_upstream_of_interval[] = "\n        Find `num_intervals` intervals that lie completely upstream of\n        `interval` and are no further than `max_dist` positions away\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_upstream_of_interval(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_interval = 0;
  PyObject *__pyx_v_num_intervals = 0;
  PyObject *__pyx_v_max_dist = 0;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_right __pyx_t_8;
  struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_left __pyx_t_9;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__interval,&__pyx_n_s__num_intervals,&__pyx_n_s__max_dist,0};
  __Pyx_RefNannySetupContext("upstream_of_interval");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)__pyx_int_1);
    values[2] = ((PyObject *)__pyx_int_2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__interval);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__num_intervals);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_dist);
        if (value) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "upstream_of_interval") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_interval = values[0];
    __pyx_v_num_intervals = values[1];
    __pyx_v_max_dist = values[2];
  } else {
    __pyx_v_num_intervals = ((PyObject *)__pyx_int_1);
    __pyx_v_max_dist = ((PyObject *)__pyx_int_2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: __pyx_v_max_dist = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_num_intervals = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_interval = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("upstream_of_interval", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.upstream_of_interval");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":444
 *         `interval` and are no further than `max_dist` positions away
 *         """
 *         if self.root is None:             # <<<<<<<<<<<<<<
 *             return []
 *         if interval.strand == -1 or interval.strand == "-":
 */
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root) == Py_None);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":445
 *         """
 *         if self.root is None:
 *             return []             # <<<<<<<<<<<<<<
 *         if interval.strand == -1 or interval.strand == "-":
 *             return self.root.right( interval.end, num_intervals, max_dist )
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_r = ((PyObject *)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":446
 *         if self.root is None:
 *             return []
 *         if interval.strand == -1 or interval.strand == "-":             # <<<<<<<<<<<<<<
 *             return self.root.right( interval.end, num_intervals, max_dist )
 *         else:
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_interval, __pyx_n_s__strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_1) {
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_interval, __pyx_n_s__strand); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, ((PyObject *)__pyx_kp_s_7), Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_1;
  }
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":447
 *             return []
 *         if interval.strand == -1 or interval.strand == "-":
 *             return self.root.right( interval.end, num_intervals, max_dist )             # <<<<<<<<<<<<<<
 *         else:
 *             return self.root.left( interval.start, num_intervals, max_dist )
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_interval, __pyx_n_s__end); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_num_intervals); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_v_max_dist); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8.__pyx_n = 2;
    __pyx_t_8.n = __pyx_t_6;
    __pyx_t_8.max_dist = __pyx_t_7;
    __pyx_t_3 = ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root->__pyx_vtab)->right(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root, __pyx_t_2, 0, &__pyx_t_8); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L7;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":449
 *             return self.root.right( interval.end, num_intervals, max_dist )
 *         else:
 *             return self.root.left( interval.start, num_intervals, max_dist )             # <<<<<<<<<<<<<<
 * 
 *     def downstream_of_interval( self, interval, num_intervals=1, max_dist=2500 ):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_interval, __pyx_n_s__start); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_v_num_intervals); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_max_dist); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 2;
    __pyx_t_9.n = __pyx_t_7;
    __pyx_t_9.max_dist = __pyx_t_6;
    __pyx_t_2 = ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root->__pyx_vtab)->left(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root, __pyx_t_3, 0, &__pyx_t_9); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __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;
  }
  __pyx_L7:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.upstream_of_interval");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":451
 *             return self.root.left( interval.start, num_intervals, max_dist )
 * 
 *     def downstream_of_interval( self, interval, num_intervals=1, max_dist=2500 ):             # <<<<<<<<<<<<<<
 *         """
 *         Find `num_intervals` intervals that lie completely downstream of
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_downstream_of_interval(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_downstream_of_interval[] = "\n        Find `num_intervals` intervals that lie completely downstream of\n        `interval` and are no further than `max_dist` positions away\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_downstream_of_interval(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_interval = 0;
  PyObject *__pyx_v_num_intervals = 0;
  PyObject *__pyx_v_max_dist = 0;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_left __pyx_t_8;
  struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_right __pyx_t_9;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__interval,&__pyx_n_s__num_intervals,&__pyx_n_s__max_dist,0};
  __Pyx_RefNannySetupContext("downstream_of_interval");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)__pyx_int_1);
    values[2] = ((PyObject *)__pyx_int_2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__interval);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__num_intervals);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_dist);
        if (value) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "downstream_of_interval") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_interval = values[0];
    __pyx_v_num_intervals = values[1];
    __pyx_v_max_dist = values[2];
  } else {
    __pyx_v_num_intervals = ((PyObject *)__pyx_int_1);
    __pyx_v_max_dist = ((PyObject *)__pyx_int_2500);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: __pyx_v_max_dist = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_num_intervals = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_interval = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("downstream_of_interval", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.downstream_of_interval");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":456
 *         `interval` and are no further than `max_dist` positions away
 *         """
 *         if self.root is None:             # <<<<<<<<<<<<<<
 *             return []
 *         if interval.strand == -1 or interval.strand == "-":
 */
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root) == Py_None);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":457
 *         """
 *         if self.root is None:
 *             return []             # <<<<<<<<<<<<<<
 *         if interval.strand == -1 or interval.strand == "-":
 *             return self.root.left( interval.start, num_intervals, max_dist )
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_r = ((PyObject *)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":458
 *         if self.root is None:
 *             return []
 *         if interval.strand == -1 or interval.strand == "-":             # <<<<<<<<<<<<<<
 *             return self.root.left( interval.start, num_intervals, max_dist )
 *         else:
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_interval, __pyx_n_s__strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_1) {
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_interval, __pyx_n_s__strand); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, ((PyObject *)__pyx_kp_s_7), Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_1;
  }
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":459
 *             return []
 *         if interval.strand == -1 or interval.strand == "-":
 *             return self.root.left( interval.start, num_intervals, max_dist )             # <<<<<<<<<<<<<<
 *         else:
 *             return self.root.right( interval.end, num_intervals, max_dist )
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_interval, __pyx_n_s__start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_num_intervals); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_v_max_dist); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8.__pyx_n = 2;
    __pyx_t_8.n = __pyx_t_6;
    __pyx_t_8.max_dist = __pyx_t_7;
    __pyx_t_3 = ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root->__pyx_vtab)->left(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root, __pyx_t_2, 0, &__pyx_t_8); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L7;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":461
 *             return self.root.left( interval.start, num_intervals, max_dist )
 *         else:
 *             return self.root.right( interval.end, num_intervals, max_dist )             # <<<<<<<<<<<<<<
 * 
 *     def traverse(self, fn):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_interval, __pyx_n_s__end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_v_num_intervals); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_max_dist); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 2;
    __pyx_t_9.n = __pyx_t_7;
    __pyx_t_9.max_dist = __pyx_t_6;
    __pyx_t_2 = ((struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root->__pyx_vtab)->right(((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root, __pyx_t_3, 0, &__pyx_t_9); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __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;
  }
  __pyx_L7:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.downstream_of_interval");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":463
 *             return self.root.right( interval.end, num_intervals, max_dist )
 * 
 *     def traverse(self, fn):             # <<<<<<<<<<<<<<
 *         """
 *         call fn for each element in the tree
 */

static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_traverse(PyObject *__pyx_v_self, PyObject *__pyx_v_fn); /*proto*/
static char __pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_traverse[] = "\n        call fn for each element in the tree\n        ";
static PyObject *__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_traverse(PyObject *__pyx_v_self, PyObject *__pyx_v_fn) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("traverse");

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":467
 *         call fn for each element in the tree
 *         """
 *         if self.root is None:             # <<<<<<<<<<<<<<
 *             return None
 *         return self.root.traverse(fn)
 */
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root) == Py_None);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":468
 *         """
 *         if self.root is None:
 *             return None             # <<<<<<<<<<<<<<
 *         return self.root.traverse(fn)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":469
 *         if self.root is None:
 *             return None
 *         return self.root.traverse(fn)             # <<<<<<<<<<<<<<
 * 
 * # For backward compatibility
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyObject_GetAttr(((PyObject *)((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)__pyx_v_self)->root), __pyx_n_s__traverse); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_fn);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_fn);
  __Pyx_GIVEREF(__pyx_v_fn);
  __pyx_t_4 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("chimerascan.bx.intersection.IntervalTree.traverse");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_11chimerascan_2bx_12intersection_IntervalNode __pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode;

static PyObject *__pyx_tp_new_11chimerascan_2bx_12intersection_IntervalNode(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)o);
  p->__pyx_vtab = __pyx_vtabptr_11chimerascan_2bx_12intersection_IntervalNode;
  p->interval = Py_None; Py_INCREF(Py_None);
  p->cleft = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)Py_None); Py_INCREF(Py_None);
  p->cright = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)Py_None); Py_INCREF(Py_None);
  p->croot = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)Py_None); Py_INCREF(Py_None);
  if (__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode___cinit__(o, a, k) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_11chimerascan_2bx_12intersection_IntervalNode(PyObject *o) {
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *p = (struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)o;
  Py_XDECREF(p->interval);
  Py_XDECREF(((PyObject *)p->cleft));
  Py_XDECREF(((PyObject *)p->cright));
  Py_XDECREF(((PyObject *)p->croot));
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_11chimerascan_2bx_12intersection_IntervalNode(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *p = (struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)o;
  if (p->interval) {
    e = (*v)(p->interval, a); if (e) return e;
  }
  if (p->cleft) {
    e = (*v)(((PyObject*)p->cleft), a); if (e) return e;
  }
  if (p->cright) {
    e = (*v)(((PyObject*)p->cright), a); if (e) return e;
  }
  if (p->croot) {
    e = (*v)(((PyObject*)p->croot), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_11chimerascan_2bx_12intersection_IntervalNode(PyObject *o) {
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *p = (struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->interval);
  p->interval = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->cleft);
  p->cleft = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->cright);
  p->cright = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->croot);
  p->croot = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_11chimerascan_2bx_12intersection_12IntervalNode_left_node(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_9left_node___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_2bx_12intersection_12IntervalNode_right_node(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_10right_node___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_2bx_12intersection_12IntervalNode_root_node(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_9root_node___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_2bx_12intersection_12IntervalNode_interval(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_8interval___get__(o);
}

static int __pyx_setprop_11chimerascan_2bx_12intersection_12IntervalNode_interval(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_8interval___set__(o, v);
  }
  else {
    return __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_8interval___del__(o);
  }
}

static PyObject *__pyx_getprop_11chimerascan_2bx_12intersection_12IntervalNode_start(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_5start___get__(o);
}

static int __pyx_setprop_11chimerascan_2bx_12intersection_12IntervalNode_start(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_5start___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_2bx_12intersection_12IntervalNode_end(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_3end___get__(o);
}

static int __pyx_setprop_11chimerascan_2bx_12intersection_12IntervalNode_end(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_3end___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_11chimerascan_2bx_12intersection_IntervalNode[] = {
  {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_insert, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalNode_insert)},
  {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_intersect, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalNode_intersect)},
  {__Pyx_NAMESTR("left"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_left, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalNode_left)},
  {__Pyx_NAMESTR("right"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_right, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalNode_right)},
  {__Pyx_NAMESTR("traverse"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode_traverse, METH_O, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_11chimerascan_2bx_12intersection_IntervalNode[] = {
  {(char *)"left_node", __pyx_getprop_11chimerascan_2bx_12intersection_12IntervalNode_left_node, 0, 0, 0},
  {(char *)"right_node", __pyx_getprop_11chimerascan_2bx_12intersection_12IntervalNode_right_node, 0, 0, 0},
  {(char *)"root_node", __pyx_getprop_11chimerascan_2bx_12intersection_12IntervalNode_root_node, 0, 0, 0},
  {(char *)"interval", __pyx_getprop_11chimerascan_2bx_12intersection_12IntervalNode_interval, __pyx_setprop_11chimerascan_2bx_12intersection_12IntervalNode_interval, 0, 0},
  {(char *)"start", __pyx_getprop_11chimerascan_2bx_12intersection_12IntervalNode_start, __pyx_setprop_11chimerascan_2bx_12intersection_12IntervalNode_start, 0, 0},
  {(char *)"end", __pyx_getprop_11chimerascan_2bx_12intersection_12IntervalNode_end, __pyx_setprop_11chimerascan_2bx_12intersection_12IntervalNode_end, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_IntervalNode = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

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

static PyMappingMethods __pyx_tp_as_mapping_IntervalNode = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_IntervalNode = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_11chimerascan_2bx_12intersection_IntervalNode = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("chimerascan.bx.intersection.IntervalNode"), /*tp_name*/
  sizeof(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_11chimerascan_2bx_12intersection_IntervalNode, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  __pyx_pf_11chimerascan_2bx_12intersection_12IntervalNode___repr__, /*tp_repr*/
  &__pyx_tp_as_number_IntervalNode, /*tp_as_number*/
  &__pyx_tp_as_sequence_IntervalNode, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_IntervalNode, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_IntervalNode, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("\n    A single node of an `IntervalTree`.\n    \n    NOTE: Unless you really know what you are doing, you probably should us\n          `IntervalTree` rather than using this directly. \n    "), /*tp_doc*/
  __pyx_tp_traverse_11chimerascan_2bx_12intersection_IntervalNode, /*tp_traverse*/
  __pyx_tp_clear_11chimerascan_2bx_12intersection_IntervalNode, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_11chimerascan_2bx_12intersection_IntervalNode, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_11chimerascan_2bx_12intersection_IntervalNode, /*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_11chimerascan_2bx_12intersection_IntervalNode, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_11chimerascan_2bx_12intersection_Interval(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)o);
  p->value = Py_None; Py_INCREF(Py_None);
  p->chrom = Py_None; Py_INCREF(Py_None);
  p->strand = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_11chimerascan_2bx_12intersection_Interval(PyObject *o) {
  struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *p = (struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)o;
  Py_XDECREF(p->value);
  Py_XDECREF(p->chrom);
  Py_XDECREF(p->strand);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_11chimerascan_2bx_12intersection_Interval(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *p = (struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)o;
  if (p->value) {
    e = (*v)(p->value, a); if (e) return e;
  }
  if (p->chrom) {
    e = (*v)(p->chrom, a); if (e) return e;
  }
  if (p->strand) {
    e = (*v)(p->strand, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_11chimerascan_2bx_12intersection_Interval(PyObject *o) {
  struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *p = (struct __pyx_obj_11chimerascan_2bx_12intersection_Interval *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->value);
  p->value = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->chrom);
  p->chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->strand);
  p->strand = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_11chimerascan_2bx_12intersection_8Interval_start(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5start___get__(o);
}

static int __pyx_setprop_11chimerascan_2bx_12intersection_8Interval_start(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5start___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_2bx_12intersection_8Interval_end(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_3end___get__(o);
}

static int __pyx_setprop_11chimerascan_2bx_12intersection_8Interval_end(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_3end___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_2bx_12intersection_8Interval_value(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5value___get__(o);
}

static int __pyx_setprop_11chimerascan_2bx_12intersection_8Interval_value(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5value___set__(o, v);
  }
  else {
    return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5value___del__(o);
  }
}

static PyObject *__pyx_getprop_11chimerascan_2bx_12intersection_8Interval_chrom(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5chrom___get__(o);
}

static int __pyx_setprop_11chimerascan_2bx_12intersection_8Interval_chrom(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5chrom___set__(o, v);
  }
  else {
    return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_5chrom___del__(o);
  }
}

static PyObject *__pyx_getprop_11chimerascan_2bx_12intersection_8Interval_strand(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_6strand___get__(o);
}

static int __pyx_setprop_11chimerascan_2bx_12intersection_8Interval_strand(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_6strand___set__(o, v);
  }
  else {
    return __pyx_pf_11chimerascan_2bx_12intersection_8Interval_6strand___del__(o);
  }
}

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

static struct PyGetSetDef __pyx_getsets_11chimerascan_2bx_12intersection_Interval[] = {
  {(char *)"start", __pyx_getprop_11chimerascan_2bx_12intersection_8Interval_start, __pyx_setprop_11chimerascan_2bx_12intersection_8Interval_start, 0, 0},
  {(char *)"end", __pyx_getprop_11chimerascan_2bx_12intersection_8Interval_end, __pyx_setprop_11chimerascan_2bx_12intersection_8Interval_end, 0, 0},
  {(char *)"value", __pyx_getprop_11chimerascan_2bx_12intersection_8Interval_value, __pyx_setprop_11chimerascan_2bx_12intersection_8Interval_value, 0, 0},
  {(char *)"chrom", __pyx_getprop_11chimerascan_2bx_12intersection_8Interval_chrom, __pyx_setprop_11chimerascan_2bx_12intersection_8Interval_chrom, 0, 0},
  {(char *)"strand", __pyx_getprop_11chimerascan_2bx_12intersection_8Interval_strand, __pyx_setprop_11chimerascan_2bx_12intersection_8Interval_strand, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_Interval = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

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

static PyMappingMethods __pyx_tp_as_mapping_Interval = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_Interval = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_11chimerascan_2bx_12intersection_Interval = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("chimerascan.bx.intersection.Interval"), /*tp_name*/
  sizeof(struct __pyx_obj_11chimerascan_2bx_12intersection_Interval), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_11chimerascan_2bx_12intersection_Interval, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  __pyx_pf_11chimerascan_2bx_12intersection_8Interval___cmp__, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  __pyx_pf_11chimerascan_2bx_12intersection_8Interval___repr__, /*tp_repr*/
  &__pyx_tp_as_number_Interval, /*tp_as_number*/
  &__pyx_tp_as_sequence_Interval, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_Interval, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_Interval, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("\n    Basic feature, with required integer start and end properties.\n    Also accepts optional strand as +1 or -1 (used for up/downstream queries),\n    a name, and any arbitrary data is sent in on the info keyword argument\n\n    >>> from bx.intervals.intersection import Interval\n\n    >>> f1 = Interval(23, 36)\n    >>> f2 = Interval(34, 48, value={'chr':12, 'anno':'transposon'})\n    >>> f2\n    Interval(34, 48, value={'anno': 'transposon', 'chr': 12})\n\n    "), /*tp_doc*/
  __pyx_tp_traverse_11chimerascan_2bx_12intersection_Interval, /*tp_traverse*/
  __pyx_tp_clear_11chimerascan_2bx_12intersection_Interval, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_11chimerascan_2bx_12intersection_Interval, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_11chimerascan_2bx_12intersection_Interval, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_11chimerascan_2bx_12intersection_8Interval___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_11chimerascan_2bx_12intersection_Interval, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_11chimerascan_2bx_12intersection_IntervalTree(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)o);
  p->root = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)Py_None); Py_INCREF(Py_None);
  if (__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree___cinit__(o, __pyx_empty_tuple, NULL) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_11chimerascan_2bx_12intersection_IntervalTree(PyObject *o) {
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *p = (struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)o;
  Py_XDECREF(((PyObject *)p->root));
  (*Py_TYPE(o)->tp_free)(o);
}

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

static int __pyx_tp_clear_11chimerascan_2bx_12intersection_IntervalTree(PyObject *o) {
  struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *p = (struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->root);
  p->root = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_11chimerascan_2bx_12intersection_IntervalTree[] = {
  {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_insert, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_insert)},
  {__Pyx_NAMESTR("find"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_find, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_find)},
  {__Pyx_NAMESTR("before"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_before, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_before)},
  {__Pyx_NAMESTR("after"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_after, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_after)},
  {__Pyx_NAMESTR("insert_interval"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_insert_interval, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_insert_interval)},
  {__Pyx_NAMESTR("before_interval"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_before_interval, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_before_interval)},
  {__Pyx_NAMESTR("after_interval"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_after_interval, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_after_interval)},
  {__Pyx_NAMESTR("upstream_of_interval"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_upstream_of_interval, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_upstream_of_interval)},
  {__Pyx_NAMESTR("downstream_of_interval"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_downstream_of_interval, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_downstream_of_interval)},
  {__Pyx_NAMESTR("traverse"), (PyCFunction)__pyx_pf_11chimerascan_2bx_12intersection_12IntervalTree_traverse, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_2bx_12intersection_12IntervalTree_traverse)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_IntervalTree = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

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

static PyMappingMethods __pyx_tp_as_mapping_IntervalTree = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_IntervalTree = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_11chimerascan_2bx_12intersection_IntervalTree = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("chimerascan.bx.intersection.IntervalTree"), /*tp_name*/
  sizeof(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalTree), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_11chimerascan_2bx_12intersection_IntervalTree, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_IntervalTree, /*tp_as_number*/
  &__pyx_tp_as_sequence_IntervalTree, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_IntervalTree, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_IntervalTree, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("\n    Data structure for performing window intersect queries on a set of \n    of possibly overlapping 1d intervals.\n    \n    Usage\n    =====\n    \n    Create an empty IntervalTree\n    \n    >>> from bx.intervals.intersection import Interval, IntervalTree\n    >>> intersecter = IntervalTree()\n    \n    An interval is a start and end position and a value (possibly None).\n    You can add any object as an interval:\n    \n    >>> intersecter.insert( 0, 10, \"food\" )\n    >>> intersecter.insert( 3, 7, dict(foo='bar') )\n    \n    >>> intersecter.find( 2, 5 )\n    ['food', {'foo': 'bar'}]\n    \n    If the object has start and end attributes (like the Interval class) there\n    is are some shortcuts:\n    \n    >>> intersecter = IntervalTree()\n    >>> intersecter.insert_interval( Interval( 0, 10 ) )\n    >>> intersecter.insert_interval( Interval( 3, 7 ) )\n    >>> intersecter.insert_interval( Interval( 3, 40 ) )\n    >>> intersecter.insert_interval( Interval( 13, 50 ) )\n    \n    >>> intersecter.find( 30, 50 )\n    [Interval(3, 40), Interval(13, 50)]\n    >>> intersecter.find( 100, 200 )\n    []\n    \n    Before/after for intervals\n    \n    >>> intersecter.before_interval( Interval( 10, 20 ) )\n    [Interval(3, 7)]\n    >>> intersecter.before_interval( Interval( 5, 20 ) )\n    []\n    \n    Upstream/downstream\n    \n    >>> intersecter.upstream_of_interval(Interval(11, 12))\n    [Interval(0, 10)]\n    >>> intersecter.upstream_of_interval(Interval(11, 12, strand=\"-\"))\n    [Interval(13, 50)]\n\n    >>> intersecter.upstream_of_interval(Interval(1, 2, strand=\"-\"), num_intervals=3)\n    [Interval(3, 7), Interval(3, 40), Interval(13, 50)]\n\n    \n    "), /*tp_doc*/
  __pyx_tp_traverse_11chimerascan_2bx_12intersection_IntervalTree, /*tp_traverse*/
  __pyx_tp_clear_11chimerascan_2bx_12intersection_IntervalTree, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_11chimerascan_2bx_12intersection_IntervalTree, /*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_11chimerascan_2bx_12intersection_IntervalTree, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

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

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("intersection"),
    __Pyx_DOCSTR(__pyx_k_8), /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__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_16, __pyx_k_16, sizeof(__pyx_k_16), 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_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 1, 0, 0},
  {&__pyx_n_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 1},
  {&__pyx_kp_u_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 1, 0, 0},
  {&__pyx_n_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 1},
  {&__pyx_kp_u_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 1, 0, 0},
  {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
  {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0},
  {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0},
  {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0},
  {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0},
  {&__pyx_kp_u_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 1, 0, 0},
  {&__pyx_n_s__Intersecter, __pyx_k__Intersecter, sizeof(__pyx_k__Intersecter), 0, 0, 1, 1},
  {&__pyx_n_s__IntervalNode, __pyx_k__IntervalNode, sizeof(__pyx_k__IntervalNode), 0, 0, 1, 1},
  {&__pyx_n_s__IntervalTree, __pyx_k__IntervalTree, sizeof(__pyx_k__IntervalTree), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s___intersect, __pyx_k___intersect, sizeof(__pyx_k___intersect), 0, 0, 1, 1},
  {&__pyx_n_s___seek_left, __pyx_k___seek_left, sizeof(__pyx_k___seek_left), 0, 0, 1, 1},
  {&__pyx_n_s___seek_right, __pyx_k___seek_right, sizeof(__pyx_k___seek_right), 0, 0, 1, 1},
  {&__pyx_n_s___traverse, __pyx_k___traverse, sizeof(__pyx_k___traverse), 0, 0, 1, 1},
  {&__pyx_n_s__add, __pyx_k__add, sizeof(__pyx_k__add), 0, 0, 1, 1},
  {&__pyx_n_s__add_interval, __pyx_k__add_interval, sizeof(__pyx_k__add_interval), 0, 0, 1, 1},
  {&__pyx_n_s__after, __pyx_k__after, sizeof(__pyx_k__after), 0, 0, 1, 1},
  {&__pyx_n_s__after_interval, __pyx_k__after_interval, sizeof(__pyx_k__after_interval), 0, 0, 1, 1},
  {&__pyx_n_s__attrgetter, __pyx_k__attrgetter, sizeof(__pyx_k__attrgetter), 0, 0, 1, 1},
  {&__pyx_n_s__before, __pyx_k__before, sizeof(__pyx_k__before), 0, 0, 1, 1},
  {&__pyx_n_s__before_interval, __pyx_k__before_interval, sizeof(__pyx_k__before_interval), 0, 0, 1, 1},
  {&__pyx_n_s__chrom, __pyx_k__chrom, sizeof(__pyx_k__chrom), 0, 0, 1, 1},
  {&__pyx_n_s__cleft, __pyx_k__cleft, sizeof(__pyx_k__cleft), 0, 0, 1, 1},
  {&__pyx_n_s__cmp, __pyx_k__cmp, sizeof(__pyx_k__cmp), 0, 0, 1, 1},
  {&__pyx_n_s__cright, __pyx_k__cright, sizeof(__pyx_k__cright), 0, 0, 1, 1},
  {&__pyx_n_s__croot, __pyx_k__croot, sizeof(__pyx_k__croot), 0, 0, 1, 1},
  {&__pyx_n_s__end, __pyx_k__end, sizeof(__pyx_k__end), 0, 0, 1, 1},
  {&__pyx_n_s__find, __pyx_k__find, sizeof(__pyx_k__find), 0, 0, 1, 1},
  {&__pyx_n_s__insert, __pyx_k__insert, sizeof(__pyx_k__insert), 0, 0, 1, 1},
  {&__pyx_n_s__insert_interval, __pyx_k__insert_interval, sizeof(__pyx_k__insert_interval), 0, 0, 1, 1},
  {&__pyx_n_s__intersect, __pyx_k__intersect, sizeof(__pyx_k__intersect), 0, 0, 1, 1},
  {&__pyx_n_s__interval, __pyx_k__interval, sizeof(__pyx_k__interval), 0, 0, 1, 1},
  {&__pyx_n_s__key, __pyx_k__key, sizeof(__pyx_k__key), 0, 0, 1, 1},
  {&__pyx_n_s__left, __pyx_k__left, sizeof(__pyx_k__left), 0, 0, 1, 1},
  {&__pyx_n_s__max_dist, __pyx_k__max_dist, sizeof(__pyx_k__max_dist), 0, 0, 1, 1},
  {&__pyx_n_s__maxend, __pyx_k__maxend, sizeof(__pyx_k__maxend), 0, 0, 1, 1},
  {&__pyx_n_s__minend, __pyx_k__minend, sizeof(__pyx_k__minend), 0, 0, 1, 1},
  {&__pyx_n_s__minstart, __pyx_k__minstart, sizeof(__pyx_k__minstart), 0, 0, 1, 1},
  {&__pyx_n_s__n, __pyx_k__n, sizeof(__pyx_k__n), 0, 0, 1, 1},
  {&__pyx_n_s__num_intervals, __pyx_k__num_intervals, sizeof(__pyx_k__num_intervals), 0, 0, 1, 1},
  {&__pyx_n_s__operator, __pyx_k__operator, sizeof(__pyx_k__operator), 0, 0, 1, 1},
  {&__pyx_n_s__position, __pyx_k__position, sizeof(__pyx_k__position), 0, 0, 1, 1},
  {&__pyx_n_s__priority, __pyx_k__priority, sizeof(__pyx_k__priority), 0, 0, 1, 1},
  {&__pyx_n_s__reverse, __pyx_k__reverse, sizeof(__pyx_k__reverse), 0, 0, 1, 1},
  {&__pyx_n_s__right, __pyx_k__right, sizeof(__pyx_k__right), 0, 0, 1, 1},
  {&__pyx_n_s__root, __pyx_k__root, sizeof(__pyx_k__root), 0, 0, 1, 1},
  {&__pyx_n_s__rotate_left, __pyx_k__rotate_left, sizeof(__pyx_k__rotate_left), 0, 0, 1, 1},
  {&__pyx_n_s__rotate_right, __pyx_k__rotate_right, sizeof(__pyx_k__rotate_right), 0, 0, 1, 1},
  {&__pyx_n_s__set_ends, __pyx_k__set_ends, sizeof(__pyx_k__set_ends), 0, 0, 1, 1},
  {&__pyx_n_s__sort, __pyx_k__sort, sizeof(__pyx_k__sort), 0, 0, 1, 1},
  {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1},
  {&__pyx_n_s__strand, __pyx_k__strand, sizeof(__pyx_k__strand), 0, 0, 1, 1},
  {&__pyx_n_s__traverse, __pyx_k__traverse, sizeof(__pyx_k__traverse), 0, 0, 1, 1},
  {&__pyx_n_s__value, __pyx_k__value, sizeof(__pyx_k__value), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_cmp = __Pyx_GetName(__pyx_b, __pyx_n_s__cmp); if (!__pyx_builtin_cmp) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_2500 = PyInt_FromLong(2500); if (unlikely(!__pyx_int_2500)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initintersection(void); /*proto*/
PyMODINIT_FUNC initintersection(void)
#else
PyMODINIT_FUNC PyInit_intersection(void); /*proto*/
PyMODINIT_FUNC PyInit_intersection(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  double __pyx_t_2;
  float __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  #if CYTHON_REFNANNY
  void* __pyx_refnanny = NULL;
  __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");
  }
  __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit_intersection(void)", __LINE__, __FILE__);
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __pyx_binding_PyCFunctionType_USED
  if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("intersection"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_8), 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_module_is_main_chimerascan__bx__intersection) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  __pyx_v_11chimerascan_2bx_12intersection_EmptyNode = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)Py_None); Py_INCREF(Py_None);
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  __pyx_vtabptr_11chimerascan_2bx_12intersection_IntervalNode = &__pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode;
  #if PY_MAJOR_VERSION >= 3
  __pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode.insert = (struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *(*)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, int, int, PyObject *, int __pyx_skip_dispatch))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_insert;
  __pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode.rotate_right = (struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *(*)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_rotate_right;
  __pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode.rotate_left = (struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *(*)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_rotate_left;
  __pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode.set_ends = (void (*)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_set_ends;
  __pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode._intersect = (void (*)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, int, int, PyObject *))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode__intersect;
  __pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode._seek_left = (void (*)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, int, PyObject *, int, int))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode__seek_left;
  __pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode._seek_right = (void (*)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, int, PyObject *, int, int))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode__seek_right;
  __pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode.left = (PyObject *(*)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_left *__pyx_optional_args))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_left;
  __pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode.right = (PyObject *(*)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_11chimerascan_2bx_12intersection_12IntervalNode_right *__pyx_optional_args))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_right;
  __pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode._traverse = (void (*)(struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *, PyObject *))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode__traverse;
  #else
  *(void(**)(void))&__pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode.insert = (void(*)(void))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_insert;
  *(void(**)(void))&__pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode.rotate_right = (void(*)(void))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_rotate_right;
  *(void(**)(void))&__pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode.rotate_left = (void(*)(void))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_rotate_left;
  *(void(**)(void))&__pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode.set_ends = (void(*)(void))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_set_ends;
  *(void(**)(void))&__pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode._intersect = (void(*)(void))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode__intersect;
  *(void(**)(void))&__pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode._seek_left = (void(*)(void))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode__seek_left;
  *(void(**)(void))&__pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode._seek_right = (void(*)(void))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode__seek_right;
  *(void(**)(void))&__pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode.left = (void(*)(void))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_left;
  *(void(**)(void))&__pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode.right = (void(*)(void))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode_right;
  *(void(**)(void))&__pyx_vtable_11chimerascan_2bx_12intersection_IntervalNode._traverse = (void(*)(void))__pyx_f_11chimerascan_2bx_12intersection_12IntervalNode__traverse;
  #endif
  if (PyType_Ready(&__pyx_type_11chimerascan_2bx_12intersection_IntervalNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_11chimerascan_2bx_12intersection_IntervalNode.tp_dict, __pyx_vtabptr_11chimerascan_2bx_12intersection_IntervalNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "IntervalNode", (PyObject *)&__pyx_type_11chimerascan_2bx_12intersection_IntervalNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_11chimerascan_2bx_12intersection_IntervalNode = &__pyx_type_11chimerascan_2bx_12intersection_IntervalNode;
  if (PyType_Ready(&__pyx_type_11chimerascan_2bx_12intersection_Interval) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "Interval", (PyObject *)&__pyx_type_11chimerascan_2bx_12intersection_Interval) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_11chimerascan_2bx_12intersection_Interval = &__pyx_type_11chimerascan_2bx_12intersection_Interval;
  if (PyType_Ready(&__pyx_type_11chimerascan_2bx_12intersection_IntervalTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "IntervalTree", (PyObject *)&__pyx_type_11chimerascan_2bx_12intersection_IntervalTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_11chimerascan_2bx_12intersection_IntervalTree = &__pyx_type_11chimerascan_2bx_12intersection_IntervalTree;
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":23
 * #    implement the same interface as the original Intersecter.
 * 
 * import operator             # <<<<<<<<<<<<<<
 * 
 * cdef extern from "stdlib.h":
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__operator), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__operator, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":59
 *     return a
 * 
 * cdef float nlog = -1.0 / log(0.5)             # <<<<<<<<<<<<<<
 * 
 * cdef class IntervalNode:
 */
  __pyx_t_2 = (-1.0);
  __pyx_t_3 = log(0.5);
  if (unlikely(__pyx_t_3 == 0)) {
    PyErr_Format(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_11chimerascan_2bx_12intersection_nlog = (__pyx_t_2 / __pyx_t_3);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":169
 * 
 * 
 *     def intersect( self, int start, int end, sort=True ):             # <<<<<<<<<<<<<<
 *         """
 *         given a start and a end, return a list of features
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_2 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":178
 *         return results
 * 
 *     find = intersect             # <<<<<<<<<<<<<<
 * 
 *     cdef void _intersect( IntervalNode self, int start, int end, list results ):
 */
  __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_11chimerascan_2bx_12intersection_IntervalNode, __pyx_n_s__intersect); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_11chimerascan_2bx_12intersection_IntervalNode->tp_dict, __pyx_n_s__find, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyType_Modified(__pyx_ptype_11chimerascan_2bx_12intersection_IntervalNode);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":270
 *         if self.cright is not EmptyNode: self.cright._traverse(func)
 * 
 * cdef IntervalNode EmptyNode = IntervalNode( 0, 0, Interval(0, 0))             # <<<<<<<<<<<<<<
 * 
 * ## ---- Wrappers that retain the old interface -------------------------------
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_2bx_12intersection_Interval)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_2bx_12intersection_IntervalNode)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GOTREF(((PyObject *)__pyx_v_11chimerascan_2bx_12intersection_EmptyNode));
  __Pyx_DECREF(((PyObject *)__pyx_v_11chimerascan_2bx_12intersection_EmptyNode));
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_v_11chimerascan_2bx_12intersection_EmptyNode = ((struct __pyx_obj_11chimerascan_2bx_12intersection_IntervalNode *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":381
 *             self.root = self.root.insert( start, end, value )
 * 
 *     add = insert             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_4 = __Pyx_GetName((PyObject *)__pyx_ptype_11chimerascan_2bx_12intersection_IntervalTree, __pyx_n_s__insert); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_11chimerascan_2bx_12intersection_IntervalTree->tp_dict, __pyx_n_s__add, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  PyType_Modified(__pyx_ptype_11chimerascan_2bx_12intersection_IntervalTree);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":419
 *         self.insert( interval.start, interval.end, interval )
 * 
 *     add_interval = insert_interval             # <<<<<<<<<<<<<<
 * 
 *     def before_interval( self, interval, num_intervals=1, max_dist=2500 ):
 */
  __pyx_t_4 = __Pyx_GetName((PyObject *)__pyx_ptype_11chimerascan_2bx_12intersection_IntervalTree, __pyx_n_s__insert_interval); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_11chimerascan_2bx_12intersection_IntervalTree->tp_dict, __pyx_n_s__add_interval, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  PyType_Modified(__pyx_ptype_11chimerascan_2bx_12intersection_IntervalTree);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":472
 * 
 * # For backward compatibility
 * Intersecter = IntervalTree             # <<<<<<<<<<<<<<
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Intersecter, ((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_2bx_12intersection_IntervalTree))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/bx/intersection.pyx":1
 * """             # <<<<<<<<<<<<<<
 * Downloaded from:
 * https://bitbucket.org/james_taylor/bx-python/wiki/Home
 */
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalNode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__insert); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_9), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalNode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__intersect); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_10), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalNode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__left); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_11), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalNode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__right); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_12), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalTree); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__insert); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_13), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalTree); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__find); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_14), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalTree); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__before); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_15), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalTree); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__after); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_16), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalTree); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__insert_interval); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_17), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalTree); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__before_interval); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_18), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalTree); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__after_interval); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_19), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalTree); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s_21); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_20), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalTree); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s_23); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_22), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IntervalTree); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__traverse); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_5, "__doc__"); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_u_24), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  if (__pyx_m) {
    __Pyx_AddTraceback("init chimerascan.bx.intersection");
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init chimerascan.bx.intersection");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* Runtime support code */

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

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_AS_STRING(kw_name));
        #endif
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *number, *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";
    }
    number = (num_expected == 1) ? "" : "s";
    PyErr_Format(PyExc_TypeError,
        #if PY_VERSION_HEX < 0x02050000
            "%s() takes %s %d positional argument%s (%d given)",
        #else
            "%s() takes %s %zd positional argument%s (%zd given)",
        #endif
        func_name, more_or_less, num_expected, number, num_found);
}

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;
        } else {
            #if PY_MAJOR_VERSION < 3
            if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
            #else
            if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
            #endif
                goto invalid_keyword_type;
            } else {
                for (name = first_kw_arg; *name; name++) {
                    #if PY_MAJOR_VERSION >= 3
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                        PyUnicode_Compare(**name, key) == 0) break;
                    #else
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                        _PyString_Eq(**name, key)) break;
                    #endif
                }
                if (*name) {
                    values[name-argnames] = value;
                } else {
                    /* unexpected keyword found */
                    for (name=argnames; name != first_kw_arg; name++) {
                        if (**name == key) goto arg_passed_twice;
                        #if PY_MAJOR_VERSION >= 3
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
                        #else
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                            _PyString_Eq(**name, key)) goto arg_passed_twice;
                        #endif
                    }
                    if (kwds2) {
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
                    } else {
                        goto invalid_keyword;
                    }
                }
            }
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

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

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

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *py_import = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!py_import)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    module = PyObject_CallFunctionObjArgs(py_import,
        name, global_dict, empty_dict, list, NULL);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(py_import);
    Py_XDECREF(empty_dict);
    return module;
}

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;

    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}


static void __Pyx_WriteUnraisable(const char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(const char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;

    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(__pyx_filename);
    #else
    py_srcfile = PyUnicode_FromString(__pyx_filename);
    #endif
    if (!py_srcfile) goto bad;
    if (__pyx_clineno) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,            /*int kwonlyargcount,*/
        #endif
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple,  /*PyObject *consts,*/
        __pyx_empty_tuple,  /*PyObject *names,*/
        __pyx_empty_tuple,  /*PyObject *varnames,*/
        __pyx_empty_tuple,  /*PyObject *freevars,*/
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

/* Type Conversion Functions */

static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}

static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
