1. Davide Cittaro
  2. gilbert

Commits

dawe  committed 97ef02f

added bigwig script

  • Participants
  • Parent commits 066a78f
  • Branches default

Comments (0)

Files changed (4)

File bin/hc_bigwig.py

View file
+#!/usr/bin/env python2.7
+
+import gilbert
+import sys
+import numpy as np
+import argparse
+import bx.bbi.bigwig_file
+import os
+import struct
+
+def getChromosomeSizesFromBigWig(bwname):
+  csize = {}
+  fh = open(os.path.expanduser(bwname), "rb")
+  magic = fh.read(4)
+  if magic == '&\xfc\x8f\x88':
+    endianness = '<'
+  elif magic == '\x88\x8f\xfc&':
+    endianness = '>'
+  else:
+    raise IOError("The file is not in bigwig format")
+  (version,zoomLevels,chromosomeTreeOffset,fullDataOffset,fullIndexOffset,fieldCount,definedFieldCount,autoSqlOffset,totalSummaryOffset,uncompressBufSize,reserved)=struct.unpack(endianness+'HHQQQHHQQIQ',fh.read(60))
+  if version < 3:
+    raise IOError("Bigwig files version <3 are not supported")
+  fh.seek(chromosomeTreeOffset)
+  magic = fh.read(4)
+  if magic == '\x91\x8c\xcax':
+    endianness = '<'
+  elif magic == 'x\xca\x8c\x91':
+    endianness = '>'
+  else:
+    raise ValueError("Wrong magic for this bigwig data file")
+  (blockSize, keySize, valSize, itemCount, reserved) = struct.unpack(endianness + 'IIIQQ', fh.read(28))
+  (isLeaf, reserved, count) = struct.unpack(endianness + 'BBH', fh.read(4))
+  for n in range(count):
+    (key, chromId, chromSize) = struct.unpack(endianness + str(keySize) + 'sII', fh.read(keySize + 2 * 4))
+    csize[key.replace('\x00', '')] = chromSize
+  return csize
+
+
+def hc_bam():
+  # parse options
+  option_parser = argparse.ArgumentParser(
+  description="Plot Hilbert curve from a BAM file",
+  prog="hc_bam.py",
+  epilog="For any question, write to cittaro.davide@hsr.it")
+  option_parser.add_argument("--version", action="version", version="%(prog)s 0.1")
+  option_parser.add_argument("-f","--file", help="File to convert", action='store', type=argparse.FileType('rb'), default=sys.stdin)
+  option_parser.add_argument("-n","--name", help="Map prefix", action='store', default="Gilbert")
+  option_parser.add_argument("-l","--level", help="Map level (<10)", type=int, default=8)
+  option_parser.add_argument("-x","--exclude", help="Exclude this chromosome from the analysis", action='append')
+  option_parser.add_argument("-i","--include", help="Limit the analysis to this chromosome", action='append')
+  option_parser.add_argument("-L","--linearscale", help="Plot map in linear scale", action="store_true", default=False)
+  option_parser.add_argument("-r","--resolution", help="Resolution of resulting map", type=int, default=600)
+  option_parser.add_argument("-s","--summarize", help="Function to summarize data", choices=['sum', 'mean', 'max'], default='sum')
+  option_parser.add_argument("-g","--genome", help="Plot a map for the whole genome",action="store_true", default=False)
+  options = option_parser.parse_args()
+  
+  if not options.file:
+    gilbert.terminate("read from stdin not yet implemented\n", 1)
+  chromosome_sizes = getChromosomeSizesFromBigWig(options.file.name)
+  
+  bw_handler = bx.bbi.bigwig_file.BigWigFile(options.file)
+  for chromosome in chromosome_sizes.keys():
+    chromosome_size = chromosome_sizes[chromosome]
+    # cycle on actual data data
+    if options.exclude and chromosome in options.exclude: continue
+    if options.include and not chromosome in options.include: continue
+    # random chrom are ecluded by default
+    if '_' in chromosome: continue
+
+    file_prefix = "%s_%s" % (options.name, chromosome)
+
+    sys.stderr.write("Processing %s [%d bp] " % (chromosome, chromosome_size))
+    
+    sys.stderr.write("Creating map ")
+    hc = gilbert.create_map_from_bigwig(bw_handler, chromosome, chromosome_size, options.level, options.summarize)
+
+    if not options.linearscale:
+      hc = np.log1p(hc)
+    sys.stderr.write("\n")
+    sys.stderr.write("Dumping Map into numpy array %s.npy \n" % file_prefix)
+    np.save(file_prefix, hc)
+    
+    sys.stderr.write("Plotting image %s.npy \n" % file_prefix)
+    gilbert.dump_png(hc, chromosome, chromosome_size, options.name, options.level, options.resolution)
+    
+if __name__ == "__main__": hc_bam()

File gilbert/gilbert.c

View file
-/* Generated by Cython 0.17.2 on Mon Dec  3 08:46:37 2012 */
+/* Generated by Cython 0.17.2 on Mon Dec  3 09:11:26 2012 */
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
 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 CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */
+
+static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
+
+static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
+
+static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/
+
+static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/
+
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
+    PyObject *r;
+    if (!j) return NULL;
+    r = PyObject_GetItem(o, j);
+    Py_DECREF(j);
+    return r;
+}
+#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+                                                    __Pyx_GetItemInt_List_Fast(o, i) : \
+                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
+#if CYTHON_COMPILING_IN_CPYTHON
+    if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
+        PyObject *r = PyList_GET_ITEM(o, i);
+        Py_INCREF(r);
+        return r;
+    }
+    else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
+        PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
+        Py_INCREF(r);
+        return r;
+    }
+    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+    return PySequence_GetItem(o, i);
+#endif
+}
+#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+                                                    __Pyx_GetItemInt_Tuple_Fast(o, i) : \
+                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
+#if CYTHON_COMPILING_IN_CPYTHON
+    if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
+        PyObject *r = PyTuple_GET_ITEM(o, i);
+        Py_INCREF(r);
+        return r;
+    }
+    else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
+        PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
+        Py_INCREF(r);
+        return r;
+    }
+    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+    return PySequence_GetItem(o, i);
+#endif
+}
+#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+                                                    __Pyx_GetItemInt_Fast(o, i) : \
+                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
+#if CYTHON_COMPILING_IN_CPYTHON
+    if (PyList_CheckExact(o)) {
+        Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
+        if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
+            PyObject *r = PyList_GET_ITEM(o, n);
+            Py_INCREF(r);
+            return r;
+        }
+    }
+    else if (PyTuple_CheckExact(o)) {
+        Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
+        if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
+            PyObject *r = PyTuple_GET_ITEM(o, n);
+            Py_INCREF(r);
+            return r;
+        }
+    } else {  /* inlined PySequence_GetItem() */
+        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
+        if (likely(m && m->sq_item)) {
+            if (unlikely(i < 0) && likely(m->sq_length)) {
+                Py_ssize_t l = m->sq_length(o);
+                if (unlikely(l < 0)) return NULL;
+                i += l;
+            }
+            return m->sq_item(o, i);
+        }
+    }
+#else
+    if (PySequence_Check(o)) {
+        return PySequence_GetItem(o, i);
+    }
+#endif
+    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+}
+
+static CYTHON_INLINE long __Pyx_mod_long(long, long); /* proto */
+
+#define UNARY_NEG_WOULD_OVERFLOW(x)            (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x)))
+
 static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
 static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
 
 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/
 
-static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
-
-static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
-
-static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/
-
-static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/
-
-static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */
-
-static CYTHON_INLINE long __Pyx_mod_long(long, long); /* proto */
-
-#define UNARY_NEG_WOULD_OVERFLOW(x)            (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x)))
-
 static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);
 
 static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
 int __pyx_module_is_main_gilbert = 0;
 
 /* Implementation of 'gilbert' */
-static PyObject *__pyx_builtin_open;
-static PyObject *__pyx_builtin_IOError;
+static PyObject *__pyx_builtin_range;
 static PyObject *__pyx_builtin_ValueError;
-static PyObject *__pyx_builtin_range;
 static PyObject *__pyx_builtin_RuntimeError;
 static PyObject *__pyx_pf_7gilbert_terminate(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_msg, PyObject *__pyx_v_exit_status); /* proto */
-static PyObject *__pyx_pf_7gilbert_2getChromosomeSizesFromBigWig(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_bwname); /* proto */
-static PyObject *__pyx_pf_7gilbert_4dump_png(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_hc, PyObject *__pyx_v_chromosome, int __pyx_v_chromosome_size, PyObject *__pyx_v_name, int __pyx_v_level, int __pyx_v_resolution); /* proto */
-static PyObject *__pyx_pf_7gilbert_6create_map_from_interval_tree(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_interval_tree, int __pyx_v_chromosome_size, int __pyx_v_level, PyObject *__pyx_v_summarize); /* proto */
-static PyObject *__pyx_pf_7gilbert_8create_map_from_bam(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_fh, PyObject *__pyx_v_chromosome, int __pyx_v_chromosome_size, int __pyx_v_level, PyObject *__pyx_v_summarize); /* proto */
+static PyObject *__pyx_pf_7gilbert_2dump_png(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_hc, PyObject *__pyx_v_chromosome, int __pyx_v_chromosome_size, PyObject *__pyx_v_name, int __pyx_v_level, int __pyx_v_resolution); /* proto */
+static PyObject *__pyx_pf_7gilbert_4create_map_from_array(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data_array, int __pyx_v_chromosome_size, int __pyx_v_level, PyObject *__pyx_v_summarize); /* proto */
+static PyObject *__pyx_pf_7gilbert_6create_map_from_bigwig(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_bw_handler, PyObject *__pyx_v_chromosome, int __pyx_v_chromosome_size, int __pyx_v_level, PyObject *__pyx_v_summarize); /* proto */
+static PyObject *__pyx_pf_7gilbert_8create_map_from_interval_tree(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_interval_tree, int __pyx_v_chromosome_size, int __pyx_v_level, PyObject *__pyx_v_summarize); /* proto */
+static PyObject *__pyx_pf_7gilbert_10create_map_from_bam(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_fh, PyObject *__pyx_v_chromosome, int __pyx_v_chromosome_size, int __pyx_v_level, PyObject *__pyx_v_summarize); /* proto */
 static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
 static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */
 static char __pyx_k_1[] = "%s\n";
-#if PY_MAJOR_VERSION >= 3
-static char __pyx_k_3[] = "&\303\274\302\217\302\210";
-#endif
-#if PY_MAJOR_VERSION < 3
-static char __pyx_k_4[] = "&\374\217\210";
-#endif
-static char __pyx_k_5[] = "<";
-#if PY_MAJOR_VERSION >= 3
-static char __pyx_k_6[] = "\302\210\302\217\303\274&";
-#endif
-#if PY_MAJOR_VERSION < 3
-static char __pyx_k_7[] = "\210\217\374&";
-#endif
-static char __pyx_k_8[] = ">";
-static char __pyx_k_9[] = "The file is not in bigwig format";
-static char __pyx_k_12[] = "Bigwig files version <3 are not supported";
-#if PY_MAJOR_VERSION >= 3
-static char __pyx_k_15[] = "\302\221\302\214\303\212x";
-#endif
-#if PY_MAJOR_VERSION < 3
-static char __pyx_k_16[] = "\221\214\312x";
-#endif
-#if PY_MAJOR_VERSION >= 3
-static char __pyx_k_17[] = "x\303\212\302\214\302\221";
-#endif
-#if PY_MAJOR_VERSION < 3
-static char __pyx_k_18[] = "x\312\214\221";
-#endif
-static char __pyx_k_19[] = "Wrong magic for this bigwig data file";
-static char __pyx_k_23[] = "\000";
-static char __pyx_k_24[] = "";
-static char __pyx_k_26[] = "k+";
-static char __pyx_k_27[] = "%dM";
-static char __pyx_k_28[] = "Hilbert curve for %s";
-static char __pyx_k_29[] = "%s_%s.png";
-static char __pyx_k_30[] = ".";
-static char __pyx_k_33[] = "ndarray is not C contiguous";
-static char __pyx_k_35[] = "ndarray is not Fortran contiguous";
-static char __pyx_k_37[] = "Non-native byte order not supported";
-static char __pyx_k_39[] = "unknown dtype code in numpy.pxd (%d)";
-static char __pyx_k_40[] = "Format string allocated too short, see comment in numpy.pxd";
-static char __pyx_k_43[] = "Format string allocated too short.";
-static char __pyx_k_45[] = "bx.bbi.bigwig_file";
-static char __pyx_k_46[] = "bx.intervals";
-static char __pyx_k_48[] = "matplotlib.pyplot";
-static char __pyx_k_49[] = "*";
-static char __pyx_k_52[] = "/Users/dawe/Developer/gilbert/gilbert/gilbert.pyx";
-static char __pyx_k_53[] = "chromosomeTreeOffset";
-static char __pyx_k_56[] = "getChromosomeSizesFromBigWig";
-static char __pyx_k_61[] = "create_map_from_interval_tree";
+static char __pyx_k_2[] = "k+";
+static char __pyx_k_3[] = "%dM";
+static char __pyx_k_4[] = "Hilbert curve for %s";
+static char __pyx_k_5[] = "%s_%s.png";
+static char __pyx_k_6[] = ".";
+static char __pyx_k_8[] = "create_map_from_array";
+static char __pyx_k_11[] = "ndarray is not C contiguous";
+static char __pyx_k_13[] = "ndarray is not Fortran contiguous";
+static char __pyx_k_15[] = "Non-native byte order not supported";
+static char __pyx_k_17[] = "unknown dtype code in numpy.pxd (%d)";
+static char __pyx_k_18[] = "Format string allocated too short, see comment in numpy.pxd";
+static char __pyx_k_21[] = "Format string allocated too short.";
+static char __pyx_k_23[] = "bx.bbi.bigwig_file";
+static char __pyx_k_24[] = "bx.intervals";
+static char __pyx_k_26[] = "matplotlib.pyplot";
+static char __pyx_k_27[] = "*";
+static char __pyx_k_30[] = "/Users/dawe/Developer/gilbert/gilbert/gilbert.pyx";
+static char __pyx_k_37[] = "create_map_from_bigwig";
+static char __pyx_k_40[] = "create_map_from_interval_tree";
 static char __pyx_k__B[] = "B";
 static char __pyx_k__H[] = "H";
 static char __pyx_k__I[] = "I";
 static char __pyx_k__hc[] = "hc";
 static char __pyx_k__np[] = "np";
 static char __pyx_k__os[] = "os";
-static char __pyx_k__rb[] = "rb";
 static char __pyx_k__Agg[] = "Agg";
-static char __pyx_k__BBH[] = "BBH";
 static char __pyx_k__dpi[] = "dpi";
-static char __pyx_k__key[] = "key";
 static char __pyx_k__max[] = "max";
 static char __pyx_k__msg[] = "msg";
 static char __pyx_k__plt[] = "plt";
 static char __pyx_k__pos[] = "pos";
-static char __pyx_k__sII[] = "sII";
 static char __pyx_k__sum[] = "sum";
 static char __pyx_k__sys[] = "sys";
 static char __pyx_k__use[] = "use";
 static char __pyx_k__Reds[] = "Reds";
 static char __pyx_k__cmap[] = "cmap";
+static char __pyx_k__data[] = "data";
 static char __pyx_k__exit[] = "exit";
 static char __pyx_k__find[] = "find";
 static char __pyx_k__mean[] = "mean";
 static char __pyx_k__name[] = "name";
-static char __pyx_k__open[] = "open";
-static char __pyx_k__path[] = "path";
 static char __pyx_k__plot[] = "plot";
-static char __pyx_k__read[] = "read";
-static char __pyx_k__seek[] = "seek";
 static char __pyx_k__text[] = "text";
 static char __pyx_k__xlim[] = "xlim";
 static char __pyx_k__ylim[] = "ylim";
-static char __pyx_k__IIIQQ[] = "IIIQQ";
 static char __pyx_k__close[] = "close";
-static char __pyx_k__count[] = "count";
-static char __pyx_k__csize[] = "csize";
+static char __pyx_k__isnan[] = "isnan";
 static char __pyx_k__level[] = "level";
-static char __pyx_k__magic[] = "magic";
 static char __pyx_k__numpy[] = "numpy";
 static char __pyx_k__pysam[] = "pysam";
 static char __pyx_k__range[] = "range";
 static char __pyx_k__title[] = "title";
-static char __pyx_k__value[] = "value";
 static char __pyx_k__write[] = "write";
 static char __pyx_k__zeros[] = "zeros";
-static char __pyx_k__bwname[] = "bwname";
 static char __pyx_k__counts[] = "counts";
 static char __pyx_k__hc_map[] = "hc_map";
-static char __pyx_k__isLeaf[] = "isLeaf";
 static char __pyx_k__origin[] = "origin";
 static char __pyx_k__pileup[] = "pileup";
 static char __pyx_k__stderr[] = "stderr";
 static char __pyx_k__struct[] = "struct";
-static char __pyx_k__unpack[] = "unpack";
 static char __pyx_k__xticks[] = "xticks";
 static char __pyx_k__yticks[] = "yticks";
-static char __pyx_k__IOError[] = "IOError";
-static char __pyx_k__chromId[] = "chromId";
+static char __pyx_k__g_value[] = "g_value";
 static char __pyx_k__gilbert[] = "gilbert";
-static char __pyx_k__keySize[] = "keySize";
 static char __pyx_k__matshow[] = "matshow";
-static char __pyx_k__replace[] = "replace";
 static char __pyx_k__savefig[] = "savefig";
-static char __pyx_k__valSize[] = "valSize";
-static char __pyx_k__version[] = "version";
 static char __pyx_k____main__[] = "__main__";
 static char __pyx_k____test__[] = "__test__";
 static char __pyx_k__colorbar[] = "colorbar";
 static char __pyx_k__colormap[] = "colormap";
 static char __pyx_k__dump_png[] = "dump_png";
 static char __pyx_k__position[] = "position";
-static char __pyx_k__reserved[] = "reserved";
-static char __pyx_k__blockSize[] = "blockSize";
-static char __pyx_k__chromSize[] = "chromSize";
-static char __pyx_k__itemCount[] = "itemCount";
 static char __pyx_k__summarize[] = "summarize";
 static char __pyx_k__terminate[] = "terminate";
 static char __pyx_k__ValueError[] = "ValueError";
+static char __pyx_k__bw_handler[] = "bw_handler";
 static char __pyx_k__chromosome[] = "chromosome";
-static char __pyx_k__endianness[] = "endianness";
-static char __pyx_k__expanduser[] = "expanduser";
-static char __pyx_k__fieldCount[] = "fieldCount";
+static char __pyx_k__data_array[] = "data_array";
 static char __pyx_k__matplotlib[] = "matplotlib";
 static char __pyx_k__resolution[] = "resolution";
-static char __pyx_k__zoomLevels[] = "zoomLevels";
-static char __pyx_k__HHQQQHHQQIQ[] = "HHQQQHHQQIQ";
 static char __pyx_k__exit_status[] = "exit_status";
 static char __pyx_k__RuntimeError[] = "RuntimeError";
-static char __pyx_k__autoSqlOffset[] = "autoSqlOffset";
+static char __pyx_k__get_as_array[] = "get_as_array";
 static char __pyx_k__interval_tree[] = "interval_tree";
-static char __pyx_k__fullDataOffset[] = "fullDataOffset";
 static char __pyx_k__chromosome_size[] = "chromosome_size";
-static char __pyx_k__fullIndexOffset[] = "fullIndexOffset";
-static char __pyx_k__definedFieldCount[] = "definedFieldCount";
-static char __pyx_k__uncompressBufSize[] = "uncompressBufSize";
-static char __pyx_k__totalSummaryOffset[] = "totalSummaryOffset";
 static char __pyx_k__create_map_from_bam[] = "create_map_from_bam";
 static PyObject *__pyx_kp_s_1;
-static PyObject *__pyx_kp_s_12;
-static PyObject *__pyx_kp_s_16;
-static PyObject *__pyx_kp_s_18;
-static PyObject *__pyx_kp_s_19;
-static PyObject *__pyx_kp_s_23;
-static PyObject *__pyx_kp_s_24;
-static PyObject *__pyx_kp_s_26;
-static PyObject *__pyx_kp_s_27;
-static PyObject *__pyx_kp_s_28;
-static PyObject *__pyx_kp_s_29;
+static PyObject *__pyx_kp_u_11;
+static PyObject *__pyx_kp_u_13;
+static PyObject *__pyx_kp_u_15;
+static PyObject *__pyx_kp_u_17;
+static PyObject *__pyx_kp_u_18;
+static PyObject *__pyx_kp_s_2;
+static PyObject *__pyx_kp_u_21;
+static PyObject *__pyx_n_s_23;
+static PyObject *__pyx_n_s_24;
+static PyObject *__pyx_n_s_26;
+static PyObject *__pyx_n_s_27;
+static PyObject *__pyx_kp_s_3;
 static PyObject *__pyx_kp_s_30;
-static PyObject *__pyx_kp_u_33;
-static PyObject *__pyx_kp_u_35;
-static PyObject *__pyx_kp_u_37;
-static PyObject *__pyx_kp_u_39;
+static PyObject *__pyx_n_s_37;
 static PyObject *__pyx_kp_s_4;
-static PyObject *__pyx_kp_u_40;
-static PyObject *__pyx_kp_u_43;
-static PyObject *__pyx_n_s_45;
-static PyObject *__pyx_n_s_46;
-static PyObject *__pyx_n_s_48;
-static PyObject *__pyx_n_s_49;
+static PyObject *__pyx_n_s_40;
 static PyObject *__pyx_kp_s_5;
-static PyObject *__pyx_kp_s_52;
-static PyObject *__pyx_n_s_53;
-static PyObject *__pyx_n_s_56;
-static PyObject *__pyx_n_s_61;
-static PyObject *__pyx_kp_s_7;
-static PyObject *__pyx_kp_s_8;
-static PyObject *__pyx_kp_s_9;
+static PyObject *__pyx_kp_s_6;
+static PyObject *__pyx_n_s_8;
 static PyObject *__pyx_n_s__Agg;
-static PyObject *__pyx_n_s__BBH;
-static PyObject *__pyx_n_s__HHQQQHHQQIQ;
-static PyObject *__pyx_n_s__IIIQQ;
-static PyObject *__pyx_n_s__IOError;
 static PyObject *__pyx_n_s__Reds;
 static PyObject *__pyx_n_s__RuntimeError;
 static PyObject *__pyx_n_s__ValueError;
 static PyObject *__pyx_n_s____main__;
 static PyObject *__pyx_n_s____test__;
-static PyObject *__pyx_n_s__autoSqlOffset;
-static PyObject *__pyx_n_s__blockSize;
-static PyObject *__pyx_n_s__bwname;
+static PyObject *__pyx_n_s__bw_handler;
 static PyObject *__pyx_n_s__bx;
-static PyObject *__pyx_n_s__chromId;
-static PyObject *__pyx_n_s__chromSize;
 static PyObject *__pyx_n_s__chromosome;
 static PyObject *__pyx_n_s__chromosome_size;
 static PyObject *__pyx_n_s__close;
 static PyObject *__pyx_n_s__cmap;
 static PyObject *__pyx_n_s__colorbar;
 static PyObject *__pyx_n_s__colormap;
-static PyObject *__pyx_n_s__count;
 static PyObject *__pyx_n_s__counts;
 static PyObject *__pyx_n_s__create_map_from_bam;
-static PyObject *__pyx_n_s__csize;
-static PyObject *__pyx_n_s__definedFieldCount;
+static PyObject *__pyx_n_s__data;
+static PyObject *__pyx_n_s__data_array;
 static PyObject *__pyx_n_s__dpi;
 static PyObject *__pyx_n_s__dump_png;
-static PyObject *__pyx_n_s__endianness;
 static PyObject *__pyx_n_s__exit;
 static PyObject *__pyx_n_s__exit_status;
-static PyObject *__pyx_n_s__expanduser;
 static PyObject *__pyx_n_s__fh;
-static PyObject *__pyx_n_s__fieldCount;
 static PyObject *__pyx_n_s__find;
-static PyObject *__pyx_n_s__fullDataOffset;
-static PyObject *__pyx_n_s__fullIndexOffset;
+static PyObject *__pyx_n_s__g_value;
+static PyObject *__pyx_n_s__get_as_array;
 static PyObject *__pyx_n_s__gilbert;
 static PyObject *__pyx_n_s__hc;
 static PyObject *__pyx_n_s__hc_map;
 static PyObject *__pyx_n_s__i;
 static PyObject *__pyx_n_s__interval_tree;
-static PyObject *__pyx_n_s__isLeaf;
-static PyObject *__pyx_n_s__itemCount;
-static PyObject *__pyx_n_s__key;
-static PyObject *__pyx_n_s__keySize;
+static PyObject *__pyx_n_s__isnan;
 static PyObject *__pyx_n_s__level;
-static PyObject *__pyx_n_s__magic;
 static PyObject *__pyx_n_s__matplotlib;
 static PyObject *__pyx_n_s__matshow;
 static PyObject *__pyx_n_s__max;
 static PyObject *__pyx_n_s__name;
 static PyObject *__pyx_n_s__np;
 static PyObject *__pyx_n_s__numpy;
-static PyObject *__pyx_n_s__open;
 static PyObject *__pyx_n_s__origin;
 static PyObject *__pyx_n_s__os;
-static PyObject *__pyx_n_s__path;
 static PyObject *__pyx_n_s__pileup;
 static PyObject *__pyx_n_s__plot;
 static PyObject *__pyx_n_s__plt;
 static PyObject *__pyx_n_s__position;
 static PyObject *__pyx_n_s__pysam;
 static PyObject *__pyx_n_s__range;
-static PyObject *__pyx_n_s__rb;
-static PyObject *__pyx_n_s__read;
-static PyObject *__pyx_n_s__replace;
-static PyObject *__pyx_n_s__reserved;
 static PyObject *__pyx_n_s__resolution;
-static PyObject *__pyx_n_s__sII;
 static PyObject *__pyx_n_s__savefig;
-static PyObject *__pyx_n_s__seek;
 static PyObject *__pyx_n_s__stderr;
 static PyObject *__pyx_n_s__struct;
 static PyObject *__pyx_n_s__sum;
 static PyObject *__pyx_n_s__terminate;
 static PyObject *__pyx_n_s__text;
 static PyObject *__pyx_n_s__title;
-static PyObject *__pyx_n_s__totalSummaryOffset;
-static PyObject *__pyx_n_s__uncompressBufSize;
-static PyObject *__pyx_n_s__unpack;
 static PyObject *__pyx_n_s__use;
-static PyObject *__pyx_n_s__valSize;
-static PyObject *__pyx_n_s__value;
-static PyObject *__pyx_n_s__version;
 static PyObject *__pyx_n_s__write;
 static PyObject *__pyx_n_s__x;
 static PyObject *__pyx_n_s__xlim;
 static PyObject *__pyx_n_s__ylim;
 static PyObject *__pyx_n_s__yticks;
 static PyObject *__pyx_n_s__zeros;
-static PyObject *__pyx_n_s__zoomLevels;
 static PyObject *__pyx_int_0;
 static PyObject *__pyx_int_1;
 static PyObject *__pyx_int_2;
-static PyObject *__pyx_int_3;
-static PyObject *__pyx_int_4;
-static PyObject *__pyx_int_8;
 static PyObject *__pyx_int_15;
-static PyObject *__pyx_int_28;
-static PyObject *__pyx_int_60;
 static PyObject *__pyx_int_1000000;
 static PyObject *__pyx_int_4000000;
-static PyObject *__pyx_k_tuple_2;
+static PyObject *__pyx_k_tuple_7;
+static PyObject *__pyx_k_tuple_9;
 static PyObject *__pyx_k_tuple_10;
-static PyObject *__pyx_k_tuple_11;
-static PyObject *__pyx_k_tuple_13;
+static PyObject *__pyx_k_tuple_12;
 static PyObject *__pyx_k_tuple_14;
+static PyObject *__pyx_k_tuple_16;
+static PyObject *__pyx_k_tuple_19;
 static PyObject *__pyx_k_tuple_20;
-static PyObject *__pyx_k_tuple_21;
 static PyObject *__pyx_k_tuple_22;
 static PyObject *__pyx_k_tuple_25;
+static PyObject *__pyx_k_tuple_28;
 static PyObject *__pyx_k_tuple_31;
-static PyObject *__pyx_k_tuple_32;
-static PyObject *__pyx_k_tuple_34;
-static PyObject *__pyx_k_tuple_36;
+static PyObject *__pyx_k_tuple_33;
+static PyObject *__pyx_k_tuple_35;
 static PyObject *__pyx_k_tuple_38;
 static PyObject *__pyx_k_tuple_41;
-static PyObject *__pyx_k_tuple_42;
-static PyObject *__pyx_k_tuple_44;
-static PyObject *__pyx_k_tuple_47;
-static PyObject *__pyx_k_tuple_50;
-static PyObject *__pyx_k_tuple_54;
-static PyObject *__pyx_k_tuple_57;
-static PyObject *__pyx_k_tuple_59;
-static PyObject *__pyx_k_tuple_62;
-static PyObject *__pyx_k_codeobj_51;
-static PyObject *__pyx_k_codeobj_55;
-static PyObject *__pyx_k_codeobj_58;
-static PyObject *__pyx_k_codeobj_60;
-static PyObject *__pyx_k_codeobj_63;
+static PyObject *__pyx_k_codeobj_29;
+static PyObject *__pyx_k_codeobj_32;
+static PyObject *__pyx_k_codeobj_34;
+static PyObject *__pyx_k_codeobj_36;
+static PyObject *__pyx_k_codeobj_39;
+static PyObject *__pyx_k_codeobj_42;
 
 /* Python wrapper */
 static PyObject *__pyx_pw_7gilbert_1terminate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
  *   sys.stderr.write("%s\n" % msg)
  *   sys.exit(exit_status)             # <<<<<<<<<<<<<<
  * 
- * def getChromosomeSizesFromBigWig(bwname):
+ * 
  */
   __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   return __pyx_r;
 }
 
-/* Python wrapper */
-static PyObject *__pyx_pw_7gilbert_3getChromosomeSizesFromBigWig(PyObject *__pyx_self, PyObject *__pyx_v_bwname); /*proto*/
-static PyMethodDef __pyx_mdef_7gilbert_3getChromosomeSizesFromBigWig = {__Pyx_NAMESTR("getChromosomeSizesFromBigWig"), (PyCFunction)__pyx_pw_7gilbert_3getChromosomeSizesFromBigWig, METH_O, __Pyx_DOCSTR(0)};
-static PyObject *__pyx_pw_7gilbert_3getChromosomeSizesFromBigWig(PyObject *__pyx_self, PyObject *__pyx_v_bwname) {
-  PyObject *__pyx_r = 0;
-  __Pyx_RefNannyDeclarations
-  __Pyx_RefNannySetupContext("getChromosomeSizesFromBigWig (wrapper)", 0);
-  __pyx_r = __pyx_pf_7gilbert_2getChromosomeSizesFromBigWig(__pyx_self, ((PyObject *)__pyx_v_bwname));
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* "gilbert.pyx":20
- *   sys.exit(exit_status)
- * 
- * def getChromosomeSizesFromBigWig(bwname):             # <<<<<<<<<<<<<<
- *   csize = {}
- *   fh = open(os.path.expanduser(bwname), "rb")
- */
-
-static PyObject *__pyx_pf_7gilbert_2getChromosomeSizesFromBigWig(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_bwname) {
-  PyObject *__pyx_v_csize = NULL;
-  PyObject *__pyx_v_fh = NULL;
-  PyObject *__pyx_v_magic = NULL;
-  PyObject *__pyx_v_endianness = NULL;
-  PyObject *__pyx_v_version = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_zoomLevels = NULL;
-  PyObject *__pyx_v_chromosomeTreeOffset = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_fullDataOffset = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_fullIndexOffset = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_fieldCount = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_definedFieldCount = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_autoSqlOffset = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_totalSummaryOffset = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_uncompressBufSize = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_reserved = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_blockSize = NULL;
-  PyObject *__pyx_v_keySize = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_valSize = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_itemCount = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_isLeaf = NULL;
-  PyObject *__pyx_v_count = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_n = NULL;
-  PyObject *__pyx_v_key = NULL;
-  CYTHON_UNUSED PyObject *__pyx_v_chromId = NULL;
-  PyObject *__pyx_v_chromSize = NULL;
-  PyObject *__pyx_r = NULL;
-  __Pyx_RefNannyDeclarations
-  PyObject *__pyx_t_1 = NULL;
-  PyObject *__pyx_t_2 = NULL;
-  PyObject *__pyx_t_3 = NULL;
-  int __pyx_t_4;
-  PyObject *__pyx_t_5 = NULL;
-  PyObject *__pyx_t_6 = NULL;
-  PyObject *__pyx_t_7 = NULL;
-  PyObject *__pyx_t_8 = NULL;
-  PyObject *__pyx_t_9 = NULL;
-  PyObject *__pyx_t_10 = NULL;
-  PyObject *__pyx_t_11 = NULL;
-  PyObject *__pyx_t_12 = NULL;
-  PyObject *__pyx_t_13 = NULL;
-  PyObject *__pyx_t_14 = NULL;
-  PyObject *(*__pyx_t_15)(PyObject *);
-  Py_ssize_t __pyx_t_16;
-  PyObject *(*__pyx_t_17)(PyObject *);
-  int __pyx_lineno = 0;
-  const char *__pyx_filename = NULL;
-  int __pyx_clineno = 0;
-  __Pyx_RefNannySetupContext("getChromosomeSizesFromBigWig", 0);
-
-  /* "gilbert.pyx":21
- * 
- * def getChromosomeSizesFromBigWig(bwname):
- *   csize = {}             # <<<<<<<<<<<<<<
- *   fh = open(os.path.expanduser(bwname), "rb")
- *   magic = fh.read(4)
- */
-  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-  __pyx_v_csize = __pyx_t_1;
-  __pyx_t_1 = 0;
-
-  /* "gilbert.pyx":22
- * def getChromosomeSizesFromBigWig(bwname):
- *   csize = {}
- *   fh = open(os.path.expanduser(bwname), "rb")             # <<<<<<<<<<<<<<
- *   magic = fh.read(4)
- *   if magic == '&\xfc\x8f\x88':
- */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_2);
-  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__expanduser); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_1);
-  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_2);
-  __Pyx_INCREF(__pyx_v_bwname);
-  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_bwname);
-  __Pyx_GIVEREF(__pyx_v_bwname);
-  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_3);
-  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
-  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_2);
-  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
-  __Pyx_GIVEREF(__pyx_t_3);
-  __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
-  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__rb));
-  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rb));
-  __pyx_t_3 = 0;
-  __pyx_t_3 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_3);
-  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
-  __pyx_v_fh = __pyx_t_3;
-  __pyx_t_3 = 0;
-
-  /* "gilbert.pyx":23
- *   csize = {}
- *   fh = open(os.path.expanduser(bwname), "rb")
- *   magic = fh.read(4)             # <<<<<<<<<<<<<<
- *   if magic == '&\xfc\x8f\x88':
- *     endianness = '<'
- */
-  __pyx_t_3 = PyObject_GetAttr(__pyx_v_fh, __pyx_n_s__read); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_2);
-  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-  __pyx_v_magic = __pyx_t_2;
-  __pyx_t_2 = 0;
-
-  /* "gilbert.pyx":24
- *   fh = open(os.path.expanduser(bwname), "rb")
- *   magic = fh.read(4)
- *   if magic == '&\xfc\x8f\x88':             # <<<<<<<<<<<<<<
- *     endianness = '<'
- *   elif magic == '\x88\x8f\xfc&':
- */
-  __pyx_t_2 = PyObject_RichCompare(__pyx_v_magic, ((PyObject *)__pyx_kp_s_4), Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  if (__pyx_t_4) {
-
-    /* "gilbert.pyx":25
- *   magic = fh.read(4)
- *   if magic == '&\xfc\x8f\x88':
- *     endianness = '<'             # <<<<<<<<<<<<<<
- *   elif magic == '\x88\x8f\xfc&':
- *     endianness = '>'
- */
-    __Pyx_INCREF(((PyObject *)__pyx_kp_s_5));
-    __pyx_v_endianness = ((PyObject *)__pyx_kp_s_5);
-    goto __pyx_L3;
-  }
-
-  /* "gilbert.pyx":26
- *   if magic == '&\xfc\x8f\x88':
- *     endianness = '<'
- *   elif magic == '\x88\x8f\xfc&':             # <<<<<<<<<<<<<<
- *     endianness = '>'
- *   else:
- */
-  __pyx_t_2 = PyObject_RichCompare(__pyx_v_magic, ((PyObject *)__pyx_kp_s_7), Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  if (__pyx_t_4) {
-
-    /* "gilbert.pyx":27
- *     endianness = '<'
- *   elif magic == '\x88\x8f\xfc&':
- *     endianness = '>'             # <<<<<<<<<<<<<<
- *   else:
- *     raise IOError("The file is not in bigwig format")
- */
-    __Pyx_INCREF(((PyObject *)__pyx_kp_s_8));
-    __pyx_v_endianness = ((PyObject *)__pyx_kp_s_8);
-    goto __pyx_L3;
-  }
-  /*else*/ {
-
-    /* "gilbert.pyx":29
- *     endianness = '>'
- *   else:
- *     raise IOError("The file is not in bigwig format")             # <<<<<<<<<<<<<<
- *   (version,zoomLevels,chromosomeTreeOffset,fullDataOffset,fullIndexOffset,fieldCount,definedFieldCount,autoSqlOffset,totalSummaryOffset,uncompressBufSize,reserved)=struct.unpack(endianness+'HHQQQHHQQIQ',fh.read(60))
- *   if version < 3:
- */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_2);
-    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
-    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  }
-  __pyx_L3:;
-
-  /* "gilbert.pyx":30
- *   else:
- *     raise IOError("The file is not in bigwig format")
- *   (version,zoomLevels,chromosomeTreeOffset,fullDataOffset,fullIndexOffset,fieldCount,definedFieldCount,autoSqlOffset,totalSummaryOffset,uncompressBufSize,reserved)=struct.unpack(endianness+'HHQQQHHQQIQ',fh.read(60))             # <<<<<<<<<<<<<<
- *   if version < 3:
- *     raise IOError("Bigwig files version <3 are not supported")
- */
-  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__unpack); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __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(__pyx_v_endianness, ((PyObject *)__pyx_n_s__HHQQQHHQQIQ)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyObject_GetAttr(__pyx_v_fh, __pyx_n_s__read); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_11), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_5);
-  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_1);
-  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
-  __Pyx_GIVEREF(__pyx_t_2);
-  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
-  __Pyx_GIVEREF(__pyx_t_5);
-  __pyx_t_2 = 0;
-  __pyx_t_5 = 0;
-  __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_5);
-  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
-  if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
-    PyObject* sequence = __pyx_t_5;
-    #if CYTHON_COMPILING_IN_CPYTHON
-    Py_ssize_t size = Py_SIZE(sequence);
-    #else
-    Py_ssize_t size = PySequence_Size(sequence);
-    #endif
-    if (unlikely(size != 11)) {
-      if (size > 11) __Pyx_RaiseTooManyValuesError(11);
-      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    }
-    #if CYTHON_COMPILING_IN_CPYTHON
-    if (likely(PyTuple_CheckExact(sequence))) {
-      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
-      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
-      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 2); 
-      __pyx_t_6 = PyTuple_GET_ITEM(sequence, 3); 
-      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 4); 
-      __pyx_t_8 = PyTuple_GET_ITEM(sequence, 5); 
-      __pyx_t_9 = PyTuple_GET_ITEM(sequence, 6); 
-      __pyx_t_10 = PyTuple_GET_ITEM(sequence, 7); 
-      __pyx_t_11 = PyTuple_GET_ITEM(sequence, 8); 
-      __pyx_t_12 = PyTuple_GET_ITEM(sequence, 9); 
-      __pyx_t_13 = PyTuple_GET_ITEM(sequence, 10); 
-    } else {
-      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
-      __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
-      __pyx_t_2 = PyList_GET_ITEM(sequence, 2); 
-      __pyx_t_6 = PyList_GET_ITEM(sequence, 3); 
-      __pyx_t_7 = PyList_GET_ITEM(sequence, 4); 
-      __pyx_t_8 = PyList_GET_ITEM(sequence, 5); 
-      __pyx_t_9 = PyList_GET_ITEM(sequence, 6); 
-      __pyx_t_10 = PyList_GET_ITEM(sequence, 7); 
-      __pyx_t_11 = PyList_GET_ITEM(sequence, 8); 
-      __pyx_t_12 = PyList_GET_ITEM(sequence, 9); 
-      __pyx_t_13 = PyList_GET_ITEM(sequence, 10); 
-    }
-    __Pyx_INCREF(__pyx_t_1);
-    __Pyx_INCREF(__pyx_t_3);
-    __Pyx_INCREF(__pyx_t_2);
-    __Pyx_INCREF(__pyx_t_6);
-    __Pyx_INCREF(__pyx_t_7);
-    __Pyx_INCREF(__pyx_t_8);
-    __Pyx_INCREF(__pyx_t_9);
-    __Pyx_INCREF(__pyx_t_10);
-    __Pyx_INCREF(__pyx_t_11);
-    __Pyx_INCREF(__pyx_t_12);
-    __Pyx_INCREF(__pyx_t_13);
-    #else
-    Py_ssize_t i;
-    PyObject** temps[11] = {&__pyx_t_1,&__pyx_t_3,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7,&__pyx_t_8,&__pyx_t_9,&__pyx_t_10,&__pyx_t_11,&__pyx_t_12,&__pyx_t_13};
-    for (i=0; i < 11; i++) {
-      PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      *(temps[i]) = item;
-    }
-    #endif
-    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-  } else
-  {
-    Py_ssize_t index = -1;
-    PyObject** temps[11] = {&__pyx_t_1,&__pyx_t_3,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7,&__pyx_t_8,&__pyx_t_9,&__pyx_t_10,&__pyx_t_11,&__pyx_t_12,&__pyx_t_13};
-    __pyx_t_14 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_14);
-    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-    __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext;
-    for (index=0; index < 11; index++) {
-      PyObject* item = __pyx_t_15(__pyx_t_14); if (unlikely(!item)) goto __pyx_L4_unpacking_failed;
-      __Pyx_GOTREF(item);
-      *(temps[index]) = item;
-    }
-    if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 11) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_15 = NULL;
-    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
-    goto __pyx_L5_unpacking_done;
-    __pyx_L4_unpacking_failed:;
-    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
-    __pyx_t_15 = NULL;
-    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_L5_unpacking_done:;
-  }
-  __pyx_v_version = __pyx_t_1;
-  __pyx_t_1 = 0;
-  __pyx_v_zoomLevels = __pyx_t_3;
-  __pyx_t_3 = 0;
-  __pyx_v_chromosomeTreeOffset = __pyx_t_2;
-  __pyx_t_2 = 0;
-  __pyx_v_fullDataOffset = __pyx_t_6;
-  __pyx_t_6 = 0;
-  __pyx_v_fullIndexOffset = __pyx_t_7;
-  __pyx_t_7 = 0;
-  __pyx_v_fieldCount = __pyx_t_8;
-  __pyx_t_8 = 0;
-  __pyx_v_definedFieldCount = __pyx_t_9;
-  __pyx_t_9 = 0;
-  __pyx_v_autoSqlOffset = __pyx_t_10;
-  __pyx_t_10 = 0;
-  __pyx_v_totalSummaryOffset = __pyx_t_11;
-  __pyx_t_11 = 0;
-  __pyx_v_uncompressBufSize = __pyx_t_12;
-  __pyx_t_12 = 0;
-  __pyx_v_reserved = __pyx_t_13;
-  __pyx_t_13 = 0;
-
-  /* "gilbert.pyx":31
- *     raise IOError("The file is not in bigwig format")
- *   (version,zoomLevels,chromosomeTreeOffset,fullDataOffset,fullIndexOffset,fieldCount,definedFieldCount,autoSqlOffset,totalSummaryOffset,uncompressBufSize,reserved)=struct.unpack(endianness+'HHQQQHHQQIQ',fh.read(60))
- *   if version < 3:             # <<<<<<<<<<<<<<
- *     raise IOError("Bigwig files version <3 are not supported")
- *   fh.seek(chromosomeTreeOffset)
- */
-  __pyx_t_5 = PyObject_RichCompare(__pyx_v_version, __pyx_int_3, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-  if (__pyx_t_4) {
-
-    /* "gilbert.pyx":32
- *   (version,zoomLevels,chromosomeTreeOffset,fullDataOffset,fullIndexOffset,fieldCount,definedFieldCount,autoSqlOffset,totalSummaryOffset,uncompressBufSize,reserved)=struct.unpack(endianness+'HHQQQHHQQIQ',fh.read(60))
- *   if version < 3:
- *     raise IOError("Bigwig files version <3 are not supported")             # <<<<<<<<<<<<<<
- *   fh.seek(chromosomeTreeOffset)
- *   magic = fh.read(4)
- */
-    __pyx_t_5 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_k_tuple_13), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_5);
-    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
-    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    goto __pyx_L6;
-  }
-  __pyx_L6:;
-
-  /* "gilbert.pyx":33
- *   if version < 3:
- *     raise IOError("Bigwig files version <3 are not supported")
- *   fh.seek(chromosomeTreeOffset)             # <<<<<<<<<<<<<<
- *   magic = fh.read(4)
- *   if magic == '\x91\x8c\xcax':
- */
-  __pyx_t_5 = PyObject_GetAttr(__pyx_v_fh, __pyx_n_s__seek); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_5);
-  __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_13);
-  __Pyx_INCREF(__pyx_v_chromosomeTreeOffset);
-  PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_v_chromosomeTreeOffset);
-  __Pyx_GIVEREF(__pyx_v_chromosomeTreeOffset);
-  __pyx_t_12 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_12);
-  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-  __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0;
-  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
-
-  /* "gilbert.pyx":34
- *     raise IOError("Bigwig files version <3 are not supported")
- *   fh.seek(chromosomeTreeOffset)
- *   magic = fh.read(4)             # <<<<<<<<<<<<<<
- *   if magic == '\x91\x8c\xcax':
- *     endianness = '<'
- */
-  __pyx_t_12 = PyObject_GetAttr(__pyx_v_fh, __pyx_n_s__read); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_12);
-  __pyx_t_13 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_13);
-  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
-  __Pyx_DECREF(__pyx_v_magic);
-  __pyx_v_magic = __pyx_t_13;
-  __pyx_t_13 = 0;
-
-  /* "gilbert.pyx":35
- *   fh.seek(chromosomeTreeOffset)
- *   magic = fh.read(4)
- *   if magic == '\x91\x8c\xcax':             # <<<<<<<<<<<<<<
- *     endianness = '<'
- *   elif magic == 'x\xca\x8c\x91':
- */
-  __pyx_t_13 = PyObject_RichCompare(__pyx_v_magic, ((PyObject *)__pyx_kp_s_16), Py_EQ); __Pyx_XGOTREF(__pyx_t_13); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
-  if (__pyx_t_4) {
-
-    /* "gilbert.pyx":36
- *   magic = fh.read(4)
- *   if magic == '\x91\x8c\xcax':
- *     endianness = '<'             # <<<<<<<<<<<<<<
- *   elif magic == 'x\xca\x8c\x91':
- *     endianness = '>'
- */
-    __Pyx_INCREF(((PyObject *)__pyx_kp_s_5));
-    __Pyx_DECREF(__pyx_v_endianness);
-    __pyx_v_endianness = ((PyObject *)__pyx_kp_s_5);
-    goto __pyx_L7;
-  }
-
-  /* "gilbert.pyx":37
- *   if magic == '\x91\x8c\xcax':
- *     endianness = '<'
- *   elif magic == 'x\xca\x8c\x91':             # <<<<<<<<<<<<<<
- *     endianness = '>'
- *   else:
- */
-  __pyx_t_13 = PyObject_RichCompare(__pyx_v_magic, ((PyObject *)__pyx_kp_s_18), Py_EQ); __Pyx_XGOTREF(__pyx_t_13); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
-  if (__pyx_t_4) {
-
-    /* "gilbert.pyx":38
- *     endianness = '<'
- *   elif magic == 'x\xca\x8c\x91':
- *     endianness = '>'             # <<<<<<<<<<<<<<
- *   else:
- *     raise ValueError("Wrong magic for this bigwig data file")
- */
-    __Pyx_INCREF(((PyObject *)__pyx_kp_s_8));
-    __Pyx_DECREF(__pyx_v_endianness);
-    __pyx_v_endianness = ((PyObject *)__pyx_kp_s_8);
-    goto __pyx_L7;
-  }
-  /*else*/ {
-
-    /* "gilbert.pyx":40
- *     endianness = '>'
- *   else:
- *     raise ValueError("Wrong magic for this bigwig data file")             # <<<<<<<<<<<<<<
- *   (blockSize, keySize, valSize, itemCount, reserved) = struct.unpack(endianness + 'IIIQQ', fh.read(28))
- *   (isLeaf, reserved, count) = struct.unpack(endianness + 'BBH', fh.read(4))
- */
-    __pyx_t_13 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_13);
-    __Pyx_Raise(__pyx_t_13, 0, 0, 0);
-    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  }
-  __pyx_L7:;
-
-  /* "gilbert.pyx":41
- *   else:
- *     raise ValueError("Wrong magic for this bigwig data file")
- *   (blockSize, keySize, valSize, itemCount, reserved) = struct.unpack(endianness + 'IIIQQ', fh.read(28))             # <<<<<<<<<<<<<<
- *   (isLeaf, reserved, count) = struct.unpack(endianness + 'BBH', fh.read(4))
- *   for n in range(count):
- */
-  __pyx_t_13 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_13);
-  __pyx_t_12 = PyObject_GetAttr(__pyx_t_13, __pyx_n_s__unpack); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_12);
-  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
-  __pyx_t_13 = PyNumber_Add(__pyx_v_endianness, ((PyObject *)__pyx_n_s__IIIQQ)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_13);
-  __pyx_t_5 = PyObject_GetAttr(__pyx_v_fh, __pyx_n_s__read); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_5);
-  __pyx_t_11 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_11);
-  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_5);
-  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_13);
-  __Pyx_GIVEREF(__pyx_t_13);
-  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_11);
-  __Pyx_GIVEREF(__pyx_t_11);
-  __pyx_t_13 = 0;
-  __pyx_t_11 = 0;
-  __pyx_t_11 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_11);
-  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
-  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
-  if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) {
-    PyObject* sequence = __pyx_t_11;
-    #if CYTHON_COMPILING_IN_CPYTHON
-    Py_ssize_t size = Py_SIZE(sequence);
-    #else
-    Py_ssize_t size = PySequence_Size(sequence);
-    #endif
-    if (unlikely(size != 5)) {
-      if (size > 5) __Pyx_RaiseTooManyValuesError(5);
-      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    }
-    #if CYTHON_COMPILING_IN_CPYTHON
-    if (likely(PyTuple_CheckExact(sequence))) {
-      __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
-      __pyx_t_12 = PyTuple_GET_ITEM(sequence, 1); 
-      __pyx_t_13 = PyTuple_GET_ITEM(sequence, 2); 
-      __pyx_t_10 = PyTuple_GET_ITEM(sequence, 3); 
-      __pyx_t_9 = PyTuple_GET_ITEM(sequence, 4); 
-    } else {
-      __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
-      __pyx_t_12 = PyList_GET_ITEM(sequence, 1); 
-      __pyx_t_13 = PyList_GET_ITEM(sequence, 2); 
-      __pyx_t_10 = PyList_GET_ITEM(sequence, 3); 
-      __pyx_t_9 = PyList_GET_ITEM(sequence, 4); 
-    }
-    __Pyx_INCREF(__pyx_t_5);
-    __Pyx_INCREF(__pyx_t_12);
-    __Pyx_INCREF(__pyx_t_13);
-    __Pyx_INCREF(__pyx_t_10);
-    __Pyx_INCREF(__pyx_t_9);
-    #else
-    Py_ssize_t i;
-    PyObject** temps[5] = {&__pyx_t_5,&__pyx_t_12,&__pyx_t_13,&__pyx_t_10,&__pyx_t_9};
-    for (i=0; i < 5; i++) {
-      PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      *(temps[i]) = item;
-    }
-    #endif
-    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
-  } else
-  {
-    Py_ssize_t index = -1;
-    PyObject** temps[5] = {&__pyx_t_5,&__pyx_t_12,&__pyx_t_13,&__pyx_t_10,&__pyx_t_9};
-    __pyx_t_8 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_8);
-    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
-    __pyx_t_15 = Py_TYPE(__pyx_t_8)->tp_iternext;
-    for (index=0; index < 5; index++) {
-      PyObject* item = __pyx_t_15(__pyx_t_8); if (unlikely(!item)) goto __pyx_L8_unpacking_failed;
-      __Pyx_GOTREF(item);
-      *(temps[index]) = item;
-    }
-    if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_8), 5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_15 = NULL;
-    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-    goto __pyx_L9_unpacking_done;
-    __pyx_L8_unpacking_failed:;
-    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-    __pyx_t_15 = NULL;
-    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_L9_unpacking_done:;
-  }
-  __pyx_v_blockSize = __pyx_t_5;
-  __pyx_t_5 = 0;
-  __pyx_v_keySize = __pyx_t_12;
-  __pyx_t_12 = 0;
-  __pyx_v_valSize = __pyx_t_13;
-  __pyx_t_13 = 0;
-  __pyx_v_itemCount = __pyx_t_10;
-  __pyx_t_10 = 0;
-  __Pyx_DECREF(__pyx_v_reserved);
-  __pyx_v_reserved = __pyx_t_9;
-  __pyx_t_9 = 0;
-
-  /* "gilbert.pyx":42
- *     raise ValueError("Wrong magic for this bigwig data file")
- *   (blockSize, keySize, valSize, itemCount, reserved) = struct.unpack(endianness + 'IIIQQ', fh.read(28))
- *   (isLeaf, reserved, count) = struct.unpack(endianness + 'BBH', fh.read(4))             # <<<<<<<<<<<<<<
- *   for n in range(count):
- *     (key, chromId, chromSize) = struct.unpack(endianness + str(keySize) + 'sII', fh.read(keySize + 2 * 4))
- */
-  __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_11);
-  __pyx_t_9 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__unpack); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_9);
-  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
-  __pyx_t_11 = PyNumber_Add(__pyx_v_endianness, ((PyObject *)__pyx_n_s__BBH)); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_11);
-  __pyx_t_10 = PyObject_GetAttr(__pyx_v_fh, __pyx_n_s__read); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_10);
-  __pyx_t_13 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_13);
-  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
-  __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_10);
-  PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_11);
-  __Pyx_GIVEREF(__pyx_t_11);
-  PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_13);
-  __Pyx_GIVEREF(__pyx_t_13);
-  __pyx_t_11 = 0;
-  __pyx_t_13 = 0;
-  __pyx_t_13 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_13);
-  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-  __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
-  if ((likely(PyTuple_CheckExact(__pyx_t_13))) || (PyList_CheckExact(__pyx_t_13))) {
-    PyObject* sequence = __pyx_t_13;
-    #if CYTHON_COMPILING_IN_CPYTHON
-    Py_ssize_t size = Py_SIZE(sequence);
-    #else
-    Py_ssize_t size = PySequence_Size(sequence);
-    #endif
-    if (unlikely(size != 3)) {
-      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
-      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    }
-    #if CYTHON_COMPILING_IN_CPYTHON
-    if (likely(PyTuple_CheckExact(sequence))) {
-      __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); 
-      __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
-      __pyx_t_11 = PyTuple_GET_ITEM(sequence, 2); 
-    } else {
-      __pyx_t_10 = PyList_GET_ITEM(sequence, 0); 
-      __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
-      __pyx_t_11 = PyList_GET_ITEM(sequence, 2); 
-    }
-    __Pyx_INCREF(__pyx_t_10);
-    __Pyx_INCREF(__pyx_t_9);
-    __Pyx_INCREF(__pyx_t_11);
-    #else
-    __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_11 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    #endif
-    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
-  } else
-  {
-    Py_ssize_t index = -1;
-    __pyx_t_12 = PyObject_GetIter(__pyx_t_13); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_12);
-    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
-    __pyx_t_15 = Py_TYPE(__pyx_t_12)->tp_iternext;
-    index = 0; __pyx_t_10 = __pyx_t_15(__pyx_t_12); if (unlikely(!__pyx_t_10)) goto __pyx_L10_unpacking_failed;
-    __Pyx_GOTREF(__pyx_t_10);
-    index = 1; __pyx_t_9 = __pyx_t_15(__pyx_t_12); if (unlikely(!__pyx_t_9)) goto __pyx_L10_unpacking_failed;
-    __Pyx_GOTREF(__pyx_t_9);
-    index = 2; __pyx_t_11 = __pyx_t_15(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L10_unpacking_failed;
-    __Pyx_GOTREF(__pyx_t_11);
-    if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_12), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_15 = NULL;
-    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
-    goto __pyx_L11_unpacking_done;
-    __pyx_L10_unpacking_failed:;
-    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
-    __pyx_t_15 = NULL;
-    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_L11_unpacking_done:;
-  }
-  __pyx_v_isLeaf = __pyx_t_10;
-  __pyx_t_10 = 0;
-  __Pyx_DECREF(__pyx_v_reserved);
-  __pyx_v_reserved = __pyx_t_9;
-  __pyx_t_9 = 0;
-  __pyx_v_count = __pyx_t_11;
-  __pyx_t_11 = 0;
-
-  /* "gilbert.pyx":43
- *   (blockSize, keySize, valSize, itemCount, reserved) = struct.unpack(endianness + 'IIIQQ', fh.read(28))
- *   (isLeaf, reserved, count) = struct.unpack(endianness + 'BBH', fh.read(4))
- *   for n in range(count):             # <<<<<<<<<<<<<<
- *     (key, chromId, chromSize) = struct.unpack(endianness + str(keySize) + 'sII', fh.read(keySize + 2 * 4))
- *     csize[key.replace('\x00', '')] = chromSize
- */
-  __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_13);
-  __Pyx_INCREF(__pyx_v_count);
-  PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_v_count);
-  __Pyx_GIVEREF(__pyx_v_count);
-  __pyx_t_11 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_11);
-  __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0;
-  if (PyList_CheckExact(__pyx_t_11) || PyTuple_CheckExact(__pyx_t_11)) {
-    __pyx_t_13 = __pyx_t_11; __Pyx_INCREF(__pyx_t_13); __pyx_t_16 = 0;
-    __pyx_t_17 = NULL;
-  } else {
-    __pyx_t_16 = -1; __pyx_t_13 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_13);
-    __pyx_t_17 = Py_TYPE(__pyx_t_13)->tp_iternext;
-  }
-  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
-  for (;;) {
-    if (!__pyx_t_17 && PyList_CheckExact(__pyx_t_13)) {
-      if (__pyx_t_16 >= PyList_GET_SIZE(__pyx_t_13)) break;
-      #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_11 = PyList_GET_ITEM(__pyx_t_13, __pyx_t_16); __Pyx_INCREF(__pyx_t_11); __pyx_t_16++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      #else
-      __pyx_t_11 = PySequence_ITEM(__pyx_t_13, __pyx_t_16); __pyx_t_16++; if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      #endif
-    } else if (!__pyx_t_17 && PyTuple_CheckExact(__pyx_t_13)) {
-      if (__pyx_t_16 >= PyTuple_GET_SIZE(__pyx_t_13)) break;
-      #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_13, __pyx_t_16); __Pyx_INCREF(__pyx_t_11); __pyx_t_16++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      #else
-      __pyx_t_11 = PySequence_ITEM(__pyx_t_13, __pyx_t_16); __pyx_t_16++; if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      #endif
-    } else {
-      __pyx_t_11 = __pyx_t_17(__pyx_t_13);
-      if (unlikely(!__pyx_t_11)) {
-        if (PyErr_Occurred()) {
-          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        }
-        break;
-      }
-      __Pyx_GOTREF(__pyx_t_11);
-    }
-    __Pyx_XDECREF(__pyx_v_n);
-    __pyx_v_n = __pyx_t_11;
-    __pyx_t_11 = 0;
-
-    /* "gilbert.pyx":44
- *   (isLeaf, reserved, count) = struct.unpack(endianness + 'BBH', fh.read(4))
- *   for n in range(count):
- *     (key, chromId, chromSize) = struct.unpack(endianness + str(keySize) + 'sII', fh.read(keySize + 2 * 4))             # <<<<<<<<<<<<<<
- *     csize[key.replace('\x00', '')] = chromSize
- *   return csize
- */
-    __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_11);
-    __pyx_t_9 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__unpack); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_9);
-    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
-    __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_11);
-    __Pyx_INCREF(__pyx_v_keySize);
-    PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_keySize);
-    __Pyx_GIVEREF(__pyx_v_keySize);
-    __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_10);
-    __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
-    __pyx_t_11 = PyNumber_Add(__pyx_v_endianness, __pyx_t_10); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_11);
-    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
-    __pyx_t_10 = PyNumber_Add(__pyx_t_11, ((PyObject *)__pyx_n_s__sII)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_10);
-    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
-    __pyx_t_11 = PyObject_GetAttr(__pyx_v_fh, __pyx_n_s__read); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_11);
-    __pyx_t_12 = PyNumber_Add(__pyx_v_keySize, __pyx_int_8); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_12);
-    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_5);
-    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_12);
-    __Pyx_GIVEREF(__pyx_t_12);
-    __pyx_t_12 = 0;
-    __pyx_t_12 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_12);
-    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
-    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
-    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_5);
-    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_10);
-    __Pyx_GIVEREF(__pyx_t_10);
-    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_12);
-    __Pyx_GIVEREF(__pyx_t_12);
-    __pyx_t_10 = 0;
-    __pyx_t_12 = 0;
-    __pyx_t_12 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_12);
-    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
-    if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) {
-      PyObject* sequence = __pyx_t_12;
-      #if CYTHON_COMPILING_IN_CPYTHON
-      Py_ssize_t size = Py_SIZE(sequence);
-      #else
-      Py_ssize_t size = PySequence_Size(sequence);
-      #endif
-      if (unlikely(size != 3)) {
-        if (size > 3) __Pyx_RaiseTooManyValuesError(3);
-        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      }
-      #if CYTHON_COMPILING_IN_CPYTHON
-      if (likely(PyTuple_CheckExact(sequence))) {
-        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
-        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
-        __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); 
-      } else {
-        __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
-        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
-        __pyx_t_10 = PyList_GET_ITEM(sequence, 2); 
-      }
-      __Pyx_INCREF(__pyx_t_5);
-      __Pyx_INCREF(__pyx_t_9);
-      __Pyx_INCREF(__pyx_t_10);
-      #else
-      __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_10 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      #endif
-      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
-    } else
-    {
-      Py_ssize_t index = -1;
-      __pyx_t_11 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_11);
-      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
-      __pyx_t_15 = Py_TYPE(__pyx_t_11)->tp_iternext;
-      index = 0; __pyx_t_5 = __pyx_t_15(__pyx_t_11); if (unlikely(!__pyx_t_5)) goto __pyx_L14_unpacking_failed;
-      __Pyx_GOTREF(__pyx_t_5);
-      index = 1; __pyx_t_9 = __pyx_t_15(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L14_unpacking_failed;
-      __Pyx_GOTREF(__pyx_t_9);
-      index = 2; __pyx_t_10 = __pyx_t_15(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L14_unpacking_failed;
-      __Pyx_GOTREF(__pyx_t_10);
-      if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_15 = NULL;
-      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
-      goto __pyx_L15_unpacking_done;
-      __pyx_L14_unpacking_failed:;
-      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
-      __pyx_t_15 = NULL;
-      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_L15_unpacking_done:;
-    }
-    __Pyx_XDECREF(__pyx_v_key);
-    __pyx_v_key = __pyx_t_5;
-    __pyx_t_5 = 0;
-    __Pyx_XDECREF(__pyx_v_chromId);
-    __pyx_v_chromId = __pyx_t_9;
-    __pyx_t_9 = 0;
-    __Pyx_XDECREF(__pyx_v_chromSize);
-    __pyx_v_chromSize = __pyx_t_10;
-    __pyx_t_10 = 0;
-
-    /* "gilbert.pyx":45
- *   for n in range(count):
- *     (key, chromId, chromSize) = struct.unpack(endianness + str(keySize) + 'sII', fh.read(keySize + 2 * 4))
- *     csize[key.replace('\x00', '')] = chromSize             # <<<<<<<<<<<<<<
- *   return csize
- * 
- */
-    __pyx_t_12 = PyObject_GetAttr(__pyx_v_key, __pyx_n_s__replace); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_12);
-    __pyx_t_10 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_10);
-    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
-    if (PyDict_SetItem(((PyObject *)__pyx_v_csize), __pyx_t_10, __pyx_v_chromSize) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
-  }
-  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
-
-  /* "gilbert.pyx":46
- *     (key, chromId, chromSize) = struct.unpack(endianness + str(keySize) + 'sII', fh.read(keySize + 2 * 4))
- *     csize[key.replace('\x00', '')] = chromSize
- *   return csize             # <<<<<<<<<<<<<<
- * 
- * # These functions were copied from simpleHilbertCurve (https://github.com/dentearl/simpleHilbertCurve.git)
- */
-  __Pyx_XDECREF(__pyx_r);
-  __Pyx_INCREF(((PyObject *)__pyx_v_csize));
-  __pyx_r = ((PyObject *)__pyx_v_csize);
-  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_5);
-  __Pyx_XDECREF(__pyx_t_6);
-  __Pyx_XDECREF(__pyx_t_7);
-  __Pyx_XDECREF(__pyx_t_8);
-  __Pyx_XDECREF(__pyx_t_9);
-  __Pyx_XDECREF(__pyx_t_10);
-  __Pyx_XDECREF(__pyx_t_11);
-  __Pyx_XDECREF(__pyx_t_12);
-  __Pyx_XDECREF(__pyx_t_13);
-  __Pyx_XDECREF(__pyx_t_14);
-  __Pyx_AddTraceback("gilbert.getChromosomeSizesFromBigWig", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
-  __pyx_L0:;
-  __Pyx_XDECREF(__pyx_v_csize);
-  __Pyx_XDECREF(__pyx_v_fh);
-  __Pyx_XDECREF(__pyx_v_magic);
-  __Pyx_XDECREF(__pyx_v_endianness);
-  __Pyx_XDECREF(__pyx_v_version);
-  __Pyx_XDECREF(__pyx_v_zoomLevels);
-  __Pyx_XDECREF(__pyx_v_chromosomeTreeOffset);
-  __Pyx_XDECREF(__pyx_v_fullDataOffset);
-  __Pyx_XDECREF(__pyx_v_fullIndexOffset);
-  __Pyx_XDECREF(__pyx_v_fieldCount);
-  __Pyx_XDECREF(__pyx_v_definedFieldCount);
-  __Pyx_XDECREF(__pyx_v_autoSqlOffset);
-  __Pyx_XDECREF(__pyx_v_totalSummaryOffset);
-  __Pyx_XDECREF(__pyx_v_uncompressBufSize);
-  __Pyx_XDECREF(__pyx_v_reserved);
-  __Pyx_XDECREF(__pyx_v_blockSize);
-  __Pyx_XDECREF(__pyx_v_keySize);
-  __Pyx_XDECREF(__pyx_v_valSize);
-  __Pyx_XDECREF(__pyx_v_itemCount);
-  __Pyx_XDECREF(__pyx_v_isLeaf);
-  __Pyx_XDECREF(__pyx_v_count);
-  __Pyx_XDECREF(__pyx_v_n);
-  __Pyx_XDECREF(__pyx_v_key);
-  __Pyx_XDECREF(__pyx_v_chromId);
-  __Pyx_XDECREF(__pyx_v_chromSize);
-  __Pyx_XGIVEREF(__pyx_r);
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* "gilbert.pyx":50
+/* "gilbert.pyx":23
  * # These functions were copied from simpleHilbertCurve (https://github.com/dentearl/simpleHilbertCurve.git)
  * 
  * cdef d2xy(int n, int d):             # <<<<<<<<<<<<<<
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("d2xy", 0);
 
-  /* "gilbert.pyx":55
+  /* "gilbert.pyx":28
  *     an x, y value (e.g. c, r).
  *     """
  *     assert(d <= n**2 - 1)             # <<<<<<<<<<<<<<
   #ifndef CYTHON_WITHOUT_ASSERTIONS
   if (unlikely(!(__pyx_v_d <= (__Pyx_pow_long(((long)__pyx_v_n), 2) - 1)))) {
     PyErr_SetNone(PyExc_AssertionError);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #endif
 
-  /* "gilbert.pyx":57
+  /* "gilbert.pyx":30
  *     assert(d <= n**2 - 1)
  *     cdef int t, x, y, s
  *     t = d             # <<<<<<<<<<<<<<
  */
   __pyx_v_t = __pyx_v_d;
 
-  /* "gilbert.pyx":58
+  /* "gilbert.pyx":31
  *     cdef int t, x, y, s
  *     t = d
  *     x = y = 0             # <<<<<<<<<<<<<<
   __pyx_v_x = 0;
   __pyx_v_y = 0;
 
-  /* "gilbert.pyx":59
+  /* "gilbert.pyx":32
  *     t = d
  *     x = y = 0
  *     s = 1             # <<<<<<<<<<<<<<
  */
   __pyx_v_s = 1;
 
-  /* "gilbert.pyx":60
+  /* "gilbert.pyx":33
  *     x = y = 0
  *     s = 1
  *     while (s < n):             # <<<<<<<<<<<<<<
     __pyx_t_1 = (__pyx_v_s < __pyx_v_n);
     if (!__pyx_t_1) break;
 
-    /* "gilbert.pyx":61
+    /* "gilbert.pyx":34
  *     s = 1
  *     while (s < n):
  *         rx = 1 & (t / 2)             # <<<<<<<<<<<<<<
  *         ry = 1 & (t ^ rx)
  *         x, y = rot(s, x, y, rx, ry)
  */
-    __pyx_t_2 = PyInt_FromLong((1 & __Pyx_div_long(__pyx_v_t, 2))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyInt_FromLong((1 & __Pyx_div_long(__pyx_v_t, 2))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_XDECREF(__pyx_v_rx);
     __pyx_v_rx = __pyx_t_2;
     __pyx_t_2 = 0;
 
-    /* "gilbert.pyx":62
+    /* "gilbert.pyx":35
  *     while (s < n):
  *         rx = 1 & (t / 2)
  *         ry = 1 & (t ^ rx)             # <<<<<<<<<<<<<<
  *         x, y = rot(s, x, y, rx, ry)
  *         x += s * rx
  */
-    __pyx_t_2 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyNumber_Xor(__pyx_t_2, __pyx_v_rx); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyNumber_Xor(__pyx_t_2, __pyx_v_rx); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __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_And(__pyx_int_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyNumber_And(__pyx_int_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
     __Pyx_XDECREF(__pyx_v_ry);
     __pyx_v_ry = __pyx_t_2;
     __pyx_t_2 = 0;
 
-    /* "gilbert.pyx":63
+    /* "gilbert.pyx":36
  *         rx = 1 & (t / 2)
  *         ry = 1 & (t ^ rx)
  *         x, y = rot(s, x, y, rx, ry)             # <<<<<<<<<<<<<<
  *         x += s * rx
  *         y += s * ry
  */
-    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_rx); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_v_ry); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_2 = __pyx_f_7gilbert_rot(__pyx_v_s, __pyx_v_x, __pyx_v_y, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_rx); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_v_ry); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __pyx_f_7gilbert_rot(__pyx_v_s, __pyx_v_x, __pyx_v_y, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
       PyObject* sequence = __pyx_t_2;
       if (unlikely(size != 2)) {
         if (size > 2) __Pyx_RaiseTooManyValuesError(2);
         else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
       #if CYTHON_COMPILING_IN_CPYTHON
       if (likely(PyTuple_CheckExact(sequence))) {
       __Pyx_INCREF(__pyx_t_3);
       __Pyx_INCREF(__pyx_t_6);
       #else
-      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     } else
     {
       Py_ssize_t index = -1;
-      __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
       __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
       __Pyx_GOTREF(__pyx_t_3);
       index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed;
       __Pyx_GOTREF(__pyx_t_6);
-      if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_t_8 = NULL;
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       goto __pyx_L6_unpacking_done;
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       __pyx_t_8 = NULL;
       if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_L6_unpacking_done:;
     }
-    __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     __pyx_v_x = __pyx_t_5;
     __pyx_v_y = __pyx_t_4;
 
-    /* "gilbert.pyx":64
+    /* "gilbert.pyx":37
  *         ry = 1 & (t ^ rx)
  *         x, y = rot(s, x, y, rx, ry)
  *         x += s * rx             # <<<<<<<<<<<<<<
  *         y += s * ry
  *         t /= 4
  */
-    __pyx_t_2 = PyInt_FromLong(__pyx_v_x); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyInt_FromLong(__pyx_v_x); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_6 = PyInt_FromLong(__pyx_v_s); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyInt_FromLong(__pyx_v_s); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
-    __pyx_t_3 = PyNumber_Multiply(__pyx_t_6, __pyx_v_rx); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyNumber_Multiply(__pyx_t_6, __pyx_v_rx); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-    __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     __pyx_v_x = __pyx_t_4;
 
-    /* "gilbert.pyx":65
+    /* "gilbert.pyx":38
  *         x, y = rot(s, x, y, rx, ry)
  *         x += s * rx
  *         y += s * ry             # <<<<<<<<<<<<<<
  *         t /= 4
  *         s *= 2
  */
-    __pyx_t_6 = PyInt_FromLong(__pyx_v_y); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyInt_FromLong(__pyx_v_y); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
-    __pyx_t_3 = PyInt_FromLong(__pyx_v_s); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyInt_FromLong(__pyx_v_s); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_2 = PyNumber_Multiply(__pyx_t_3, __pyx_v_ry); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyNumber_Multiply(__pyx_t_3, __pyx_v_ry); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __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_t_6, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
     __pyx_v_y = __pyx_t_4;
 
-    /* "gilbert.pyx":66
+    /* "gilbert.pyx":39
  *         x += s * rx
  *         y += s * ry
  *         t /= 4             # <<<<<<<<<<<<<<
  */
     __pyx_v_t = __Pyx_div_long(__pyx_v_t, 4);
 
-    /* "gilbert.pyx":67
+    /* "gilbert.pyx":40
  *         y += s * ry
  *         t /= 4
  *         s *= 2             # <<<<<<<<<<<<<<
     __pyx_v_s = (__pyx_v_s * 2);
   }
 
-  /* "gilbert.pyx":68
+  /* "gilbert.pyx":41
  *         t /= 4
  *         s *= 2
  *     return x, y             # <<<<<<<<<<<<<<
  * cdef rot(int n, int x,int  y, int rx,int ry):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_3 = PyInt_FromLong(__pyx_v_x); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyInt_FromLong(__pyx_v_x); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_2 = PyInt_FromLong(__pyx_v_y); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyInt_FromLong(__pyx_v_y); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_6);
   PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
   __Pyx_GIVEREF(__pyx_t_3);
   return __pyx_r;
 }
 
-/* "gilbert.pyx":70
+/* "gilbert.pyx":43
  *     return x, y
  * 
  * cdef rot(int n, int x,int  y, int rx,int ry):             # <<<<<<<<<<<<<<
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("rot", 0);
 
-  /* "gilbert.pyx":74
+  /* "gilbert.pyx":47
  *     rotate/flip a quadrant appropriately
  *     """
  *     if ry == 0:             # <<<<<<<<<<<<<<
   __pyx_t_1 = (__pyx_v_ry == 0);
   if (__pyx_t_1) {
 
-    /* "gilbert.pyx":75
+    /* "gilbert.pyx":48
  *     """
  *     if ry == 0:
  *         if rx == 1:             # <<<<<<<<<<<<<<
     __pyx_t_1 = (__pyx_v_rx == 1);
     if (__pyx_t_1) {
 
-      /* "gilbert.pyx":76
+      /* "gilbert.pyx":49
  *     if ry == 0:
  *         if rx == 1:
  *             x = n - 1 - x             # <<<<<<<<<<<<<<
  */
       __pyx_v_x = ((__pyx_v_n - 1) - __pyx_v_x);
 
-      /* "gilbert.pyx":77
+      /* "gilbert.pyx":50
  *         if rx == 1:
  *             x = n - 1 - x
  *             y = n - 1 - y             # <<<<<<<<<<<<<<
     }
     __pyx_L4:;
 
-    /* "gilbert.pyx":78
+    /* "gilbert.pyx":51
  *             x = n - 1 - x
  *             y = n - 1 - y
  *         return y, x             # <<<<<<<<<<<<<<
  * 
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = PyInt_FromLong(__pyx_v_y); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyInt_FromLong(__pyx_v_y); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyInt_FromLong(__pyx_v_x); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyInt_FromLong(__pyx_v_x); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __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);
   }
   __pyx_L3:;
 
-  /* "gilbert.pyx":79
+  /* "gilbert.pyx":52
  *             y = n - 1 - y
  *         return y, x
  *     return x, y             # <<<<<<<<<<<<<<
  * 
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_4 = PyInt_FromLong(__pyx_v_x); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyInt_FromLong(__pyx_v_x); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  __pyx_t_3 = PyInt_FromLong(__pyx_v_y); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyInt_FromLong(__pyx_v_y); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
   __Pyx_GIVEREF(__pyx_t_4);
 }
 
 /* Python wrapper */
-static PyObject *__pyx_pw_7gilbert_5dump_png(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static PyMethodDef __pyx_mdef_7gilbert_5dump_png = {__Pyx_NAMESTR("dump_png"), (PyCFunction)__pyx_pw_7gilbert_5dump_png, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
-static PyObject *__pyx_pw_7gilbert_5dump_png(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pw_7gilbert_3dump_png(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyMethodDef __pyx_mdef_7gilbert_3dump_png = {__Pyx_NAMESTR("dump_png"), (PyCFunction)__pyx_pw_7gilbert_3dump_png, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
+static PyObject *__pyx_pw_7gilbert_3dump_png(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
   PyObject *__pyx_v_hc = 0;
   PyObject *__pyx_v_chromosome = 0;
   int __pyx_v_chromosome_size;
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__chromosome)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("dump_png", 1, 6, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("dump_png", 1, 6, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  2:
         if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__chromosome_size)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("dump_png", 1, 6, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("dump_png", 1, 6, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  3:
         if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__name)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("dump_png", 1, 6, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("dump_png", 1, 6, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  4:
         if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__level)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("dump_png", 1, 6, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("dump_png", 1, 6, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  5:
         if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__resolution)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("dump_png", 1, 6, 6, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("dump_png", 1, 6, 6, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dump_png") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dump_png") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 6) {
       goto __pyx_L5_argtuple_error;
     }
     __pyx_v_hc = values[0];
     __pyx_v_chromosome = values[1];
-    __pyx_v_chromosome_size = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_chromosome_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_chromosome_size = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_chromosome_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     __pyx_v_name = values[3];
-    __pyx_v_level = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    __pyx_v_resolution = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_resolution == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_level = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_resolution = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_resolution == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("dump_png", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("dump_png", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("gilbert.dump_png", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return NULL;
   __pyx_L4_argument_unpacking_done:;
-  __pyx_r = __pyx_pf_7gilbert_4dump_png(__pyx_self, __pyx_v_hc, __pyx_v_chromosome, __pyx_v_chromosome_size, __pyx_v_name, __pyx_v_level, __pyx_v_resolution);
+  __pyx_r = __pyx_pf_7gilbert_2dump_png(__pyx_self, __pyx_v_hc, __pyx_v_chromosome, __pyx_v_chromosome_size, __pyx_v_name, __pyx_v_level, __pyx_v_resolution);
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
-/* "gilbert.pyx":82
+/* "gilbert.pyx":55
  * 
  * 
  * def dump_png(hc, chromosome, int chromosome_size, name, int level, int resolution):             # <<<<<<<<<<<<<<
  *   colormap = plt.cm.Reds
  */
 
-static PyObject *__pyx_pf_7gilbert_4dump_png(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_hc, PyObject *__pyx_v_chromosome, int __pyx_v_chromosome_size, PyObject *__pyx_v_name, int __pyx_v_level, int __pyx_v_resolution) {
+static PyObject *__pyx_pf_7gilbert_2dump_png(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_hc, PyObject *__pyx_v_chromosome, int __pyx_v_chromosome_size, PyObject *__pyx_v_name, int __pyx_v_level, int __pyx_v_resolution) {
   PyObject *__pyx_v_n = NULL;
   PyObject *__pyx_v_colormap = NULL;
   PyObject *__pyx_v_i = NULL;
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("dump_png", 0);
 
-  /* "gilbert.pyx":83
+  /* "gilbert.pyx":56
  * 
  * def dump_png(hc, chromosome, int chromosome_size, name, int level, int resolution):
  *   n = 1 <<  level             # <<<<<<<<<<<<<<
  *   colormap = plt.cm.Reds
  *   plt.matshow(hc, origin=0, cmap = colormap)
  */
-  __pyx_t_1 = PyInt_FromLong((1 << __pyx_v_level)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong((1 << __pyx_v_level)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_n = __pyx_t_1;
   __pyx_t_1 = 0;
 
-  /* "gilbert.pyx":84
+  /* "gilbert.pyx":57
  * def dump_png(hc, chromosome, int chromosome_size, name, int level, int resolution):
  *   n = 1 <<  level
  *   colormap = plt.cm.Reds             # <<<<<<<<<<<<<<
  *   plt.matshow(hc, origin=0, cmap = colormap)
  *   plt.colorbar()
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__plt); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__plt); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__cm); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__cm); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__Reds); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__Reds); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_v_colormap = __pyx_t_1;
   __pyx_t_1 = 0;
 
-  /* "gilbert.pyx":85
+  /* "gilbert.pyx":58
  *   n = 1 <<  level
  *   colormap = plt.cm.Reds
  *   plt.matshow(hc, origin=0, cmap = colormap)             # <<<<<<<<<<<<<<
  *   plt.colorbar()
  *   for i in range(0, chromosome_size, 4000000):
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__plt); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__plt); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__matshow); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__matshow); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__pyx_v_hc);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_hc);
   __Pyx_GIVEREF(__pyx_v_hc);
-  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
-  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__origin), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__cmap), __pyx_v_colormap) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__origin), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__cmap), __pyx_v_colormap) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "gilbert.pyx":86
+  /* "gilbert.pyx":59
  *   colormap = plt.cm.Reds
  *   plt.matshow(hc, origin=0, cmap = colormap)
  *   plt.colorbar()             # <<<<<<<<<<<<<<
  *   for i in range(0, chromosome_size, 4000000):
  *     # add crosshatches for chrom position
  */
-  __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__plt); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__plt); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__colorbar); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__colorbar); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "gilbert.pyx":87