[med-svn] [python-pysam] 03/05: Imported Upstream version 0.7.7

Charles Plessy plessy at moszumanska.debian.org
Sat Apr 19 02:48:44 UTC 2014


This is an automated email from the git hooks/post-receive script.

plessy pushed a commit to branch master
in repository python-pysam.

commit a757e53aa364a0816cbebb22c43c9918f08522f8
Author: Charles Plessy <plessy at debian.org>
Date:   Sat Apr 19 11:42:00 2014 +0900

    Imported Upstream version 0.7.7
---
 PKG-INFO                |     2 +-
 doc/release.rst         |     6 +
 pysam.egg-info/PKG-INFO |     2 +-
 pysam/TabProxies.c      |    60 +-
 pysam/csamtools.c       | 13364 ++++++++++++++++++++++++++--------------------
 pysam/csamtools.pxd     |    12 +-
 pysam/csamtools.pyx     |   125 +-
 pysam/ctabix.c          |  5261 +++++++++---------
 pysam/ctabix.pxd        |    63 +-
 pysam/ctabix.pyx        |   262 +-
 pysam/cvcf.c            |   455 +-
 pysam/tabix_util.c      |     2 +
 pysam/tabix_util.h      |     7 +
 pysam/version.py        |     2 +-
 tests/Makefile          |     5 +-
 tests/pysam_test.py     |    61 +-
 tests/tabix_test.py     |   167 +-
 17 files changed, 10690 insertions(+), 9166 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index dbb2aed..663796e 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: pysam
-Version: 0.7.6
+Version: 0.7.7
 Summary: pysam
 Home-page: http://code.google.com/p/pysam/
 Author: Andreas Heger
diff --git a/doc/release.rst b/doc/release.rst
index 3413c1f..062ab52 100644
--- a/doc/release.rst
+++ b/doc/release.rst
@@ -2,6 +2,12 @@
 Release notes
 =============
 
+Release 0.7.7
+=============
+
+   * added Fastafile.references, .nreferences and .lengths
+   * tabix_iterator now uses kseq.h for python 2.7
+
 Release 0.7.6
 =============
 
diff --git a/pysam.egg-info/PKG-INFO b/pysam.egg-info/PKG-INFO
index dbb2aed..663796e 100644
--- a/pysam.egg-info/PKG-INFO
+++ b/pysam.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: pysam
-Version: 0.7.6
+Version: 0.7.7
 Summary: pysam
 Home-page: http://code.google.com/p/pysam/
 Author: Andreas Heger
diff --git a/pysam/TabProxies.c b/pysam/TabProxies.c
index 099e19e..c1ab8fe 100644
--- a/pysam/TabProxies.c
+++ b/pysam/TabProxies.c
@@ -1,4 +1,4 @@
-/* Generated by Cython 0.18 on Fri Sep 20 00:20:26 2013 */
+/* Generated by Cython 0.18 on Sat Nov 16 01:37:33 2013 */
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
@@ -341,8 +341,8 @@ static const char *__pyx_f[] = {
 /*--- Type declarations ---*/
 struct __pyx_obj_5pysam_10TabProxies_TupleProxy;
 struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy;
-struct __pyx_obj_5pysam_10TabProxies_BedProxy;
 struct __pyx_obj_5pysam_10TabProxies_GTFProxy;
+struct __pyx_obj_5pysam_10TabProxies_BedProxy;
 struct __pyx_obj_5pysam_10TabProxies_VCFProxy;
 
 /* "pysam/TabProxies.pxd":41
@@ -377,6 +377,20 @@ struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy {
 };
 
 
+/* "pysam/TabProxies.pxd":60
+ *     cdef update( self, char * buffer, size_t nbytes )
+ * 
+ * cdef class GTFProxy( TupleProxy) :             # <<<<<<<<<<<<<<
+ * 
+ *     cdef:
+ */
+struct __pyx_obj_5pysam_10TabProxies_GTFProxy {
+  struct __pyx_obj_5pysam_10TabProxies_TupleProxy __pyx_base;
+  char *_attributes;
+  int hasOwnAttributes;
+};
+
+
 /* "pysam/TabProxies.pxd":72
  *     pass
  * 
@@ -393,20 +407,6 @@ struct __pyx_obj_5pysam_10TabProxies_BedProxy {
 };
 
 
-/* "pysam/TabProxies.pxd":60
- *     cdef update( self, char * buffer, size_t nbytes )
- * 
- * cdef class GTFProxy( TupleProxy) :             # <<<<<<<<<<<<<<
- * 
- *     cdef:
- */
-struct __pyx_obj_5pysam_10TabProxies_GTFProxy {
-  struct __pyx_obj_5pysam_10TabProxies_TupleProxy __pyx_base;
-  char *_attributes;
-  int hasOwnAttributes;
-};
-
-
 /* "pysam/TabProxies.pxd":83
  *     cdef update( self, char * buffer, size_t nbytes )
  * 
@@ -454,20 +454,6 @@ struct __pyx_vtabstruct_5pysam_10TabProxies_NamedTupleProxy {
 static struct __pyx_vtabstruct_5pysam_10TabProxies_NamedTupleProxy *__pyx_vtabptr_5pysam_10TabProxies_NamedTupleProxy;
 
 
-/* "pysam/TabProxies.pyx":590
- *         return f( self.fields[idx] )
- * 
- * cdef class BedProxy( NamedTupleProxy ):             # <<<<<<<<<<<<<<
- *     '''Proxy class for access to Bed fields.
- * 
- */
-
-struct __pyx_vtabstruct_5pysam_10TabProxies_BedProxy {
-  struct __pyx_vtabstruct_5pysam_10TabProxies_NamedTupleProxy __pyx_base;
-};
-static struct __pyx_vtabstruct_5pysam_10TabProxies_BedProxy *__pyx_vtabptr_5pysam_10TabProxies_BedProxy;
-
-
 /* "pysam/TabProxies.pyx":656
  *         TupleProxy._setindex(self, idx, str(value) )
  * 
@@ -495,6 +481,20 @@ struct __pyx_vtabstruct_5pysam_10TabProxies_GTFProxy {
   char *(*getAttributes)(struct __pyx_obj_5pysam_10TabProxies_GTFProxy *);
 };
 static struct __pyx_vtabstruct_5pysam_10TabProxies_GTFProxy *__pyx_vtabptr_5pysam_10TabProxies_GTFProxy;
+
+
+/* "pysam/TabProxies.pyx":590
+ *         return f( self.fields[idx] )
+ * 
+ * cdef class BedProxy( NamedTupleProxy ):             # <<<<<<<<<<<<<<
+ *     '''Proxy class for access to Bed fields.
+ * 
+ */
+
+struct __pyx_vtabstruct_5pysam_10TabProxies_BedProxy {
+  struct __pyx_vtabstruct_5pysam_10TabProxies_NamedTupleProxy __pyx_base;
+};
+static struct __pyx_vtabstruct_5pysam_10TabProxies_BedProxy *__pyx_vtabptr_5pysam_10TabProxies_BedProxy;
 #ifndef CYTHON_REFNANNY
   #define CYTHON_REFNANNY 0
 #endif
diff --git a/pysam/csamtools.c b/pysam/csamtools.c
index 66c8778..5eff100 100644
--- a/pysam/csamtools.c
+++ b/pysam/csamtools.c
@@ -1,4 +1,4 @@
-/* Generated by Cython 0.18 on Fri Sep 20 00:20:26 2013 */
+/* Generated by Cython 0.18 on Sat Nov 16 01:37:33 2013 */
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
@@ -347,25 +347,28 @@ static const char *__pyx_f[] = {
 };
 
 /*--- Type declarations ---*/
-struct __pyx_obj_5pysam_9csamtools_IteratorRow;
-struct __pyx_obj_5pysam_9csamtools_IteratorRowAllRefs;
+struct __pyx_obj_5pysam_9csamtools_PileupRead;
 struct __pyx_obj_5pysam_9csamtools_SNPCall;
-struct __pyx_obj_5pysam_9csamtools_AlignedRead;
-struct __pyx_obj_5pysam_9csamtools_Fastqfile;
-struct __pyx_obj_5pysam_9csamtools_IteratorRowSelection;
-struct __pyx_obj_5pysam_9csamtools_IndexedReads;
-struct __pyx_obj_5pysam_9csamtools_IteratorRowAll;
 struct __pyx_obj_5pysam_9csamtools_IteratorColumn;
-struct __pyx_obj_5pysam_9csamtools_IteratorColumnRegion;
-struct __pyx_obj_5pysam_9csamtools_Samfile;
+struct __pyx_obj_5pysam_9csamtools_IteratorRow;
+struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion;
+struct __pyx_obj_5pysam_9csamtools_IndexedReads;
+struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr;
 struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr;
+struct __pyx_obj_5pysam_9csamtools_Fastqfile;
+struct __pyx_obj_5pysam_9csamtools_FastqProxy;
+struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr;
+struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open;
+struct __pyx_obj_5pysam_9csamtools_IteratorRowAllRefs;
 struct __pyx_obj_5pysam_9csamtools_IteratorColumnAllRefs;
 struct __pyx_obj_5pysam_9csamtools_Fastafile;
+struct __pyx_obj_5pysam_9csamtools_AlignedRead;
+struct __pyx_obj_5pysam_9csamtools_IteratorRowSelection;
+struct __pyx_obj_5pysam_9csamtools_Samfile;
+struct __pyx_obj_5pysam_9csamtools_IteratorColumnRegion;
 struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct__genexpr;
 struct __pyx_obj_5pysam_9csamtools_PileupProxy;
-struct __pyx_obj_5pysam_9csamtools_PileupRead;
-struct __pyx_obj_5pysam_9csamtools_FastqProxy;
-struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion;
+struct __pyx_obj_5pysam_9csamtools_IteratorRowAll;
 struct __pyx_t_5pysam_9csamtools___iterdata;
 typedef struct __pyx_t_5pysam_9csamtools___iterdata __pyx_t_5pysam_9csamtools___iterdata;
 struct __pyx_opt_args_5pysam_9csamtools_14IteratorColumn_setupIteratorData;
@@ -388,7 +391,7 @@ struct __pyx_t_5pysam_9csamtools___iterdata {
   int seq_len;
 };
 
-/* "pysam/csamtools.pxd":554
+/* "pysam/csamtools.pxd":552
  *     cdef char * getSequence( self )
  *     cdef setMask( self, mask )
  *     cdef setupIteratorData( self,             # <<<<<<<<<<<<<<
@@ -400,7 +403,7 @@ struct __pyx_opt_args_5pysam_9csamtools_14IteratorColumn_setupIteratorData {
   int reopen;
 };
 
-/* "pysam/csamtools.pyx":644
+/* "pysam/csamtools.pyx":657
  *      counter[0] += 1;
  * 
  * ctypedef struct MateData:             # <<<<<<<<<<<<<<
@@ -413,34 +416,26 @@ struct __pyx_t_5pysam_9csamtools_MateData {
   uint32_t flag;
 };
 
-/* "pysam/csamtools.pxd":495
- *     cdef uint32_t _is_tail
- * 
- * cdef class IteratorRow:             # <<<<<<<<<<<<<<
- *     pass
+/* "pysam/csamtools.pxd":484
+ *     cdef int n_pu
  * 
+ * cdef class PileupRead:             # <<<<<<<<<<<<<<
+ *     cdef AlignedRead _alignment
+ *     cdef int32_t  _qpos
  */
-struct __pyx_obj_5pysam_9csamtools_IteratorRow {
+struct __pyx_obj_5pysam_9csamtools_PileupRead {
   PyObject_HEAD
+  struct __pyx_obj_5pysam_9csamtools_AlignedRead *_alignment;
+  int32_t _qpos;
+  int _indel;
+  int _level;
+  uint32_t _is_del;
+  uint32_t _is_head;
+  uint32_t _is_tail;
 };
 
 
-/* "pysam/csamtools.pxd":518
- *     cdef int cnext(self)
- * 
- * cdef class IteratorRowAllRefs(IteratorRow):             # <<<<<<<<<<<<<<
- *     cdef Samfile     samfile
- *     cdef int         tid
- */
-struct __pyx_obj_5pysam_9csamtools_IteratorRowAllRefs {
-  struct __pyx_obj_5pysam_9csamtools_IteratorRow __pyx_base;
-  struct __pyx_obj_5pysam_9csamtools_Samfile *samfile;
-  int tid;
-  struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *rowiter;
-};
-
-
-/* "pysam/csamtools.pyx":3467
+/* "pysam/csamtools.pyx":3474
  *     return retval, out_stderr, out_stdout
  * 
  * cdef class SNPCall:             # <<<<<<<<<<<<<<
@@ -460,54 +455,63 @@ struct __pyx_obj_5pysam_9csamtools_SNPCall {
 };
 
 
-/* "pysam/csamtools.pxd":446
+/* "pysam/csamtools.pxd":533
  *     cdef int cnext(self)
  * 
- * cdef class AlignedRead:             # <<<<<<<<<<<<<<
+ * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
  * 
- *     # object that this AlignedRead represents
+ *     # result of the last plbuf_push
  */
-struct __pyx_obj_5pysam_9csamtools_AlignedRead {
+struct __pyx_obj_5pysam_9csamtools_IteratorColumn {
   PyObject_HEAD
-  bam1_t *_delegate;
+  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumn *__pyx_vtab;
+  struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *iter;
+  int tid;
+  int pos;
+  int n_plp;
+  int mask;
+  const bam_pileup1_t * plp;
+  bam_plp_t pileup_iter;
+  __pyx_t_5pysam_9csamtools___iterdata iterdata;
+  struct __pyx_obj_5pysam_9csamtools_Samfile *samfile;
+  struct __pyx_obj_5pysam_9csamtools_Fastafile *fastafile;
+  PyObject *stepper;
+  int max_depth;
 };
 
 
-/* "pysam/csamtools.pxd":438
- *     cdef kseq_t * _delegate
+/* "pysam/csamtools.pxd":493
+ *     cdef uint32_t _is_tail
+ * 
+ * cdef class IteratorRow:             # <<<<<<<<<<<<<<
+ *     pass
  * 
- * cdef class Fastqfile:             # <<<<<<<<<<<<<<
- *     cdef char * _filename
- *     cdef gzFile fastqfile
  */
-struct __pyx_obj_5pysam_9csamtools_Fastqfile {
+struct __pyx_obj_5pysam_9csamtools_IteratorRow {
   PyObject_HEAD
-  struct __pyx_vtabstruct_5pysam_9csamtools_Fastqfile *__pyx_vtab;
-  char *_filename;
-  gzFile fastqfile;
-  kseq_t *entry;
 };
 
 
-/* "pysam/csamtools.pxd":523
- *     cdef IteratorRowRegion rowiter
+/* "pysam/csamtools.pxd":496
+ *     pass
  * 
- * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
- *     cdef bam1_t * b
- *     cdef int current_pos
+ * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
+ *     cdef bam_iter_t             iter # iterator state object
+ *     cdef bam1_t *               b
  */
-struct __pyx_obj_5pysam_9csamtools_IteratorRowSelection {
+struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion {
   struct __pyx_obj_5pysam_9csamtools_IteratorRow __pyx_base;
-  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowSelection *__pyx_vtab;
+  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowRegion *__pyx_vtab;
+  bam_iter_t iter;
   bam1_t *b;
-  int current_pos;
+  int retval;
+  struct __pyx_obj_5pysam_9csamtools_Samfile *samfile;
   samfile_t *fp;
-  PyObject *positions;
   int owns_samfile;
 };
 
 
-/* "pysam/csamtools.pxd":570
+/* "pysam/csamtools.pxd":568
  *     pass
  * 
  * cdef class IndexedReads:             # <<<<<<<<<<<<<<
@@ -523,102 +527,113 @@ struct __pyx_obj_5pysam_9csamtools_IndexedReads {
 };
 
 
-/* "pysam/csamtools.pxd":511
- *     cdef int cnext(self)
+/* "pysam/csamtools.pyx":432
+ *             data = [ x.split("\t") for x in inf ]
+ *             self._references = tuple(x[0] for x in data)
+ *             self._lengths = tuple(int(x[1]) for x in data)             # <<<<<<<<<<<<<<
+ *             self.reference2length = dict(zip(self._references, self._lengths))
  * 
- * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
- *     cdef bam1_t * b
- *     cdef samfile_t * fp
  */
-struct __pyx_obj_5pysam_9csamtools_IteratorRowAll {
-  struct __pyx_obj_5pysam_9csamtools_IteratorRow __pyx_base;
-  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowAll *__pyx_vtab;
-  bam1_t *b;
-  samfile_t *fp;
-  int owns_samfile;
+struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr {
+  PyObject_HEAD
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *__pyx_outer_scope;
+  PyObject *__pyx_v_x;
+  PyObject *__pyx_t_0;
+  Py_ssize_t __pyx_t_1;
 };
 
 
-/* "pysam/csamtools.pxd":535
- *     cdef int cnext(self)
- * 
- * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
+/* "pysam/csamtools.pyx":141
+ *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
+ * else:
+ *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
+ * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )
  * 
- *     # result of the last plbuf_push
  */
-struct __pyx_obj_5pysam_9csamtools_IteratorColumn {
+struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr {
   PyObject_HEAD
-  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumn *__pyx_vtab;
-  struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *iter;
-  int tid;
-  int pos;
-  int n_plp;
-  int mask;
-  const bam_pileup1_t * plp;
-  bam_plp_t pileup_iter;
-  __pyx_t_5pysam_9csamtools___iterdata iterdata;
-  struct __pyx_obj_5pysam_9csamtools_Samfile *samfile;
-  struct __pyx_obj_5pysam_9csamtools_Fastafile *fastafile;
-  PyObject *stepper;
-  int max_depth;
+  PyObject *__pyx_v_x;
+  PyObject *__pyx_v_y;
+  PyObject *__pyx_t_0;
+  PyObject *__pyx_t_1;
+  PyObject *(*__pyx_t_2)(PyObject *);
 };
 
 
-/* "pysam/csamtools.pxd":562
- *     cdef reset( self, tid, start, end )
+/* "pysam/csamtools.pxd":436
+ *     cdef kseq_t * _delegate
  * 
- * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
- *     cdef int start
- *     cdef int end
+ * cdef class Fastqfile:             # <<<<<<<<<<<<<<
+ *     cdef object _filename
+ *     cdef gzFile fastqfile
  */
-struct __pyx_obj_5pysam_9csamtools_IteratorColumnRegion {
-  struct __pyx_obj_5pysam_9csamtools_IteratorColumn __pyx_base;
-  int start;
-  int end;
-  int truncate;
+struct __pyx_obj_5pysam_9csamtools_Fastqfile {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_5pysam_9csamtools_Fastqfile *__pyx_vtab;
+  PyObject *_filename;
+  gzFile fastqfile;
+  kseq_t *entry;
 };
 
 
-/* "pysam/csamtools.pxd":451
- *     cdef bam1_t * _delegate
+/* "pysam/csamtools.pxd":433
+ *     cdef char* _fetch(self, char* reference, int start, int end, int* length)
+ * 
+ * cdef class FastqProxy:             # <<<<<<<<<<<<<<
+ *     cdef kseq_t * _delegate
  * 
- * cdef class Samfile:             # <<<<<<<<<<<<<<
- *     cdef char * _filename
- *     # pointer to samfile
  */
-struct __pyx_obj_5pysam_9csamtools_Samfile {
+struct __pyx_obj_5pysam_9csamtools_FastqProxy {
   PyObject_HEAD
-  struct __pyx_vtabstruct_5pysam_9csamtools_Samfile *__pyx_vtab;
-  char *_filename;
-  samfile_t *samfile;
-  bam_index_t *index;
-  int isbam;
-  int isstream;
-  int isremote;
-  bam1_t *b;
-  char *mode;
-  int64_t start_offset;
+  kseq_t *_delegate;
 };
 
 
-/* "pysam/csamtools.pyx":142
- *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
- * else:
- *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
- * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )
- * 
+/* "pysam/csamtools.pyx":431
+ *         with open( self._filename + b".fai" ) as inf:
+ *             data = [ x.split("\t") for x in inf ]
+ *             self._references = tuple(x[0] for x in data)             # <<<<<<<<<<<<<<
+ *             self._lengths = tuple(int(x[1]) for x in data)
+ *             self.reference2length = dict(zip(self._references, self._lengths))
  */
-struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr {
+struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr {
   PyObject_HEAD
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *__pyx_outer_scope;
   PyObject *__pyx_v_x;
-  PyObject *__pyx_v_y;
   PyObject *__pyx_t_0;
-  PyObject *__pyx_t_1;
-  PyObject *(*__pyx_t_2)(PyObject *);
+  Py_ssize_t __pyx_t_1;
+};
+
+
+/* "pysam/csamtools.pyx":411
+ *         return faidx_fetch_nseq(self.fastafile)
+ * 
+ *     def _open(self, filename):             # <<<<<<<<<<<<<<
+ *         '''open an indexed fasta file.
+ * 
+ */
+struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open {
+  PyObject_HEAD
+  PyObject *__pyx_v_data;
 };
 
 
-/* "pysam/csamtools.pxd":567
+/* "pysam/csamtools.pxd":516
+ *     cdef int cnext(self)
+ * 
+ * cdef class IteratorRowAllRefs(IteratorRow):             # <<<<<<<<<<<<<<
+ *     cdef Samfile     samfile
+ *     cdef int         tid
+ */
+struct __pyx_obj_5pysam_9csamtools_IteratorRowAllRefs {
+  struct __pyx_obj_5pysam_9csamtools_IteratorRow __pyx_base;
+  struct __pyx_obj_5pysam_9csamtools_Samfile *samfile;
+  int tid;
+  struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *rowiter;
+};
+
+
+/* "pysam/csamtools.pxd":565
  *     cdef int truncate
  * 
  * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
@@ -634,18 +649,89 @@ struct __pyx_obj_5pysam_9csamtools_IteratorColumnAllRefs {
  * # Note: need to declare all C fields and methods here
  * #
  * cdef class Fastafile:             # <<<<<<<<<<<<<<
- *     cdef char * _filename
- *     # pointer to fastafile
+ *     cdef object _filename, _references, _lengths, reference2length
+ *     cdef faidx_t* fastafile
  */
 struct __pyx_obj_5pysam_9csamtools_Fastafile {
   PyObject_HEAD
   struct __pyx_vtabstruct_5pysam_9csamtools_Fastafile *__pyx_vtab;
-  char *_filename;
+  PyObject *_filename;
+  PyObject *_references;
+  PyObject *_lengths;
+  PyObject *reference2length;
   faidx_t *fastafile;
 };
 
 
-/* "pysam/csamtools.pyx":140
+/* "pysam/csamtools.pxd":444
+ *     cdef int cnext(self)
+ * 
+ * cdef class AlignedRead:             # <<<<<<<<<<<<<<
+ * 
+ *     # object that this AlignedRead represents
+ */
+struct __pyx_obj_5pysam_9csamtools_AlignedRead {
+  PyObject_HEAD
+  bam1_t *_delegate;
+};
+
+
+/* "pysam/csamtools.pxd":521
+ *     cdef IteratorRowRegion rowiter
+ * 
+ * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
+ *     cdef bam1_t * b
+ *     cdef int current_pos
+ */
+struct __pyx_obj_5pysam_9csamtools_IteratorRowSelection {
+  struct __pyx_obj_5pysam_9csamtools_IteratorRow __pyx_base;
+  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowSelection *__pyx_vtab;
+  bam1_t *b;
+  int current_pos;
+  samfile_t *fp;
+  PyObject *positions;
+  int owns_samfile;
+};
+
+
+/* "pysam/csamtools.pxd":449
+ *     cdef bam1_t * _delegate
+ * 
+ * cdef class Samfile:             # <<<<<<<<<<<<<<
+ *     cdef object _filename
+ *     # pointer to samfile
+ */
+struct __pyx_obj_5pysam_9csamtools_Samfile {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_5pysam_9csamtools_Samfile *__pyx_vtab;
+  PyObject *_filename;
+  samfile_t *samfile;
+  bam_index_t *index;
+  int isbam;
+  int isstream;
+  int isremote;
+  bam1_t *b;
+  char *mode;
+  int64_t start_offset;
+};
+
+
+/* "pysam/csamtools.pxd":560
+ *     cdef reset( self, tid, start, end )
+ * 
+ * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
+ *     cdef int start
+ *     cdef int end
+ */
+struct __pyx_obj_5pysam_9csamtools_IteratorColumnRegion {
+  struct __pyx_obj_5pysam_9csamtools_IteratorColumn __pyx_base;
+  int start;
+  int end;
+  int truncate;
+};
+
+
+/* "pysam/csamtools.pyx":139
  * cdef char* CODE2CIGAR= "MIDNSHP=X"
  * if IS_PYTHON3:
  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
@@ -662,7 +748,7 @@ struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct__genexpr {
 };
 
 
-/* "pysam/csamtools.pxd":480
+/* "pysam/csamtools.pxd":478
  *     cdef char * _getrname( self, int tid )
  * 
  * cdef class PileupProxy:             # <<<<<<<<<<<<<<
@@ -678,59 +764,53 @@ struct __pyx_obj_5pysam_9csamtools_PileupProxy {
 };
 
 
-/* "pysam/csamtools.pxd":486
- *     cdef int n_pu
+/* "pysam/csamtools.pxd":509
+ *     cdef int cnext(self)
  * 
- * cdef class PileupRead:             # <<<<<<<<<<<<<<
- *     cdef AlignedRead _alignment
- *     cdef int32_t  _qpos
+ * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
+ *     cdef bam1_t * b
+ *     cdef samfile_t * fp
  */
-struct __pyx_obj_5pysam_9csamtools_PileupRead {
-  PyObject_HEAD
-  struct __pyx_obj_5pysam_9csamtools_AlignedRead *_alignment;
-  int32_t _qpos;
-  int _indel;
-  int _level;
-  uint32_t _is_del;
-  uint32_t _is_head;
-  uint32_t _is_tail;
+struct __pyx_obj_5pysam_9csamtools_IteratorRowAll {
+  struct __pyx_obj_5pysam_9csamtools_IteratorRow __pyx_base;
+  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowAll *__pyx_vtab;
+  bam1_t *b;
+  samfile_t *fp;
+  int owns_samfile;
 };
 
 
-/* "pysam/csamtools.pxd":435
- *     cdef char * _fetch( self, char * reference, int start, int end, int * length )
- * 
- * cdef class FastqProxy:             # <<<<<<<<<<<<<<
- *     cdef kseq_t * _delegate
+
+/* "pysam/csamtools.pyx":381
+ * ## Public methods
+ * ######################################################################
+ * cdef class Fastafile:             # <<<<<<<<<<<<<<
+ *     '''*(filename)*
  * 
  */
-struct __pyx_obj_5pysam_9csamtools_FastqProxy {
-  PyObject_HEAD
-  kseq_t *_delegate;
+
+struct __pyx_vtabstruct_5pysam_9csamtools_Fastafile {
+  char *(*_fetch)(struct __pyx_obj_5pysam_9csamtools_Fastafile *, char *, int, int, int *);
 };
+static struct __pyx_vtabstruct_5pysam_9csamtools_Fastafile *__pyx_vtabptr_5pysam_9csamtools_Fastafile;
 
 
-/* "pysam/csamtools.pxd":498
- *     pass
+/* "pysam/csamtools.pyx":578
+ *             else: return None
+ * 
+ * cdef class Fastqfile:             # <<<<<<<<<<<<<<
+ *     '''*(filename)*
  * 
- * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
- *     cdef bam_iter_t             iter # iterator state object
- *     cdef bam1_t *               b
  */
-struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion {
-  struct __pyx_obj_5pysam_9csamtools_IteratorRow __pyx_base;
-  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowRegion *__pyx_vtab;
-  bam_iter_t iter;
-  bam1_t *b;
-  int retval;
-  struct __pyx_obj_5pysam_9csamtools_Samfile *samfile;
-  samfile_t *fp;
-  int owns_samfile;
-};
 
+struct __pyx_vtabstruct_5pysam_9csamtools_Fastqfile {
+  kseq_t *(*getCurrent)(struct __pyx_obj_5pysam_9csamtools_Fastqfile *);
+  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_Fastqfile *);
+};
+static struct __pyx_vtabstruct_5pysam_9csamtools_Fastqfile *__pyx_vtabptr_5pysam_9csamtools_Fastqfile;
 
 
-/* "pysam/csamtools.pyx":1921
+/* "pysam/csamtools.pyx":1924
  *     return ret
  * 
  * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
@@ -748,7 +828,7 @@ struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumn {
 static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumn *__pyx_vtabptr_5pysam_9csamtools_IteratorColumn;
 
 
-/* "pysam/csamtools.pyx":2083
+/* "pysam/csamtools.pyx":2086
  *             self.iterdata.seq = NULL
  * 
  * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
@@ -762,22 +842,22 @@ struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnRegion {
 static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnRegion *__pyx_vtabptr_5pysam_9csamtools_IteratorColumnRegion;
 
 
-/* "pysam/csamtools.pyx":1597
- * 
+/* "pysam/csamtools.pyx":1684
+ *         if self.owns_samfile: samclose( self.fp )
  * 
- * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
- *     """*(Samfile samfile, int tid, int beg, int end, int reopen = True )*
+ * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
+ *     """*(Samfile samfile, int reopen = True)*
  * 
  */
 
-struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowRegion {
-  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *);
-  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *);
+struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowAll {
+  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_9csamtools_IteratorRowAll *);
+  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_IteratorRowAll *);
 };
-static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowRegion *__pyx_vtabptr_5pysam_9csamtools_IteratorRowRegion;
+static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowAll *__pyx_vtabptr_5pysam_9csamtools_IteratorRowAll;
 
 
-/* "pysam/csamtools.pyx":1792
+/* "pysam/csamtools.pyx":1795
  *                 raise StopIteration
  * 
  * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
@@ -792,36 +872,25 @@ struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowSelection {
 static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowSelection *__pyx_vtabptr_5pysam_9csamtools_IteratorRowSelection;
 
 
-/* "pysam/csamtools.pyx":382
- * ## Public methods
- * ######################################################################
- * cdef class Fastafile:             # <<<<<<<<<<<<<<
- *     '''*(filename)*
- * 
- */
-
-struct __pyx_vtabstruct_5pysam_9csamtools_Fastafile {
-  char *(*_fetch)(struct __pyx_obj_5pysam_9csamtools_Fastafile *, char *, int, int, int *);
-};
-static struct __pyx_vtabstruct_5pysam_9csamtools_Fastafile *__pyx_vtabptr_5pysam_9csamtools_Fastafile;
-
-
-/* "pysam/csamtools.pyx":546
- *             else: return None
+/* "pysam/csamtools.pyx":684
  * 
- * cdef class Fastqfile:             # <<<<<<<<<<<<<<
- *     '''*(filename)*
  * 
+ * cdef class Samfile:             # <<<<<<<<<<<<<<
+ *     '''*(filename, mode=None, template = None, referencenames = None, referencelengths = None, text = NULL, header = None,
+ *          add_sq_text = False, check_header = True, check_sq = True )*
  */
 
-struct __pyx_vtabstruct_5pysam_9csamtools_Fastqfile {
-  kseq_t *(*getCurrent)(struct __pyx_obj_5pysam_9csamtools_Fastqfile *);
-  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_Fastqfile *);
+struct __pyx_vtabstruct_5pysam_9csamtools_Samfile {
+  bam_header_t *(*_buildHeader)(struct __pyx_obj_5pysam_9csamtools_Samfile *, PyObject *);
+  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_9csamtools_Samfile *);
+  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_Samfile *);
+  int (*write)(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_AlignedRead *, int __pyx_skip_dispatch);
+  char *(*_getrname)(struct __pyx_obj_5pysam_9csamtools_Samfile *, int);
 };
-static struct __pyx_vtabstruct_5pysam_9csamtools_Fastqfile *__pyx_vtabptr_5pysam_9csamtools_Fastqfile;
+static struct __pyx_vtabstruct_5pysam_9csamtools_Samfile *__pyx_vtabptr_5pysam_9csamtools_Samfile;
 
 
-/* "pysam/csamtools.pyx":2120
+/* "pysam/csamtools.pyx":2123
  *                                      self.n_plp )
  * 
  * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
@@ -835,37 +904,19 @@ struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnAllRefs {
 static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnAllRefs *__pyx_vtabptr_5pysam_9csamtools_IteratorColumnAllRefs;
 
 
-/* "pysam/csamtools.pyx":671
+/* "pysam/csamtools.pyx":1600
  * 
  * 
- * cdef class Samfile:             # <<<<<<<<<<<<<<
- *     '''*(filename, mode=None, template = None, referencenames = None, referencelengths = None, text = NULL, header = None,
- *          add_sq_text = False, check_header = True, check_sq = True )*
- */
-
-struct __pyx_vtabstruct_5pysam_9csamtools_Samfile {
-  bam_header_t *(*_buildHeader)(struct __pyx_obj_5pysam_9csamtools_Samfile *, PyObject *);
-  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_9csamtools_Samfile *);
-  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_Samfile *);
-  int (*write)(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_AlignedRead *, int __pyx_skip_dispatch);
-  char *(*_getrname)(struct __pyx_obj_5pysam_9csamtools_Samfile *, int);
-};
-static struct __pyx_vtabstruct_5pysam_9csamtools_Samfile *__pyx_vtabptr_5pysam_9csamtools_Samfile;
-
-
-/* "pysam/csamtools.pyx":1681
- *         if self.owns_samfile: samclose( self.fp )
- * 
- * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
- *     """*(Samfile samfile, int reopen = True)*
+ * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
+ *     """*(Samfile samfile, int tid, int beg, int end, int reopen = True )*
  * 
  */
 
-struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowAll {
-  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_9csamtools_IteratorRowAll *);
-  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_IteratorRowAll *);
+struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowRegion {
+  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *);
+  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *);
 };
-static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowAll *__pyx_vtabptr_5pysam_9csamtools_IteratorRowAll;
+static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowRegion *__pyx_vtabptr_5pysam_9csamtools_IteratorRowRegion;
 #ifndef CYTHON_REFNANNY
   #define CYTHON_REFNANNY 0
 #endif
@@ -992,19 +1043,7 @@ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*pr
 
 static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/
 
-static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/
-
-static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
-    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
-    const char* function_name); /*proto*/
-
-static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
-    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
-
-static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
-    const char *name, int exact); /*proto*/
-
-static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
+static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname);
 
 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
     PyObject *r;
@@ -1108,6 +1147,25 @@ static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
 #define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
 #endif
 
+static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
+
+static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/
+
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
+    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
+    const char* function_name); /*proto*/
+
+static 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 int __Pyx_PySequence_Contains(PyObject* item, PyObject* seq, int eq) {
+    int result = PySequence_Contains(seq, item);
+    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
+}
+
+static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
+    const char *name, int exact); /*proto*/
+
 static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
     if (likely(PyList_CheckExact(L))) {
         if (unlikely(PyList_Append(L, x) < 0)) return NULL;
@@ -1131,11 +1189,6 @@ static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/
 
 static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/
 
-static CYTHON_INLINE int __Pyx_PySequence_Contains(PyObject* item, PyObject* seq, int eq) {
-    int result = PySequence_Contains(seq, item);
-    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
-}
-
 static CYTHON_INLINE int __Pyx_PyDict_Contains(PyObject* item, PyObject* dict, int eq) {
     int result = PyDict_Contains(dict, item);
     return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
@@ -1505,12 +1558,15 @@ static PyTypeObject *__pyx_ptype_5pysam_9csamtools_IndexedReads = 0;
 static PyTypeObject *__pyx_ptype_5pysam_9csamtools_SNPCall = 0;
 static PyTypeObject *__pyx_ptype_5pysam_9csamtools___pyx_scope_struct__genexpr = 0;
 static PyTypeObject *__pyx_ptype_5pysam_9csamtools___pyx_scope_struct_1_genexpr = 0;
+static PyTypeObject *__pyx_ptype_5pysam_9csamtools___pyx_scope_struct_2__open = 0;
+static PyTypeObject *__pyx_ptype_5pysam_9csamtools___pyx_scope_struct_3_genexpr = 0;
+static PyTypeObject *__pyx_ptype_5pysam_9csamtools___pyx_scope_struct_4_genexpr = 0;
 static PyObject *__pyx_v_5pysam_9csamtools__FILENAME_ENCODING = 0;
 static char *__pyx_v_5pysam_9csamtools_CODE2CIGAR;
 static char *__pyx_v_5pysam_9csamtools_bam_nt16_rev_table;
 static int __pyx_v_5pysam_9csamtools_max_pos;
 static PyObject *__pyx_f_5pysam_9csamtools_from_string_and_size(char *, size_t); /*proto*/
-static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *); /*proto*/
+static PyObject *__pyx_f_5pysam_9csamtools__encodeFilename(PyObject *); /*proto*/
 static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *); /*proto*/
 static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools__force_cmdline_bytes(PyObject *); /*proto*/
 static PyObject *__pyx_f_5pysam_9csamtools__charptr_to_str(char *); /*proto*/
@@ -1542,18 +1598,19 @@ static PyObject *__pyx_builtin_ord;
 static PyObject *__pyx_builtin_map;
 static PyObject *__pyx_builtin_ValueError;
 static PyObject *__pyx_builtin_IOError;
+static PyObject *__pyx_builtin_open;
+static PyObject *__pyx_builtin_zip;
+static PyObject *__pyx_builtin_IndexError;
 static PyObject *__pyx_builtin_StopIteration;
 static PyObject *__pyx_builtin_OverflowError;
 static PyObject *__pyx_builtin_NotImplementedError;
 static PyObject *__pyx_builtin_OSError;
 static PyObject *__pyx_builtin_AttributeError;
-static PyObject *__pyx_builtin_zip;
 static PyObject *__pyx_builtin_sorted;
 static PyObject *__pyx_builtin_KeyError;
 static PyObject *__pyx_builtin_min;
 static PyObject *__pyx_builtin_max;
 static PyObject *__pyx_builtin_chr;
-static PyObject *__pyx_builtin_open;
 static PyObject *__pyx_builtin_UnicodeDecodeError;
 static PyObject *__pyx_pf_5pysam_9csamtools_2genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
 static PyObject *__pyx_pf_5pysam_9csamtools_5genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
@@ -1568,11 +1625,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18StderrStoreWindows_4release(CYTHON
 static int __pyx_pf_5pysam_9csamtools_9Fastafile___cinit__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_2_isOpen(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self); /* proto */
 static Py_ssize_t __pyx_pf_5pysam_9csamtools_9Fastafile_4__len__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_5_open_genexpr(PyObject *__pyx_self); /* proto */
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_5_open_3genexpr(PyObject *__pyx_self); /* proto */
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_6_open(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_filename); /* proto */
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_8close(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self); /* proto */
 static void __pyx_pf_5pysam_9csamtools_9Fastafile_10__dealloc__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_8filename___get__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_10references___get__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_11nreferences___get__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_7lengths___get__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region); /* proto */
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_14getReferenceLength(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_16__getitem__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
+static int __pyx_pf_5pysam_9csamtools_9Fastafile_18__contains__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
 static int __pyx_pf_5pysam_9csamtools_10FastqProxy___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_9csamtools_FastqProxy *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_4name___get__(struct __pyx_obj_5pysam_9csamtools_FastqProxy *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_8sequence___get__(struct __pyx_obj_5pysam_9csamtools_FastqProxy *__pyx_v_self); /* proto */
@@ -1586,7 +1651,6 @@ static void __pyx_pf_5pysam_9csamtools_9Fastqfile_8__dealloc__(struct __pyx_obj_
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_8filename___get__(struct __pyx_obj_5pysam_9csamtools_Fastqfile *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_10__iter__(struct __pyx_obj_5pysam_9csamtools_Fastqfile *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_12__next__(struct __pyx_obj_5pysam_9csamtools_Fastqfile *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_14test(struct __pyx_obj_5pysam_9csamtools_Fastqfile *__pyx_v_self); /* proto */
 static int __pyx_pf_5pysam_9csamtools_7Samfile___cinit__(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
 static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_2_isOpen(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_4_hasIndex(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_self); /* proto */
@@ -1761,23 +1825,20 @@ static char __pyx_k_5[] = "\t";
 static char __pyx_k_6[] = "\n";
 static char __pyx_k_7[] = "calling len() on closed file";
 static char __pyx_k_9[] = "could not open file `%s`";
-static char __pyx_k_10[] = "I/O operation on closed file";
-static char __pyx_k_13[] = "no sequence/region supplied.";
-static char __pyx_k_15[] = "invalid region: start (%i) > end (%i)";
-static char __pyx_k_16[] = "";
-static char __pyx_k_17[] = "start out of range (%i)";
-static char __pyx_k_18[] = "end out of range (%i)";
-static char __pyx_k_19[] = "%s:%i-%i";
-static char __pyx_k_21[] = "No such file or directory: %s";
-static char __pyx_k_24[] = "name: %s\n";
-static char __pyx_k_25[] = "comment: %s\n";
-static char __pyx_k_26[] = "seq: %s\n";
-static char __pyx_k_27[] = "qual: %s\n";
-static char __pyx_k_28[] = "return value: %d\n";
-static char __pyx_k_32[] = "invalid file opening mode `%s`";
-static char __pyx_k_34[] = "-";
-static char __pyx_k_35[] = "http:";
-static char __pyx_k_36[] = "ftp:";
+static char __pyx_k_10[] = ".fai";
+static char __pyx_k_11[] = "could not locate index file";
+static char __pyx_k_15[] = "I/O operation on closed file";
+static char __pyx_k_17[] = "no sequence/region supplied.";
+static char __pyx_k_19[] = "invalid region: start (%i) > end (%i)";
+static char __pyx_k_20[] = "";
+static char __pyx_k_21[] = "start out of range (%i)";
+static char __pyx_k_22[] = "end out of range (%i)";
+static char __pyx_k_23[] = "%s:%i-%i";
+static char __pyx_k_25[] = "No such file or directory: %s";
+static char __pyx_k_30[] = "invalid file opening mode `%s`";
+static char __pyx_k_32[] = "-";
+static char __pyx_k_33[] = "http:";
+static char __pyx_k_35[] = "ftp:";
 static char __pyx_k_37[] = "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing";
 static char __pyx_k_38[] = "unequal names and lengths of reference sequences";
 static char __pyx_k_39[] = "@SQ\tSN:%s\tLN:%s\n";
@@ -1807,6 +1868,7 @@ static char __pyx_k_84[] = "counting functionality requires a region/reference";
 static char __pyx_k_87[] = "count for a region is not available for sam files";
 static char __pyx_k_90[] = "no index available for pileup";
 static char __pyx_k_93[] = "pileup of samfiles not implemented yet";
+static char __pyx_k_99[] = "Samfile.mapped only available in bam files";
 static char __pyx_k__A[] = "A";
 static char __pyx_k__B[] = "B";
 static char __pyx_k__C[] = "C";
@@ -1827,108 +1889,108 @@ static char __pyx_k__n[] = "n";
 static char __pyx_k__r[] = "r";
 static char __pyx_k__s[] = "s";
 static char __pyx_k__w[] = "w";
-static char __pyx_k_100[] = "Samfile.mapped only available in bam files";
-static char __pyx_k_102[] = "mapping information not recorded in index or index not available";
-static char __pyx_k_105[] = "Samfile.unmapped only available in bam files";
-static char __pyx_k_110[] = "@";
-static char __pyx_k_112[] = "header line without '@': '%s'";
-static char __pyx_k_114[] = "header line with invalid type '%s': '%s'";
-static char __pyx_k_115[] = ":";
-static char __pyx_k_116[] = "malformatted header: no ':' in field";
-static char __pyx_k_119[] = "unknown field code '%s' in record '%s'";
-static char __pyx_k_120[] = "multiple '%s' lines are not permitted";
-static char __pyx_k_121[] = "@%s";
-static char __pyx_k_122[] = "%s:%s";
-static char __pyx_k_123[] = "invalid type for record %s: %s, expected %s";
-static char __pyx_k_125[] = "incomplete sequence information in '%s'";
-static char __pyx_k_128[] = "can not iterate over samfile without header";
-static char __pyx_k_131[] = "no index available for iteration";
-static char __pyx_k_137[] = "can only use this iterator on bam files";
-static char __pyx_k_138[] = "reference sequence for '%s' (tid=%i) not found";
-static char __pyx_k_139[] = "unknown stepper option `%s` in IteratorColumn";
-static char __pyx_k_141[] = "error during iteration";
-static char __pyx_k_144[] = "Invalid clipping in CIGAR string";
-static char __pyx_k_147[] = "%i%c";
-static char __pyx_k_148[] = "quality and sequence mismatch: %i != %i";
-static char __pyx_k_149[] = "%c";
-static char __pyx_k_150[] = "<";
-static char __pyx_k_152[] = "integer %i out of range of BAM/SAM specification";
-static char __pyx_k_153[] = "2sccI%i%s";
-static char __pyx_k_157[] = "2sc%is";
-static char __pyx_k_159[] = "create_string_buffer";
-static char __pyx_k_160[] = "tag '%s' not present";
-static char __pyx_k_161[] = "unknown auxilliary type '%s'";
-static char __pyx_k_162[] = "Contig index";
-static char __pyx_k_163[] = "Mapped position on contig";
-static char __pyx_k_164[] = "Contig index for mate pair";
-static char __pyx_k_165[] = "Position of mate pair";
-static char __pyx_k_166[] = "Insert size";
-static char __pyx_k_167[] = "Binary flag";
-static char __pyx_k_168[] = "Count of cigar entries";
-static char __pyx_k_169[] = "Cigar entries";
-static char __pyx_k_170[] = "Mapping quality";
-static char __pyx_k_171[] = "Bam index bin number";
-static char __pyx_k_172[] = "Length of query name";
-static char __pyx_k_173[] = "Query name";
-static char __pyx_k_174[] = "Length of query sequence";
-static char __pyx_k_175[] = "Query sequence";
-static char __pyx_k_176[] = "Quality scores";
-static char __pyx_k_177[] = "Length of auxilary data";
-static char __pyx_k_178[] = "Maximum data length";
-static char __pyx_k_179[] = "Current data length";
-static char __pyx_k_180[] = "%-30s %-10s= %s";
-static char __pyx_k_181[] = "(";
-static char __pyx_k_182[] = ")";
-static char __pyx_k_183[] = "This class cannot be instantiated from Python";
-static char __pyx_k_185[] = "PileupProxy accessed after iterator finished";
-static char __pyx_k_189[] = "No such file or directory: '%s'";
-static char __pyx_k_190[] = "-o";
-static char __pyx_k_191[] = "option -o is forbidden in samtools view";
-static char __pyx_k_197[] = "can only IndexReads on bam files";
-static char __pyx_k_198[] = "read %s not found";
-static char __pyx_k_199[] = "number of :term:`filename` associated with this object.";
-static char __pyx_k_200[] = "the query name (None if not present)";
-static char __pyx_k_201[] = "the :term:`cigar` alignment (None if not present). The alignment\n        is returned as a list of tuples of (operation, length). \n        The operations are:\n\n        +-----+--------------+-----+\n        |M    |BAM_CMATCH    |0    |\n        +-----+--------------+-----+\n        |I    |BAM_CINS      |1    |\n        +-----+--------------+-----+\n        |D    |BAM_CDEL      |2    |\n        +-----+--------------+-----+\n        |N    |BAM_CREF_SKIP |3    [...]
-static char __pyx_k_202[] = "the :term:`cigar` alignment as a string.\n        \n        The cigar string is a string of alternating integers\n        and characters denoting the length and the type of\n        an operation.\n\n        .. note::\n            The order length,operation is specified in the\n            SAM format. It is different from the order of\n            the :meth:`cigar` property.\n\n        Returns the empty string if not present.\n        ";
-static char __pyx_k_203[] = "read sequence bases, including :term:`soft clipped` bases \n        (None if not present).\n\n        In Python 3, this property is of type bytes and assigning a\n        unicode string to it consisting of ASCII characters only will\n        work, but is inefficient.\n\n        Note that assigning to seq will invalidate any quality scores.\n        Thus, to in-place edit the sequence and quality scores, copies of\n        the quality scores need to be taken.  [...]
-static char __pyx_k_204[] = "read sequence base qualities, including :term:`soft\n        clipped` bases (None if not present).\n\n        In Python 3, this property is of type bytes and assigning a\n        unicode string to it consisting of ASCII characters only will\n        work, but is inefficient.\n\n        Note that to set quality scores the sequence has to be set\n        previously as this will determine the permitted length of\n        the quality score array.\n\n        This  [...]
-static char __pyx_k_205[] = "aligned portion of the read and excludes any flanking bases that were :term:`soft clipped` (None if not present).\n\n        In Python 3, this property is of type bytes. Assigning a unicode string to it consisting of ASCII characters only will work, but is inefficient.\n\n        SAM/BAM files may included extra flanking bases sequences that were\n        not part of the alignment.  These bases may be the result of the\n        Smith-Waterman or other algorit [...]
-static char __pyx_k_206[] = "aligned query sequence quality values (None if not present). This property is read-only.\n\n        In Python 3, this property is of type bytes.";
-static char __pyx_k_207[] = "start index of the aligned query portion of the sequence (0-based, inclusive)";
-static char __pyx_k_208[] = "end index of the aligned query portion of the sequence (0-based, exclusive)";
-static char __pyx_k_209[] = "Length of the aligned query sequence";
-static char __pyx_k_210[] = "the tags in the AUX field.\n\n        This property permits convenience access to\n        the tags. Changes it the returned list will\n        not update the tags automatically. Instead,\n        the following is required for adding a\n        new tag::\n\n            read.tags = read.tags + [(\"RG\",0)]\n\n\n        This method will happily write the same tag\n        multiple times.\n        ";
-static char __pyx_k_211[] = "properties flag";
-static char __pyx_k_212[] = "\n        :term:`target` ID\n\n        DEPRECATED from pysam-0.4 - use tid in the future.\n        The rname field caused a lot of confusion as it returns\n        the :term:`target` ID instead of the reference sequence\n        name.\n\n        .. note::\n\n            This field contains the index of the reference sequence\n            in the sequence dictionary. To obtain the name\n            of the reference sequence, use :meth:`pysam.Samfile.getrname()` [...]
-static char __pyx_k_213[] = "\n        :term:`target` ID\n\n        .. note::\n\n            This field contains the index of the reference sequence\n            in the sequence dictionary. To obtain the name\n            of the reference sequence, use :meth:`pysam.Samfile.getrname()`\n\n        ";
-static char __pyx_k_214[] = "0-based leftmost coordinate";
-static char __pyx_k_215[] = "properties bin";
-static char __pyx_k_216[] = "length of the read (read only). Returns 0 if not given.";
-static char __pyx_k_217[] = "aligned reference position of the read on the reference genome.  \n        \n        aend points to one past the last aligned residue.\n        Returns None if not available.";
-static char __pyx_k_218[] = "aligned length of the read on the reference genome.  Returns None if\n        not available.";
-static char __pyx_k_219[] = "mapping quality";
-static char __pyx_k_220[] = "the :term:`reference` id of the mate\n        deprecated, use RNEXT instead.\n        ";
-static char __pyx_k_221[] = "the :term:`reference` id of the mate ";
-static char __pyx_k_222[] = "the position of the mate\n        deprecated, use PNEXT instead.";
-static char __pyx_k_223[] = "the position of the mate";
-static char __pyx_k_224[] = "the insert size\n        deprecated: use tlen instead";
-static char __pyx_k_225[] = "the insert size";
-static char __pyx_k_226[] = "true if read is paired in sequencing";
-static char __pyx_k_227[] = "true if read is mapped in a proper pair";
-static char __pyx_k_228[] = "true if read itself is unmapped";
-static char __pyx_k_229[] = "true if the mate is unmapped";
-static char __pyx_k_230[] = "true if read is mapped to reverse strand";
-static char __pyx_k_231[] = "true is read is mapped to reverse strand";
-static char __pyx_k_232[] = "true if this is read1";
-static char __pyx_k_233[] = "true if this is read2";
-static char __pyx_k_234[] = "true if not primary alignment";
-static char __pyx_k_235[] = "true if QC failure";
-static char __pyx_k_236[] = "true if optical or PCR duplicate";
-static char __pyx_k_237[] = "a list of reference positions that this read aligns to.";
-static char __pyx_k_238[] = "inferred read length from CIGAR string.\n\n        Returns 0 if CIGAR string is not present.\n        ";
-static char __pyx_k_239[] = "a list of aligned read and reference positions.\n\n       Unaligned position are marked by None.\n       ";
-static char __pyx_k_240[] = "number of :term:`reference` sequences in the file.";
-static char __pyx_k_241[] = "tuple with the names of :term:`reference` sequences.";
+static char __pyx_k_101[] = "mapping information not recorded in index or index not available";
+static char __pyx_k_104[] = "Samfile.unmapped only available in bam files";
+static char __pyx_k_109[] = "@";
+static char __pyx_k_111[] = "header line without '@': '%s'";
+static char __pyx_k_113[] = "header line with invalid type '%s': '%s'";
+static char __pyx_k_114[] = ":";
+static char __pyx_k_115[] = "malformatted header: no ':' in field";
+static char __pyx_k_118[] = "unknown field code '%s' in record '%s'";
+static char __pyx_k_119[] = "multiple '%s' lines are not permitted";
+static char __pyx_k_120[] = "@%s";
+static char __pyx_k_121[] = "%s:%s";
+static char __pyx_k_122[] = "invalid type for record %s: %s, expected %s";
+static char __pyx_k_124[] = "incomplete sequence information in '%s'";
+static char __pyx_k_127[] = "can not iterate over samfile without header";
+static char __pyx_k_130[] = "no index available for iteration";
+static char __pyx_k_136[] = "can only use this iterator on bam files";
+static char __pyx_k_137[] = "reference sequence for '%s' (tid=%i) not found";
+static char __pyx_k_138[] = "unknown stepper option `%s` in IteratorColumn";
+static char __pyx_k_140[] = "error during iteration";
+static char __pyx_k_143[] = "Invalid clipping in CIGAR string";
+static char __pyx_k_146[] = "%i%c";
+static char __pyx_k_147[] = "quality and sequence mismatch: %i != %i";
+static char __pyx_k_148[] = "%c";
+static char __pyx_k_149[] = "<";
+static char __pyx_k_151[] = "integer %i out of range of BAM/SAM specification";
+static char __pyx_k_152[] = "2sccI%i%s";
+static char __pyx_k_156[] = "2sc%is";
+static char __pyx_k_158[] = "create_string_buffer";
+static char __pyx_k_159[] = "tag '%s' not present";
+static char __pyx_k_160[] = "unknown auxilliary type '%s'";
+static char __pyx_k_161[] = "Contig index";
+static char __pyx_k_162[] = "Mapped position on contig";
+static char __pyx_k_163[] = "Contig index for mate pair";
+static char __pyx_k_164[] = "Position of mate pair";
+static char __pyx_k_165[] = "Insert size";
+static char __pyx_k_166[] = "Binary flag";
+static char __pyx_k_167[] = "Count of cigar entries";
+static char __pyx_k_168[] = "Cigar entries";
+static char __pyx_k_169[] = "Mapping quality";
+static char __pyx_k_170[] = "Bam index bin number";
+static char __pyx_k_171[] = "Length of query name";
+static char __pyx_k_172[] = "Query name";
+static char __pyx_k_173[] = "Length of query sequence";
+static char __pyx_k_174[] = "Query sequence";
+static char __pyx_k_175[] = "Quality scores";
+static char __pyx_k_176[] = "Length of auxilary data";
+static char __pyx_k_177[] = "Maximum data length";
+static char __pyx_k_178[] = "Current data length";
+static char __pyx_k_179[] = "%-30s %-10s= %s";
+static char __pyx_k_180[] = "(";
+static char __pyx_k_181[] = ")";
+static char __pyx_k_182[] = "This class cannot be instantiated from Python";
+static char __pyx_k_184[] = "PileupProxy accessed after iterator finished";
+static char __pyx_k_188[] = "No such file or directory: '%s'";
+static char __pyx_k_189[] = "-o";
+static char __pyx_k_190[] = "option -o is forbidden in samtools view";
+static char __pyx_k_196[] = "can only IndexReads on bam files";
+static char __pyx_k_197[] = "read %s not found";
+static char __pyx_k_198[] = "number of :term:`filename` associated with this object.";
+static char __pyx_k_199[] = "tuple with the names of :term:`reference` sequences.";
+static char __pyx_k_200[] = "number of :term:`reference` sequences in the file.";
+static char __pyx_k_201[] = "tuple with the lengths of :term:`reference` sequences.";
+static char __pyx_k_202[] = "the query name (None if not present)";
+static char __pyx_k_203[] = "the :term:`cigar` alignment (None if not present). The alignment\n        is returned as a list of tuples of (operation, length). \n        The operations are:\n\n        +-----+--------------+-----+\n        |M    |BAM_CMATCH    |0    |\n        +-----+--------------+-----+\n        |I    |BAM_CINS      |1    |\n        +-----+--------------+-----+\n        |D    |BAM_CDEL      |2    |\n        +-----+--------------+-----+\n        |N    |BAM_CREF_SKIP |3    [...]
+static char __pyx_k_204[] = "the :term:`cigar` alignment as a string.\n        \n        The cigar string is a string of alternating integers\n        and characters denoting the length and the type of\n        an operation.\n\n        .. note::\n            The order length,operation is specified in the\n            SAM format. It is different from the order of\n            the :meth:`cigar` property.\n\n        Returns the empty string if not present.\n        ";
+static char __pyx_k_205[] = "read sequence bases, including :term:`soft clipped` bases \n        (None if not present).\n\n        In Python 3, this property is of type bytes and assigning a\n        unicode string to it consisting of ASCII characters only will\n        work, but is inefficient.\n\n        Note that assigning to seq will invalidate any quality scores.\n        Thus, to in-place edit the sequence and quality scores, copies of\n        the quality scores need to be taken.  [...]
+static char __pyx_k_206[] = "read sequence base qualities, including :term:`soft\n        clipped` bases (None if not present).\n\n        In Python 3, this property is of type bytes and assigning a\n        unicode string to it consisting of ASCII characters only will\n        work, but is inefficient.\n\n        Note that to set quality scores the sequence has to be set\n        previously as this will determine the permitted length of\n        the quality score array.\n\n        This  [...]
+static char __pyx_k_207[] = "aligned portion of the read and excludes any flanking bases\n        that were :term:`soft clipped` (None if not present).\n\n        In Python 3, this property is of type bytes. Assigning a\n        unicode string to it consisting of ASCII characters only will\n        work, but is inefficient.\n\n        SAM/BAM files may included extra flanking bases sequences that were\n        not part of the alignment.  These bases may be the result of the\n        Smit [...]
+static char __pyx_k_208[] = "aligned query sequence quality values (None if not\n        present). This property is read-only.\n\n        In Python 3, this property is of type bytes.";
+static char __pyx_k_209[] = "start index of the aligned query portion of the sequence (0-based, inclusive)";
+static char __pyx_k_210[] = "end index of the aligned query portion of the sequence (0-based, exclusive)";
+static char __pyx_k_211[] = "Length of the aligned query sequence";
+static char __pyx_k_212[] = "the tags in the AUX field.\n\n        This property permits convenience access to\n        the tags. Changes it the returned list will\n        not update the tags automatically. Instead,\n        the following is required for adding a\n        new tag::\n\n            read.tags = read.tags + [(\"RG\",0)]\n\n\n        This method will happily write the same tag\n        multiple times.\n        ";
+static char __pyx_k_213[] = "properties flag";
+static char __pyx_k_214[] = "\n        :term:`target` ID\n\n        DEPRECATED from pysam-0.4 - use tid in the future.\n        The rname field caused a lot of confusion as it returns\n        the :term:`target` ID instead of the reference sequence\n        name.\n\n        .. note::\n\n            This field contains the index of the reference sequence\n            in the sequence dictionary. To obtain the name\n            of the reference sequence, use :meth:`pysam.Samfile.getrname()` [...]
+static char __pyx_k_215[] = "\n        :term:`target` ID\n\n        .. note::\n\n            This field contains the index of the reference sequence\n            in the sequence dictionary. To obtain the name\n            of the reference sequence, use :meth:`pysam.Samfile.getrname()`\n\n        ";
+static char __pyx_k_216[] = "0-based leftmost coordinate";
+static char __pyx_k_217[] = "properties bin";
+static char __pyx_k_218[] = "length of the read (read only). Returns 0 if not given.";
+static char __pyx_k_219[] = "aligned reference position of the read on the reference genome.  \n        \n        aend points to one past the last aligned residue.\n        Returns None if not available.";
+static char __pyx_k_220[] = "aligned length of the read on the reference genome.  Returns None if\n        not available.";
+static char __pyx_k_221[] = "mapping quality";
+static char __pyx_k_222[] = "the :term:`reference` id of the mate\n        deprecated, use RNEXT instead.\n        ";
+static char __pyx_k_223[] = "the :term:`reference` id of the mate ";
+static char __pyx_k_224[] = "the position of the mate\n        deprecated, use PNEXT instead.";
+static char __pyx_k_225[] = "the position of the mate";
+static char __pyx_k_226[] = "the insert size\n        deprecated: use tlen instead";
+static char __pyx_k_227[] = "the insert size";
+static char __pyx_k_228[] = "true if read is paired in sequencing";
+static char __pyx_k_229[] = "true if read is mapped in a proper pair";
+static char __pyx_k_230[] = "true if read itself is unmapped";
+static char __pyx_k_231[] = "true if the mate is unmapped";
+static char __pyx_k_232[] = "true if read is mapped to reverse strand";
+static char __pyx_k_233[] = "true is read is mapped to reverse strand";
+static char __pyx_k_234[] = "true if this is read1";
+static char __pyx_k_235[] = "true if this is read2";
+static char __pyx_k_236[] = "true if not primary alignment";
+static char __pyx_k_237[] = "true if QC failure";
+static char __pyx_k_238[] = "true if optical or PCR duplicate";
+static char __pyx_k_239[] = "a list of reference positions that this read aligns to.";
+static char __pyx_k_240[] = "inferred read length from CIGAR string.\n\n        Returns 0 if CIGAR string is not present.\n        ";
+static char __pyx_k_241[] = "a list of aligned read and reference positions.\n\n       Unaligned position are marked by None.\n       ";
 static char __pyx_k_242[] = "tuple of the lengths of the :term:`reference` sequences. The lengths are in the same order as\n        :attr:`pysam.Samfile.references`\n        ";
 static char __pyx_k_243[] = "total number of mapped reads in file.\n        ";
 static char __pyx_k_244[] = "total number of unmapped reads in file.\n        ";
@@ -2066,6 +2128,7 @@ static char __pyx_k__bqual[] = "bqual";
 static char __pyx_k__cargs[] = "cargs";
 static char __pyx_k__cigar[] = "cigar";
 static char __pyx_k__close[] = "close";
+static char __pyx_k__fetch[] = "fetch";
 static char __pyx_k__flush[] = "flush";
 static char __pyx_k__indel[] = "indel";
 static char __pyx_k__index[] = "index";
@@ -2179,6 +2242,7 @@ static char __pyx_k__traceback[] = "traceback";
 static char __pyx_k__until_eof[] = "until_eof";
 static char __pyx_k__CIGAR2CODE[] = "CIGAR2CODE";
 static char __pyx_k__IS_PYTHON3[] = "IS_PYTHON3";
+static char __pyx_k__IndexError[] = "IndexError";
 static char __pyx_k__PileupRead[] = "PileupRead";
 static char __pyx_k__ValueError[] = "ValueError";
 static char __pyx_k___buildLine[] = "_buildLine";
@@ -2224,39 +2288,37 @@ static char __pyx_k__getdefaultencoding[] = "getdefaultencoding";
 static char __pyx_k__NotImplementedError[] = "NotImplementedError";
 static char __pyx_k__VALID_HEADER_FIELDS[] = "VALID_HEADER_FIELDS";
 static PyObject *__pyx_kp_u_1;
-static PyObject *__pyx_kp_s_10;
-static PyObject *__pyx_kp_s_100;
-static PyObject *__pyx_kp_s_102;
-static PyObject *__pyx_kp_s_105;
-static PyObject *__pyx_kp_s_110;
-static PyObject *__pyx_kp_s_112;
+static PyObject *__pyx_kp_b_10;
+static PyObject *__pyx_kp_s_101;
+static PyObject *__pyx_kp_s_104;
+static PyObject *__pyx_kp_s_109;
+static PyObject *__pyx_kp_s_11;
+static PyObject *__pyx_kp_s_111;
+static PyObject *__pyx_kp_s_113;
 static PyObject *__pyx_kp_s_114;
 static PyObject *__pyx_kp_s_115;
-static PyObject *__pyx_kp_s_116;
+static PyObject *__pyx_kp_s_118;
 static PyObject *__pyx_kp_s_119;
 static PyObject *__pyx_kp_s_120;
 static PyObject *__pyx_kp_s_121;
 static PyObject *__pyx_kp_s_122;
-static PyObject *__pyx_kp_s_123;
-static PyObject *__pyx_kp_s_125;
-static PyObject *__pyx_kp_s_128;
-static PyObject *__pyx_kp_s_13;
-static PyObject *__pyx_kp_s_131;
+static PyObject *__pyx_kp_s_124;
+static PyObject *__pyx_kp_s_127;
+static PyObject *__pyx_kp_s_130;
+static PyObject *__pyx_kp_s_136;
 static PyObject *__pyx_kp_s_137;
 static PyObject *__pyx_kp_s_138;
-static PyObject *__pyx_kp_s_139;
-static PyObject *__pyx_kp_s_141;
+static PyObject *__pyx_kp_s_140;
+static PyObject *__pyx_kp_s_146;
 static PyObject *__pyx_kp_s_147;
 static PyObject *__pyx_kp_s_148;
 static PyObject *__pyx_kp_s_149;
 static PyObject *__pyx_kp_s_15;
-static PyObject *__pyx_kp_s_150;
+static PyObject *__pyx_kp_s_151;
 static PyObject *__pyx_kp_s_152;
-static PyObject *__pyx_kp_s_153;
-static PyObject *__pyx_kp_s_157;
-static PyObject *__pyx_n_s_159;
-static PyObject *__pyx_kp_b_16;
-static PyObject *__pyx_kp_s_16;
+static PyObject *__pyx_kp_s_156;
+static PyObject *__pyx_n_s_158;
+static PyObject *__pyx_kp_s_159;
 static PyObject *__pyx_kp_s_160;
 static PyObject *__pyx_kp_s_161;
 static PyObject *__pyx_kp_s_162;
@@ -2278,19 +2340,22 @@ static PyObject *__pyx_kp_s_176;
 static PyObject *__pyx_kp_s_177;
 static PyObject *__pyx_kp_s_178;
 static PyObject *__pyx_kp_s_179;
-static PyObject *__pyx_kp_s_18;
 static PyObject *__pyx_kp_s_180;
 static PyObject *__pyx_kp_s_181;
 static PyObject *__pyx_kp_s_182;
-static PyObject *__pyx_kp_s_183;
-static PyObject *__pyx_kp_s_185;
+static PyObject *__pyx_kp_s_184;
+static PyObject *__pyx_kp_s_188;
 static PyObject *__pyx_kp_s_189;
 static PyObject *__pyx_kp_s_19;
 static PyObject *__pyx_kp_s_190;
-static PyObject *__pyx_kp_s_191;
+static PyObject *__pyx_kp_s_196;
 static PyObject *__pyx_kp_s_197;
-static PyObject *__pyx_kp_s_198;
+static PyObject *__pyx_kp_b_20;
+static PyObject *__pyx_kp_s_20;
 static PyObject *__pyx_kp_s_21;
+static PyObject *__pyx_kp_s_22;
+static PyObject *__pyx_kp_s_23;
+static PyObject *__pyx_kp_s_25;
 static PyObject *__pyx_n_s_262;
 static PyObject *__pyx_kp_s_264;
 static PyObject *__pyx_kp_s_269;
@@ -2307,13 +2372,16 @@ static PyObject *__pyx_n_s_291;
 static PyObject *__pyx_n_s_294;
 static PyObject *__pyx_kp_s_295;
 static PyObject *__pyx_kp_u_3;
+static PyObject *__pyx_kp_s_30;
 static PyObject *__pyx_n_s_304;
 static PyObject *__pyx_n_s_307;
 static PyObject *__pyx_n_s_310;
 static PyObject *__pyx_n_s_313;
 static PyObject *__pyx_n_s_316;
 static PyObject *__pyx_kp_s_317;
-static PyObject *__pyx_kp_s_32;
+static PyObject *__pyx_kp_b_32;
+static PyObject *__pyx_kp_b_33;
+static PyObject *__pyx_kp_b_35;
 static PyObject *__pyx_kp_s_37;
 static PyObject *__pyx_kp_s_38;
 static PyObject *__pyx_kp_s_39;
@@ -2347,6 +2415,7 @@ static PyObject *__pyx_kp_s_87;
 static PyObject *__pyx_kp_s_9;
 static PyObject *__pyx_kp_s_90;
 static PyObject *__pyx_kp_s_93;
+static PyObject *__pyx_kp_s_99;
 static PyObject *__pyx_kp_s__2scB;
 static PyObject *__pyx_kp_s__2scH;
 static PyObject *__pyx_kp_s__2scI;
@@ -2380,6 +2449,7 @@ static PyObject *__pyx_n_s__I;
 static PyObject *__pyx_n_s__ID;
 static PyObject *__pyx_n_s__IOError;
 static PyObject *__pyx_n_s__IS_PYTHON3;
+static PyObject *__pyx_n_s__IndexError;
 static PyObject *__pyx_n_s__IndexedReads;
 static PyObject *__pyx_n_s__IteratorColumn;
 static PyObject *__pyx_n_s__IteratorRow;
@@ -2482,6 +2552,7 @@ static PyObject *__pyx_n_s__extend;
 static PyObject *__pyx_n_s__f;
 static PyObject *__pyx_n_s__fastafile;
 static PyObject *__pyx_n_s__fd;
+static PyObject *__pyx_n_s__fetch;
 static PyObject *__pyx_n_s__fields;
 static PyObject *__pyx_n_s__filename;
 static PyObject *__pyx_n_s__fileno;
@@ -2642,23 +2713,26 @@ static PyObject *__pyx_int_neg_32767;
 static PyObject *__pyx_int_536870912;
 static PyObject *__pyx_int_4294967295;
 static PyObject *__pyx_int_neg_2147483648;
+static PyObject *__pyx_k_27;
+static PyObject *__pyx_k_28;
 static PyObject *__pyx_k_29;
-static PyObject *__pyx_k_30;
-static PyObject *__pyx_k_31;
 static PyObject *__pyx_k_62;
 static PyObject *__pyx_k_81;
-static int __pyx_k_140;
-static PyObject *__pyx_k_188;
+static int __pyx_k_139;
+static PyObject *__pyx_k_187;
 static PyObject *__pyx_k_tuple_2;
 static PyObject *__pyx_k_tuple_4;
 static PyObject *__pyx_k_tuple_8;
-static PyObject *__pyx_k_tuple_11;
 static PyObject *__pyx_k_tuple_12;
+static PyObject *__pyx_k_tuple_13;
 static PyObject *__pyx_k_tuple_14;
-static PyObject *__pyx_k_tuple_20;
-static PyObject *__pyx_k_tuple_22;
-static PyObject *__pyx_k_tuple_23;
-static PyObject *__pyx_k_tuple_33;
+static PyObject *__pyx_k_tuple_16;
+static PyObject *__pyx_k_tuple_18;
+static PyObject *__pyx_k_tuple_24;
+static PyObject *__pyx_k_tuple_26;
+static PyObject *__pyx_k_tuple_31;
+static PyObject *__pyx_k_tuple_34;
+static PyObject *__pyx_k_tuple_36;
 static PyObject *__pyx_k_tuple_47;
 static PyObject *__pyx_k_tuple_48;
 static PyObject *__pyx_k_tuple_50;
@@ -2690,45 +2764,44 @@ static PyObject *__pyx_k_tuple_95;
 static PyObject *__pyx_k_tuple_96;
 static PyObject *__pyx_k_tuple_97;
 static PyObject *__pyx_k_tuple_98;
-static PyObject *__pyx_k_tuple_99;
-static PyObject *__pyx_k_tuple_101;
+static PyObject *__pyx_k_tuple_100;
+static PyObject *__pyx_k_tuple_102;
 static PyObject *__pyx_k_tuple_103;
-static PyObject *__pyx_k_tuple_104;
+static PyObject *__pyx_k_tuple_105;
 static PyObject *__pyx_k_tuple_106;
 static PyObject *__pyx_k_tuple_107;
 static PyObject *__pyx_k_tuple_108;
-static PyObject *__pyx_k_tuple_109;
-static PyObject *__pyx_k_tuple_111;
-static PyObject *__pyx_k_tuple_113;
+static PyObject *__pyx_k_tuple_110;
+static PyObject *__pyx_k_tuple_112;
+static PyObject *__pyx_k_tuple_116;
 static PyObject *__pyx_k_tuple_117;
-static PyObject *__pyx_k_tuple_118;
-static PyObject *__pyx_k_tuple_124;
+static PyObject *__pyx_k_tuple_123;
+static PyObject *__pyx_k_tuple_125;
 static PyObject *__pyx_k_tuple_126;
-static PyObject *__pyx_k_tuple_127;
+static PyObject *__pyx_k_tuple_128;
 static PyObject *__pyx_k_tuple_129;
-static PyObject *__pyx_k_tuple_130;
+static PyObject *__pyx_k_tuple_131;
 static PyObject *__pyx_k_tuple_132;
 static PyObject *__pyx_k_tuple_133;
 static PyObject *__pyx_k_tuple_134;
 static PyObject *__pyx_k_tuple_135;
-static PyObject *__pyx_k_tuple_136;
+static PyObject *__pyx_k_tuple_141;
 static PyObject *__pyx_k_tuple_142;
-static PyObject *__pyx_k_tuple_143;
+static PyObject *__pyx_k_tuple_144;
 static PyObject *__pyx_k_tuple_145;
-static PyObject *__pyx_k_tuple_146;
-static PyObject *__pyx_k_tuple_151;
+static PyObject *__pyx_k_tuple_150;
+static PyObject *__pyx_k_tuple_153;
 static PyObject *__pyx_k_tuple_154;
 static PyObject *__pyx_k_tuple_155;
-static PyObject *__pyx_k_tuple_156;
-static PyObject *__pyx_k_tuple_158;
-static PyObject *__pyx_k_tuple_184;
+static PyObject *__pyx_k_tuple_157;
+static PyObject *__pyx_k_tuple_183;
+static PyObject *__pyx_k_tuple_185;
 static PyObject *__pyx_k_tuple_186;
-static PyObject *__pyx_k_tuple_187;
+static PyObject *__pyx_k_tuple_191;
 static PyObject *__pyx_k_tuple_192;
 static PyObject *__pyx_k_tuple_193;
 static PyObject *__pyx_k_tuple_194;
 static PyObject *__pyx_k_tuple_195;
-static PyObject *__pyx_k_tuple_196;
 static PyObject *__pyx_k_tuple_265;
 static PyObject *__pyx_k_tuple_267;
 static PyObject *__pyx_k_tuple_273;
@@ -2766,7 +2839,7 @@ static PyObject *__pyx_k_codeobj_315;
 static PyObject *__pyx_k_codeobj_319;
 static PyObject *__pyx_gb_5pysam_9csamtools_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
 
-/* "pysam/csamtools.pyx":140
+/* "pysam/csamtools.pyx":139
  * cdef char* CODE2CIGAR= "MIDNSHP=X"
  * if IS_PYTHON3:
  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
@@ -2789,9 +2862,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_2genexpr(CYTHON_UNUSED PyObject *__p
     return NULL;
   }
   __Pyx_GOTREF(__pyx_cur_scope);
-  __Pyx_TraceCall("genexpr", __pyx_f[0], 140);
+  __Pyx_TraceCall("genexpr", __pyx_f[0], 139);
   {
-    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5pysam_9csamtools_4generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5pysam_9csamtools_4generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_cur_scope);
     __Pyx_RefNannyFinishContext();
     return (PyObject *) gen;
@@ -2828,12 +2901,12 @@ static PyObject *__pyx_gb_5pysam_9csamtools_4generator(__pyx_GeneratorObject *__
     return NULL;
   }
   __pyx_L3_first_run:;
-  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_INCREF(__pyx_int_0);
   __pyx_t_1 = __pyx_int_0;
-  __pyx_t_2 = PyBytes_FromString(__pyx_v_5pysam_9csamtools_CODE2CIGAR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyBytes_FromString(__pyx_v_5pysam_9csamtools_CODE2CIGAR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-  __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext;
   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
@@ -2843,7 +2916,7 @@ static PyObject *__pyx_gb_5pysam_9csamtools_4generator(__pyx_GeneratorObject *__
       if (unlikely(!__pyx_t_2)) {
         if (PyErr_Occurred()) {
           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         break;
       }
@@ -2859,12 +2932,12 @@ static PyObject *__pyx_gb_5pysam_9csamtools_4generator(__pyx_GeneratorObject *__
     __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_x);
     __Pyx_GIVEREF(__pyx_t_1);
     __pyx_cur_scope->__pyx_v_x = __pyx_t_1;
-    __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_t_1);
     __pyx_t_1 = __pyx_t_2;
     __pyx_t_2 = 0;
-    __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_INCREF(__pyx_cur_scope->__pyx_v_y);
     PyList_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_y);
@@ -2892,7 +2965,7 @@ static PyObject *__pyx_gb_5pysam_9csamtools_4generator(__pyx_GeneratorObject *__
     __pyx_cur_scope->__pyx_t_1 = 0;
     __Pyx_XGOTREF(__pyx_t_3);
     __pyx_t_4 = __pyx_cur_scope->__pyx_t_2;
-    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -2912,7 +2985,7 @@ static PyObject *__pyx_gb_5pysam_9csamtools_4generator(__pyx_GeneratorObject *__
 }
 static PyObject *__pyx_gb_5pysam_9csamtools_7generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
 
-/* "pysam/csamtools.pyx":142
+/* "pysam/csamtools.pyx":141
  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
  * else:
  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
@@ -2935,9 +3008,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_5genexpr(CYTHON_UNUSED PyObject *__p
     return NULL;
   }
   __Pyx_GOTREF(__pyx_cur_scope);
-  __Pyx_TraceCall("genexpr", __pyx_f[0], 142);
+  __Pyx_TraceCall("genexpr", __pyx_f[0], 141);
   {
-    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5pysam_9csamtools_7generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5pysam_9csamtools_7generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_cur_scope);
     __Pyx_RefNannyFinishContext();
     return (PyObject *) gen;
@@ -2975,12 +3048,12 @@ static PyObject *__pyx_gb_5pysam_9csamtools_7generator1(__pyx_GeneratorObject *_
     return NULL;
   }
   __pyx_L3_first_run:;
-  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_INCREF(__pyx_int_0);
   __pyx_t_1 = __pyx_int_0;
-  __pyx_t_2 = PyBytes_FromString(__pyx_v_5pysam_9csamtools_CODE2CIGAR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyBytes_FromString(__pyx_v_5pysam_9csamtools_CODE2CIGAR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-  __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext;
   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
@@ -2990,7 +3063,7 @@ static PyObject *__pyx_gb_5pysam_9csamtools_7generator1(__pyx_GeneratorObject *_
       if (unlikely(!__pyx_t_2)) {
         if (PyErr_Occurred()) {
           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         break;
       }
@@ -3006,20 +3079,20 @@ static PyObject *__pyx_gb_5pysam_9csamtools_7generator1(__pyx_GeneratorObject *_
     __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_x);
     __Pyx_GIVEREF(__pyx_t_1);
     __pyx_cur_scope->__pyx_v_x = __pyx_t_1;
-    __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_t_1);
     __pyx_t_1 = __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 = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_INCREF(__pyx_cur_scope->__pyx_v_y);
     PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_y);
     __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_y);
-    __pyx_t_5 = PyObject_Call(__pyx_builtin_ord, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyObject_Call(__pyx_builtin_ord, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
-    __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
     __Pyx_GIVEREF(__pyx_t_5);
@@ -3047,7 +3120,7 @@ static PyObject *__pyx_gb_5pysam_9csamtools_7generator1(__pyx_GeneratorObject *_
     __pyx_cur_scope->__pyx_t_1 = 0;
     __Pyx_XGOTREF(__pyx_t_3);
     __pyx_t_4 = __pyx_cur_scope->__pyx_t_2;
-    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -3146,12 +3219,12 @@ static PyObject *__pyx_f_5pysam_9csamtools_from_string_and_size(char *__pyx_v_s,
 /* "pysam/csamtools.pyx":41
  * #_C_FILENAME_ENCODING = <char*>_FILENAME_ENCODING
  * 
- * cdef bytes _my_encodeFilename(object filename):             # <<<<<<<<<<<<<<
- *     u"""Make sure a filename is 8-bit encoded (or None).
- *     """
+ * cdef bytes _encodeFilename(object filename):             # <<<<<<<<<<<<<<
+ *     """Make sure a filename is 8-bit encoded (or None)."""
+ *     if filename is None:
  */
 
-static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *__pyx_v_filename) {
+static PyObject *__pyx_f_5pysam_9csamtools__encodeFilename(PyObject *__pyx_v_filename) {
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
   int __pyx_t_1;
@@ -3162,12 +3235,12 @@ static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *__pyx_v_
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
-  __Pyx_RefNannySetupContext("_my_encodeFilename", 0);
-  __Pyx_TraceCall("_my_encodeFilename", __pyx_f[0], 41);
+  __Pyx_RefNannySetupContext("_encodeFilename", 0);
+  __Pyx_TraceCall("_encodeFilename", __pyx_f[0], 41);
 
-  /* "pysam/csamtools.pyx":44
- *     u"""Make sure a filename is 8-bit encoded (or None).
- *     """
+  /* "pysam/csamtools.pyx":43
+ * cdef bytes _encodeFilename(object filename):
+ *     """Make sure a filename is 8-bit encoded (or None)."""
  *     if filename is None:             # <<<<<<<<<<<<<<
  *         return None
  *     elif PyBytes_Check(filename):
@@ -3175,8 +3248,8 @@ static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *__pyx_v_
   __pyx_t_1 = (__pyx_v_filename == Py_None);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":45
- *     """
+    /* "pysam/csamtools.pyx":44
+ *     """Make sure a filename is 8-bit encoded (or None)."""
  *     if filename is None:
  *         return None             # <<<<<<<<<<<<<<
  *     elif PyBytes_Check(filename):
@@ -3189,7 +3262,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *__pyx_v_
     goto __pyx_L3;
   }
 
-  /* "pysam/csamtools.pyx":46
+  /* "pysam/csamtools.pyx":45
  *     if filename is None:
  *         return None
  *     elif PyBytes_Check(filename):             # <<<<<<<<<<<<<<
@@ -3199,7 +3272,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *__pyx_v_
   __pyx_t_1 = PyBytes_Check(__pyx_v_filename);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":47
+    /* "pysam/csamtools.pyx":46
  *         return None
  *     elif PyBytes_Check(filename):
  *         return filename             # <<<<<<<<<<<<<<
@@ -3207,14 +3280,14 @@ static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *__pyx_v_
  *         return filename.encode(_FILENAME_ENCODING)
  */
     __Pyx_XDECREF(((PyObject *)__pyx_r));
-    if (!(likely(PyBytes_CheckExact(__pyx_v_filename))||((__pyx_v_filename) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_filename)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_v_filename))||((__pyx_v_filename) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_filename)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_INCREF(__pyx_v_filename);
     __pyx_r = ((PyObject*)__pyx_v_filename);
     goto __pyx_L0;
     goto __pyx_L3;
   }
 
-  /* "pysam/csamtools.pyx":48
+  /* "pysam/csamtools.pyx":47
  *     elif PyBytes_Check(filename):
  *         return filename
  *     elif PyUnicode_Check(filename):             # <<<<<<<<<<<<<<
@@ -3224,7 +3297,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *__pyx_v_
   __pyx_t_1 = PyUnicode_Check(__pyx_v_filename);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":49
+    /* "pysam/csamtools.pyx":48
  *         return filename
  *     elif PyUnicode_Check(filename):
  *         return filename.encode(_FILENAME_ENCODING)             # <<<<<<<<<<<<<<
@@ -3232,18 +3305,18 @@ static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *__pyx_v_
  *         raise TypeError, u"Argument must be string or unicode."
  */
     __Pyx_XDECREF(((PyObject *)__pyx_r));
-    __pyx_t_2 = PyObject_GetAttr(__pyx_v_filename, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_v_filename, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_INCREF(((PyObject *)__pyx_v_5pysam_9csamtools__FILENAME_ENCODING));
     PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_5pysam_9csamtools__FILENAME_ENCODING));
     __Pyx_GIVEREF(((PyObject *)__pyx_v_5pysam_9csamtools__FILENAME_ENCODING));
-    __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __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_3)); __pyx_t_3 = 0;
-    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_r = ((PyObject*)__pyx_t_4);
     __pyx_t_4 = 0;
     goto __pyx_L0;
@@ -3251,7 +3324,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *__pyx_v_
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":51
+    /* "pysam/csamtools.pyx":50
  *         return filename.encode(_FILENAME_ENCODING)
  *     else:
  *         raise TypeError, u"Argument must be string or unicode."             # <<<<<<<<<<<<<<
@@ -3259,7 +3332,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *__pyx_v_
  * 
  */
     __Pyx_Raise(__pyx_builtin_TypeError, ((PyObject *)__pyx_kp_u_1), 0, 0);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L3:;
 
@@ -3269,7 +3342,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *__pyx_v_
   __Pyx_XDECREF(__pyx_t_2);
   __Pyx_XDECREF(__pyx_t_3);
   __Pyx_XDECREF(__pyx_t_4);
-  __Pyx_AddTraceback("pysam.csamtools._my_encodeFilename", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_AddTraceback("pysam.csamtools._encodeFilename", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __pyx_r = 0;
   __pyx_L0:;
   __Pyx_XGIVEREF(__pyx_r);
@@ -3278,7 +3351,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__my_encodeFilename(PyObject *__pyx_v_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":54
+/* "pysam/csamtools.pyx":53
  * 
  * 
  * cdef bytes _force_bytes(object s):             # <<<<<<<<<<<<<<
@@ -3297,9 +3370,9 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *__pyx_v_s) {
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_force_bytes", 0);
-  __Pyx_TraceCall("_force_bytes", __pyx_f[0], 54);
+  __Pyx_TraceCall("_force_bytes", __pyx_f[0], 53);
 
-  /* "pysam/csamtools.pyx":57
+  /* "pysam/csamtools.pyx":56
  *     u"""convert string or unicode object to bytes, assuming ascii encoding.
  *     """
  *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
@@ -3309,7 +3382,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *__pyx_v_s) {
   __pyx_t_1 = (PY_MAJOR_VERSION < 3);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":58
+    /* "pysam/csamtools.pyx":57
  *     """
  *     if PY_MAJOR_VERSION < 3:
  *         return s             # <<<<<<<<<<<<<<
@@ -3317,14 +3390,14 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *__pyx_v_s) {
  *         return None
  */
     __Pyx_XDECREF(((PyObject *)__pyx_r));
-    if (!(likely(PyBytes_CheckExact(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_s)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_s)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_INCREF(__pyx_v_s);
     __pyx_r = ((PyObject*)__pyx_v_s);
     goto __pyx_L0;
     goto __pyx_L3;
   }
 
-  /* "pysam/csamtools.pyx":59
+  /* "pysam/csamtools.pyx":58
  *     if PY_MAJOR_VERSION < 3:
  *         return s
  *     elif s is None:             # <<<<<<<<<<<<<<
@@ -3334,7 +3407,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *__pyx_v_s) {
   __pyx_t_1 = (__pyx_v_s == Py_None);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":60
+    /* "pysam/csamtools.pyx":59
  *         return s
  *     elif s is None:
  *         return None             # <<<<<<<<<<<<<<
@@ -3348,7 +3421,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *__pyx_v_s) {
     goto __pyx_L3;
   }
 
-  /* "pysam/csamtools.pyx":61
+  /* "pysam/csamtools.pyx":60
  *     elif s is None:
  *         return None
  *     elif PyBytes_Check(s):             # <<<<<<<<<<<<<<
@@ -3358,7 +3431,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *__pyx_v_s) {
   __pyx_t_1 = PyBytes_Check(__pyx_v_s);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":62
+    /* "pysam/csamtools.pyx":61
  *         return None
  *     elif PyBytes_Check(s):
  *         return s             # <<<<<<<<<<<<<<
@@ -3366,14 +3439,14 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *__pyx_v_s) {
  *         return s.encode('ascii')
  */
     __Pyx_XDECREF(((PyObject *)__pyx_r));
-    if (!(likely(PyBytes_CheckExact(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_s)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_s)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_INCREF(__pyx_v_s);
     __pyx_r = ((PyObject*)__pyx_v_s);
     goto __pyx_L0;
     goto __pyx_L3;
   }
 
-  /* "pysam/csamtools.pyx":63
+  /* "pysam/csamtools.pyx":62
  *     elif PyBytes_Check(s):
  *         return s
  *     elif PyUnicode_Check(s):             # <<<<<<<<<<<<<<
@@ -3383,7 +3456,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *__pyx_v_s) {
   __pyx_t_1 = PyUnicode_Check(__pyx_v_s);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":64
+    /* "pysam/csamtools.pyx":63
  *         return s
  *     elif PyUnicode_Check(s):
  *         return s.encode('ascii')             # <<<<<<<<<<<<<<
@@ -3391,12 +3464,12 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *__pyx_v_s) {
  *         raise TypeError, u"Argument must be string, bytes or unicode."
  */
     __Pyx_XDECREF(((PyObject *)__pyx_r));
-    __pyx_t_2 = PyObject_GetAttr(__pyx_v_s, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_v_s, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_r = ((PyObject*)__pyx_t_3);
     __pyx_t_3 = 0;
     goto __pyx_L0;
@@ -3404,7 +3477,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *__pyx_v_s) {
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":66
+    /* "pysam/csamtools.pyx":65
  *         return s.encode('ascii')
  *     else:
  *         raise TypeError, u"Argument must be string, bytes or unicode."             # <<<<<<<<<<<<<<
@@ -3412,7 +3485,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *__pyx_v_s) {
  * cdef inline bytes _force_cmdline_bytes(object s):
  */
     __Pyx_Raise(__pyx_builtin_TypeError, ((PyObject *)__pyx_kp_u_3), 0, 0);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L3:;
 
@@ -3430,7 +3503,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_bytes(PyObject *__pyx_v_s) {
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":68
+/* "pysam/csamtools.pyx":67
  *         raise TypeError, u"Argument must be string, bytes or unicode."
  * 
  * cdef inline bytes _force_cmdline_bytes(object s):             # <<<<<<<<<<<<<<
@@ -3447,9 +3520,9 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools__force_cmdline_bytes(Py
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_force_cmdline_bytes", 0);
-  __Pyx_TraceCall("_force_cmdline_bytes", __pyx_f[0], 68);
+  __Pyx_TraceCall("_force_cmdline_bytes", __pyx_f[0], 67);
 
-  /* "pysam/csamtools.pyx":69
+  /* "pysam/csamtools.pyx":68
  * 
  * cdef inline bytes _force_cmdline_bytes(object s):
  *     return _force_bytes(s)             # <<<<<<<<<<<<<<
@@ -3457,7 +3530,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools__force_cmdline_bytes(Py
  * cdef _charptr_to_str(char* s):
  */
   __Pyx_XDECREF(((PyObject *)__pyx_r));
-  __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_s)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_s)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
@@ -3476,7 +3549,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools__force_cmdline_bytes(Py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":71
+/* "pysam/csamtools.pyx":70
  *     return _force_bytes(s)
  * 
  * cdef _charptr_to_str(char* s):             # <<<<<<<<<<<<<<
@@ -3494,9 +3567,9 @@ static PyObject *__pyx_f_5pysam_9csamtools__charptr_to_str(char *__pyx_v_s) {
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_charptr_to_str", 0);
-  __Pyx_TraceCall("_charptr_to_str", __pyx_f[0], 71);
+  __Pyx_TraceCall("_charptr_to_str", __pyx_f[0], 70);
 
-  /* "pysam/csamtools.pyx":72
+  /* "pysam/csamtools.pyx":71
  * 
  * cdef _charptr_to_str(char* s):
  *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
@@ -3506,7 +3579,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__charptr_to_str(char *__pyx_v_s) {
   __pyx_t_1 = (PY_MAJOR_VERSION < 3);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":73
+    /* "pysam/csamtools.pyx":72
  * cdef _charptr_to_str(char* s):
  *     if PY_MAJOR_VERSION < 3:
  *         return s             # <<<<<<<<<<<<<<
@@ -3514,7 +3587,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__charptr_to_str(char *__pyx_v_s) {
  *         return s.decode("ascii")
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
     __pyx_r = ((PyObject *)__pyx_t_2);
     __pyx_t_2 = 0;
@@ -3523,7 +3596,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__charptr_to_str(char *__pyx_v_s) {
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":75
+    /* "pysam/csamtools.pyx":74
  *         return s
  *     else:
  *         return s.decode("ascii")             # <<<<<<<<<<<<<<
@@ -3531,7 +3604,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__charptr_to_str(char *__pyx_v_s) {
  * cdef _force_str(object s):
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_s, 0, strlen(__pyx_v_s), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_s, 0, strlen(__pyx_v_s), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
     __pyx_r = ((PyObject *)__pyx_t_2);
     __pyx_t_2 = 0;
@@ -3552,7 +3625,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__charptr_to_str(char *__pyx_v_s) {
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":77
+/* "pysam/csamtools.pyx":76
  *         return s.decode("ascii")
  * 
  * cdef _force_str(object s):             # <<<<<<<<<<<<<<
@@ -3571,9 +3644,9 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_str(PyObject *__pyx_v_s) {
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_force_str", 0);
-  __Pyx_TraceCall("_force_str", __pyx_f[0], 77);
+  __Pyx_TraceCall("_force_str", __pyx_f[0], 76);
 
-  /* "pysam/csamtools.pyx":79
+  /* "pysam/csamtools.pyx":78
  * cdef _force_str(object s):
  *     """Return s converted to str type of current Python (bytes in Py2, unicode in Py3)"""
  *     if s is None:             # <<<<<<<<<<<<<<
@@ -3583,7 +3656,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_str(PyObject *__pyx_v_s) {
   __pyx_t_1 = (__pyx_v_s == Py_None);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":80
+    /* "pysam/csamtools.pyx":79
  *     """Return s converted to str type of current Python (bytes in Py2, unicode in Py3)"""
  *     if s is None:
  *         return None             # <<<<<<<<<<<<<<
@@ -3598,7 +3671,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_str(PyObject *__pyx_v_s) {
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":81
+  /* "pysam/csamtools.pyx":80
  *     if s is None:
  *         return None
  *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
@@ -3608,7 +3681,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_str(PyObject *__pyx_v_s) {
   __pyx_t_1 = (PY_MAJOR_VERSION < 3);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":82
+    /* "pysam/csamtools.pyx":81
  *         return None
  *     if PY_MAJOR_VERSION < 3:
  *         return s             # <<<<<<<<<<<<<<
@@ -3622,7 +3695,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_str(PyObject *__pyx_v_s) {
     goto __pyx_L4;
   }
 
-  /* "pysam/csamtools.pyx":83
+  /* "pysam/csamtools.pyx":82
  *     if PY_MAJOR_VERSION < 3:
  *         return s
  *     elif PyBytes_Check(s):             # <<<<<<<<<<<<<<
@@ -3632,7 +3705,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_str(PyObject *__pyx_v_s) {
   __pyx_t_1 = PyBytes_Check(__pyx_v_s);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":84
+    /* "pysam/csamtools.pyx":83
  *         return s
  *     elif PyBytes_Check(s):
  *         return s.decode('ascii')             # <<<<<<<<<<<<<<
@@ -3640,9 +3713,9 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_str(PyObject *__pyx_v_s) {
  *         # assume unicode
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = PyObject_GetAttr(__pyx_v_s, __pyx_n_s__decode); 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_v_s, __pyx_n_s__decode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __pyx_r = __pyx_t_3;
@@ -3652,7 +3725,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_str(PyObject *__pyx_v_s) {
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":87
+    /* "pysam/csamtools.pyx":86
  *     else:
  *         # assume unicode
  *         return s             # <<<<<<<<<<<<<<
@@ -3680,7 +3753,7 @@ static PyObject *__pyx_f_5pysam_9csamtools__force_str(PyObject *__pyx_v_s) {
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":160
+/* "pysam/csamtools.pyx":159
  * #####################################################################
  * cdef class AlignedRead
  * cdef makeAlignedRead(bam1_t * src):             # <<<<<<<<<<<<<<
@@ -3698,22 +3771,22 @@ static PyObject *__pyx_f_5pysam_9csamtools_makeAlignedRead(bam1_t *__pyx_v_src)
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("makeAlignedRead", 0);
-  __Pyx_TraceCall("makeAlignedRead", __pyx_f[0], 160);
+  __Pyx_TraceCall("makeAlignedRead", __pyx_f[0], 159);
 
-  /* "pysam/csamtools.pyx":162
+  /* "pysam/csamtools.pyx":161
  * cdef makeAlignedRead(bam1_t * src):
  *     '''enter src into AlignedRead.'''
  *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)             # <<<<<<<<<<<<<<
  *     dest._delegate = bam_dup1(src)
  *     return dest
  */
-  __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5pysam_9csamtools_AlignedRead)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5pysam_9csamtools_AlignedRead)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9csamtools_AlignedRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9csamtools_AlignedRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_dest = ((struct __pyx_obj_5pysam_9csamtools_AlignedRead *)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":163
+  /* "pysam/csamtools.pyx":162
  *     '''enter src into AlignedRead.'''
  *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
  *     dest._delegate = bam_dup1(src)             # <<<<<<<<<<<<<<
@@ -3722,7 +3795,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makeAlignedRead(bam1_t *__pyx_v_src)
  */
   __pyx_v_dest->_delegate = bam_dup1(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":164
+  /* "pysam/csamtools.pyx":163
  *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
  *     dest._delegate = bam_dup1(src)
  *     return dest             # <<<<<<<<<<<<<<
@@ -3748,7 +3821,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makeAlignedRead(bam1_t *__pyx_v_src)
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":167
+/* "pysam/csamtools.pyx":166
  * 
  * cdef class PileupProxy
  * cdef makePileupProxy( bam_pileup1_t ** plp, int tid, int pos, int n ):             # <<<<<<<<<<<<<<
@@ -3766,22 +3839,22 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupProxy(bam_pileup1_t **__pyx
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("makePileupProxy", 0);
-  __Pyx_TraceCall("makePileupProxy", __pyx_f[0], 167);
+  __Pyx_TraceCall("makePileupProxy", __pyx_f[0], 166);
 
-  /* "pysam/csamtools.pyx":168
+  /* "pysam/csamtools.pyx":167
  * cdef class PileupProxy
  * cdef makePileupProxy( bam_pileup1_t ** plp, int tid, int pos, int n ):
  *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)             # <<<<<<<<<<<<<<
  *      dest.plp = plp
  *      dest.tid = tid
  */
-  __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5pysam_9csamtools_PileupProxy)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5pysam_9csamtools_PileupProxy)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9csamtools_PileupProxy)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9csamtools_PileupProxy)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_dest = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":169
+  /* "pysam/csamtools.pyx":168
  * cdef makePileupProxy( bam_pileup1_t ** plp, int tid, int pos, int n ):
  *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
  *      dest.plp = plp             # <<<<<<<<<<<<<<
@@ -3790,7 +3863,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupProxy(bam_pileup1_t **__pyx
  */
   __pyx_v_dest->plp = __pyx_v_plp;
 
-  /* "pysam/csamtools.pyx":170
+  /* "pysam/csamtools.pyx":169
  *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
  *      dest.plp = plp
  *      dest.tid = tid             # <<<<<<<<<<<<<<
@@ -3799,7 +3872,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupProxy(bam_pileup1_t **__pyx
  */
   __pyx_v_dest->tid = __pyx_v_tid;
 
-  /* "pysam/csamtools.pyx":171
+  /* "pysam/csamtools.pyx":170
  *      dest.plp = plp
  *      dest.tid = tid
  *      dest.pos = pos             # <<<<<<<<<<<<<<
@@ -3808,19 +3881,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupProxy(bam_pileup1_t **__pyx
  */
   __pyx_v_dest->pos = __pyx_v_pos;
 
-  /* "pysam/csamtools.pyx":172
+  /* "pysam/csamtools.pyx":171
  *      dest.tid = tid
  *      dest.pos = pos
  *      dest.n = n             # <<<<<<<<<<<<<<
  *      return dest
  * 
  */
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyObject_SetAttr(((PyObject *)__pyx_v_dest), __pyx_n_s__n, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(((PyObject *)__pyx_v_dest), __pyx_n_s__n, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":173
+  /* "pysam/csamtools.pyx":172
  *      dest.pos = pos
  *      dest.n = n
  *      return dest             # <<<<<<<<<<<<<<
@@ -3846,7 +3919,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupProxy(bam_pileup1_t **__pyx
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":176
+/* "pysam/csamtools.pyx":175
  * 
  * cdef class PileupRead
  * cdef makePileupRead( bam_pileup1_t * src ):             # <<<<<<<<<<<<<<
@@ -3867,38 +3940,38 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupRead(bam_pileup1_t *__pyx_v
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("makePileupRead", 0);
-  __Pyx_TraceCall("makePileupRead", __pyx_f[0], 176);
+  __Pyx_TraceCall("makePileupRead", __pyx_f[0], 175);
 
-  /* "pysam/csamtools.pyx":178
+  /* "pysam/csamtools.pyx":177
  * cdef makePileupRead( bam_pileup1_t * src ):
  *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
  *     cdef PileupRead dest = PileupRead.__new__(PileupRead)             # <<<<<<<<<<<<<<
  *     dest._alignment = makeAlignedRead( src.b )
  *     dest._qpos = src.qpos
  */
-  __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5pysam_9csamtools_PileupRead)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5pysam_9csamtools_PileupRead)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9csamtools_PileupRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9csamtools_PileupRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_dest = ((struct __pyx_obj_5pysam_9csamtools_PileupRead *)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":179
+  /* "pysam/csamtools.pyx":178
  *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
  *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
  *     dest._alignment = makeAlignedRead( src.b )             # <<<<<<<<<<<<<<
  *     dest._qpos = src.qpos
  *     dest._indel = src.indel
  */
-  __pyx_t_1 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_src->b); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_src->b); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9csamtools_AlignedRead))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9csamtools_AlignedRead))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GIVEREF(__pyx_t_1);
   __Pyx_GOTREF(__pyx_v_dest->_alignment);
   __Pyx_DECREF(((PyObject *)__pyx_v_dest->_alignment));
   __pyx_v_dest->_alignment = ((struct __pyx_obj_5pysam_9csamtools_AlignedRead *)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":180
+  /* "pysam/csamtools.pyx":179
  *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
  *     dest._alignment = makeAlignedRead( src.b )
  *     dest._qpos = src.qpos             # <<<<<<<<<<<<<<
@@ -3908,7 +3981,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupRead(bam_pileup1_t *__pyx_v
   __pyx_t_2 = __pyx_v_src->qpos;
   __pyx_v_dest->_qpos = __pyx_t_2;
 
-  /* "pysam/csamtools.pyx":181
+  /* "pysam/csamtools.pyx":180
  *     dest._alignment = makeAlignedRead( src.b )
  *     dest._qpos = src.qpos
  *     dest._indel = src.indel             # <<<<<<<<<<<<<<
@@ -3918,7 +3991,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupRead(bam_pileup1_t *__pyx_v
   __pyx_t_3 = __pyx_v_src->indel;
   __pyx_v_dest->_indel = __pyx_t_3;
 
-  /* "pysam/csamtools.pyx":182
+  /* "pysam/csamtools.pyx":181
  *     dest._qpos = src.qpos
  *     dest._indel = src.indel
  *     dest._level = src.level             # <<<<<<<<<<<<<<
@@ -3928,7 +4001,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupRead(bam_pileup1_t *__pyx_v
   __pyx_t_3 = __pyx_v_src->level;
   __pyx_v_dest->_level = __pyx_t_3;
 
-  /* "pysam/csamtools.pyx":183
+  /* "pysam/csamtools.pyx":182
  *     dest._indel = src.indel
  *     dest._level = src.level
  *     dest._is_del = src.is_del             # <<<<<<<<<<<<<<
@@ -3938,7 +4011,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupRead(bam_pileup1_t *__pyx_v
   __pyx_t_4 = __pyx_v_src->is_del;
   __pyx_v_dest->_is_del = __pyx_t_4;
 
-  /* "pysam/csamtools.pyx":184
+  /* "pysam/csamtools.pyx":183
  *     dest._level = src.level
  *     dest._is_del = src.is_del
  *     dest._is_head = src.is_head             # <<<<<<<<<<<<<<
@@ -3948,7 +4021,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupRead(bam_pileup1_t *__pyx_v
   __pyx_t_4 = __pyx_v_src->is_head;
   __pyx_v_dest->_is_head = __pyx_t_4;
 
-  /* "pysam/csamtools.pyx":185
+  /* "pysam/csamtools.pyx":184
  *     dest._is_del = src.is_del
  *     dest._is_head = src.is_head
  *     dest._is_tail = src.is_tail             # <<<<<<<<<<<<<<
@@ -3958,7 +4031,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupRead(bam_pileup1_t *__pyx_v
   __pyx_t_4 = __pyx_v_src->is_tail;
   __pyx_v_dest->_is_tail = __pyx_t_4;
 
-  /* "pysam/csamtools.pyx":186
+  /* "pysam/csamtools.pyx":185
  *     dest._is_head = src.is_head
  *     dest._is_tail = src.is_tail
  *     return dest             # <<<<<<<<<<<<<<
@@ -3984,7 +4057,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makePileupRead(bam_pileup1_t *__pyx_v
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":189
+/* "pysam/csamtools.pyx":188
  * 
  * cdef class FastqProxy
  * cdef makeFastqProxy( kseq_t * src):             # <<<<<<<<<<<<<<
@@ -4002,22 +4075,22 @@ static PyObject *__pyx_f_5pysam_9csamtools_makeFastqProxy(kseq_t *__pyx_v_src) {
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("makeFastqProxy", 0);
-  __Pyx_TraceCall("makeFastqProxy", __pyx_f[0], 189);
+  __Pyx_TraceCall("makeFastqProxy", __pyx_f[0], 188);
 
-  /* "pysam/csamtools.pyx":191
+  /* "pysam/csamtools.pyx":190
  * cdef makeFastqProxy( kseq_t * src):
  *     '''enter src into AlignedRead.'''
  *     cdef FastqProxy dest = FastqProxy.__new__(FastqProxy)             # <<<<<<<<<<<<<<
  *     dest._delegate = src
  *     return dest
  */
-  __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5pysam_9csamtools_FastqProxy)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5pysam_9csamtools_FastqProxy)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9csamtools_FastqProxy)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9csamtools_FastqProxy)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_dest = ((struct __pyx_obj_5pysam_9csamtools_FastqProxy *)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":192
+  /* "pysam/csamtools.pyx":191
  *     '''enter src into AlignedRead.'''
  *     cdef FastqProxy dest = FastqProxy.__new__(FastqProxy)
  *     dest._delegate = src             # <<<<<<<<<<<<<<
@@ -4026,7 +4099,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makeFastqProxy(kseq_t *__pyx_v_src) {
  */
   __pyx_v_dest->_delegate = __pyx_v_src;
 
-  /* "pysam/csamtools.pyx":193
+  /* "pysam/csamtools.pyx":192
  *     cdef FastqProxy dest = FastqProxy.__new__(FastqProxy)
  *     dest._delegate = src
  *     return dest             # <<<<<<<<<<<<<<
@@ -4052,7 +4125,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_makeFastqProxy(kseq_t *__pyx_v_src) {
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":195
+/* "pysam/csamtools.pyx":194
  *     return dest
  * 
  * cdef convertBinaryTagToList( uint8_t * s ):             # <<<<<<<<<<<<<<
@@ -4079,9 +4152,9 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("convertBinaryTagToList", 0);
-  __Pyx_TraceCall("convertBinaryTagToList", __pyx_f[0], 195);
+  __Pyx_TraceCall("convertBinaryTagToList", __pyx_f[0], 194);
 
-  /* "pysam/csamtools.pyx":202
+  /* "pysam/csamtools.pyx":201
  * 
  *     # get byte size
  *     auxtype = s[0]             # <<<<<<<<<<<<<<
@@ -4090,7 +4163,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
  */
   __pyx_v_auxtype = (__pyx_v_s[0]);
 
-  /* "pysam/csamtools.pyx":203
+  /* "pysam/csamtools.pyx":202
  *     # get byte size
  *     auxtype = s[0]
  *     byte_size = bam_aux_type2size( auxtype )             # <<<<<<<<<<<<<<
@@ -4099,7 +4172,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
  */
   __pyx_v_byte_size = bam_aux_type2size(__pyx_v_auxtype);
 
-  /* "pysam/csamtools.pyx":204
+  /* "pysam/csamtools.pyx":203
  *     auxtype = s[0]
  *     byte_size = bam_aux_type2size( auxtype )
  *     s += 1             # <<<<<<<<<<<<<<
@@ -4108,7 +4181,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
  */
   __pyx_v_s = (__pyx_v_s + 1);
 
-  /* "pysam/csamtools.pyx":206
+  /* "pysam/csamtools.pyx":205
  *     s += 1
  *     # get number of values in array
  *     nvalues = (<int32_t*>s)[0]             # <<<<<<<<<<<<<<
@@ -4117,7 +4190,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
  */
   __pyx_v_nvalues = (((int32_t *)__pyx_v_s)[0]);
 
-  /* "pysam/csamtools.pyx":207
+  /* "pysam/csamtools.pyx":206
  *     # get number of values in array
  *     nvalues = (<int32_t*>s)[0]
  *     s += 4             # <<<<<<<<<<<<<<
@@ -4126,19 +4199,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
  */
   __pyx_v_s = (__pyx_v_s + 4);
 
-  /* "pysam/csamtools.pyx":209
+  /* "pysam/csamtools.pyx":208
  *     s += 4
  *     # get values
  *     values = []             # <<<<<<<<<<<<<<
  *     if auxtype == 'c':
  *         for x from 0 <= x < nvalues:
  */
-  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_values = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":210
+  /* "pysam/csamtools.pyx":209
  *     # get values
  *     values = []
  *     if auxtype == 'c':             # <<<<<<<<<<<<<<
@@ -4148,7 +4221,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
   __pyx_t_2 = (__pyx_v_auxtype == 'c');
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":211
+    /* "pysam/csamtools.pyx":210
  *     values = []
  *     if auxtype == 'c':
  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
@@ -4158,19 +4231,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     __pyx_t_3 = __pyx_v_nvalues;
     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
 
-      /* "pysam/csamtools.pyx":212
+      /* "pysam/csamtools.pyx":211
  *     if auxtype == 'c':
  *         for x from 0 <= x < nvalues:
  *             values.append((<int8_t*>s)[0])             # <<<<<<<<<<<<<<
  *             s += 1
  *     elif auxtype == 'C':
  */
-      __pyx_t_1 = __Pyx_PyInt_to_py_int8_t((((int8_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_PyInt_to_py_int8_t((((int8_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-      /* "pysam/csamtools.pyx":213
+      /* "pysam/csamtools.pyx":212
  *         for x from 0 <= x < nvalues:
  *             values.append((<int8_t*>s)[0])
  *             s += 1             # <<<<<<<<<<<<<<
@@ -4182,7 +4255,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     goto __pyx_L3;
   }
 
-  /* "pysam/csamtools.pyx":214
+  /* "pysam/csamtools.pyx":213
  *             values.append((<int8_t*>s)[0])
  *             s += 1
  *     elif auxtype == 'C':             # <<<<<<<<<<<<<<
@@ -4192,7 +4265,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
   __pyx_t_2 = (__pyx_v_auxtype == 'C');
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":215
+    /* "pysam/csamtools.pyx":214
  *             s += 1
  *     elif auxtype == 'C':
  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
@@ -4202,19 +4275,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     __pyx_t_3 = __pyx_v_nvalues;
     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
 
-      /* "pysam/csamtools.pyx":216
+      /* "pysam/csamtools.pyx":215
  *     elif auxtype == 'C':
  *         for x from 0 <= x < nvalues:
  *             values.append((<uint8_t*>s)[0])             # <<<<<<<<<<<<<<
  *             s += 1
  *     elif auxtype == 's':
  */
-      __pyx_t_1 = __Pyx_PyInt_to_py_uint8_t((((uint8_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_PyInt_to_py_uint8_t((((uint8_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-      /* "pysam/csamtools.pyx":217
+      /* "pysam/csamtools.pyx":216
  *         for x from 0 <= x < nvalues:
  *             values.append((<uint8_t*>s)[0])
  *             s += 1             # <<<<<<<<<<<<<<
@@ -4226,7 +4299,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     goto __pyx_L3;
   }
 
-  /* "pysam/csamtools.pyx":218
+  /* "pysam/csamtools.pyx":217
  *             values.append((<uint8_t*>s)[0])
  *             s += 1
  *     elif auxtype == 's':             # <<<<<<<<<<<<<<
@@ -4236,7 +4309,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
   __pyx_t_2 = (__pyx_v_auxtype == 's');
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":219
+    /* "pysam/csamtools.pyx":218
  *             s += 1
  *     elif auxtype == 's':
  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
@@ -4246,19 +4319,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     __pyx_t_3 = __pyx_v_nvalues;
     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
 
-      /* "pysam/csamtools.pyx":220
+      /* "pysam/csamtools.pyx":219
  *     elif auxtype == 's':
  *         for x from 0 <= x < nvalues:
  *             values.append((<int16_t*>s)[0])             # <<<<<<<<<<<<<<
  *             s += 2
  *     elif auxtype == 'S':
  */
-      __pyx_t_1 = __Pyx_PyInt_to_py_int16_t((((int16_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_PyInt_to_py_int16_t((((int16_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-      /* "pysam/csamtools.pyx":221
+      /* "pysam/csamtools.pyx":220
  *         for x from 0 <= x < nvalues:
  *             values.append((<int16_t*>s)[0])
  *             s += 2             # <<<<<<<<<<<<<<
@@ -4270,7 +4343,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     goto __pyx_L3;
   }
 
-  /* "pysam/csamtools.pyx":222
+  /* "pysam/csamtools.pyx":221
  *             values.append((<int16_t*>s)[0])
  *             s += 2
  *     elif auxtype == 'S':             # <<<<<<<<<<<<<<
@@ -4280,7 +4353,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
   __pyx_t_2 = (__pyx_v_auxtype == 'S');
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":223
+    /* "pysam/csamtools.pyx":222
  *             s += 2
  *     elif auxtype == 'S':
  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
@@ -4290,19 +4363,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     __pyx_t_3 = __pyx_v_nvalues;
     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
 
-      /* "pysam/csamtools.pyx":224
+      /* "pysam/csamtools.pyx":223
  *     elif auxtype == 'S':
  *         for x from 0 <= x < nvalues:
  *             values.append((<uint16_t*>s)[0])             # <<<<<<<<<<<<<<
  *             s += 2
  *     elif auxtype == 'i':
  */
-      __pyx_t_1 = __Pyx_PyInt_to_py_uint16_t((((uint16_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_PyInt_to_py_uint16_t((((uint16_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-      /* "pysam/csamtools.pyx":225
+      /* "pysam/csamtools.pyx":224
  *         for x from 0 <= x < nvalues:
  *             values.append((<uint16_t*>s)[0])
  *             s += 2             # <<<<<<<<<<<<<<
@@ -4314,7 +4387,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     goto __pyx_L3;
   }
 
-  /* "pysam/csamtools.pyx":226
+  /* "pysam/csamtools.pyx":225
  *             values.append((<uint16_t*>s)[0])
  *             s += 2
  *     elif auxtype == 'i':             # <<<<<<<<<<<<<<
@@ -4324,7 +4397,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
   __pyx_t_2 = (__pyx_v_auxtype == 'i');
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":227
+    /* "pysam/csamtools.pyx":226
  *             s += 2
  *     elif auxtype == 'i':
  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
@@ -4334,19 +4407,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     __pyx_t_3 = __pyx_v_nvalues;
     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
 
-      /* "pysam/csamtools.pyx":228
+      /* "pysam/csamtools.pyx":227
  *     elif auxtype == 'i':
  *         for x from 0 <= x < nvalues:
  *             values.append((<int32_t*>s)[0])             # <<<<<<<<<<<<<<
  *             s += 4
  *     elif auxtype == 'I':
  */
-      __pyx_t_1 = __Pyx_PyInt_to_py_int32_t((((int32_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_PyInt_to_py_int32_t((((int32_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-      /* "pysam/csamtools.pyx":229
+      /* "pysam/csamtools.pyx":228
  *         for x from 0 <= x < nvalues:
  *             values.append((<int32_t*>s)[0])
  *             s += 4             # <<<<<<<<<<<<<<
@@ -4358,7 +4431,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     goto __pyx_L3;
   }
 
-  /* "pysam/csamtools.pyx":230
+  /* "pysam/csamtools.pyx":229
  *             values.append((<int32_t*>s)[0])
  *             s += 4
  *     elif auxtype == 'I':             # <<<<<<<<<<<<<<
@@ -4368,7 +4441,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
   __pyx_t_2 = (__pyx_v_auxtype == 'I');
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":231
+    /* "pysam/csamtools.pyx":230
  *             s += 4
  *     elif auxtype == 'I':
  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
@@ -4378,19 +4451,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     __pyx_t_3 = __pyx_v_nvalues;
     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
 
-      /* "pysam/csamtools.pyx":232
+      /* "pysam/csamtools.pyx":231
  *     elif auxtype == 'I':
  *         for x from 0 <= x < nvalues:
  *             values.append((<uint32_t*>s)[0])             # <<<<<<<<<<<<<<
  *             s += 4
  *     elif auxtype == 'f':
  */
-      __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t((((uint32_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t((((uint32_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-      /* "pysam/csamtools.pyx":233
+      /* "pysam/csamtools.pyx":232
  *         for x from 0 <= x < nvalues:
  *             values.append((<uint32_t*>s)[0])
  *             s += 4             # <<<<<<<<<<<<<<
@@ -4402,7 +4475,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     goto __pyx_L3;
   }
 
-  /* "pysam/csamtools.pyx":234
+  /* "pysam/csamtools.pyx":233
  *             values.append((<uint32_t*>s)[0])
  *             s += 4
  *     elif auxtype == 'f':             # <<<<<<<<<<<<<<
@@ -4412,7 +4485,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
   __pyx_t_2 = (__pyx_v_auxtype == 'f');
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":235
+    /* "pysam/csamtools.pyx":234
  *             s += 4
  *     elif auxtype == 'f':
  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
@@ -4422,19 +4495,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
     __pyx_t_3 = __pyx_v_nvalues;
     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
 
-      /* "pysam/csamtools.pyx":236
+      /* "pysam/csamtools.pyx":235
  *     elif auxtype == 'f':
  *         for x from 0 <= x < nvalues:
  *             values.append((<float*>s)[0])             # <<<<<<<<<<<<<<
  *             s += 4
  * 
  */
-      __pyx_t_1 = PyFloat_FromDouble((((float *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyFloat_FromDouble((((float *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-      /* "pysam/csamtools.pyx":237
+      /* "pysam/csamtools.pyx":236
  *         for x from 0 <= x < nvalues:
  *             values.append((<float*>s)[0])
  *             s += 4             # <<<<<<<<<<<<<<
@@ -4447,7 +4520,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":239
+  /* "pysam/csamtools.pyx":238
  *             s += 4
  * 
  *     return byte_size, nvalues, values             # <<<<<<<<<<<<<<
@@ -4455,11 +4528,11 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
  * #####################################################################
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_uint8_t(__pyx_v_byte_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_uint8_t(__pyx_v_byte_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_5 = __Pyx_PyInt_to_py_int32_t(__pyx_v_nvalues); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyInt_to_py_int32_t(__pyx_v_nvalues); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
-  __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_6);
   PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
   __Pyx_GIVEREF(__pyx_t_1);
@@ -4490,7 +4563,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_convertBinaryTagToList(uint8_t *__pyx
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":246
+/* "pysam/csamtools.pyx":245
  * ## Generic callbacks for inserting python callbacks.
  * #####################################################################
  * cdef int fetch_callback( bam1_t *alignment, void *f):             # <<<<<<<<<<<<<<
@@ -4509,33 +4582,33 @@ static int __pyx_f_5pysam_9csamtools_fetch_callback(bam1_t *__pyx_v_alignment, v
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("fetch_callback", 0);
-  __Pyx_TraceCall("fetch_callback", __pyx_f[0], 246);
+  __Pyx_TraceCall("fetch_callback", __pyx_f[0], 245);
 
-  /* "pysam/csamtools.pyx":251
+  /* "pysam/csamtools.pyx":250
  *     calls function in *f* with a new :class:`AlignedRead` object as parameter.
  *     '''
  *     a = makeAlignedRead( alignment )             # <<<<<<<<<<<<<<
  *     (<object>f)(a)
  * 
  */
-  __pyx_t_1 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_alignment); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_alignment); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_a = __pyx_t_1;
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":252
+  /* "pysam/csamtools.pyx":251
  *     '''
  *     a = makeAlignedRead( alignment )
  *     (<object>f)(a)             # <<<<<<<<<<<<<<
  * 
  * class PileupColumn(object):
  */
-  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __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 = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__pyx_v_a);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_a);
   __Pyx_GIVEREF(__pyx_v_a);
-  __pyx_t_2 = PyObject_Call(((PyObject *)__pyx_v_f), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(((PyObject *)__pyx_v_f), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
@@ -4567,7 +4640,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_12PileupColumn_1__str__(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":267
+/* "pysam/csamtools.pyx":266
  *         list of reads (:class:`pysam.PileupRead`) aligned to this column
  *     '''
  *     def __str__(self):             # <<<<<<<<<<<<<<
@@ -4588,9 +4661,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12PileupColumn___str__(CYTHON_UNUSED
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__str__", 0);
-  __Pyx_TraceCall("__str__", __pyx_f[0], 267);
+  __Pyx_TraceCall("__str__", __pyx_f[0], 266);
 
-  /* "pysam/csamtools.pyx":268
+  /* "pysam/csamtools.pyx":267
  *     '''
  *     def __str__(self):
  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
@@ -4599,30 +4672,30 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12PileupColumn___str__(CYTHON_UNUSED
  */
   __Pyx_XDECREF(__pyx_r);
 
-  /* "pysam/csamtools.pyx":269
+  /* "pysam/csamtools.pyx":268
  *     def __str__(self):
  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
  *             "\n" + "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
  * 
  * cdef int pileup_callback( uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *f):
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
 
-  /* "pysam/csamtools.pyx":268
+  /* "pysam/csamtools.pyx":267
  *     '''
  *     def __str__(self):
  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
  *             "\n" + "\n".join( map(str, self.pileups) )
  * 
  */
-  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__n); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__n); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
   __Pyx_GIVEREF(__pyx_t_2);
@@ -4633,7 +4706,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12PileupColumn___str__(CYTHON_UNUSED
   __pyx_t_2 = 0;
   __pyx_t_3 = 0;
   __pyx_t_4 = 0;
-  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __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 = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
   PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
@@ -4641,34 +4714,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12PileupColumn___str__(CYTHON_UNUSED
   PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_5));
   __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
   __pyx_t_5 = 0;
-  __pyx_t_5 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
-  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
   __Pyx_GIVEREF(__pyx_t_5);
   __pyx_t_5 = 0;
-  __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
-  __pyx_t_4 = PyNumber_Add(__pyx_t_5, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyNumber_Add(__pyx_t_5, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 
-  /* "pysam/csamtools.pyx":269
+  /* "pysam/csamtools.pyx":268
  *     def __str__(self):
  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
  *             "\n" + "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
  * 
  * cdef int pileup_callback( uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *f):
  */
-  __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_6), __pyx_n_s__join); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_6), __pyx_n_s__join); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
-  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pileups); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pileups); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
   PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
@@ -4676,19 +4749,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12PileupColumn___str__(CYTHON_UNUSED
   PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
-  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
-  __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -4713,7 +4786,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12PileupColumn___str__(CYTHON_UNUSED
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":271
+/* "pysam/csamtools.pyx":270
  *             "\n" + "\n".join( map(str, self.pileups) )
  * 
  * cdef int pileup_callback( uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *f):             # <<<<<<<<<<<<<<
@@ -4736,72 +4809,72 @@ static int __pyx_f_5pysam_9csamtools_pileup_callback(uint32_t __pyx_v_tid, uint3
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("pileup_callback", 0);
-  __Pyx_TraceCall("pileup_callback", __pyx_f[0], 271);
+  __Pyx_TraceCall("pileup_callback", __pyx_f[0], 270);
 
-  /* "pysam/csamtools.pyx":288
+  /* "pysam/csamtools.pyx":287
  *     '''
  * 
  *     p = PileupColumn()             # <<<<<<<<<<<<<<
  *     p.tid = tid
  *     p.pos = pos
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__PileupColumn); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__PileupColumn); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __pyx_v_p = __pyx_t_2;
   __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":289
+  /* "pysam/csamtools.pyx":288
  * 
  *     p = PileupColumn()
  *     p.tid = tid             # <<<<<<<<<<<<<<
  *     p.pos = pos
  *     p.n = n
  */
-  __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__tid, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__tid, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":290
+  /* "pysam/csamtools.pyx":289
  *     p = PileupColumn()
  *     p.tid = tid
  *     p.pos = pos             # <<<<<<<<<<<<<<
  *     p.n = n
  *     pileups = []
  */
-  __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__pos, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__pos, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":291
+  /* "pysam/csamtools.pyx":290
  *     p.tid = tid
  *     p.pos = pos
  *     p.n = n             # <<<<<<<<<<<<<<
  *     pileups = []
  * 
  */
-  __pyx_t_2 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__n, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__n, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":292
+  /* "pysam/csamtools.pyx":291
  *     p.pos = pos
  *     p.n = n
  *     pileups = []             # <<<<<<<<<<<<<<
  * 
  *     cdef int x
  */
-  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_v_pileups = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":295
+  /* "pysam/csamtools.pyx":294
  * 
  *     cdef int x
  *     for x from 0 <= x < n:             # <<<<<<<<<<<<<<
@@ -4811,41 +4884,41 @@ static int __pyx_f_5pysam_9csamtools_pileup_callback(uint32_t __pyx_v_tid, uint3
   __pyx_t_3 = __pyx_v_n;
   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
 
-    /* "pysam/csamtools.pyx":296
+    /* "pysam/csamtools.pyx":295
  *     cdef int x
  *     for x from 0 <= x < n:
  *         pileups.append( makePileupRead( &(pl[x]) ) )             # <<<<<<<<<<<<<<
  *     p.pileups = pileups
  * 
  */
-    __pyx_t_2 = __pyx_f_5pysam_9csamtools_makePileupRead((&(__pyx_v_pl[__pyx_v_x]))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __pyx_f_5pysam_9csamtools_makePileupRead((&(__pyx_v_pl[__pyx_v_x]))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_4 = PyList_Append(__pyx_v_pileups, __pyx_t_2); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyList_Append(__pyx_v_pileups, __pyx_t_2); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   }
 
-  /* "pysam/csamtools.pyx":297
+  /* "pysam/csamtools.pyx":296
  *     for x from 0 <= x < n:
  *         pileups.append( makePileupRead( &(pl[x]) ) )
  *     p.pileups = pileups             # <<<<<<<<<<<<<<
  * 
  *     (<object>f)(p)
  */
-  if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__pileups, ((PyObject *)__pyx_v_pileups)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__pileups, ((PyObject *)__pyx_v_pileups)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":299
+  /* "pysam/csamtools.pyx":298
  *     p.pileups = pileups
  * 
  *     (<object>f)(p)             # <<<<<<<<<<<<<<
  * 
  * cdef int pileup_fetch_callback( bam1_t *b, void *data):
  */
-  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_INCREF(__pyx_v_p);
   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_p);
   __Pyx_GIVEREF(__pyx_v_p);
-  __pyx_t_1 = PyObject_Call(((PyObject *)__pyx_v_f), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(((PyObject *)__pyx_v_f), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -4865,7 +4938,7 @@ static int __pyx_f_5pysam_9csamtools_pileup_callback(uint32_t __pyx_v_tid, uint3
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":301
+/* "pysam/csamtools.pyx":300
  *     (<object>f)(p)
  * 
  * cdef int pileup_fetch_callback( bam1_t *b, void *data):             # <<<<<<<<<<<<<<
@@ -4879,9 +4952,9 @@ static int __pyx_f_5pysam_9csamtools_pileup_fetch_callback(bam1_t *__pyx_v_b, vo
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("pileup_fetch_callback", 0);
-  __Pyx_TraceCall("pileup_fetch_callback", __pyx_f[0], 301);
+  __Pyx_TraceCall("pileup_fetch_callback", __pyx_f[0], 300);
 
-  /* "pysam/csamtools.pyx":307
+  /* "pysam/csamtools.pyx":306
  *     '''
  *     cdef bam_plbuf_t * buf
  *     buf = <bam_plbuf_t*>data             # <<<<<<<<<<<<<<
@@ -4890,7 +4963,7 @@ static int __pyx_f_5pysam_9csamtools_pileup_fetch_callback(bam1_t *__pyx_v_b, vo
  */
   __pyx_v_buf = ((bam_plbuf_t *)__pyx_v_data);
 
-  /* "pysam/csamtools.pyx":308
+  /* "pysam/csamtools.pyx":307
  *     cdef bam_plbuf_t * buf
  *     buf = <bam_plbuf_t*>data
  *     bam_plbuf_push(b, buf)             # <<<<<<<<<<<<<<
@@ -4899,7 +4972,7 @@ static int __pyx_f_5pysam_9csamtools_pileup_fetch_callback(bam1_t *__pyx_v_b, vo
  */
   bam_plbuf_push(__pyx_v_b, __pyx_v_buf);
 
-  /* "pysam/csamtools.pyx":309
+  /* "pysam/csamtools.pyx":308
  *     buf = <bam_plbuf_t*>data
  *     bam_plbuf_push(b, buf)
  *     return 0             # <<<<<<<<<<<<<<
@@ -4929,7 +5002,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11StderrStore_1__init__(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":315
+/* "pysam/csamtools.pyx":314
  *     stderr is captured.
  *     '''
  *     def __init__(self):             # <<<<<<<<<<<<<<
@@ -4942,9 +5015,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11StderrStore___init__(CYTHON_UNUSED
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__init__", 0);
-  __Pyx_TraceCall("__init__", __pyx_f[0], 315);
+  __Pyx_TraceCall("__init__", __pyx_f[0], 314);
 
-  /* "pysam/csamtools.pyx":316
+  /* "pysam/csamtools.pyx":315
  *     '''
  *     def __init__(self):
  *         return             # <<<<<<<<<<<<<<
@@ -4976,7 +5049,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11StderrStore_3readAndRelease(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":321
+/* "pysam/csamtools.pyx":320
  *         self.stderr_save.setfd( self.stderr_h )
  * 
  *     def readAndRelease( self ):             # <<<<<<<<<<<<<<
@@ -4993,9 +5066,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11StderrStore_2readAndRelease(CYTHON
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("readAndRelease", 0);
-  __Pyx_TraceCall("readAndRelease", __pyx_f[0], 321);
+  __Pyx_TraceCall("readAndRelease", __pyx_f[0], 320);
 
-  /* "pysam/csamtools.pyx":322
+  /* "pysam/csamtools.pyx":321
  * 
  *     def readAndRelease( self ):
  *         return []             # <<<<<<<<<<<<<<
@@ -5003,7 +5076,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11StderrStore_2readAndRelease(CYTHON
  *         lines = []
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = ((PyObject *)__pyx_t_1);
   __pyx_t_1 = 0;
@@ -5035,7 +5108,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11StderrStore_5release(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":330
+/* "pysam/csamtools.pyx":329
  *         return lines
  * 
  *     def release(self):             # <<<<<<<<<<<<<<
@@ -5048,9 +5121,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11StderrStore_4release(CYTHON_UNUSED
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("release", 0);
-  __Pyx_TraceCall("release", __pyx_f[0], 330);
+  __Pyx_TraceCall("release", __pyx_f[0], 329);
 
-  /* "pysam/csamtools.pyx":331
+  /* "pysam/csamtools.pyx":330
  * 
  *     def release(self):
  *         return             # <<<<<<<<<<<<<<
@@ -5082,7 +5155,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11StderrStore_7__del__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":336
+/* "pysam/csamtools.pyx":335
  *             os.remove( self.stderr_f )
  * 
  *     def __del__(self):             # <<<<<<<<<<<<<<
@@ -5100,18 +5173,18 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11StderrStore_6__del__(CYTHON_UNUSED
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__del__", 0);
-  __Pyx_TraceCall("__del__", __pyx_f[0], 336);
+  __Pyx_TraceCall("__del__", __pyx_f[0], 335);
 
-  /* "pysam/csamtools.pyx":337
+  /* "pysam/csamtools.pyx":336
  * 
  *     def __del__(self):
  *         self.release()             # <<<<<<<<<<<<<<
  * 
  * class StderrStoreWindows():
  */
-  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__release); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__release); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
@@ -5143,7 +5216,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_18StderrStoreWindows_1__init__(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":341
+/* "pysam/csamtools.pyx":340
  * class StderrStoreWindows():
  *     '''does nothing. stderr can't be redirected on windows'''
  *     def __init__(self): pass             # <<<<<<<<<<<<<<
@@ -5156,7 +5229,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18StderrStoreWindows___init__(CYTHON
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__init__", 0);
-  __Pyx_TraceCall("__init__", __pyx_f[0], 341);
+  __Pyx_TraceCall("__init__", __pyx_f[0], 340);
 
   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
   __Pyx_XGIVEREF(__pyx_r);
@@ -5178,7 +5251,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_18StderrStoreWindows_3readAndRelease
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":342
+/* "pysam/csamtools.pyx":341
  *     '''does nothing. stderr can't be redirected on windows'''
  *     def __init__(self): pass
  *     def readAndRelease(self): return []             # <<<<<<<<<<<<<<
@@ -5195,9 +5268,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18StderrStoreWindows_2readAndRelease
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("readAndRelease", 0);
-  __Pyx_TraceCall("readAndRelease", __pyx_f[0], 342);
+  __Pyx_TraceCall("readAndRelease", __pyx_f[0], 341);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = ((PyObject *)__pyx_t_1);
   __pyx_t_1 = 0;
@@ -5229,7 +5302,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_18StderrStoreWindows_5release(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":343
+/* "pysam/csamtools.pyx":342
  *     def __init__(self): pass
  *     def readAndRelease(self): return []
  *     def release(self): pass             # <<<<<<<<<<<<<<
@@ -5242,7 +5315,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18StderrStoreWindows_4release(CYTHON
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("release", 0);
-  __Pyx_TraceCall("release", __pyx_f[0], 343);
+  __Pyx_TraceCall("release", __pyx_f[0], 342);
 
   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
   __Pyx_XGIVEREF(__pyx_r);
@@ -5272,12 +5345,12 @@ static int __pyx_pw_5pysam_9csamtools_9Fastafile_1__cinit__(PyObject *__pyx_v_se
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":394
+/* "pysam/csamtools.pyx":393
  *     '''
  * 
  *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
  *         self.fastafile = NULL
- *         self._filename = NULL
+ *         self._filename = None
  */
 
 static int __pyx_pf_5pysam_9csamtools_9Fastafile___cinit__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
@@ -5292,40 +5365,83 @@ static int __pyx_pf_5pysam_9csamtools_9Fastafile___cinit__(struct __pyx_obj_5pys
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__cinit__", 0);
-  __Pyx_TraceCall("__cinit__", __pyx_f[0], 394);
+  __Pyx_TraceCall("__cinit__", __pyx_f[0], 393);
 
-  /* "pysam/csamtools.pyx":395
+  /* "pysam/csamtools.pyx":394
  * 
  *     def __cinit__(self, *args, **kwargs ):
  *         self.fastafile = NULL             # <<<<<<<<<<<<<<
- *         self._filename = NULL
- *         self._open( *args, **kwargs )
+ *         self._filename = None
+ *         self._references = None
  */
   __pyx_v_self->fastafile = NULL;
 
-  /* "pysam/csamtools.pyx":396
+  /* "pysam/csamtools.pyx":395
  *     def __cinit__(self, *args, **kwargs ):
  *         self.fastafile = NULL
- *         self._filename = NULL             # <<<<<<<<<<<<<<
+ *         self._filename = None             # <<<<<<<<<<<<<<
+ *         self._references = None
+ *         self._lengths = None
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->_filename);
+  __Pyx_DECREF(__pyx_v_self->_filename);
+  __pyx_v_self->_filename = Py_None;
+
+  /* "pysam/csamtools.pyx":396
+ *         self.fastafile = NULL
+ *         self._filename = None
+ *         self._references = None             # <<<<<<<<<<<<<<
+ *         self._lengths = None
+ *         self.reference2length = None
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->_references);
+  __Pyx_DECREF(__pyx_v_self->_references);
+  __pyx_v_self->_references = Py_None;
+
+  /* "pysam/csamtools.pyx":397
+ *         self._filename = None
+ *         self._references = None
+ *         self._lengths = None             # <<<<<<<<<<<<<<
+ *         self.reference2length = None
+ *         self._open( *args, **kwargs )
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->_lengths);
+  __Pyx_DECREF(__pyx_v_self->_lengths);
+  __pyx_v_self->_lengths = Py_None;
+
+  /* "pysam/csamtools.pyx":398
+ *         self._references = None
+ *         self._lengths = None
+ *         self.reference2length = None             # <<<<<<<<<<<<<<
  *         self._open( *args, **kwargs )
  * 
  */
-  __pyx_v_self->_filename = NULL;
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->reference2length);
+  __Pyx_DECREF(__pyx_v_self->reference2length);
+  __pyx_v_self->reference2length = Py_None;
 
-  /* "pysam/csamtools.pyx":397
- *         self.fastafile = NULL
- *         self._filename = NULL
+  /* "pysam/csamtools.pyx":399
+ *         self._lengths = None
+ *         self.reference2length = None
  *         self._open( *args, **kwargs )             # <<<<<<<<<<<<<<
  * 
  *     def _isOpen( self ):
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
   __pyx_t_3 = ((PyObject *)__pyx_v_kwargs);
   __Pyx_INCREF(__pyx_t_3);
-  __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
@@ -5359,7 +5475,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_3_isOpen(PyObject *__pyx_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":399
+/* "pysam/csamtools.pyx":401
  *         self._open( *args, **kwargs )
  * 
  *     def _isOpen( self ):             # <<<<<<<<<<<<<<
@@ -5376,9 +5492,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_2_isOpen(struct __pyx_obj
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_isOpen", 0);
-  __Pyx_TraceCall("_isOpen", __pyx_f[0], 399);
+  __Pyx_TraceCall("_isOpen", __pyx_f[0], 401);
 
-  /* "pysam/csamtools.pyx":401
+  /* "pysam/csamtools.pyx":403
  *     def _isOpen( self ):
  *         '''return true if samfile has been opened.'''
  *         return self.fastafile != NULL             # <<<<<<<<<<<<<<
@@ -5386,7 +5502,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_2_isOpen(struct __pyx_obj
  *     def __len__(self):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->fastafile != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->fastafile != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -5416,7 +5532,7 @@ static Py_ssize_t __pyx_pw_5pysam_9csamtools_9Fastafile_5__len__(PyObject *__pyx
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":403
+/* "pysam/csamtools.pyx":405
  *         return self.fastafile != NULL
  * 
  *     def __len__(self):             # <<<<<<<<<<<<<<
@@ -5434,9 +5550,9 @@ static Py_ssize_t __pyx_pf_5pysam_9csamtools_9Fastafile_4__len__(struct __pyx_ob
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__len__", 0);
-  __Pyx_TraceCall("__len__", __pyx_f[0], 403);
+  __Pyx_TraceCall("__len__", __pyx_f[0], 405);
 
-  /* "pysam/csamtools.pyx":404
+  /* "pysam/csamtools.pyx":406
  * 
  *     def __len__(self):
  *         if self.fastafile == NULL:             # <<<<<<<<<<<<<<
@@ -5446,28 +5562,28 @@ static Py_ssize_t __pyx_pf_5pysam_9csamtools_9Fastafile_4__len__(struct __pyx_ob
   __pyx_t_1 = (__pyx_v_self->fastafile == NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":405
+    /* "pysam/csamtools.pyx":407
  *     def __len__(self):
  *         if self.fastafile == NULL:
  *             raise ValueError( "calling len() on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         return faidx_fetch_nseq(self.fastafile)
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __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 = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":407
+  /* "pysam/csamtools.pyx":409
  *             raise ValueError( "calling len() on closed file" )
  * 
  *         return faidx_fetch_nseq(self.fastafile)             # <<<<<<<<<<<<<<
  * 
- *     def _open( self,
+ *     def _open(self, filename):
  */
   __pyx_r = faidx_fetch_nseq(__pyx_v_self->fastafile);
   goto __pyx_L0;
@@ -5495,42 +5611,306 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_7_open(PyObject *__pyx_v_
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
+static PyObject *__pyx_gb_5pysam_9csamtools_9Fastafile_5_open_2generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
+
+/* "pysam/csamtools.pyx":431
+ *         with open( self._filename + b".fai" ) as inf:
+ *             data = [ x.split("\t") for x in inf ]
+ *             self._references = tuple(x[0] for x in data)             # <<<<<<<<<<<<<<
+ *             self._lengths = tuple(int(x[1]) for x in data)
+ *             self.reference2length = dict(zip(self._references, self._lengths))
+ */
+
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_5_open_genexpr(PyObject *__pyx_self) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_TraceDeclarations
+  __Pyx_RefNannySetupContext("genexpr", 0);
+  __pyx_cur_scope = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr *)__pyx_ptype_5pysam_9csamtools___pyx_scope_struct_3_genexpr->tp_new(__pyx_ptype_5pysam_9csamtools___pyx_scope_struct_3_genexpr, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __Pyx_GOTREF(__pyx_cur_scope);
+  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *) __pyx_self;
+  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
+  __Pyx_TraceCall("genexpr", __pyx_f[0], 431);
+  {
+    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5pysam_9csamtools_9Fastafile_5_open_2generator2, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("pysam.csamtools.Fastafile._open.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_TraceReturn(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_5pysam_9csamtools_9Fastafile_5_open_2generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("None", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L6_resume_from_yield;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data)) { __Pyx_RaiseClosureNameError("data"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+  if (unlikely(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data) == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  }
+  __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+  for (;;) {
+    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+    #if CYTHON_COMPILING_IN_CPYTHON
+    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    #else
+    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    #endif
+    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x);
+    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_x);
+    __Pyx_GIVEREF(__pyx_t_3);
+    __pyx_cur_scope->__pyx_v_x = __pyx_t_3;
+    __pyx_t_3 = 0;
+    __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_x, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_r = __pyx_t_3;
+    __pyx_t_3 = 0;
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
+    __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
+    __Pyx_XGIVEREF(__pyx_r);
+    __Pyx_RefNannyFinishContext();
+    /* return from generator, yielding value */
+    __pyx_generator->resume_label = 1;
+    return __pyx_r;
+    __pyx_L6_resume_from_yield:;
+    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
+    __pyx_cur_scope->__pyx_t_0 = 0;
+    __Pyx_XGOTREF(__pyx_t_1);
+    __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
+    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  PyErr_SetNone(PyExc_StopIteration);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_generator->resume_label = -1;
+  __Pyx_Generator_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+}
+static PyObject *__pyx_gb_5pysam_9csamtools_9Fastafile_5_open_5generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
+
+/* "pysam/csamtools.pyx":432
+ *             data = [ x.split("\t") for x in inf ]
+ *             self._references = tuple(x[0] for x in data)
+ *             self._lengths = tuple(int(x[1]) for x in data)             # <<<<<<<<<<<<<<
+ *             self.reference2length = dict(zip(self._references, self._lengths))
+ * 
+ */
+
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_5_open_3genexpr(PyObject *__pyx_self) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_TraceDeclarations
+  __Pyx_RefNannySetupContext("genexpr", 0);
+  __pyx_cur_scope = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr *)__pyx_ptype_5pysam_9csamtools___pyx_scope_struct_4_genexpr->tp_new(__pyx_ptype_5pysam_9csamtools___pyx_scope_struct_4_genexpr, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __Pyx_GOTREF(__pyx_cur_scope);
+  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *) __pyx_self;
+  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
+  __Pyx_TraceCall("genexpr", __pyx_f[0], 432);
+  {
+    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5pysam_9csamtools_9Fastafile_5_open_5generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("pysam.csamtools.Fastafile._open.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_TraceReturn(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_5pysam_9csamtools_9Fastafile_5_open_5generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("None", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L6_resume_from_yield;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data)) { __Pyx_RaiseClosureNameError("data"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+  if (unlikely(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data) == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  }
+  __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+  for (;;) {
+    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+    #if CYTHON_COMPILING_IN_CPYTHON
+    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    #else
+    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    #endif
+    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x);
+    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_x);
+    __Pyx_GIVEREF(__pyx_t_3);
+    __pyx_cur_scope->__pyx_v_x = __pyx_t_3;
+    __pyx_t_3 = 0;
+    __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_x, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_4);
+    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
+    __Pyx_GIVEREF(__pyx_t_3);
+    __pyx_t_3 = 0;
+    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
+    __pyx_r = __pyx_t_3;
+    __pyx_t_3 = 0;
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
+    __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
+    __Pyx_XGIVEREF(__pyx_r);
+    __Pyx_RefNannyFinishContext();
+    /* return from generator, yielding value */
+    __pyx_generator->resume_label = 1;
+    return __pyx_r;
+    __pyx_L6_resume_from_yield:;
+    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
+    __pyx_cur_scope->__pyx_t_0 = 0;
+    __Pyx_XGOTREF(__pyx_t_1);
+    __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
+    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  PyErr_SetNone(PyExc_StopIteration);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_generator->resume_label = -1;
+  __Pyx_Generator_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+}
 
-/* "pysam/csamtools.pyx":409
+/* "pysam/csamtools.pyx":411
  *         return faidx_fetch_nseq(self.fastafile)
  * 
- *     def _open( self,             # <<<<<<<<<<<<<<
- *                filename ):
+ *     def _open(self, filename):             # <<<<<<<<<<<<<<
  *         '''open an indexed fasta file.
+ * 
  */
 
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_6_open(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_filename) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *__pyx_cur_scope;
+  PyObject *__pyx_v_inf = NULL;
+  PyObject *__pyx_v_x = NULL;
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
   int __pyx_t_1;
   PyObject *__pyx_t_2 = NULL;
   PyObject *__pyx_t_3 = NULL;
   char *__pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  Py_ssize_t __pyx_t_11;
+  PyObject *(*__pyx_t_12)(PyObject *);
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_open", 0);
-  __Pyx_TraceCall("_open", __pyx_f[0], 409);
-  __Pyx_INCREF(__pyx_v_filename);
+  __pyx_cur_scope = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *)__pyx_ptype_5pysam_9csamtools___pyx_scope_struct_2__open->tp_new(__pyx_ptype_5pysam_9csamtools___pyx_scope_struct_2__open, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __Pyx_GOTREF(__pyx_cur_scope);
+  __Pyx_TraceCall("_open", __pyx_f[0], 411);
 
-  /* "pysam/csamtools.pyx":417
+  /* "pysam/csamtools.pyx":418
  * 
  *         # close a previously opened file
  *         if self.fastafile != NULL: self.close()             # <<<<<<<<<<<<<<
- *         if self._filename != NULL: free(self._filename)
- *         filename = _my_encodeFilename(filename)
+ *         self._filename = _encodeFilename(filename)
+ *         self.fastafile = fai_load(self._filename)
  */
   __pyx_t_1 = (__pyx_v_self->fastafile != NULL);
   if (__pyx_t_1) {
-    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
@@ -5538,96 +5918,392 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_6_open(struct __pyx_obj_5
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":418
- *         # close a previously opened file
- *         if self.fastafile != NULL: self.close()
- *         if self._filename != NULL: free(self._filename)             # <<<<<<<<<<<<<<
- *         filename = _my_encodeFilename(filename)
- *         self._filename = strdup(filename)
- */
-  __pyx_t_1 = (__pyx_v_self->_filename != NULL);
-  if (__pyx_t_1) {
-    free(__pyx_v_self->_filename);
-    goto __pyx_L4;
-  }
-  __pyx_L4:;
-
   /* "pysam/csamtools.pyx":419
+ *         # close a previously opened file
  *         if self.fastafile != NULL: self.close()
- *         if self._filename != NULL: free(self._filename)
- *         filename = _my_encodeFilename(filename)             # <<<<<<<<<<<<<<
- *         self._filename = strdup(filename)
- *         self.fastafile = fai_load( filename )
+ *         self._filename = _encodeFilename(filename)             # <<<<<<<<<<<<<<
+ *         self.fastafile = fai_load(self._filename)
+ * 
  */
-  __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_9csamtools__my_encodeFilename(__pyx_v_filename)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_9csamtools__encodeFilename(__pyx_v_filename)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __Pyx_DECREF(__pyx_v_filename);
-  __pyx_v_filename = __pyx_t_3;
+  __Pyx_GIVEREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_v_self->_filename);
+  __Pyx_DECREF(__pyx_v_self->_filename);
+  __pyx_v_self->_filename = __pyx_t_3;
   __pyx_t_3 = 0;
 
   /* "pysam/csamtools.pyx":420
- *         if self._filename != NULL: free(self._filename)
- *         filename = _my_encodeFilename(filename)
- *         self._filename = strdup(filename)             # <<<<<<<<<<<<<<
- *         self.fastafile = fai_load( filename )
- * 
- */
-  __pyx_t_4 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_v_self->_filename = strdup(__pyx_t_4);
-
-  /* "pysam/csamtools.pyx":421
- *         filename = _my_encodeFilename(filename)
- *         self._filename = strdup(filename)
- *         self.fastafile = fai_load( filename )             # <<<<<<<<<<<<<<
+ *         if self.fastafile != NULL: self.close()
+ *         self._filename = _encodeFilename(filename)
+ *         self.fastafile = fai_load(self._filename)             # <<<<<<<<<<<<<<
  * 
  *         if self.fastafile == NULL:
  */
-  __pyx_t_4 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyBytes_AsString(__pyx_v_self->_filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->fastafile = fai_load(__pyx_t_4);
 
-  /* "pysam/csamtools.pyx":423
- *         self.fastafile = fai_load( filename )
+  /* "pysam/csamtools.pyx":422
+ *         self.fastafile = fai_load(self._filename)
  * 
  *         if self.fastafile == NULL:             # <<<<<<<<<<<<<<
- *             raise IOError("could not open file `%s`" % filename )
+ *             raise IOError("could not open file `%s`" % filename)
  * 
  */
   __pyx_t_1 = (__pyx_v_self->fastafile == NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":424
+    /* "pysam/csamtools.pyx":423
  * 
  *         if self.fastafile == NULL:
- *             raise IOError("could not open file `%s`" % filename )             # <<<<<<<<<<<<<<
+ *             raise IOError("could not open file `%s`" % filename)             # <<<<<<<<<<<<<<
  * 
- *     def close( self ):
+ *         # read index
  */
-    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), __pyx_v_filename); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), __pyx_v_filename); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
-    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
     __pyx_t_3 = 0;
-    __pyx_t_3 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
     __Pyx_Raise(__pyx_t_3, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    goto __pyx_L4;
+  }
+  __pyx_L4:;
+
+  /* "pysam/csamtools.pyx":426
+ * 
+ *         # read index
+ *         if not os.path.exists( self._filename + b".fai" ):             # <<<<<<<<<<<<<<
+ *             raise ValueError("could not locate index file")
+ * 
+ */
+  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __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_self->_filename, ((PyObject *)__pyx_kp_b_10)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_5);
+  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+  __Pyx_GIVEREF(__pyx_t_2);
+  __pyx_t_2 = 0;
+  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_6 = (!__pyx_t_1);
+  if (__pyx_t_6) {
+
+    /* "pysam/csamtools.pyx":427
+ *         # read index
+ *         if not os.path.exists( self._filename + b".fai" ):
+ *             raise ValueError("could not locate index file")             # <<<<<<<<<<<<<<
+ * 
+ *         with open( self._filename + b".fai" ) as inf:
+ */
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 427; __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 = 427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L5;
   }
   __pyx_L5:;
 
+  /* "pysam/csamtools.pyx":429
+ *             raise ValueError("could not locate index file")
+ * 
+ *         with open( self._filename + b".fai" ) as inf:             # <<<<<<<<<<<<<<
+ *             data = [ x.split("\t") for x in inf ]
+ *             self._references = tuple(x[0] for x in data)
+ */
+  /*with:*/ {
+    __pyx_t_2 = PyNumber_Add(__pyx_v_self->_filename, ((PyObject *)__pyx_kp_b_10)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+    __Pyx_GIVEREF(__pyx_t_2);
+    __pyx_t_2 = 0;
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
+    __pyx_t_7 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_7);
+    __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L6_error;}
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L6_error;}
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    /*try:*/ {
+      {
+        __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
+        __Pyx_XGOTREF(__pyx_t_8);
+        __Pyx_XGOTREF(__pyx_t_9);
+        __Pyx_XGOTREF(__pyx_t_10);
+        /*try:*/ {
+          __Pyx_INCREF(__pyx_t_3);
+          __pyx_v_inf = __pyx_t_3;
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+          /* "pysam/csamtools.pyx":430
+ * 
+ *         with open( self._filename + b".fai" ) as inf:
+ *             data = [ x.split("\t") for x in inf ]             # <<<<<<<<<<<<<<
+ *             self._references = tuple(x[0] for x in data)
+ *             self._lengths = tuple(int(x[1]) for x in data)
+ */
+          __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+          __Pyx_GOTREF(__pyx_t_3);
+          if (PyList_CheckExact(__pyx_v_inf) || PyTuple_CheckExact(__pyx_v_inf)) {
+            __pyx_t_2 = __pyx_v_inf; __Pyx_INCREF(__pyx_t_2); __pyx_t_11 = 0;
+            __pyx_t_12 = NULL;
+          } else {
+            __pyx_t_11 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_inf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+            __Pyx_GOTREF(__pyx_t_2);
+            __pyx_t_12 = Py_TYPE(__pyx_t_2)->tp_iternext;
+          }
+          for (;;) {
+            if (!__pyx_t_12 && PyList_CheckExact(__pyx_t_2)) {
+              if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_2)) break;
+              #if CYTHON_COMPILING_IN_CPYTHON
+              __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_11); __Pyx_INCREF(__pyx_t_5); __pyx_t_11++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+              #else
+              __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+              #endif
+            } else if (!__pyx_t_12 && PyTuple_CheckExact(__pyx_t_2)) {
+              if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
+              #if CYTHON_COMPILING_IN_CPYTHON
+              __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_11); __Pyx_INCREF(__pyx_t_5); __pyx_t_11++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+              #else
+              __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+              #endif
+            } else {
+              __pyx_t_5 = __pyx_t_12(__pyx_t_2);
+              if (unlikely(!__pyx_t_5)) {
+                if (PyErr_Occurred()) {
+                  if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
+                  else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+                }
+                break;
+              }
+              __Pyx_GOTREF(__pyx_t_5);
+            }
+            __Pyx_XDECREF(__pyx_v_x);
+            __pyx_v_x = __pyx_t_5;
+            __pyx_t_5 = 0;
+            __pyx_t_5 = PyObject_GetAttr(__pyx_v_x, __pyx_n_s__split); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+            __Pyx_GOTREF(__pyx_t_5);
+            __pyx_t_13 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_13), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+            __Pyx_GOTREF(__pyx_t_13);
+            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+            if (unlikely(__Pyx_PyList_Append(__pyx_t_3, (PyObject*)__pyx_t_13))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+          }
+          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+          __pyx_t_2 = ((PyObject *)__pyx_t_3);
+          __Pyx_INCREF(__pyx_t_2);
+          __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+          __Pyx_GIVEREF(__pyx_t_2);
+          __pyx_cur_scope->__pyx_v_data = ((PyObject*)__pyx_t_2);
+          __pyx_t_2 = 0;
+
+          /* "pysam/csamtools.pyx":431
+ *         with open( self._filename + b".fai" ) as inf:
+ *             data = [ x.split("\t") for x in inf ]
+ *             self._references = tuple(x[0] for x in data)             # <<<<<<<<<<<<<<
+ *             self._lengths = tuple(int(x[1]) for x in data)
+ *             self.reference2length = dict(zip(self._references, self._lengths))
+ */
+          __pyx_t_2 = __pyx_pf_5pysam_9csamtools_9Fastafile_5_open_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+          __Pyx_GOTREF(__pyx_t_2);
+          __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+          __Pyx_GOTREF(__pyx_t_3);
+          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
+          __Pyx_GIVEREF(__pyx_t_2);
+          __pyx_t_2 = 0;
+          __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+          __Pyx_GOTREF(__pyx_t_2);
+          __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+          __Pyx_GIVEREF(__pyx_t_2);
+          __Pyx_GOTREF(__pyx_v_self->_references);
+          __Pyx_DECREF(__pyx_v_self->_references);
+          __pyx_v_self->_references = __pyx_t_2;
+          __pyx_t_2 = 0;
+
+          /* "pysam/csamtools.pyx":432
+ *             data = [ x.split("\t") for x in inf ]
+ *             self._references = tuple(x[0] for x in data)
+ *             self._lengths = tuple(int(x[1]) for x in data)             # <<<<<<<<<<<<<<
+ *             self.reference2length = dict(zip(self._references, self._lengths))
+ * 
+ */
+          __pyx_t_2 = __pyx_pf_5pysam_9csamtools_9Fastafile_5_open_3genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+          __Pyx_GOTREF(__pyx_t_2);
+          __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+          __Pyx_GOTREF(__pyx_t_3);
+          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
+          __Pyx_GIVEREF(__pyx_t_2);
+          __pyx_t_2 = 0;
+          __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+          __Pyx_GOTREF(__pyx_t_2);
+          __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+          __Pyx_GIVEREF(__pyx_t_2);
+          __Pyx_GOTREF(__pyx_v_self->_lengths);
+          __Pyx_DECREF(__pyx_v_self->_lengths);
+          __pyx_v_self->_lengths = __pyx_t_2;
+          __pyx_t_2 = 0;
+
+          /* "pysam/csamtools.pyx":433
+ *             self._references = tuple(x[0] for x in data)
+ *             self._lengths = tuple(int(x[1]) for x in data)
+ *             self.reference2length = dict(zip(self._references, self._lengths))             # <<<<<<<<<<<<<<
+ * 
+ *     def close( self ):
+ */
+          __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+          __Pyx_GOTREF(__pyx_t_2);
+          __Pyx_INCREF(__pyx_v_self->_references);
+          PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self->_references);
+          __Pyx_GIVEREF(__pyx_v_self->_references);
+          __Pyx_INCREF(__pyx_v_self->_lengths);
+          PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_self->_lengths);
+          __Pyx_GIVEREF(__pyx_v_self->_lengths);
+          __pyx_t_3 = PyObject_Call(__pyx_builtin_zip, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_DECREF(((PyObject *)__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 = 433; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+          __Pyx_GOTREF(__pyx_t_2);
+          PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
+          __Pyx_GIVEREF(__pyx_t_3);
+          __pyx_t_3 = 0;
+          __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+          __Pyx_GIVEREF(__pyx_t_3);
+          __Pyx_GOTREF(__pyx_v_self->reference2length);
+          __Pyx_DECREF(__pyx_v_self->reference2length);
+          __pyx_v_self->reference2length = __pyx_t_3;
+          __pyx_t_3 = 0;
+        }
+        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+        goto __pyx_L17_try_end;
+        __pyx_L10_error:;
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+        /* "pysam/csamtools.pyx":429
+ *             raise ValueError("could not locate index file")
+ * 
+ *         with open( self._filename + b".fai" ) as inf:             # <<<<<<<<<<<<<<
+ *             data = [ x.split("\t") for x in inf ]
+ *             self._references = tuple(x[0] for x in data)
+ */
+        /*except:*/ {
+          __Pyx_AddTraceback("pysam.csamtools.Fastafile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
+          if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_2, &__pyx_t_13) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_GOTREF(__pyx_t_2);
+          __Pyx_GOTREF(__pyx_t_13);
+          __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
+          __Pyx_GOTREF(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_3);
+          PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
+          __Pyx_GIVEREF(__pyx_t_3);
+          __Pyx_INCREF(__pyx_t_2);
+          PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+          __Pyx_GIVEREF(__pyx_t_2);
+          __Pyx_INCREF(__pyx_t_13);
+          PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_13);
+          __Pyx_GIVEREF(__pyx_t_13);
+          __pyx_t_14 = PyObject_Call(__pyx_t_7, __pyx_t_5, NULL);
+          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+          if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
+          __Pyx_GOTREF(__pyx_t_14);
+          __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_14);
+          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+          if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
+          __pyx_t_1 = (!__pyx_t_6);
+          if (__pyx_t_1) {
+            __Pyx_GIVEREF(__pyx_t_3);
+            __Pyx_GIVEREF(__pyx_t_2);
+            __Pyx_GIVEREF(__pyx_t_13);
+            __Pyx_ErrRestore(__pyx_t_3, __pyx_t_2, __pyx_t_13);
+            __pyx_t_3 = 0; __pyx_t_2 = 0; __pyx_t_13 = 0; 
+            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
+            goto __pyx_L23;
+          }
+          __pyx_L23:;
+          __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+          goto __pyx_L11_exception_handled;
+        }
+        __pyx_L12_except_error:;
+        __Pyx_XGIVEREF(__pyx_t_8);
+        __Pyx_XGIVEREF(__pyx_t_9);
+        __Pyx_XGIVEREF(__pyx_t_10);
+        __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
+        goto __pyx_L1_error;
+        __pyx_L11_exception_handled:;
+        __Pyx_XGIVEREF(__pyx_t_8);
+        __Pyx_XGIVEREF(__pyx_t_9);
+        __Pyx_XGIVEREF(__pyx_t_10);
+        __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
+        __pyx_L17_try_end:;
+      }
+    }
+    /*finally:*/ {
+      if (__pyx_t_7) {
+        __pyx_t_10 = PyObject_Call(__pyx_t_7, __pyx_k_tuple_14, NULL);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_10);
+        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_10);
+        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+        if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      }
+    }
+    goto __pyx_L24;
+    __pyx_L6_error:;
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    goto __pyx_L1_error;
+    __pyx_L24:;
+  }
+
   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
   goto __pyx_L0;
   __pyx_L1_error:;
   __Pyx_XDECREF(__pyx_t_2);
   __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_13);
   __Pyx_AddTraceback("pysam.csamtools.Fastafile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __pyx_r = NULL;
   __pyx_L0:;
-  __Pyx_XDECREF(__pyx_v_filename);
+  __Pyx_XDECREF(__pyx_v_inf);
+  __Pyx_XDECREF(__pyx_v_x);
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
   __Pyx_XGIVEREF(__pyx_r);
   __Pyx_TraceReturn(__pyx_r);
   __Pyx_RefNannyFinishContext();
@@ -5646,8 +6322,8 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_9close(PyObject *__pyx_v_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":426
- *             raise IOError("could not open file `%s`" % filename )
+/* "pysam/csamtools.pyx":435
+ *             self.reference2length = dict(zip(self._references, self._lengths))
  * 
  *     def close( self ):             # <<<<<<<<<<<<<<
  *         if self.fastafile != NULL:
@@ -5660,9 +6336,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_8close(struct __pyx_obj_5
   int __pyx_t_1;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("close", 0);
-  __Pyx_TraceCall("close", __pyx_f[0], 426);
+  __Pyx_TraceCall("close", __pyx_f[0], 435);
 
-  /* "pysam/csamtools.pyx":427
+  /* "pysam/csamtools.pyx":436
  * 
  *     def close( self ):
  *         if self.fastafile != NULL:             # <<<<<<<<<<<<<<
@@ -5672,7 +6348,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_8close(struct __pyx_obj_5
   __pyx_t_1 = (__pyx_v_self->fastafile != NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":428
+    /* "pysam/csamtools.pyx":437
  *     def close( self ):
  *         if self.fastafile != NULL:
  *             fai_destroy( self.fastafile )             # <<<<<<<<<<<<<<
@@ -5681,7 +6357,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_8close(struct __pyx_obj_5
  */
     fai_destroy(__pyx_v_self->fastafile);
 
-    /* "pysam/csamtools.pyx":429
+    /* "pysam/csamtools.pyx":438
  *         if self.fastafile != NULL:
  *             fai_destroy( self.fastafile )
  *             self.fastafile = NULL             # <<<<<<<<<<<<<<
@@ -5709,54 +6385,39 @@ static void __pyx_pw_5pysam_9csamtools_9Fastafile_11__dealloc__(PyObject *__pyx_
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/csamtools.pyx":431
+/* "pysam/csamtools.pyx":440
  *             self.fastafile = NULL
  * 
  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
  *         self.close()
- *         if self._filename != NULL: free(self._filename)
+ * 
  */
 
 static void __pyx_pf_5pysam_9csamtools_9Fastafile_10__dealloc__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self) {
   __Pyx_RefNannyDeclarations
   PyObject *__pyx_t_1 = NULL;
   PyObject *__pyx_t_2 = NULL;
-  int __pyx_t_3;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__dealloc__", 0);
-  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 431);
+  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 440);
 
-  /* "pysam/csamtools.pyx":432
+  /* "pysam/csamtools.pyx":441
  * 
  *     def __dealloc__(self):
  *         self.close()             # <<<<<<<<<<<<<<
- *         if self._filename != NULL: free(self._filename)
  * 
+ *     property filename:
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":433
- *     def __dealloc__(self):
- *         self.close()
- *         if self._filename != NULL: free(self._filename)             # <<<<<<<<<<<<<<
- * 
- *     property filename:
- */
-  __pyx_t_3 = (__pyx_v_self->_filename != NULL);
-  if (__pyx_t_3) {
-    free(__pyx_v_self->_filename);
-    goto __pyx_L3;
-  }
-  __pyx_L3:;
-
   goto __pyx_L0;
   __pyx_L1_error:;
   __Pyx_XDECREF(__pyx_t_1);
@@ -5778,74 +6439,202 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_8filename_1__get__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":437
+/* "pysam/csamtools.pyx":445
  *     property filename:
  *         '''number of :term:`filename` associated with this object.'''
  *         def __get__(self):             # <<<<<<<<<<<<<<
- *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             return self._filename
+ * 
  */
 
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_8filename___get__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self) {
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
+  __Pyx_TraceDeclarations
+  __Pyx_RefNannySetupContext("__get__", 0);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 445);
+
+  /* "pysam/csamtools.pyx":446
+ *         '''number of :term:`filename` associated with this object.'''
+ *         def __get__(self):
+ *             return self._filename             # <<<<<<<<<<<<<<
+ * 
+ *     property references:
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_self->_filename);
+  __pyx_r = __pyx_v_self->_filename;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_TraceReturn(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_10references_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_10references_1__get__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_5pysam_9csamtools_9Fastafile_10references___get__(((struct __pyx_obj_5pysam_9csamtools_Fastafile *)__pyx_v_self));
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "pysam/csamtools.pyx":450
+ *     property references:
+ *         '''tuple with the names of :term:`reference` sequences.'''
+ *         def __get__(self):             # <<<<<<<<<<<<<<
+ *             return self._references
+ * 
+ */
+
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_10references___get__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_TraceDeclarations
+  __Pyx_RefNannySetupContext("__get__", 0);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 450);
+
+  /* "pysam/csamtools.pyx":451
+ *         '''tuple with the names of :term:`reference` sequences.'''
+ *         def __get__(self):
+ *             return self._references             # <<<<<<<<<<<<<<
+ * 
+ *     property nreferences:
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_self->_references);
+  __pyx_r = __pyx_v_self->_references;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_TraceReturn(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_11nreferences_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_11nreferences_1__get__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_5pysam_9csamtools_9Fastafile_11nreferences___get__(((struct __pyx_obj_5pysam_9csamtools_Fastafile *)__pyx_v_self));
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "pysam/csamtools.pyx":455
+ *     property nreferences:
+ *         '''number of :term:`reference` sequences in the file.'''
+ *         def __get__(self):             # <<<<<<<<<<<<<<
+ *             return len(self._references) if self.references else None
+ * 
+ */
+
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_11nreferences___get__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
   PyObject *__pyx_t_1 = NULL;
   PyObject *__pyx_t_2 = NULL;
   int __pyx_t_3;
-  int __pyx_t_4;
+  Py_ssize_t __pyx_t_4;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 437);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 455);
 
-  /* "pysam/csamtools.pyx":438
- *         '''number of :term:`filename` associated with this object.'''
+  /* "pysam/csamtools.pyx":456
+ *         '''number of :term:`reference` sequences in the file.'''
  *         def __get__(self):
- *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
- *             return self._filename
+ *             return len(self._references) if self.references else None             # <<<<<<<<<<<<<<
  * 
+ *     property lengths:
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__references); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_4 = (!__pyx_t_3);
-  if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_11), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_2);
-    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+  if (__pyx_t_3) {
+    __pyx_t_2 = __pyx_v_self->_references;
+    __Pyx_INCREF(__pyx_t_2);
+    __pyx_t_4 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    goto __pyx_L3;
+    __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_1 = __pyx_t_2;
+    __pyx_t_2 = 0;
+  } else {
+    __Pyx_INCREF(Py_None);
+    __pyx_t_1 = Py_None;
   }
-  __pyx_L3:;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
 
-  /* "pysam/csamtools.pyx":439
+  __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_AddTraceback("pysam.csamtools.Fastafile.nreferences.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_TraceReturn(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_7lengths_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_7lengths_1__get__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_5pysam_9csamtools_9Fastafile_7lengths___get__(((struct __pyx_obj_5pysam_9csamtools_Fastafile *)__pyx_v_self));
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "pysam/csamtools.pyx":460
+ *     property lengths:
+ *         '''tuple with the lengths of :term:`reference` sequences.'''
+ *         def __get__(self):             # <<<<<<<<<<<<<<
+ *             return self._lengths
+ * 
+ */
+
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_7lengths___get__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_TraceDeclarations
+  __Pyx_RefNannySetupContext("__get__", 0);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 460);
+
+  /* "pysam/csamtools.pyx":461
+ *         '''tuple with the lengths of :term:`reference` sequences.'''
  *         def __get__(self):
- *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
- *             return self._filename             # <<<<<<<<<<<<<<
+ *             return self._lengths             # <<<<<<<<<<<<<<
  * 
  *     def fetch( self,
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = PyBytes_FromString(__pyx_v_self->_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-  __pyx_r = ((PyObject *)__pyx_t_2);
-  __pyx_t_2 = 0;
+  __Pyx_INCREF(__pyx_v_self->_lengths);
+  __pyx_r = __pyx_v_self->_lengths;
   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_AddTraceback("pysam.csamtools.Fastafile.filename.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
   __pyx_L0:;
   __Pyx_XGIVEREF(__pyx_r);
   __Pyx_TraceReturn(__pyx_r);
@@ -5868,7 +6657,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_13fetch(PyObject *__pyx_v
     static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,0};
     PyObject* values[4] = {0,0,0,0};
 
-    /* "pysam/csamtools.pyx":442
+    /* "pysam/csamtools.pyx":464
  * 
  *     def fetch( self,
  *                reference = None,             # <<<<<<<<<<<<<<
@@ -5877,7 +6666,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_13fetch(PyObject *__pyx_v
  */
     values[0] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":443
+    /* "pysam/csamtools.pyx":465
  *     def fetch( self,
  *                reference = None,
  *                start = None,             # <<<<<<<<<<<<<<
@@ -5886,7 +6675,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_13fetch(PyObject *__pyx_v
  */
     values[1] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":444
+    /* "pysam/csamtools.pyx":466
  *                reference = None,
  *                start = None,
  *                end = None,             # <<<<<<<<<<<<<<
@@ -5895,7 +6684,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_13fetch(PyObject *__pyx_v
  */
     values[2] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":445
+    /* "pysam/csamtools.pyx":467
  *                start = None,
  *                end = None,
  *                region = None):             # <<<<<<<<<<<<<<
@@ -5938,7 +6727,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_13fetch(PyObject *__pyx_v
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -5957,7 +6746,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_13fetch(PyObject *__pyx_v
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.Fastafile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -5968,8 +6757,8 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_13fetch(PyObject *__pyx_v
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":441
- *             return self._filename
+/* "pysam/csamtools.pyx":463
+ *             return self._lengths
  * 
  *     def fetch( self,             # <<<<<<<<<<<<<<
  *                reference = None,
@@ -5992,56 +6781,56 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("fetch", 0);
-  __Pyx_TraceCall("fetch", __pyx_f[0], 441);
+  __Pyx_TraceCall("fetch", __pyx_f[0], 463);
   __Pyx_INCREF(__pyx_v_start);
   __Pyx_INCREF(__pyx_v_end);
   __Pyx_INCREF(__pyx_v_region);
 
-  /* "pysam/csamtools.pyx":462
+  /* "pysam/csamtools.pyx":484
  *         '''
  * 
  *         if not self._isOpen():             # <<<<<<<<<<<<<<
  *             raise ValueError( "I/O operation on closed file" )
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":463
+    /* "pysam/csamtools.pyx":485
  * 
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         cdef int length
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_16), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __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 = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":468
+  /* "pysam/csamtools.pyx":490
  *         cdef char * seq
  * 
  *         if not region:             # <<<<<<<<<<<<<<
  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )
  *             if start is None: start = 0
  */
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_t_3 = (!__pyx_t_4);
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":469
+    /* "pysam/csamtools.pyx":491
  * 
  *         if not region:
  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )             # <<<<<<<<<<<<<<
@@ -6050,16 +6839,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
  */
     __pyx_t_3 = (__pyx_v_reference == Py_None);
     if (__pyx_t_3) {
-      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_18), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __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 = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L5;
     }
     __pyx_L5:;
 
-    /* "pysam/csamtools.pyx":470
+    /* "pysam/csamtools.pyx":492
  *         if not region:
  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )
  *             if start is None: start = 0             # <<<<<<<<<<<<<<
@@ -6075,7 +6864,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
     }
     __pyx_L6:;
 
-    /* "pysam/csamtools.pyx":471
+    /* "pysam/csamtools.pyx":493
  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )
  *             if start is None: start = 0
  *             if end is None: end = max_pos -1             # <<<<<<<<<<<<<<
@@ -6084,7 +6873,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
  */
     __pyx_t_3 = (__pyx_v_end == Py_None);
     if (__pyx_t_3) {
-      __pyx_t_2 = PyInt_FromLong((__pyx_v_5pysam_9csamtools_max_pos - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyInt_FromLong((__pyx_v_5pysam_9csamtools_max_pos - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(__pyx_v_end);
       __pyx_v_end = __pyx_t_2;
@@ -6093,18 +6882,18 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
     }
     __pyx_L7:;
 
-    /* "pysam/csamtools.pyx":473
+    /* "pysam/csamtools.pyx":495
  *             if end is None: end = max_pos -1
  * 
  *             if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )             # <<<<<<<<<<<<<<
  *             if start == end: return b""
  *             # valid ranges are from 0 to 2^29-1
  */
-    __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     if (__pyx_t_3) {
-      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __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 = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_INCREF(__pyx_v_start);
       PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_start);
@@ -6112,125 +6901,125 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
       __Pyx_INCREF(__pyx_v_end);
       PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_end);
       __Pyx_GIVEREF(__pyx_v_end);
-      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_15), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_19), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_1));
       __Pyx_DECREF(((PyObject *)__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 = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
       __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
       __pyx_t_1 = 0;
-      __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
       __Pyx_Raise(__pyx_t_1, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L8;
     }
     __pyx_L8:;
 
-    /* "pysam/csamtools.pyx":474
+    /* "pysam/csamtools.pyx":496
  * 
  *             if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )
  *             if start == end: return b""             # <<<<<<<<<<<<<<
  *             # valid ranges are from 0 to 2^29-1
- *             if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )
+ *             if not 0 <= start < max_pos: raise IndexError( 'start out of range (%i)' % start )
  */
-    __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     if (__pyx_t_3) {
       __Pyx_XDECREF(__pyx_r);
-      __Pyx_INCREF(((PyObject *)__pyx_kp_b_16));
-      __pyx_r = ((PyObject *)__pyx_kp_b_16);
+      __Pyx_INCREF(((PyObject *)__pyx_kp_b_20));
+      __pyx_r = ((PyObject *)__pyx_kp_b_20);
       goto __pyx_L0;
       goto __pyx_L9;
     }
     __pyx_L9:;
 
-    /* "pysam/csamtools.pyx":476
+    /* "pysam/csamtools.pyx":498
  *             if start == end: return b""
  *             # valid ranges are from 0 to 2^29-1
- *             if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )             # <<<<<<<<<<<<<<
- *             if not 0 <= end < max_pos: raise ValueError( 'end out of range (%i)' % end )
+ *             if not 0 <= start < max_pos: raise IndexError( 'start out of range (%i)' % start )             # <<<<<<<<<<<<<<
+ *             if not 0 <= end < max_pos: raise IndexError( 'end out of range (%i)' % end )
  *             # note: faidx_fetch_seq has a bug such that out-of-range access
  */
-    __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_start, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_start, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (__Pyx_PyObject_IsTrue(__pyx_t_1)) {
       __Pyx_DECREF(__pyx_t_1);
-      __pyx_t_2 = PyInt_FromLong(__pyx_v_5pysam_9csamtools_max_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyInt_FromLong(__pyx_v_5pysam_9csamtools_max_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
-      __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     }
-    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __pyx_t_4 = (!__pyx_t_3);
     if (__pyx_t_4) {
-      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_17), __pyx_v_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_v_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
       __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
       __pyx_t_1 = 0;
-      __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
       __Pyx_Raise(__pyx_t_1, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L10;
     }
     __pyx_L10:;
 
-    /* "pysam/csamtools.pyx":477
+    /* "pysam/csamtools.pyx":499
  *             # valid ranges are from 0 to 2^29-1
- *             if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )
- *             if not 0 <= end < max_pos: raise ValueError( 'end out of range (%i)' % end )             # <<<<<<<<<<<<<<
+ *             if not 0 <= start < max_pos: raise IndexError( 'start out of range (%i)' % start )
+ *             if not 0 <= end < max_pos: raise IndexError( 'end out of range (%i)' % end )             # <<<<<<<<<<<<<<
  *             # note: faidx_fetch_seq has a bug such that out-of-range access
  *             # always returns the last residue. Hence do not use faidx_fetch_seq,
  */
-    __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_end, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_end, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (__Pyx_PyObject_IsTrue(__pyx_t_1)) {
       __Pyx_DECREF(__pyx_t_1);
-      __pyx_t_2 = PyInt_FromLong(__pyx_v_5pysam_9csamtools_max_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyInt_FromLong(__pyx_v_5pysam_9csamtools_max_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
-      __pyx_t_1 = PyObject_RichCompare(__pyx_v_end, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_RichCompare(__pyx_v_end, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     }
-    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __pyx_t_3 = (!__pyx_t_4);
     if (__pyx_t_3) {
-      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), __pyx_v_end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
       __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
       __pyx_t_1 = 0;
-      __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
       __Pyx_Raise(__pyx_t_1, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L11;
     }
     __pyx_L11:;
 
-    /* "pysam/csamtools.pyx":486
+    /* "pysam/csamtools.pyx":508
  *             #                       end-1,
  *             #                       &length)
  *             region = "%s:%i-%i" % (reference, start+1, end)             # <<<<<<<<<<<<<<
  *             if PY_MAJOR_VERSION >= 3:
  *                 region = region.encode('ascii')
  */
-    __pyx_t_1 = PyNumber_Add(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyNumber_Add(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_INCREF(__pyx_v_reference);
     PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_reference);
@@ -6241,14 +7030,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
     PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_end);
     __Pyx_GIVEREF(__pyx_v_end);
     __pyx_t_1 = 0;
-    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_19), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_23), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
     __Pyx_DECREF(__pyx_v_region);
     __pyx_v_region = ((PyObject *)__pyx_t_1);
     __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":487
+    /* "pysam/csamtools.pyx":509
  *             #                       &length)
  *             region = "%s:%i-%i" % (reference, start+1, end)
  *             if PY_MAJOR_VERSION >= 3:             # <<<<<<<<<<<<<<
@@ -6258,16 +7047,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
     __pyx_t_3 = (PY_MAJOR_VERSION >= 3);
     if (__pyx_t_3) {
 
-      /* "pysam/csamtools.pyx":488
+      /* "pysam/csamtools.pyx":510
  *             region = "%s:%i-%i" % (reference, start+1, end)
  *             if PY_MAJOR_VERSION >= 3:
  *                 region = region.encode('ascii')             # <<<<<<<<<<<<<<
  *             seq = fai_fetch( self.fastafile,
  *                              region,
  */
-      __pyx_t_1 = PyObject_GetAttr(__pyx_v_region, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_GetAttr(__pyx_v_region, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __Pyx_DECREF(__pyx_v_region);
@@ -6277,16 +7066,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
     }
     __pyx_L12:;
 
-    /* "pysam/csamtools.pyx":490
+    /* "pysam/csamtools.pyx":512
  *                 region = region.encode('ascii')
  *             seq = fai_fetch( self.fastafile,
  *                              region,             # <<<<<<<<<<<<<<
  *                              &length )
  *         else:
  */
-    __pyx_t_5 = PyBytes_AsString(__pyx_v_region); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyBytes_AsString(__pyx_v_region); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "pysam/csamtools.pyx":491
+    /* "pysam/csamtools.pyx":513
  *             seq = fai_fetch( self.fastafile,
  *                              region,
  *                              &length )             # <<<<<<<<<<<<<<
@@ -6298,19 +7087,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":494
+    /* "pysam/csamtools.pyx":516
  *         else:
  *             # samtools adds a '\0' at the end
  *             seq = fai_fetch( self.fastafile, region, &length )             # <<<<<<<<<<<<<<
  * 
  *         # copy to python
  */
-    __pyx_t_5 = PyBytes_AsString(__pyx_v_region); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyBytes_AsString(__pyx_v_region); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_v_seq = fai_fetch(__pyx_v_self->fastafile, __pyx_t_5, (&__pyx_v_length));
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":497
+  /* "pysam/csamtools.pyx":519
  * 
  *         # copy to python
  *         if seq == NULL:             # <<<<<<<<<<<<<<
@@ -6320,7 +7109,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
   __pyx_t_3 = (__pyx_v_seq == NULL);
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":498
+    /* "pysam/csamtools.pyx":520
  *         # copy to python
  *         if seq == NULL:
  *             return b""             # <<<<<<<<<<<<<<
@@ -6328,14 +7117,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
  *             try:
  */
     __Pyx_XDECREF(__pyx_r);
-    __Pyx_INCREF(((PyObject *)__pyx_kp_b_16));
-    __pyx_r = ((PyObject *)__pyx_kp_b_16);
+    __Pyx_INCREF(((PyObject *)__pyx_kp_b_20));
+    __pyx_r = ((PyObject *)__pyx_kp_b_20);
     goto __pyx_L0;
     goto __pyx_L13;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":500
+    /* "pysam/csamtools.pyx":522
  *             return b""
  *         else:
  *             try:             # <<<<<<<<<<<<<<
@@ -6344,20 +7133,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
  */
     /*try:*/ {
 
-      /* "pysam/csamtools.pyx":501
+      /* "pysam/csamtools.pyx":523
  *         else:
  *             try:
  *                 py_seq = seq[:length]             # <<<<<<<<<<<<<<
  *             finally:
  *                 free(seq)
  */
-      __pyx_t_2 = PyBytes_FromStringAndSize(__pyx_v_seq + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L15;}
+      __pyx_t_2 = PyBytes_FromStringAndSize(__pyx_v_seq + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L15;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
       __pyx_v_py_seq = ((PyObject*)__pyx_t_2);
       __pyx_t_2 = 0;
     }
 
-    /* "pysam/csamtools.pyx":503
+    /* "pysam/csamtools.pyx":525
  *                 py_seq = seq[:length]
  *             finally:
  *                 free(seq)             # <<<<<<<<<<<<<<
@@ -6394,7 +7183,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
   }
   __pyx_L13:;
 
-  /* "pysam/csamtools.pyx":505
+  /* "pysam/csamtools.pyx":527
  *                 free(seq)
  * 
  *         return py_seq             # <<<<<<<<<<<<<<
@@ -6424,7 +7213,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_12fetch(struct __pyx_obj_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":507
+/* "pysam/csamtools.pyx":529
  *         return py_seq
  * 
  *     cdef char * _fetch( self, char * reference, int start, int end, int * length ):             # <<<<<<<<<<<<<<
@@ -6437,14 +7226,14 @@ static char *__pyx_f_5pysam_9csamtools_9Fastafile__fetch(struct __pyx_obj_5pysam
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_fetch", 0);
-  __Pyx_TraceCall("_fetch", __pyx_f[0], 507);
+  __Pyx_TraceCall("_fetch", __pyx_f[0], 529);
 
-  /* "pysam/csamtools.pyx":514
+  /* "pysam/csamtools.pyx":536
  *                                start,
  *                                end-1,
  *                                length )             # <<<<<<<<<<<<<<
  * 
- * 
+ *     def getReferenceLength( self, reference ):
  */
   __pyx_r = faidx_fetch_seq(__pyx_v_self->fastafile, __pyx_v_reference, __pyx_v_start, (__pyx_v_end - 1), __pyx_v_length);
   goto __pyx_L0;
@@ -6457,6 +7246,190 @@ static char *__pyx_f_5pysam_9csamtools_9Fastafile__fetch(struct __pyx_obj_5pysam
 }
 
 /* Python wrapper */
+static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_15getReferenceLength(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
+static char __pyx_doc_5pysam_9csamtools_9Fastafile_14getReferenceLength[] = "Fastafile.getReferenceLength(self, reference)\nreturn the length of reference.";
+static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_15getReferenceLength(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("getReferenceLength (wrapper)", 0);
+  __pyx_r = __pyx_pf_5pysam_9csamtools_9Fastafile_14getReferenceLength(((struct __pyx_obj_5pysam_9csamtools_Fastafile *)__pyx_v_self), ((PyObject *)__pyx_v_reference));
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "pysam/csamtools.pyx":538
+ *                                length )
+ * 
+ *     def getReferenceLength( self, reference ):             # <<<<<<<<<<<<<<
+ *         '''return the length of reference.'''
+ *         return self.reference2length[reference]
+ */
+
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_14getReferenceLength(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_reference) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_TraceDeclarations
+  __Pyx_RefNannySetupContext("getReferenceLength", 0);
+  __Pyx_TraceCall("getReferenceLength", __pyx_f[0], 538);
+
+  /* "pysam/csamtools.pyx":540
+ *     def getReferenceLength( self, reference ):
+ *         '''return the length of reference.'''
+ *         return self.reference2length[reference]             # <<<<<<<<<<<<<<
+ * 
+ *     def __getitem__(self, reference):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyObject_GetItem(__pyx_v_self->reference2length, __pyx_v_reference); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("pysam.csamtools.Fastafile.getReferenceLength", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_TraceReturn(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_17__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
+static PyObject *__pyx_pw_5pysam_9csamtools_9Fastafile_17__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_5pysam_9csamtools_9Fastafile_16__getitem__(((struct __pyx_obj_5pysam_9csamtools_Fastafile *)__pyx_v_self), ((PyObject *)__pyx_v_reference));
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "pysam/csamtools.pyx":542
+ *         return self.reference2length[reference]
+ * 
+ *     def __getitem__(self, reference):             # <<<<<<<<<<<<<<
+ *         return self.fetch(reference)
+ * 
+ */
+
+static PyObject *__pyx_pf_5pysam_9csamtools_9Fastafile_16__getitem__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_reference) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_TraceDeclarations
+  __Pyx_RefNannySetupContext("__getitem__", 0);
+  __Pyx_TraceCall("__getitem__", __pyx_f[0], 542);
+
+  /* "pysam/csamtools.pyx":543
+ * 
+ *     def __getitem__(self, reference):
+ *         return self.fetch(reference)             # <<<<<<<<<<<<<<
+ * 
+ *     def __contains__( self, reference ):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__fetch); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(__pyx_v_reference);
+  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_reference);
+  __Pyx_GIVEREF(__pyx_v_reference);
+  __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 = 543; __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_r = __pyx_t_3;
+  __pyx_t_3 = 0;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("pysam.csamtools.Fastafile.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_TraceReturn(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static int __pyx_pw_5pysam_9csamtools_9Fastafile_19__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
+static char __pyx_doc_5pysam_9csamtools_9Fastafile_18__contains__[] = "return true if reference in fasta file.";
+#if CYTHON_COMPILING_IN_CPYTHON
+struct wrapperbase __pyx_wrapperbase_5pysam_9csamtools_9Fastafile_18__contains__;
+#endif
+static int __pyx_pw_5pysam_9csamtools_9Fastafile_19__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_5pysam_9csamtools_9Fastafile_18__contains__(((struct __pyx_obj_5pysam_9csamtools_Fastafile *)__pyx_v_self), ((PyObject *)__pyx_v_reference));
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "pysam/csamtools.pyx":545
+ *         return self.fetch(reference)
+ * 
+ *     def __contains__( self, reference ):             # <<<<<<<<<<<<<<
+ *         '''return true if reference in fasta file.'''
+ *         return reference in self.reference2length
+ */
+
+static int __pyx_pf_5pysam_9csamtools_9Fastafile_18__contains__(struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_reference) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_TraceDeclarations
+  __Pyx_RefNannySetupContext("__contains__", 0);
+  __Pyx_TraceCall("__contains__", __pyx_f[0], 545);
+
+  /* "pysam/csamtools.pyx":547
+ *     def __contains__( self, reference ):
+ *         '''return true if reference in fasta file.'''
+ *         return reference in self.reference2length             # <<<<<<<<<<<<<<
+ * 
+ * ######################################################################
+ */
+  __pyx_t_1 = (__Pyx_PySequence_Contains(__pyx_v_reference, __pyx_v_self->reference2length, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 547; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_r = __pyx_t_1;
+  goto __pyx_L0;
+
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("pysam.csamtools.Fastafile.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_TraceReturn(Py_None);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
 static int __pyx_pw_5pysam_9csamtools_10FastqProxy_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 static int __pyx_pw_5pysam_9csamtools_10FastqProxy_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
   int __pyx_r;
@@ -6470,7 +7443,7 @@ static int __pyx_pw_5pysam_9csamtools_10FastqProxy_1__init__(PyObject *__pyx_v_s
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":524
+/* "pysam/csamtools.pyx":556
  * 
  * cdef class FastqProxy:
  *     def __init__(self): pass             # <<<<<<<<<<<<<<
@@ -6483,7 +7456,7 @@ static int __pyx_pf_5pysam_9csamtools_10FastqProxy___init__(CYTHON_UNUSED struct
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__init__", 0);
-  __Pyx_TraceCall("__init__", __pyx_f[0], 524);
+  __Pyx_TraceCall("__init__", __pyx_f[0], 556);
 
   __pyx_r = 0;
   __Pyx_TraceReturn(Py_None);
@@ -6502,7 +7475,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_10FastqProxy_4name_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":527
+/* "pysam/csamtools.pyx":559
  * 
  *     property name:
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -6519,9 +7492,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_4name___get__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 527);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 559);
 
-  /* "pysam/csamtools.pyx":528
+  /* "pysam/csamtools.pyx":560
  *     property name:
  *         def __get__(self):
  *             return self._delegate.name.s             # <<<<<<<<<<<<<<
@@ -6529,7 +7502,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_4name___get__(struct __
  *     property sequence:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyBytes_FromString(__pyx_v_self->_delegate->name.s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyBytes_FromString(__pyx_v_self->_delegate->name.s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
   __pyx_r = ((PyObject *)__pyx_t_1);
   __pyx_t_1 = 0;
@@ -6559,7 +7532,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_10FastqProxy_8sequence_1__get__(PyOb
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":531
+/* "pysam/csamtools.pyx":563
  * 
  *     property sequence:
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -6576,9 +7549,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_8sequence___get__(struc
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 531);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 563);
 
-  /* "pysam/csamtools.pyx":532
+  /* "pysam/csamtools.pyx":564
  *     property sequence:
  *         def __get__(self):
  *             return self._delegate.seq.s             # <<<<<<<<<<<<<<
@@ -6586,7 +7559,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_8sequence___get__(struc
  *     property comment:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyBytes_FromString(__pyx_v_self->_delegate->seq.s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyBytes_FromString(__pyx_v_self->_delegate->seq.s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
   __pyx_r = ((PyObject *)__pyx_t_1);
   __pyx_t_1 = 0;
@@ -6616,7 +7589,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_10FastqProxy_7comment_1__get__(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":535
+/* "pysam/csamtools.pyx":567
  * 
  *     property comment:
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -6633,9 +7606,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_7comment___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 535);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 567);
 
-  /* "pysam/csamtools.pyx":536
+  /* "pysam/csamtools.pyx":568
  *     property comment:
  *         def __get__(self):
  *             if self._delegate.comment.l:             # <<<<<<<<<<<<<<
@@ -6644,7 +7617,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_7comment___get__(struct
  */
   if (__pyx_v_self->_delegate->comment.l) {
 
-    /* "pysam/csamtools.pyx":537
+    /* "pysam/csamtools.pyx":569
  *         def __get__(self):
  *             if self._delegate.comment.l:
  *                 return self._delegate.comment.s             # <<<<<<<<<<<<<<
@@ -6652,7 +7625,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_7comment___get__(struct
  * 
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_1 = PyBytes_FromString(__pyx_v_self->_delegate->comment.s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 537; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyBytes_FromString(__pyx_v_self->_delegate->comment.s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
     __pyx_r = ((PyObject *)__pyx_t_1);
     __pyx_t_1 = 0;
@@ -6661,7 +7634,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_7comment___get__(struct
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":538
+    /* "pysam/csamtools.pyx":570
  *             if self._delegate.comment.l:
  *                 return self._delegate.comment.s
  *             else: return None             # <<<<<<<<<<<<<<
@@ -6699,7 +7672,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_10FastqProxy_7quality_1__get__(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":541
+/* "pysam/csamtools.pyx":573
  * 
  *     property quality:
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -6716,9 +7689,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_7quality___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 541);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 573);
 
-  /* "pysam/csamtools.pyx":542
+  /* "pysam/csamtools.pyx":574
  *     property quality:
  *         def __get__(self):
  *             if self._delegate.qual.l:             # <<<<<<<<<<<<<<
@@ -6727,7 +7700,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_7quality___get__(struct
  */
   if (__pyx_v_self->_delegate->qual.l) {
 
-    /* "pysam/csamtools.pyx":543
+    /* "pysam/csamtools.pyx":575
  *         def __get__(self):
  *             if self._delegate.qual.l:
  *                 return self._delegate.qual.s             # <<<<<<<<<<<<<<
@@ -6735,7 +7708,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_7quality___get__(struct
  * 
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_1 = PyBytes_FromString(__pyx_v_self->_delegate->qual.s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyBytes_FromString(__pyx_v_self->_delegate->qual.s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
     __pyx_r = ((PyObject *)__pyx_t_1);
     __pyx_t_1 = 0;
@@ -6744,7 +7717,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10FastqProxy_7quality___get__(struct
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":544
+    /* "pysam/csamtools.pyx":576
  *             if self._delegate.qual.l:
  *                 return self._delegate.qual.s
  *             else: return None             # <<<<<<<<<<<<<<
@@ -6792,12 +7765,12 @@ static int __pyx_pw_5pysam_9csamtools_9Fastqfile_1__cinit__(PyObject *__pyx_v_se
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":553
- *     '''
+/* "pysam/csamtools.pyx":584
  * 
+ *     '''
  *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
- *         # self.fastqfile = NULL
- *         self._filename = NULL
+ *         # self.fastqfile = <gzFile*>NULL
+ *         self._filename = None
  */
 
 static int __pyx_pf_5pysam_9csamtools_9Fastqfile___cinit__(struct __pyx_obj_5pysam_9csamtools_Fastqfile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
@@ -6812,31 +7785,44 @@ static int __pyx_pf_5pysam_9csamtools_9Fastqfile___cinit__(struct __pyx_obj_5pys
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__cinit__", 0);
-  __Pyx_TraceCall("__cinit__", __pyx_f[0], 553);
+  __Pyx_TraceCall("__cinit__", __pyx_f[0], 584);
 
-  /* "pysam/csamtools.pyx":555
+  /* "pysam/csamtools.pyx":586
  *     def __cinit__(self, *args, **kwargs ):
- *         # self.fastqfile = NULL
- *         self._filename = NULL             # <<<<<<<<<<<<<<
+ *         # self.fastqfile = <gzFile*>NULL
+ *         self._filename = None             # <<<<<<<<<<<<<<
+ *         self.entry = NULL
+ *         self._open( *args, **kwargs )
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->_filename);
+  __Pyx_DECREF(__pyx_v_self->_filename);
+  __pyx_v_self->_filename = Py_None;
+
+  /* "pysam/csamtools.pyx":587
+ *         # self.fastqfile = <gzFile*>NULL
+ *         self._filename = None
+ *         self.entry = NULL             # <<<<<<<<<<<<<<
  *         self._open( *args, **kwargs )
  * 
  */
-  __pyx_v_self->_filename = NULL;
+  __pyx_v_self->entry = NULL;
 
-  /* "pysam/csamtools.pyx":556
- *         # self.fastqfile = NULL
- *         self._filename = NULL
+  /* "pysam/csamtools.pyx":588
+ *         self._filename = None
+ *         self.entry = NULL
  *         self._open( *args, **kwargs )             # <<<<<<<<<<<<<<
  * 
  *     def _isOpen( self ):
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
   __pyx_t_3 = ((PyObject *)__pyx_v_kwargs);
   __Pyx_INCREF(__pyx_t_3);
-  __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
@@ -6870,12 +7856,12 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastqfile_3_isOpen(PyObject *__pyx_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":558
+/* "pysam/csamtools.pyx":590
  *         self._open( *args, **kwargs )
  * 
  *     def _isOpen( self ):             # <<<<<<<<<<<<<<
  *         '''return true if samfile has been opened.'''
- *         return self._filename != NULL
+ *         return self.entry != NULL
  */
 
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_2_isOpen(struct __pyx_obj_5pysam_9csamtools_Fastqfile *__pyx_v_self) {
@@ -6887,17 +7873,17 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_2_isOpen(struct __pyx_obj
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_isOpen", 0);
-  __Pyx_TraceCall("_isOpen", __pyx_f[0], 558);
+  __Pyx_TraceCall("_isOpen", __pyx_f[0], 590);
 
-  /* "pysam/csamtools.pyx":560
+  /* "pysam/csamtools.pyx":592
  *     def _isOpen( self ):
  *         '''return true if samfile has been opened.'''
- *         return self._filename != NULL             # <<<<<<<<<<<<<<
+ *         return self.entry != NULL             # <<<<<<<<<<<<<<
  * 
- *     def _open( self,
+ *     def _open(self, filename):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->_filename != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->entry != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -6928,12 +7914,12 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastqfile_5_open(PyObject *__pyx_v_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":562
- *         return self._filename != NULL
+/* "pysam/csamtools.pyx":594
+ *         return self.entry != NULL
  * 
- *     def _open( self,             # <<<<<<<<<<<<<<
- *                filename ):
+ *     def _open(self, filename):             # <<<<<<<<<<<<<<
  *         '''open an indexed fasta file.
+ * 
  */
 
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_4_open(struct __pyx_obj_5pysam_9csamtools_Fastqfile *__pyx_v_self, PyObject *__pyx_v_filename) {
@@ -6950,118 +7936,121 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_4_open(struct __pyx_obj_5
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_open", 0);
-  __Pyx_TraceCall("_open", __pyx_f[0], 562);
+  __Pyx_TraceCall("_open", __pyx_f[0], 594);
   __Pyx_INCREF(__pyx_v_filename);
 
-  /* "pysam/csamtools.pyx":569
+  /* "pysam/csamtools.pyx":599
+ *         This method expects an indexed fasta file.
  *         '''
+ *         self.close()             # <<<<<<<<<<<<<<
+ * 
+ *         if not os.path.exists( filename ):
+ */
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "pysam/csamtools.pyx":601
+ *         self.close()
  * 
  *         if not os.path.exists( filename ):             # <<<<<<<<<<<<<<
  *             raise IOError( "No such file or directory: %s" % filename )
  * 
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __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 = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __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__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__path); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __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 = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__exists); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __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 = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__pyx_v_filename);
-  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_filename);
+  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_filename);
   __Pyx_GIVEREF(__pyx_v_filename);
-  __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 = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __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_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   __pyx_t_5 = (!__pyx_t_4);
   if (__pyx_t_5) {
 
-    /* "pysam/csamtools.pyx":570
+    /* "pysam/csamtools.pyx":602
  * 
  *         if not os.path.exists( filename ):
  *             raise IOError( "No such file or directory: %s" % filename )             # <<<<<<<<<<<<<<
  * 
- *         # close a previously opened file
+ *         filename = _encodeFilename(filename)
  */
-    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_v_filename); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_25), __pyx_v_filename); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
-    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_2);
-    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
+    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_1);
+    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
     __pyx_t_3 = 0;
-    __pyx_t_3 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
     __Pyx_Raise(__pyx_t_3, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":574
- *         # close a previously opened file
- *         # if self.fastqfile != NULL: self.close()
- *         if self._filename != NULL: free(self._filename)             # <<<<<<<<<<<<<<
- *         filename = _my_encodeFilename(filename)
- *         self._filename = strdup(filename)
- */
-  __pyx_t_5 = (__pyx_v_self->_filename != NULL);
-  if (__pyx_t_5) {
-    free(__pyx_v_self->_filename);
-    goto __pyx_L4;
-  }
-  __pyx_L4:;
-
-  /* "pysam/csamtools.pyx":575
- *         # if self.fastqfile != NULL: self.close()
- *         if self._filename != NULL: free(self._filename)
- *         filename = _my_encodeFilename(filename)             # <<<<<<<<<<<<<<
- *         self._filename = strdup(filename)
+  /* "pysam/csamtools.pyx":604
+ *             raise IOError( "No such file or directory: %s" % filename )
+ * 
+ *         filename = _encodeFilename(filename)             # <<<<<<<<<<<<<<
  *         self.fastqfile = gzopen( filename, "r" )
+ *         self.entry = kseq_init( self.fastqfile )
  */
-  __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_9csamtools__my_encodeFilename(__pyx_v_filename)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_9csamtools__encodeFilename(__pyx_v_filename)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_v_filename);
   __pyx_v_filename = __pyx_t_3;
   __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":576
- *         if self._filename != NULL: free(self._filename)
- *         filename = _my_encodeFilename(filename)
- *         self._filename = strdup(filename)             # <<<<<<<<<<<<<<
- *         self.fastqfile = gzopen( filename, "r" )
- *         self.entry = kseq_init( self.fastqfile )
- */
-  __pyx_t_6 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_v_self->_filename = strdup(__pyx_t_6);
-
-  /* "pysam/csamtools.pyx":577
- *         filename = _my_encodeFilename(filename)
- *         self._filename = strdup(filename)
+  /* "pysam/csamtools.pyx":605
+ * 
+ *         filename = _encodeFilename(filename)
  *         self.fastqfile = gzopen( filename, "r" )             # <<<<<<<<<<<<<<
  *         self.entry = kseq_init( self.fastqfile )
- * 
+ *         self._filename = filename
  */
-  __pyx_t_6 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_6 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->fastqfile = gzopen(__pyx_t_6, __pyx_k__r);
 
-  /* "pysam/csamtools.pyx":578
- *         self._filename = strdup(filename)
+  /* "pysam/csamtools.pyx":606
+ *         filename = _encodeFilename(filename)
  *         self.fastqfile = gzopen( filename, "r" )
  *         self.entry = kseq_init( self.fastqfile )             # <<<<<<<<<<<<<<
+ *         self._filename = filename
  * 
- *     def close( self ):
  */
   __pyx_v_self->entry = kseq_init(__pyx_v_self->fastqfile);
 
+  /* "pysam/csamtools.pyx":607
+ *         self.fastqfile = gzopen( filename, "r" )
+ *         self.entry = kseq_init( self.fastqfile )
+ *         self._filename = filename             # <<<<<<<<<<<<<<
+ * 
+ *     def close( self ):
+ */
+  __Pyx_INCREF(__pyx_v_filename);
+  __Pyx_GIVEREF(__pyx_v_filename);
+  __Pyx_GOTREF(__pyx_v_self->_filename);
+  __Pyx_DECREF(__pyx_v_self->_filename);
+  __pyx_v_self->_filename = __pyx_v_filename;
+
   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -7090,12 +8079,12 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastqfile_7close(PyObject *__pyx_v_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":580
- *         self.entry = kseq_init( self.fastqfile )
+/* "pysam/csamtools.pyx":609
+ *         self._filename = filename
  * 
  *     def close( self ):             # <<<<<<<<<<<<<<
  *         '''close file.'''
- *         if self._filename != NULL:
+ *         if self.entry != NULL:
  */
 
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_6close(struct __pyx_obj_5pysam_9csamtools_Fastqfile *__pyx_v_self) {
@@ -7104,35 +8093,57 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_6close(struct __pyx_obj_5
   int __pyx_t_1;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("close", 0);
-  __Pyx_TraceCall("close", __pyx_f[0], 580);
+  __Pyx_TraceCall("close", __pyx_f[0], 609);
 
-  /* "pysam/csamtools.pyx":582
+  /* "pysam/csamtools.pyx":611
  *     def close( self ):
  *         '''close file.'''
- *         if self._filename != NULL:             # <<<<<<<<<<<<<<
+ *         if self.entry != NULL:             # <<<<<<<<<<<<<<
  *             gzclose( self.fastqfile )
- *             free(self._filename)
+ *             if self.entry:
  */
-  __pyx_t_1 = (__pyx_v_self->_filename != NULL);
+  __pyx_t_1 = (__pyx_v_self->entry != NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":583
+    /* "pysam/csamtools.pyx":612
  *         '''close file.'''
- *         if self._filename != NULL:
+ *         if self.entry != NULL:
  *             gzclose( self.fastqfile )             # <<<<<<<<<<<<<<
- *             free(self._filename)
- * 
+ *             if self.entry:
+ *                 kseq_destroy(self.entry)
  */
     gzclose(__pyx_v_self->fastqfile);
 
-    /* "pysam/csamtools.pyx":584
- *         if self._filename != NULL:
+    /* "pysam/csamtools.pyx":613
+ *         if self.entry != NULL:
  *             gzclose( self.fastqfile )
- *             free(self._filename)             # <<<<<<<<<<<<<<
+ *             if self.entry:             # <<<<<<<<<<<<<<
+ *                 kseq_destroy(self.entry)
+ *                 self.entry = NULL
+ */
+    __pyx_t_1 = (__pyx_v_self->entry != 0);
+    if (__pyx_t_1) {
+
+      /* "pysam/csamtools.pyx":614
+ *             gzclose( self.fastqfile )
+ *             if self.entry:
+ *                 kseq_destroy(self.entry)             # <<<<<<<<<<<<<<
+ *                 self.entry = NULL
+ * 
+ */
+      kseq_destroy(__pyx_v_self->entry);
+
+      /* "pysam/csamtools.pyx":615
+ *             if self.entry:
+ *                 kseq_destroy(self.entry)
+ *                 self.entry = NULL             # <<<<<<<<<<<<<<
  * 
  *     def __dealloc__(self):
  */
-    free(__pyx_v_self->_filename);
+      __pyx_v_self->entry = NULL;
+      goto __pyx_L4;
+    }
+    __pyx_L4:;
     goto __pyx_L3;
   }
   __pyx_L3:;
@@ -7153,12 +8164,12 @@ static void __pyx_pw_5pysam_9csamtools_9Fastqfile_9__dealloc__(PyObject *__pyx_v
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/csamtools.pyx":586
- *             free(self._filename)
+/* "pysam/csamtools.pyx":617
+ *                 self.entry = NULL
  * 
  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
- *         kseq_destroy(self.entry)
  *         self.close()
+ * 
  */
 
 static void __pyx_pf_5pysam_9csamtools_9Fastqfile_8__dealloc__(struct __pyx_obj_5pysam_9csamtools_Fastqfile *__pyx_v_self) {
@@ -7170,27 +8181,18 @@ static void __pyx_pf_5pysam_9csamtools_9Fastqfile_8__dealloc__(struct __pyx_obj_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__dealloc__", 0);
-  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 586);
+  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 617);
 
-  /* "pysam/csamtools.pyx":587
+  /* "pysam/csamtools.pyx":618
  * 
  *     def __dealloc__(self):
- *         kseq_destroy(self.entry)             # <<<<<<<<<<<<<<
- *         self.close()
- * 
- */
-  kseq_destroy(__pyx_v_self->entry);
-
-  /* "pysam/csamtools.pyx":588
- *     def __dealloc__(self):
- *         kseq_destroy(self.entry)
  *         self.close()             # <<<<<<<<<<<<<<
  * 
  *     property filename:
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 618; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 618; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
@@ -7216,74 +8218,34 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastqfile_8filename_1__get__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":592
+/* "pysam/csamtools.pyx":622
  *     property filename:
  *         '''number of :term:`filename` associated with this object.'''
  *         def __get__(self):             # <<<<<<<<<<<<<<
- *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             return self._filename
+ * 
  */
 
 static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_8filename___get__(struct __pyx_obj_5pysam_9csamtools_Fastqfile *__pyx_v_self) {
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
-  PyObject *__pyx_t_1 = NULL;
-  PyObject *__pyx_t_2 = NULL;
-  int __pyx_t_3;
-  int __pyx_t_4;
-  int __pyx_lineno = 0;
-  const char *__pyx_filename = NULL;
-  int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 592);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 622);
 
-  /* "pysam/csamtools.pyx":593
+  /* "pysam/csamtools.pyx":623
  *         '''number of :term:`filename` associated with this object.'''
  *         def __get__(self):
- *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
- *             return self._filename
- * 
- */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_2);
-  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_4 = (!__pyx_t_3);
-  if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __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 = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    goto __pyx_L3;
-  }
-  __pyx_L3:;
-
-  /* "pysam/csamtools.pyx":594
- *         def __get__(self):
- *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             return self._filename             # <<<<<<<<<<<<<<
  * 
  *     def __iter__(self):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = PyBytes_FromString(__pyx_v_self->_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-  __pyx_r = ((PyObject *)__pyx_t_2);
-  __pyx_t_2 = 0;
+  __Pyx_INCREF(__pyx_v_self->_filename);
+  __pyx_r = __pyx_v_self->_filename;
   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_AddTraceback("pysam.csamtools.Fastqfile.filename.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
   __pyx_L0:;
   __Pyx_XGIVEREF(__pyx_r);
   __Pyx_TraceReturn(__pyx_r);
@@ -7302,7 +8264,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastqfile_11__iter__(PyObject *__py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":596
+/* "pysam/csamtools.pyx":625
  *             return self._filename
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
@@ -7322,34 +8284,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_10__iter__(struct __pyx_o
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__iter__", 0);
-  __Pyx_TraceCall("__iter__", __pyx_f[0], 596);
+  __Pyx_TraceCall("__iter__", __pyx_f[0], 625);
 
-  /* "pysam/csamtools.pyx":597
+  /* "pysam/csamtools.pyx":626
  * 
  *     def __iter__(self):
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         return self
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __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 = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":598
+  /* "pysam/csamtools.pyx":627
  *     def __iter__(self):
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *         return self             # <<<<<<<<<<<<<<
@@ -7375,7 +8337,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_10__iter__(struct __pyx_o
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":600
+/* "pysam/csamtools.pyx":629
  *         return self
  * 
  *     cdef kseq_t * getCurrent( self ):             # <<<<<<<<<<<<<<
@@ -7388,9 +8350,9 @@ static kseq_t *__pyx_f_5pysam_9csamtools_9Fastqfile_getCurrent(struct __pyx_obj_
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("getCurrent", 0);
-  __Pyx_TraceCall("getCurrent", __pyx_f[0], 600);
+  __Pyx_TraceCall("getCurrent", __pyx_f[0], 629);
 
-  /* "pysam/csamtools.pyx":601
+  /* "pysam/csamtools.pyx":630
  * 
  *     cdef kseq_t * getCurrent( self ):
  *         return self.entry             # <<<<<<<<<<<<<<
@@ -7407,7 +8369,7 @@ static kseq_t *__pyx_f_5pysam_9csamtools_9Fastqfile_getCurrent(struct __pyx_obj_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":603
+/* "pysam/csamtools.pyx":632
  *         return self.entry
  * 
  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
@@ -7420,9 +8382,9 @@ static int __pyx_f_5pysam_9csamtools_9Fastqfile_cnext(struct __pyx_obj_5pysam_9c
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("cnext", 0);
-  __Pyx_TraceCall("cnext", __pyx_f[0], 603);
+  __Pyx_TraceCall("cnext", __pyx_f[0], 632);
 
-  /* "pysam/csamtools.pyx":606
+  /* "pysam/csamtools.pyx":635
  *         '''C version of iterator
  *         '''
  *         return kseq_read(self.entry)             # <<<<<<<<<<<<<<
@@ -7454,7 +8416,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_9Fastqfile_13__next__(PyObject *__py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":608
+/* "pysam/csamtools.pyx":637
  *         return kseq_read(self.entry)
  * 
  *     def __next__(self):             # <<<<<<<<<<<<<<
@@ -7473,9 +8435,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_12__next__(struct __pyx_o
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__next__", 0);
-  __Pyx_TraceCall("__next__", __pyx_f[0], 608);
+  __Pyx_TraceCall("__next__", __pyx_f[0], 637);
 
-  /* "pysam/csamtools.pyx":613
+  /* "pysam/csamtools.pyx":642
  *         """
  *         cdef int l
  *         l = kseq_read( self.entry)             # <<<<<<<<<<<<<<
@@ -7484,7 +8446,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_12__next__(struct __pyx_o
  */
   __pyx_v_l = kseq_read(__pyx_v_self->entry);
 
-  /* "pysam/csamtools.pyx":614
+  /* "pysam/csamtools.pyx":643
  *         cdef int l
  *         l = kseq_read( self.entry)
  *         if (l > 0):             # <<<<<<<<<<<<<<
@@ -7494,7 +8456,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_12__next__(struct __pyx_o
   __pyx_t_1 = (__pyx_v_l > 0);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":615
+    /* "pysam/csamtools.pyx":644
  *         l = kseq_read( self.entry)
  *         if (l > 0):
  *             return makeFastqProxy( self.entry )             # <<<<<<<<<<<<<<
@@ -7502,7 +8464,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_12__next__(struct __pyx_o
  *             raise StopIteration
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = __pyx_f_5pysam_9csamtools_makeFastqProxy(__pyx_v_self->entry); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __pyx_f_5pysam_9csamtools_makeFastqProxy(__pyx_v_self->entry); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __pyx_r = __pyx_t_2;
     __pyx_t_2 = 0;
@@ -7511,15 +8473,15 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_12__next__(struct __pyx_o
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":617
+    /* "pysam/csamtools.pyx":646
  *             return makeFastqProxy( self.entry )
  *         else:
  *             raise StopIteration             # <<<<<<<<<<<<<<
  * 
- *     def test( self ):
+ * #------------------------------------------------------------------------
  */
     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L3:;
 
@@ -7536,147 +8498,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_12__next__(struct __pyx_o
   return __pyx_r;
 }
 
-/* Python wrapper */
-static PyObject *__pyx_pw_5pysam_9csamtools_9Fastqfile_15test(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static char __pyx_doc_5pysam_9csamtools_9Fastqfile_14test[] = "Fastqfile.test(self)";
-static PyObject *__pyx_pw_5pysam_9csamtools_9Fastqfile_15test(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
-  PyObject *__pyx_r = 0;
-  __Pyx_RefNannyDeclarations
-  __Pyx_RefNannySetupContext("test (wrapper)", 0);
-  __pyx_r = __pyx_pf_5pysam_9csamtools_9Fastqfile_14test(((struct __pyx_obj_5pysam_9csamtools_Fastqfile *)__pyx_v_self));
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* "pysam/csamtools.pyx":619
- *             raise StopIteration
- * 
- *     def test( self ):             # <<<<<<<<<<<<<<
- * 
- *         cdef int l
- */
-
-static PyObject *__pyx_pf_5pysam_9csamtools_9Fastqfile_14test(struct __pyx_obj_5pysam_9csamtools_Fastqfile *__pyx_v_self) {
-  int __pyx_v_l;
-  PyObject *__pyx_r = NULL;
-  __Pyx_RefNannyDeclarations
-  int __pyx_t_1;
-  __Pyx_TraceDeclarations
-  __Pyx_RefNannySetupContext("test", 0);
-  __Pyx_TraceCall("test", __pyx_f[0], 619);
-
-  /* "pysam/csamtools.pyx":623
- *         cdef int l
- * 
- *         while 1:             # <<<<<<<<<<<<<<
- *             l = kseq_read(self.entry)
- *             if l <= 0: break
- */
-  while (1) {
-    if (!1) break;
-
-    /* "pysam/csamtools.pyx":624
- * 
- *         while 1:
- *             l = kseq_read(self.entry)             # <<<<<<<<<<<<<<
- *             if l <= 0: break
- *             printf( "name: %s\n", self.entry.name.s)
- */
-    __pyx_v_l = kseq_read(__pyx_v_self->entry);
-
-    /* "pysam/csamtools.pyx":625
- *         while 1:
- *             l = kseq_read(self.entry)
- *             if l <= 0: break             # <<<<<<<<<<<<<<
- *             printf( "name: %s\n", self.entry.name.s)
- *             if self.entry.comment.l:
- */
-    __pyx_t_1 = (__pyx_v_l <= 0);
-    if (__pyx_t_1) {
-      goto __pyx_L4_break;
-      goto __pyx_L5;
-    }
-    __pyx_L5:;
-
-    /* "pysam/csamtools.pyx":626
- *             l = kseq_read(self.entry)
- *             if l <= 0: break
- *             printf( "name: %s\n", self.entry.name.s)             # <<<<<<<<<<<<<<
- *             if self.entry.comment.l:
- *                 printf("comment: %s\n", self.entry.comment.s)
- */
-    printf(__pyx_k_24, __pyx_v_self->entry->name.s);
-
-    /* "pysam/csamtools.pyx":627
- *             if l <= 0: break
- *             printf( "name: %s\n", self.entry.name.s)
- *             if self.entry.comment.l:             # <<<<<<<<<<<<<<
- *                 printf("comment: %s\n", self.entry.comment.s)
- *             printf("seq: %s\n", self.entry.seq.s)
- */
-    if (__pyx_v_self->entry->comment.l) {
-
-      /* "pysam/csamtools.pyx":628
- *             printf( "name: %s\n", self.entry.name.s)
- *             if self.entry.comment.l:
- *                 printf("comment: %s\n", self.entry.comment.s)             # <<<<<<<<<<<<<<
- *             printf("seq: %s\n", self.entry.seq.s)
- *             if (self.entry.qual.l):
- */
-      printf(__pyx_k_25, __pyx_v_self->entry->comment.s);
-      goto __pyx_L6;
-    }
-    __pyx_L6:;
-
-    /* "pysam/csamtools.pyx":629
- *             if self.entry.comment.l:
- *                 printf("comment: %s\n", self.entry.comment.s)
- *             printf("seq: %s\n", self.entry.seq.s)             # <<<<<<<<<<<<<<
- *             if (self.entry.qual.l):
- *                 printf("qual: %s\n", self.entry.qual.s);
- */
-    printf(__pyx_k_26, __pyx_v_self->entry->seq.s);
-
-    /* "pysam/csamtools.pyx":630
- *                 printf("comment: %s\n", self.entry.comment.s)
- *             printf("seq: %s\n", self.entry.seq.s)
- *             if (self.entry.qual.l):             # <<<<<<<<<<<<<<
- *                 printf("qual: %s\n", self.entry.qual.s);
- * 
- */
-    if (__pyx_v_self->entry->qual.l) {
-
-      /* "pysam/csamtools.pyx":631
- *             printf("seq: %s\n", self.entry.seq.s)
- *             if (self.entry.qual.l):
- *                 printf("qual: %s\n", self.entry.qual.s);             # <<<<<<<<<<<<<<
- * 
- *         printf("return value: %d\n", l);
- */
-      printf(__pyx_k_27, __pyx_v_self->entry->qual.s);
-      goto __pyx_L7;
-    }
-    __pyx_L7:;
-  }
-  __pyx_L4_break:;
-
-  /* "pysam/csamtools.pyx":633
- *                 printf("qual: %s\n", self.entry.qual.s);
- * 
- *         printf("return value: %d\n", l);             # <<<<<<<<<<<<<<
- * 
- * #------------------------------------------------------------------------
- */
-  printf(__pyx_k_28, __pyx_v_l);
-
-  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
-  __Pyx_XGIVEREF(__pyx_r);
-  __Pyx_TraceReturn(__pyx_r);
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* "pysam/csamtools.pyx":638
+/* "pysam/csamtools.pyx":651
  * #------------------------------------------------------------------------
  * #------------------------------------------------------------------------
  * cdef int count_callback( bam1_t *alignment, void *f):             # <<<<<<<<<<<<<<
@@ -7691,9 +8513,9 @@ static int __pyx_f_5pysam_9csamtools_count_callback(CYTHON_UNUSED bam1_t *__pyx_
   long __pyx_t_1;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("count_callback", 0);
-  __Pyx_TraceCall("count_callback", __pyx_f[0], 638);
+  __Pyx_TraceCall("count_callback", __pyx_f[0], 651);
 
-  /* "pysam/csamtools.pyx":641
+  /* "pysam/csamtools.pyx":654
  *      '''callback for bam_fetch - count number of reads.
  *      '''
  *      cdef int* counter = (<int*>f)             # <<<<<<<<<<<<<<
@@ -7702,7 +8524,7 @@ static int __pyx_f_5pysam_9csamtools_count_callback(CYTHON_UNUSED bam1_t *__pyx_
  */
   __pyx_v_counter = ((int *)__pyx_v_f);
 
-  /* "pysam/csamtools.pyx":642
+  /* "pysam/csamtools.pyx":655
  *      '''
  *      cdef int* counter = (<int*>f)
  *      counter[0] += 1;             # <<<<<<<<<<<<<<
@@ -7718,7 +8540,7 @@ static int __pyx_f_5pysam_9csamtools_count_callback(CYTHON_UNUSED bam1_t *__pyx_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":652
+/* "pysam/csamtools.pyx":665
  * #------------------------------------------------------------------------
  * #------------------------------------------------------------------------
  * cdef int mate_callback( bam1_t *alignment, void *f):             # <<<<<<<<<<<<<<
@@ -7735,9 +8557,9 @@ static int __pyx_f_5pysam_9csamtools_mate_callback(bam1_t *__pyx_v_alignment, vo
   int __pyx_t_3;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("mate_callback", 0);
-  __Pyx_TraceCall("mate_callback", __pyx_f[0], 652);
+  __Pyx_TraceCall("mate_callback", __pyx_f[0], 665);
 
-  /* "pysam/csamtools.pyx":655
+  /* "pysam/csamtools.pyx":668
  *      '''callback for bam_fetch = filter mate
  *      '''
  *      cdef MateData * d = (<MateData*>f)             # <<<<<<<<<<<<<<
@@ -7746,7 +8568,7 @@ static int __pyx_f_5pysam_9csamtools_mate_callback(bam1_t *__pyx_v_alignment, vo
  */
   __pyx_v_d = ((__pyx_t_5pysam_9csamtools_MateData *)__pyx_v_f);
 
-  /* "pysam/csamtools.pyx":660
+  /* "pysam/csamtools.pyx":673
  *      #        d.flag, alignment.core.flag, alignment.core.flag & d.flag)
  * 
  *      if d.mate == NULL:             # <<<<<<<<<<<<<<
@@ -7756,7 +8578,7 @@ static int __pyx_f_5pysam_9csamtools_mate_callback(bam1_t *__pyx_v_alignment, vo
   __pyx_t_1 = (__pyx_v_d->mate == NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":666
+    /* "pysam/csamtools.pyx":679
  *          # also, make sure that we get the other read by comparing
  *          # the flags
  *          if alignment.core.flag & d.flag != 0 and \             # <<<<<<<<<<<<<<
@@ -7766,7 +8588,7 @@ static int __pyx_f_5pysam_9csamtools_mate_callback(bam1_t *__pyx_v_alignment, vo
     __pyx_t_1 = ((__pyx_v_alignment->core.flag & __pyx_v_d->flag) != 0);
     if (__pyx_t_1) {
 
-      /* "pysam/csamtools.pyx":667
+      /* "pysam/csamtools.pyx":680
  *          # the flags
  *          if alignment.core.flag & d.flag != 0 and \
  *                  strcmp( bam1_qname( alignment ), d.name ) == 0:             # <<<<<<<<<<<<<<
@@ -7780,7 +8602,7 @@ static int __pyx_f_5pysam_9csamtools_mate_callback(bam1_t *__pyx_v_alignment, vo
     }
     if (__pyx_t_3) {
 
-      /* "pysam/csamtools.pyx":668
+      /* "pysam/csamtools.pyx":681
  *          if alignment.core.flag & d.flag != 0 and \
  *                  strcmp( bam1_qname( alignment ), d.name ) == 0:
  *              d.mate = bam_dup1( alignment )             # <<<<<<<<<<<<<<
@@ -7822,12 +8644,12 @@ static int __pyx_pw_5pysam_9csamtools_7Samfile_1__cinit__(PyObject *__pyx_v_self
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":718
+/* "pysam/csamtools.pyx":731
  *     '''
  * 
  *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
  *         self.samfile = NULL
- *         self._filename = NULL
+ *         self._filename = None
  */
 
 static int __pyx_pf_5pysam_9csamtools_7Samfile___cinit__(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
@@ -7842,37 +8664,41 @@ static int __pyx_pf_5pysam_9csamtools_7Samfile___cinit__(struct __pyx_obj_5pysam
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__cinit__", 0);
-  __Pyx_TraceCall("__cinit__", __pyx_f[0], 718);
+  __Pyx_TraceCall("__cinit__", __pyx_f[0], 731);
 
-  /* "pysam/csamtools.pyx":719
+  /* "pysam/csamtools.pyx":732
  * 
  *     def __cinit__(self, *args, **kwargs ):
  *         self.samfile = NULL             # <<<<<<<<<<<<<<
- *         self._filename = NULL
+ *         self._filename = None
  *         self.isbam = False
  */
   __pyx_v_self->samfile = NULL;
 
-  /* "pysam/csamtools.pyx":720
+  /* "pysam/csamtools.pyx":733
  *     def __cinit__(self, *args, **kwargs ):
  *         self.samfile = NULL
- *         self._filename = NULL             # <<<<<<<<<<<<<<
+ *         self._filename = None             # <<<<<<<<<<<<<<
  *         self.isbam = False
  *         self.isstream = False
  */
-  __pyx_v_self->_filename = NULL;
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->_filename);
+  __Pyx_DECREF(__pyx_v_self->_filename);
+  __pyx_v_self->_filename = Py_None;
 
-  /* "pysam/csamtools.pyx":721
+  /* "pysam/csamtools.pyx":734
  *         self.samfile = NULL
- *         self._filename = NULL
+ *         self._filename = None
  *         self.isbam = False             # <<<<<<<<<<<<<<
  *         self.isstream = False
  *         self._open( *args, **kwargs )
  */
   __pyx_v_self->isbam = 0;
 
-  /* "pysam/csamtools.pyx":722
- *         self._filename = NULL
+  /* "pysam/csamtools.pyx":735
+ *         self._filename = None
  *         self.isbam = False
  *         self.isstream = False             # <<<<<<<<<<<<<<
  *         self._open( *args, **kwargs )
@@ -7880,27 +8706,27 @@ static int __pyx_pf_5pysam_9csamtools_7Samfile___cinit__(struct __pyx_obj_5pysam
  */
   __pyx_v_self->isstream = 0;
 
-  /* "pysam/csamtools.pyx":723
+  /* "pysam/csamtools.pyx":736
  *         self.isbam = False
  *         self.isstream = False
  *         self._open( *args, **kwargs )             # <<<<<<<<<<<<<<
  * 
  *         # allocate memory for iterator
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
   __pyx_t_3 = ((PyObject *)__pyx_v_kwargs);
   __Pyx_INCREF(__pyx_t_3);
-  __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":726
+  /* "pysam/csamtools.pyx":739
  * 
  *         # allocate memory for iterator
  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
@@ -7936,7 +8762,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_3_isOpen(PyObject *__pyx_v_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":728
+/* "pysam/csamtools.pyx":741
  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
  * 
  *     def _isOpen( self ):             # <<<<<<<<<<<<<<
@@ -7953,9 +8779,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_2_isOpen(struct __pyx_obj_5
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_isOpen", 0);
-  __Pyx_TraceCall("_isOpen", __pyx_f[0], 728);
+  __Pyx_TraceCall("_isOpen", __pyx_f[0], 741);
 
-  /* "pysam/csamtools.pyx":730
+  /* "pysam/csamtools.pyx":743
  *     def _isOpen( self ):
  *         '''return true if samfile has been opened.'''
  *         return self.samfile != NULL             # <<<<<<<<<<<<<<
@@ -7963,7 +8789,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_2_isOpen(struct __pyx_obj_5
  *     def _hasIndex( self ):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->samfile != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->samfile != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -7994,7 +8820,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_5_hasIndex(PyObject *__pyx_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":732
+/* "pysam/csamtools.pyx":745
  *         return self.samfile != NULL
  * 
  *     def _hasIndex( self ):             # <<<<<<<<<<<<<<
@@ -8011,9 +8837,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_4_hasIndex(struct __pyx_obj
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_hasIndex", 0);
-  __Pyx_TraceCall("_hasIndex", __pyx_f[0], 732);
+  __Pyx_TraceCall("_hasIndex", __pyx_f[0], 745);
 
-  /* "pysam/csamtools.pyx":734
+  /* "pysam/csamtools.pyx":747
  *     def _hasIndex( self ):
  *         '''return true if samfile has an existing (and opened) index.'''
  *         return self.index != NULL             # <<<<<<<<<<<<<<
@@ -8021,7 +8847,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_4_hasIndex(struct __pyx_obj
  *     def _open( self,
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->index != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->index != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -8062,7 +8888,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_7_open(PyObject *__pyx_v_se
     static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__filename,&__pyx_n_s__mode,&__pyx_n_s__template,&__pyx_n_s__referencenames,&__pyx_n_s__referencelengths,&__pyx_n_s__text,&__pyx_n_s__header,&__pyx_n_s__port,&__pyx_n_s__add_sq_text,&__pyx_n_s__check_header,&__pyx_n_s__check_sq,0};
     PyObject* values[11] = {0,0,0,0,0,0,0,0,0,0,0};
 
-    /* "pysam/csamtools.pyx":738
+    /* "pysam/csamtools.pyx":751
  *     def _open( self,
  *                filename,
  *                mode = None,             # <<<<<<<<<<<<<<
@@ -8071,7 +8897,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_7_open(PyObject *__pyx_v_se
  */
     values[1] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":739
+    /* "pysam/csamtools.pyx":752
  *                filename,
  *                mode = None,
  *                Samfile template = None,             # <<<<<<<<<<<<<<
@@ -8080,7 +8906,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_7_open(PyObject *__pyx_v_se
  */
     values[2] = (PyObject *)((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None);
 
-    /* "pysam/csamtools.pyx":740
+    /* "pysam/csamtools.pyx":753
  *                mode = None,
  *                Samfile template = None,
  *                referencenames = None,             # <<<<<<<<<<<<<<
@@ -8089,7 +8915,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_7_open(PyObject *__pyx_v_se
  */
     values[3] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":741
+    /* "pysam/csamtools.pyx":754
  *                Samfile template = None,
  *                referencenames = None,
  *                referencelengths = None,             # <<<<<<<<<<<<<<
@@ -8098,7 +8924,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_7_open(PyObject *__pyx_v_se
  */
     values[4] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":742
+    /* "pysam/csamtools.pyx":755
  *                referencenames = None,
  *                referencelengths = None,
  *                text = None,             # <<<<<<<<<<<<<<
@@ -8107,7 +8933,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_7_open(PyObject *__pyx_v_se
  */
     values[5] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":743
+    /* "pysam/csamtools.pyx":756
  *                referencelengths = None,
  *                text = None,
  *                header = None,             # <<<<<<<<<<<<<<
@@ -8116,7 +8942,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_7_open(PyObject *__pyx_v_se
  */
     values[6] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":744
+    /* "pysam/csamtools.pyx":757
  *                text = None,
  *                header = None,
  *                port = None,             # <<<<<<<<<<<<<<
@@ -8124,9 +8950,9 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_7_open(PyObject *__pyx_v_se
  *                check_header = True,
  */
     values[7] = ((PyObject *)Py_None);
-    values[8] = __pyx_k_29;
-    values[9] = __pyx_k_30;
-    values[10] = __pyx_k_31;
+    values[8] = __pyx_k_27;
+    values[9] = __pyx_k_28;
+    values[10] = __pyx_k_29;
     if (unlikely(__pyx_kwds)) {
       Py_ssize_t kw_args;
       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
@@ -8202,7 +9028,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_7_open(PyObject *__pyx_v_se
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -8235,13 +9061,13 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_7_open(PyObject *__pyx_v_se
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 11, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 11, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.Samfile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return NULL;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_template), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "template", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_template), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "template", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_7Samfile_6_open(((struct __pyx_obj_5pysam_9csamtools_Samfile *)__pyx_v_self), __pyx_v_filename, __pyx_v_mode, __pyx_v_template, __pyx_v_referencenames, __pyx_v_referencelengths, __pyx_v_text, __pyx_v_header, __pyx_v_port, __pyx_v_add_sq_text, __pyx_v_check_header, __pyx_v_check_sq);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -8251,7 +9077,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_7_open(PyObject *__pyx_v_se
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":736
+/* "pysam/csamtools.pyx":749
  *         return self.index != NULL
  * 
  *     def _open( self,             # <<<<<<<<<<<<<<
@@ -8282,15 +9108,15 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
   int __pyx_t_9;
   int __pyx_t_10;
   int __pyx_t_11;
-  char *__pyx_t_12;
-  Py_ssize_t __pyx_t_13;
-  bam_header_t *__pyx_t_14;
-  Py_ssize_t __pyx_t_15;
-  PyObject *(*__pyx_t_16)(PyObject *);
-  size_t __pyx_t_17;
-  int32_t __pyx_t_18;
-  long __pyx_t_19;
-  uint32_t __pyx_t_20;
+  Py_ssize_t __pyx_t_12;
+  bam_header_t *__pyx_t_13;
+  Py_ssize_t __pyx_t_14;
+  PyObject *(*__pyx_t_15)(PyObject *);
+  size_t __pyx_t_16;
+  int32_t __pyx_t_17;
+  long __pyx_t_18;
+  uint32_t __pyx_t_19;
+  char *__pyx_t_20;
   const char* __pyx_t_21;
   int __pyx_t_22;
   int __pyx_lineno = 0;
@@ -8298,12 +9124,12 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_open", 0);
-  __Pyx_TraceCall("_open", __pyx_f[0], 736);
+  __Pyx_TraceCall("_open", __pyx_f[0], 749);
   __Pyx_INCREF(__pyx_v_filename);
   __Pyx_INCREF(__pyx_v_referencenames);
   __Pyx_INCREF(__pyx_v_text);
 
-  /* "pysam/csamtools.pyx":756
+  /* "pysam/csamtools.pyx":769
  * 
  *         # read mode autodetection
  *         if mode is None:             # <<<<<<<<<<<<<<
@@ -8313,7 +9139,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
   __pyx_t_1 = (__pyx_v_mode == Py_None);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":757
+    /* "pysam/csamtools.pyx":770
  *         # read mode autodetection
  *         if mode is None:
  *             try:             # <<<<<<<<<<<<<<
@@ -8327,16 +9153,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
       __Pyx_XGOTREF(__pyx_t_4);
       /*try:*/ {
 
-        /* "pysam/csamtools.pyx":758
+        /* "pysam/csamtools.pyx":771
  *         if mode is None:
  *             try:
  *                 self._open(filename, 'rb', template=template,             # <<<<<<<<<<<<<<
  *                            referencenames=referencenames,
  *                            referencelengths=referencelengths,
  */
-        __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___open); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___open); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
         __Pyx_GOTREF(__pyx_t_5);
-        __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
         __Pyx_GOTREF(__pyx_t_6);
         __Pyx_INCREF(__pyx_v_filename);
         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_filename);
@@ -8344,64 +9170,64 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
         __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
         PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_n_s__rb));
         __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rb));
-        __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_7));
-        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__template), ((PyObject *)__pyx_v_template)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__template), ((PyObject *)__pyx_v_template)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
 
-        /* "pysam/csamtools.pyx":759
+        /* "pysam/csamtools.pyx":772
  *             try:
  *                 self._open(filename, 'rb', template=template,
  *                            referencenames=referencenames,             # <<<<<<<<<<<<<<
  *                            referencelengths=referencelengths,
  *                            text=text, header=header, port=port,
  */
-        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__referencenames), __pyx_v_referencenames) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__referencenames), __pyx_v_referencenames) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
 
-        /* "pysam/csamtools.pyx":760
+        /* "pysam/csamtools.pyx":773
  *                 self._open(filename, 'rb', template=template,
  *                            referencenames=referencenames,
  *                            referencelengths=referencelengths,             # <<<<<<<<<<<<<<
  *                            text=text, header=header, port=port,
  *                            check_header=check_header,
  */
-        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__referencelengths), __pyx_v_referencelengths) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__referencelengths), __pyx_v_referencelengths) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
 
-        /* "pysam/csamtools.pyx":761
+        /* "pysam/csamtools.pyx":774
  *                            referencenames=referencenames,
  *                            referencelengths=referencelengths,
  *                            text=text, header=header, port=port,             # <<<<<<<<<<<<<<
  *                            check_header=check_header,
  *                            check_sq=check_sq)
  */
-        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__text), __pyx_v_text) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
-        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__header), __pyx_v_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
-        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__port), __pyx_v_port) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__text), __pyx_v_text) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__header), __pyx_v_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__port), __pyx_v_port) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
 
-        /* "pysam/csamtools.pyx":762
+        /* "pysam/csamtools.pyx":775
  *                            referencelengths=referencelengths,
  *                            text=text, header=header, port=port,
  *                            check_header=check_header,             # <<<<<<<<<<<<<<
  *                            check_sq=check_sq)
  *                 return
  */
-        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__check_header), __pyx_v_check_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__check_header), __pyx_v_check_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
 
-        /* "pysam/csamtools.pyx":763
+        /* "pysam/csamtools.pyx":776
  *                            text=text, header=header, port=port,
  *                            check_header=check_header,
  *                            check_sq=check_sq)             # <<<<<<<<<<<<<<
  *                 return
  *             except ValueError, msg:
  */
-        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__check_sq), __pyx_v_check_sq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
-        __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__check_sq), __pyx_v_check_sq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
         __Pyx_GOTREF(__pyx_t_8);
         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
 
-        /* "pysam/csamtools.pyx":764
+        /* "pysam/csamtools.pyx":777
  *                            check_header=check_header,
  *                            check_sq=check_sq)
  *                 return             # <<<<<<<<<<<<<<
@@ -8428,7 +9254,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
       __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
       __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
 
-      /* "pysam/csamtools.pyx":765
+      /* "pysam/csamtools.pyx":778
  *                            check_sq=check_sq)
  *                 return
  *             except ValueError, msg:             # <<<<<<<<<<<<<<
@@ -8438,7 +9264,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
       __pyx_t_9 = PyErr_ExceptionMatches(__pyx_builtin_ValueError);
       if (__pyx_t_9) {
         __Pyx_AddTraceback("pysam.csamtools.Samfile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
-        if (__Pyx_GetException(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
+        if (__Pyx_GetException(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
         __Pyx_GOTREF(__pyx_t_8);
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_GOTREF(__pyx_t_6);
@@ -8463,16 +9289,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
       __pyx_L11_try_end:;
     }
 
-    /* "pysam/csamtools.pyx":768
+    /* "pysam/csamtools.pyx":781
  *                 pass
  * 
  *             self._open(filename, 'r', template=template,             # <<<<<<<<<<<<<<
  *                        referencenames=referencenames,
  *                        referencelengths=referencelengths,
  */
-    __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___open); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___open); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
-    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
     __Pyx_INCREF(__pyx_v_filename);
     PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_filename);
@@ -8480,64 +9306,64 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
     __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
     PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_n_s__r));
     __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
-    __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_8));
-    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__template), ((PyObject *)__pyx_v_template)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__template), ((PyObject *)__pyx_v_template)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "pysam/csamtools.pyx":769
+    /* "pysam/csamtools.pyx":782
  * 
  *             self._open(filename, 'r', template=template,
  *                        referencenames=referencenames,             # <<<<<<<<<<<<<<
  *                        referencelengths=referencelengths,
  *                        text=text, header=header, port=port,
  */
-    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__referencenames), __pyx_v_referencenames) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__referencenames), __pyx_v_referencenames) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "pysam/csamtools.pyx":770
+    /* "pysam/csamtools.pyx":783
  *             self._open(filename, 'r', template=template,
  *                        referencenames=referencenames,
  *                        referencelengths=referencelengths,             # <<<<<<<<<<<<<<
  *                        text=text, header=header, port=port,
  *                        check_header=check_header,
  */
-    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__referencelengths), __pyx_v_referencelengths) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__referencelengths), __pyx_v_referencelengths) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "pysam/csamtools.pyx":771
+    /* "pysam/csamtools.pyx":784
  *                        referencenames=referencenames,
  *                        referencelengths=referencelengths,
  *                        text=text, header=header, port=port,             # <<<<<<<<<<<<<<
  *                        check_header=check_header,
  *                        check_sq=check_sq)
  */
-    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__text), __pyx_v_text) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__header), __pyx_v_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__port), __pyx_v_port) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__text), __pyx_v_text) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__header), __pyx_v_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__port), __pyx_v_port) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "pysam/csamtools.pyx":772
+    /* "pysam/csamtools.pyx":785
  *                        referencelengths=referencelengths,
  *                        text=text, header=header, port=port,
  *                        check_header=check_header,             # <<<<<<<<<<<<<<
  *                        check_sq=check_sq)
  *             return
  */
-    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__check_header), __pyx_v_check_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__check_header), __pyx_v_check_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "pysam/csamtools.pyx":773
+    /* "pysam/csamtools.pyx":786
  *                        text=text, header=header, port=port,
  *                        check_header=check_header,
  *                        check_sq=check_sq)             # <<<<<<<<<<<<<<
  *             return
  * 
  */
-    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__check_sq), __pyx_v_check_sq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_5 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_7), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__check_sq), __pyx_v_check_sq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_7), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 
-    /* "pysam/csamtools.pyx":774
+    /* "pysam/csamtools.pyx":787
  *                        check_header=check_header,
  *                        check_sq=check_sq)
  *             return             # <<<<<<<<<<<<<<
@@ -8551,62 +9377,62 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":776
+  /* "pysam/csamtools.pyx":789
  *             return
  * 
  *         assert mode in ( "r","w","rb","wb", "wh", "wbu", "rU" ), "invalid file opening mode `%s`" % mode             # <<<<<<<<<<<<<<
  * 
- *         #assert filename != NULL
+ *         # close a previously opened file
  */
   #ifndef CYTHON_WITHOUT_ASSERTIONS
   __Pyx_INCREF(__pyx_v_mode);
   __pyx_t_5 = __pyx_v_mode;
-  __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__r), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__r), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
   if (!((int)__pyx_t_1)) {
-    __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__w), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__w), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     __pyx_t_11 = ((int)__pyx_t_10);
   } else {
     __pyx_t_11 = ((int)__pyx_t_1);
   }
   if (!__pyx_t_11) {
-    __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__rb), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__rb), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     __pyx_t_10 = ((int)__pyx_t_1);
   } else {
     __pyx_t_10 = __pyx_t_11;
   }
   if (!__pyx_t_10) {
-    __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__wb), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__wb), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     __pyx_t_1 = ((int)__pyx_t_11);
   } else {
     __pyx_t_1 = __pyx_t_10;
   }
   if (!__pyx_t_1) {
-    __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__wh), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__wh), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     __pyx_t_11 = ((int)__pyx_t_10);
   } else {
     __pyx_t_11 = __pyx_t_1;
   }
   if (!__pyx_t_11) {
-    __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__wbu), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__wbu), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     __pyx_t_10 = ((int)__pyx_t_1);
   } else {
     __pyx_t_10 = __pyx_t_11;
   }
   if (!__pyx_t_10) {
-    __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__rU), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__rU), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     __pyx_t_1 = ((int)__pyx_t_11);
   } else {
@@ -8614,26 +9440,26 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
   }
   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
   if (unlikely(!__pyx_t_1)) {
-    __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_32), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_30), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_5));
     PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_5));
     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #endif
 
-  /* "pysam/csamtools.pyx":781
+  /* "pysam/csamtools.pyx":792
  * 
  *         # close a previously opened file
  *         if self.samfile != NULL: self.close()             # <<<<<<<<<<<<<<
- *         self.samfile = NULL
  * 
+ *         cdef bam_header_t * header_to_write
  */
   __pyx_t_1 = (__pyx_v_self->samfile != NULL);
   if (__pyx_t_1) {
-    __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
-    __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
@@ -8641,103 +9467,78 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
   }
   __pyx_L14:;
 
-  /* "pysam/csamtools.pyx":782
- *         # close a previously opened file
- *         if self.samfile != NULL: self.close()
- *         self.samfile = NULL             # <<<<<<<<<<<<<<
- * 
- *         cdef bam_header_t * header_to_write
- */
-  __pyx_v_self->samfile = NULL;
-
-  /* "pysam/csamtools.pyx":785
+  /* "pysam/csamtools.pyx":795
  * 
  *         cdef bam_header_t * header_to_write
  *         header_to_write = NULL             # <<<<<<<<<<<<<<
  * 
- *         if self._filename != NULL: free(self._filename )
+ *         cdef bytes bmode = mode.encode('ascii')
  */
   __pyx_v_header_to_write = NULL;
 
-  /* "pysam/csamtools.pyx":787
+  /* "pysam/csamtools.pyx":797
  *         header_to_write = NULL
  * 
- *         if self._filename != NULL: free(self._filename )             # <<<<<<<<<<<<<<
- *         filename = _my_encodeFilename(filename)
- *         cdef bytes bmode = mode.encode('ascii')
- */
-  __pyx_t_1 = (__pyx_v_self->_filename != NULL);
-  if (__pyx_t_1) {
-    free(__pyx_v_self->_filename);
-    goto __pyx_L15;
-  }
-  __pyx_L15:;
-
-  /* "pysam/csamtools.pyx":788
- * 
- *         if self._filename != NULL: free(self._filename )
- *         filename = _my_encodeFilename(filename)             # <<<<<<<<<<<<<<
- *         cdef bytes bmode = mode.encode('ascii')
- *         #cdef char* cfilename
- */
-  __pyx_t_8 = ((PyObject *)__pyx_f_5pysam_9csamtools__my_encodeFilename(__pyx_v_filename)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_8);
-  __Pyx_DECREF(__pyx_v_filename);
-  __pyx_v_filename = __pyx_t_8;
-  __pyx_t_8 = 0;
-
-  /* "pysam/csamtools.pyx":789
- *         if self._filename != NULL: free(self._filename )
- *         filename = _my_encodeFilename(filename)
  *         cdef bytes bmode = mode.encode('ascii')             # <<<<<<<<<<<<<<
- *         #cdef char* cfilename
- *         #cfilename = filename.encode(_FILENAME_ENCODING)
+ *         self._filename = filename = _encodeFilename(filename)
+ *         self.isstream = filename == b"-"
  */
-  __pyx_t_8 = PyObject_GetAttr(__pyx_v_mode, __pyx_n_s__encode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = PyObject_GetAttr(__pyx_v_mode, __pyx_n_s__encode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
-  __pyx_t_5 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_33), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_31), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-  if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_bmode = ((PyObject*)__pyx_t_5);
   __pyx_t_5 = 0;
 
-  /* "pysam/csamtools.pyx":792
- *         #cdef char* cfilename
- *         #cfilename = filename.encode(_FILENAME_ENCODING)
- *         self._filename = strdup(filename)             # <<<<<<<<<<<<<<
- *         self.isstream = strcmp( filename, "-" ) == 0
+  /* "pysam/csamtools.pyx":798
+ * 
+ *         cdef bytes bmode = mode.encode('ascii')
+ *         self._filename = filename = _encodeFilename(filename)             # <<<<<<<<<<<<<<
+ *         self.isstream = filename == b"-"
  * 
  */
-  __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_v_self->_filename = strdup(__pyx_t_12);
+  __pyx_t_5 = ((PyObject *)__pyx_f_5pysam_9csamtools__encodeFilename(__pyx_v_filename)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_INCREF(__pyx_t_5);
+  __Pyx_GIVEREF(__pyx_t_5);
+  __Pyx_GOTREF(__pyx_v_self->_filename);
+  __Pyx_DECREF(__pyx_v_self->_filename);
+  __pyx_v_self->_filename = __pyx_t_5;
+  __Pyx_INCREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_v_filename);
+  __pyx_v_filename = __pyx_t_5;
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 
-  /* "pysam/csamtools.pyx":793
- *         #cfilename = filename.encode(_FILENAME_ENCODING)
- *         self._filename = strdup(filename)
- *         self.isstream = strcmp( filename, "-" ) == 0             # <<<<<<<<<<<<<<
+  /* "pysam/csamtools.pyx":799
+ *         cdef bytes bmode = mode.encode('ascii')
+ *         self._filename = filename = _encodeFilename(filename)
+ *         self.isstream = filename == b"-"             # <<<<<<<<<<<<<<
  * 
  *         self.isbam = len(mode) > 1 and mode[1] == 'b'
  */
-  __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_v_self->isstream = (strcmp(__pyx_t_12, __pyx_k_34) == 0);
+  __pyx_t_5 = PyObject_RichCompare(__pyx_v_filename, ((PyObject *)__pyx_kp_b_32), Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_v_self->isstream = __pyx_t_9;
 
-  /* "pysam/csamtools.pyx":795
- *         self.isstream = strcmp( filename, "-" ) == 0
+  /* "pysam/csamtools.pyx":801
+ *         self.isstream = filename == b"-"
  * 
  *         self.isbam = len(mode) > 1 and mode[1] == 'b'             # <<<<<<<<<<<<<<
  * 
- *         self.isremote = strncmp(filename,"http:",5) == 0 or \
+ *         self.isremote = filename.startswith(b"http:") or filename.startswith(b"ftp:")
  */
-  __pyx_t_13 = PyObject_Length(__pyx_v_mode); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_5 = __Pyx_PyBool_FromLong((__pyx_t_13 > 1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_12 = PyObject_Length(__pyx_v_mode); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyBool_FromLong((__pyx_t_12 > 1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_mode, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_mode, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
-    __pyx_t_7 = PyObject_RichCompare(__pyx_t_8, ((PyObject *)__pyx_n_s__b), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyObject_RichCompare(__pyx_t_8, ((PyObject *)__pyx_n_s__b), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     __pyx_t_8 = __pyx_t_7;
     __pyx_t_7 = 0;
@@ -8745,45 +9546,41 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
     __pyx_t_8 = __pyx_t_5;
     __pyx_t_5 = 0;
   }
-  __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_8); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_8); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
   __pyx_v_self->isbam = __pyx_t_9;
 
-  /* "pysam/csamtools.pyx":797
+  /* "pysam/csamtools.pyx":803
  *         self.isbam = len(mode) > 1 and mode[1] == 'b'
  * 
- *         self.isremote = strncmp(filename,"http:",5) == 0 or \             # <<<<<<<<<<<<<<
- *             strncmp(filename,"ftp:",4) == 0
- * 
- */
-  __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_1 = (strncmp(__pyx_t_12, __pyx_k_35, 5) == 0);
-  if (!__pyx_t_1) {
-
-    /* "pysam/csamtools.pyx":798
- * 
- *         self.isremote = strncmp(filename,"http:",5) == 0 or \
- *             strncmp(filename,"ftp:",4) == 0             # <<<<<<<<<<<<<<
+ *         self.isremote = filename.startswith(b"http:") or filename.startswith(b"ftp:")             # <<<<<<<<<<<<<<
  * 
  *         cdef char * ctext
  */
-    __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_10 = (strncmp(__pyx_t_12, __pyx_k_36, 4) == 0);
-    __pyx_t_11 = __pyx_t_10;
+  __pyx_t_8 = PyObject_GetAttr(__pyx_v_filename, __pyx_n_s__startswith); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_8);
+  __pyx_t_5 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_34), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!__pyx_t_1) {
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_8 = PyObject_GetAttr(__pyx_v_filename, __pyx_n_s__startswith); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_7);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __pyx_t_8 = __pyx_t_7;
+    __pyx_t_7 = 0;
   } else {
-    __pyx_t_11 = __pyx_t_1;
+    __pyx_t_8 = __pyx_t_5;
+    __pyx_t_5 = 0;
   }
+  __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_8); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+  __pyx_v_self->isremote = __pyx_t_9;
 
-  /* "pysam/csamtools.pyx":797
- *         self.isbam = len(mode) > 1 and mode[1] == 'b'
- * 
- *         self.isremote = strncmp(filename,"http:",5) == 0 or \             # <<<<<<<<<<<<<<
- *             strncmp(filename,"ftp:",4) == 0
- * 
- */
-  __pyx_v_self->isremote = __pyx_t_11;
-
-  /* "pysam/csamtools.pyx":801
+  /* "pysam/csamtools.pyx":806
  * 
  *         cdef char * ctext
  *         ctext = NULL             # <<<<<<<<<<<<<<
@@ -8792,54 +9589,54 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  */
   __pyx_v_ctext = NULL;
 
-  /* "pysam/csamtools.pyx":803
+  /* "pysam/csamtools.pyx":808
  *         ctext = NULL
  * 
  *         if mode[0] == 'w':             # <<<<<<<<<<<<<<
  *             # open file for writing
  * 
  */
-  __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
-  __pyx_t_5 = PyObject_RichCompare(__pyx_t_8, ((PyObject *)__pyx_n_s__w), Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_RichCompare(__pyx_t_8, ((PyObject *)__pyx_n_s__w), Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-  if (__pyx_t_11) {
+  if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":807
+    /* "pysam/csamtools.pyx":812
  * 
  *             # header structure (used for writing)
  *             if template:             # <<<<<<<<<<<<<<
  *                 # copy header from another file
  *                 header_to_write = template.samfile.header
  */
-    __pyx_t_11 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    if (__pyx_t_11) {
+    __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (__pyx_t_1) {
 
-      /* "pysam/csamtools.pyx":809
+      /* "pysam/csamtools.pyx":814
  *             if template:
  *                 # copy header from another file
  *                 header_to_write = template.samfile.header             # <<<<<<<<<<<<<<
  * 
  *             elif header:
  */
-      __pyx_t_14 = __pyx_v_template->samfile->header;
-      __pyx_v_header_to_write = __pyx_t_14;
-      goto __pyx_L17;
+      __pyx_t_13 = __pyx_v_template->samfile->header;
+      __pyx_v_header_to_write = __pyx_t_13;
+      goto __pyx_L16;
     }
 
-    /* "pysam/csamtools.pyx":811
+    /* "pysam/csamtools.pyx":816
  *                 header_to_write = template.samfile.header
  * 
  *             elif header:             # <<<<<<<<<<<<<<
  *                 header_to_write = self._buildHeader( header )
  * 
  */
-    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_header); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    if (__pyx_t_11) {
+    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_header); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (__pyx_t_1) {
 
-      /* "pysam/csamtools.pyx":812
+      /* "pysam/csamtools.pyx":817
  * 
  *             elif header:
  *                 header_to_write = self._buildHeader( header )             # <<<<<<<<<<<<<<
@@ -8847,11 +9644,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  *             else:
  */
       __pyx_v_header_to_write = ((struct __pyx_vtabstruct_5pysam_9csamtools_Samfile *)__pyx_v_self->__pyx_vtab)->_buildHeader(__pyx_v_self, __pyx_v_header);
-      goto __pyx_L17;
+      goto __pyx_L16;
     }
     /*else*/ {
 
-      /* "pysam/csamtools.pyx":816
+      /* "pysam/csamtools.pyx":821
  *             else:
  *                 # build header from a target names and lengths
  *                 assert referencenames and referencelengths, "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing"             # <<<<<<<<<<<<<<
@@ -8859,20 +9656,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  * 
  */
       #ifndef CYTHON_WITHOUT_ASSERTIONS
-      __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_referencenames); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      if (__pyx_t_11) {
-        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_referencelengths); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_t_10 = __pyx_t_1;
+      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_referencenames); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (__pyx_t_1) {
+        __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_referencelengths); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_11 = __pyx_t_10;
       } else {
-        __pyx_t_10 = __pyx_t_11;
+        __pyx_t_11 = __pyx_t_1;
       }
-      if (unlikely(!__pyx_t_10)) {
+      if (unlikely(!__pyx_t_11)) {
         PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_37));
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
       #endif
 
-      /* "pysam/csamtools.pyx":817
+      /* "pysam/csamtools.pyx":822
  *                 # build header from a target names and lengths
  *                 assert referencenames and referencelengths, "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing"
  *                 assert len(referencenames) == len(referencelengths), "unequal names and lengths of reference sequences"             # <<<<<<<<<<<<<<
@@ -8880,52 +9677,52 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  *                 # allocate and fill header
  */
       #ifndef CYTHON_WITHOUT_ASSERTIONS
-      __pyx_t_13 = PyObject_Length(__pyx_v_referencenames); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_15 = PyObject_Length(__pyx_v_referencelengths); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      if (unlikely(!(__pyx_t_13 == __pyx_t_15))) {
+      __pyx_t_12 = PyObject_Length(__pyx_v_referencenames); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_14 = PyObject_Length(__pyx_v_referencelengths); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (unlikely(!(__pyx_t_12 == __pyx_t_14))) {
         PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_38));
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
       #endif
 
-      /* "pysam/csamtools.pyx":820
+      /* "pysam/csamtools.pyx":825
  * 
  *                 # allocate and fill header
  *                 referencenames = [ _force_bytes(ref) for ref in referencenames ]             # <<<<<<<<<<<<<<
  *                 header_to_write = bam_header_init()
  *                 header_to_write.n_targets = len(referencenames)
  */
-      __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
       if (PyList_CheckExact(__pyx_v_referencenames) || PyTuple_CheckExact(__pyx_v_referencenames)) {
-        __pyx_t_8 = __pyx_v_referencenames; __Pyx_INCREF(__pyx_t_8); __pyx_t_15 = 0;
-        __pyx_t_16 = NULL;
+        __pyx_t_8 = __pyx_v_referencenames; __Pyx_INCREF(__pyx_t_8); __pyx_t_14 = 0;
+        __pyx_t_15 = NULL;
       } else {
-        __pyx_t_15 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_referencenames); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_14 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_referencenames); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __pyx_t_16 = Py_TYPE(__pyx_t_8)->tp_iternext;
+        __pyx_t_15 = Py_TYPE(__pyx_t_8)->tp_iternext;
       }
       for (;;) {
-        if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_8)) {
-          if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_8)) break;
+        if (!__pyx_t_15 && PyList_CheckExact(__pyx_t_8)) {
+          if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_8)) break;
           #if CYTHON_COMPILING_IN_CPYTHON
-          __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_15); __Pyx_INCREF(__pyx_t_7); __pyx_t_15++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_7); __pyx_t_14++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #else
-          __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #endif
-        } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_8)) {
-          if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
+        } else if (!__pyx_t_15 && PyTuple_CheckExact(__pyx_t_8)) {
+          if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
           #if CYTHON_COMPILING_IN_CPYTHON
-          __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_15); __Pyx_INCREF(__pyx_t_7); __pyx_t_15++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_7); __pyx_t_14++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #else
-          __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #endif
         } else {
-          __pyx_t_7 = __pyx_t_16(__pyx_t_8);
+          __pyx_t_7 = __pyx_t_15(__pyx_t_8);
           if (unlikely(!__pyx_t_7)) {
             if (PyErr_Occurred()) {
               if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             }
             break;
           }
@@ -8934,9 +9731,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
         __Pyx_XDECREF(__pyx_v_ref);
         __pyx_v_ref = __pyx_t_7;
         __pyx_t_7 = 0;
-        __pyx_t_7 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_ref)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_ref)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
-        if (unlikely(__Pyx_PyList_Append(__pyx_t_5, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (unlikely(__Pyx_PyList_Append(__pyx_t_5, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       }
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
@@ -8947,7 +9744,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
       __pyx_v_referencenames = __pyx_t_8;
       __pyx_t_8 = 0;
 
-      /* "pysam/csamtools.pyx":821
+      /* "pysam/csamtools.pyx":826
  *                 # allocate and fill header
  *                 referencenames = [ _force_bytes(ref) for ref in referencenames ]
  *                 header_to_write = bam_header_init()             # <<<<<<<<<<<<<<
@@ -8956,17 +9753,17 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  */
       __pyx_v_header_to_write = bam_header_init();
 
-      /* "pysam/csamtools.pyx":822
+      /* "pysam/csamtools.pyx":827
  *                 referencenames = [ _force_bytes(ref) for ref in referencenames ]
  *                 header_to_write = bam_header_init()
  *                 header_to_write.n_targets = len(referencenames)             # <<<<<<<<<<<<<<
  *                 n = 0
  *                 for x in referencenames: n += len(x) + 1
  */
-      __pyx_t_15 = PyObject_Length(__pyx_v_referencenames); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_v_header_to_write->n_targets = __pyx_t_15;
+      __pyx_t_14 = PyObject_Length(__pyx_v_referencenames); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_v_header_to_write->n_targets = __pyx_t_14;
 
-      /* "pysam/csamtools.pyx":823
+      /* "pysam/csamtools.pyx":828
  *                 header_to_write = bam_header_init()
  *                 header_to_write.n_targets = len(referencenames)
  *                 n = 0             # <<<<<<<<<<<<<<
@@ -8976,7 +9773,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
       __Pyx_INCREF(__pyx_int_0);
       __pyx_v_n = __pyx_int_0;
 
-      /* "pysam/csamtools.pyx":824
+      /* "pysam/csamtools.pyx":829
  *                 header_to_write.n_targets = len(referencenames)
  *                 n = 0
  *                 for x in referencenames: n += len(x) + 1             # <<<<<<<<<<<<<<
@@ -8984,34 +9781,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
  */
       if (PyList_CheckExact(__pyx_v_referencenames) || PyTuple_CheckExact(__pyx_v_referencenames)) {
-        __pyx_t_8 = __pyx_v_referencenames; __Pyx_INCREF(__pyx_t_8); __pyx_t_15 = 0;
-        __pyx_t_16 = NULL;
+        __pyx_t_8 = __pyx_v_referencenames; __Pyx_INCREF(__pyx_t_8); __pyx_t_14 = 0;
+        __pyx_t_15 = NULL;
       } else {
-        __pyx_t_15 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_referencenames); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_14 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_referencenames); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __pyx_t_16 = Py_TYPE(__pyx_t_8)->tp_iternext;
+        __pyx_t_15 = Py_TYPE(__pyx_t_8)->tp_iternext;
       }
       for (;;) {
-        if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_8)) {
-          if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_8)) break;
+        if (!__pyx_t_15 && PyList_CheckExact(__pyx_t_8)) {
+          if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_8)) break;
           #if CYTHON_COMPILING_IN_CPYTHON
-          __pyx_t_5 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_15); __Pyx_INCREF(__pyx_t_5); __pyx_t_15++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_5 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_5); __pyx_t_14++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #else
-          __pyx_t_5 = PySequence_ITEM(__pyx_t_8, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_5 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #endif
-        } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_8)) {
-          if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
+        } else if (!__pyx_t_15 && PyTuple_CheckExact(__pyx_t_8)) {
+          if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
           #if CYTHON_COMPILING_IN_CPYTHON
-          __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_15); __Pyx_INCREF(__pyx_t_5); __pyx_t_15++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_5); __pyx_t_14++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #else
-          __pyx_t_5 = PySequence_ITEM(__pyx_t_8, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_5 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #endif
         } else {
-          __pyx_t_5 = __pyx_t_16(__pyx_t_8);
+          __pyx_t_5 = __pyx_t_15(__pyx_t_8);
           if (unlikely(!__pyx_t_5)) {
             if (PyErr_Occurred()) {
               if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             }
             break;
           }
@@ -9020,10 +9817,10 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
         __Pyx_XDECREF(__pyx_v_x);
         __pyx_v_x = __pyx_t_5;
         __pyx_t_5 = 0;
-        __pyx_t_13 = PyObject_Length(__pyx_v_x); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_t_5 = PyInt_FromSsize_t((__pyx_t_13 + 1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_12 = PyObject_Length(__pyx_v_x); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = PyInt_FromSsize_t((__pyx_t_12 + 1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_5);
-        __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_v_n, __pyx_t_5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_v_n, __pyx_t_5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
         __Pyx_DECREF(__pyx_v_n);
@@ -9032,253 +9829,264 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
       }
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
 
-      /* "pysam/csamtools.pyx":825
+      /* "pysam/csamtools.pyx":830
  *                 n = 0
  *                 for x in referencenames: n += len(x) + 1
  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))             # <<<<<<<<<<<<<<
  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
  *                 for x from 0 <= x < header_to_write.n_targets:
  */
-      __pyx_t_17 = __Pyx_PyInt_AsSize_t(__pyx_v_n); if (unlikely((__pyx_t_17 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_v_header_to_write->target_name = ((char **)calloc(__pyx_t_17, (sizeof(char *))));
+      __pyx_t_16 = __Pyx_PyInt_AsSize_t(__pyx_v_n); if (unlikely((__pyx_t_16 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_v_header_to_write->target_name = ((char **)calloc(__pyx_t_16, (sizeof(char *))));
 
-      /* "pysam/csamtools.pyx":826
+      /* "pysam/csamtools.pyx":831
  *                 for x in referencenames: n += len(x) + 1
  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))             # <<<<<<<<<<<<<<
  *                 for x from 0 <= x < header_to_write.n_targets:
  *                     header_to_write.target_len[x] = referencelengths[x]
  */
-      __pyx_t_17 = __Pyx_PyInt_AsSize_t(__pyx_v_n); if (unlikely((__pyx_t_17 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_v_header_to_write->target_len = ((uint32_t *)calloc(__pyx_t_17, (sizeof(uint32_t))));
+      __pyx_t_16 = __Pyx_PyInt_AsSize_t(__pyx_v_n); if (unlikely((__pyx_t_16 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_v_header_to_write->target_len = ((uint32_t *)calloc(__pyx_t_16, (sizeof(uint32_t))));
 
-      /* "pysam/csamtools.pyx":827
+      /* "pysam/csamtools.pyx":832
  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
  *                 for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
  *                     header_to_write.target_len[x] = referencelengths[x]
  *                     name = referencenames[x]
  */
-      __pyx_t_18 = __pyx_v_header_to_write->n_targets;
-      for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19++) {
-        __pyx_t_8 = PyInt_FromLong(__pyx_t_19); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_17 = __pyx_v_header_to_write->n_targets;
+      for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18++) {
+        __pyx_t_8 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
         __Pyx_XDECREF(__pyx_v_x);
         __pyx_v_x = __pyx_t_8;
         __pyx_t_8 = 0;
 
-        /* "pysam/csamtools.pyx":828
+        /* "pysam/csamtools.pyx":833
  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
  *                 for x from 0 <= x < header_to_write.n_targets:
  *                     header_to_write.target_len[x] = referencelengths[x]             # <<<<<<<<<<<<<<
  *                     name = referencenames[x]
  *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))
  */
-        __pyx_t_8 = PyObject_GetItem(__pyx_v_referencelengths, __pyx_v_x); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyObject_GetItem(__pyx_v_referencelengths, __pyx_v_x); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __pyx_t_20 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_20 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_19 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_19 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-        __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        (__pyx_v_header_to_write->target_len[__pyx_t_15]) = __pyx_t_20;
+        __pyx_t_14 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_14 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        (__pyx_v_header_to_write->target_len[__pyx_t_14]) = __pyx_t_19;
 
-        /* "pysam/csamtools.pyx":829
+        /* "pysam/csamtools.pyx":834
  *                 for x from 0 <= x < header_to_write.n_targets:
  *                     header_to_write.target_len[x] = referencelengths[x]
  *                     name = referencenames[x]             # <<<<<<<<<<<<<<
  *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))
  *                     strncpy( header_to_write.target_name[x], name, len(name) )
  */
-        __pyx_t_8 = PyObject_GetItem(__pyx_v_referencenames, __pyx_v_x); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyObject_GetItem(__pyx_v_referencenames, __pyx_v_x); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
         __Pyx_XDECREF(__pyx_v_name);
         __pyx_v_name = __pyx_t_8;
         __pyx_t_8 = 0;
 
-        /* "pysam/csamtools.pyx":830
+        /* "pysam/csamtools.pyx":835
  *                     header_to_write.target_len[x] = referencelengths[x]
  *                     name = referencenames[x]
  *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))             # <<<<<<<<<<<<<<
  *                     strncpy( header_to_write.target_name[x], name, len(name) )
  * 
  */
-        __pyx_t_15 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_t_13 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_13 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        (__pyx_v_header_to_write->target_name[__pyx_t_13]) = ((char *)calloc((__pyx_t_15 + 1), (sizeof(char))));
+        __pyx_t_14 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        (__pyx_v_header_to_write->target_name[__pyx_t_12]) = ((char *)calloc((__pyx_t_14 + 1), (sizeof(char))));
 
-        /* "pysam/csamtools.pyx":831
+        /* "pysam/csamtools.pyx":836
  *                     name = referencenames[x]
  *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))
  *                     strncpy( header_to_write.target_name[x], name, len(name) )             # <<<<<<<<<<<<<<
  * 
  *                 # Optionally, if there is no text, add a SAM compatible header to output
  */
-        __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_t_12 = PyBytes_AsString(__pyx_v_name); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_t_13 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        strncpy((__pyx_v_header_to_write->target_name[__pyx_t_15]), __pyx_t_12, __pyx_t_13);
-        __pyx_t_19 = __Pyx_PyInt_AsLong(__pyx_v_x); if (unlikely((__pyx_t_19 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_14 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_14 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_20 = PyBytes_AsString(__pyx_v_name); if (unlikely((!__pyx_t_20) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_12 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        strncpy((__pyx_v_header_to_write->target_name[__pyx_t_14]), __pyx_t_20, __pyx_t_12);
+        __pyx_t_18 = __Pyx_PyInt_AsLong(__pyx_v_x); if (unlikely((__pyx_t_18 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
 
-      /* "pysam/csamtools.pyx":827
+      /* "pysam/csamtools.pyx":832
  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
  *                 for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
  *                     header_to_write.target_len[x] = referencelengths[x]
  *                     name = referencenames[x]
  */
-      __pyx_t_8 = PyInt_FromLong(__pyx_t_19); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
       __Pyx_XDECREF(__pyx_v_x);
       __pyx_v_x = __pyx_t_8;
       __pyx_t_8 = 0;
 
-      /* "pysam/csamtools.pyx":835
+      /* "pysam/csamtools.pyx":840
  *                 # Optionally, if there is no text, add a SAM compatible header to output
  *                 # file.
  *                 if text is None and add_sq_text:             # <<<<<<<<<<<<<<
  *                     text = []
  *                     for x from 0 <= x < header_to_write.n_targets:
  */
-      __pyx_t_10 = (__pyx_v_text == Py_None);
-      if (__pyx_t_10) {
-        __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_add_sq_text); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_t_1 = __pyx_t_11;
+      __pyx_t_11 = (__pyx_v_text == Py_None);
+      if (__pyx_t_11) {
+        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_add_sq_text); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_10 = __pyx_t_1;
       } else {
-        __pyx_t_1 = __pyx_t_10;
+        __pyx_t_10 = __pyx_t_11;
       }
-      if (__pyx_t_1) {
+      if (__pyx_t_10) {
 
-        /* "pysam/csamtools.pyx":836
+        /* "pysam/csamtools.pyx":841
  *                 # file.
  *                 if text is None and add_sq_text:
  *                     text = []             # <<<<<<<<<<<<<<
  *                     for x from 0 <= x < header_to_write.n_targets:
- *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] ) )
+ *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % \
  */
-        __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
         __Pyx_DECREF(__pyx_v_text);
         __pyx_v_text = ((PyObject *)__pyx_t_8);
         __pyx_t_8 = 0;
 
-        /* "pysam/csamtools.pyx":837
+        /* "pysam/csamtools.pyx":842
  *                 if text is None and add_sq_text:
  *                     text = []
  *                     for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
- *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] ) )
- *                     text = ''.join(text)
+ *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % \
+ *                                          (_force_str(referencenames[x]),
  */
-        __pyx_t_18 = __pyx_v_header_to_write->n_targets;
-        for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19++) {
-          __pyx_t_8 = PyInt_FromLong(__pyx_t_19); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_17 = __pyx_v_header_to_write->n_targets;
+        for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18++) {
+          __pyx_t_8 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_8);
           __Pyx_XDECREF(__pyx_v_x);
           __pyx_v_x = __pyx_t_8;
           __pyx_t_8 = 0;
 
-          /* "pysam/csamtools.pyx":838
- *                     text = []
+          /* "pysam/csamtools.pyx":844
  *                     for x from 0 <= x < header_to_write.n_targets:
- *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] ) )             # <<<<<<<<<<<<<<
+ *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % \
+ *                                          (_force_str(referencenames[x]),             # <<<<<<<<<<<<<<
+ *                                           referencelengths[x] ) )
  *                     text = ''.join(text)
- * 
  */
-          __pyx_t_8 = PyObject_GetItem(__pyx_v_referencenames, __pyx_v_x); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_8 = PyObject_GetItem(__pyx_v_referencenames, __pyx_v_x); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_8);
-          __pyx_t_7 = PyObject_GetItem(__pyx_v_referencelengths, __pyx_v_x); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = __pyx_f_5pysam_9csamtools__force_str(__pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_7);
-          __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+          /* "pysam/csamtools.pyx":845
+ *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % \
+ *                                          (_force_str(referencenames[x]),
+ *                                           referencelengths[x] ) )             # <<<<<<<<<<<<<<
+ *                     text = ''.join(text)
+ * 
+ */
+          __pyx_t_8 = PyObject_GetItem(__pyx_v_referencelengths, __pyx_v_x); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_GOTREF(__pyx_t_8);
+          __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_5);
-          PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_8);
-          __Pyx_GIVEREF(__pyx_t_8);
-          PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_7);
+          PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
           __Pyx_GIVEREF(__pyx_t_7);
-          __pyx_t_8 = 0;
+          PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_8);
+          __Pyx_GIVEREF(__pyx_t_8);
           __pyx_t_7 = 0;
-          __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_39), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __Pyx_GOTREF(((PyObject *)__pyx_t_7));
+          __pyx_t_8 = 0;
+          __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_39), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_GOTREF(((PyObject *)__pyx_t_8));
           __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
-          __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_text, ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_text, ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_5);
-          __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
+          __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
           __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-          __pyx_t_19 = __Pyx_PyInt_AsLong(__pyx_v_x); if (unlikely((__pyx_t_19 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_18 = __Pyx_PyInt_AsLong(__pyx_v_x); if (unlikely((__pyx_t_18 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
 
-        /* "pysam/csamtools.pyx":837
+        /* "pysam/csamtools.pyx":842
  *                 if text is None and add_sq_text:
  *                     text = []
  *                     for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
- *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] ) )
- *                     text = ''.join(text)
+ *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % \
+ *                                          (_force_str(referencenames[x]),
  */
-        __pyx_t_5 = PyInt_FromLong(__pyx_t_19); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_5);
         __Pyx_XDECREF(__pyx_v_x);
         __pyx_v_x = __pyx_t_5;
         __pyx_t_5 = 0;
 
-        /* "pysam/csamtools.pyx":839
- *                     for x from 0 <= x < header_to_write.n_targets:
- *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] ) )
+        /* "pysam/csamtools.pyx":846
+ *                                          (_force_str(referencenames[x]),
+ *                                           referencelengths[x] ) )
  *                     text = ''.join(text)             # <<<<<<<<<<<<<<
  * 
  *                 if text != None:
  */
-        __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_16), __pyx_n_s__join); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_20), __pyx_n_s__join); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_5);
-        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_GOTREF(__pyx_t_7);
+        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_8);
         __Pyx_INCREF(__pyx_v_text);
-        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_text);
+        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_text);
         __Pyx_GIVEREF(__pyx_v_text);
-        __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_GOTREF(__pyx_t_8);
+        __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_7);
         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-        __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
+        __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
         __Pyx_DECREF(__pyx_v_text);
-        __pyx_v_text = __pyx_t_8;
-        __pyx_t_8 = 0;
-        goto __pyx_L24;
+        __pyx_v_text = __pyx_t_7;
+        __pyx_t_7 = 0;
+        goto __pyx_L23;
       }
-      __pyx_L24:;
+      __pyx_L23:;
 
-      /* "pysam/csamtools.pyx":841
+      /* "pysam/csamtools.pyx":848
  *                     text = ''.join(text)
  * 
  *                 if text != None:             # <<<<<<<<<<<<<<
  *                     # copy without \0
  *                     text = _force_bytes(text)
  */
-      __pyx_t_8 = PyObject_RichCompare(__pyx_v_text, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-      if (__pyx_t_1) {
+      __pyx_t_7 = PyObject_RichCompare(__pyx_v_text, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      if (__pyx_t_10) {
 
-        /* "pysam/csamtools.pyx":843
+        /* "pysam/csamtools.pyx":850
  *                 if text != None:
  *                     # copy without \0
  *                     text = _force_bytes(text)             # <<<<<<<<<<<<<<
  *                     ctext = text
  *                     header_to_write.l_text = strlen(ctext)
  */
-        __pyx_t_8 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_text)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_GOTREF(__pyx_t_8);
+        __pyx_t_7 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_text)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_7);
         __Pyx_DECREF(__pyx_v_text);
-        __pyx_v_text = __pyx_t_8;
-        __pyx_t_8 = 0;
+        __pyx_v_text = __pyx_t_7;
+        __pyx_t_7 = 0;
 
-        /* "pysam/csamtools.pyx":844
+        /* "pysam/csamtools.pyx":851
  *                     # copy without \0
  *                     text = _force_bytes(text)
  *                     ctext = text             # <<<<<<<<<<<<<<
  *                     header_to_write.l_text = strlen(ctext)
  *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )
  */
-        __pyx_t_12 = PyBytes_AsString(__pyx_v_text); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_v_ctext = __pyx_t_12;
+        __pyx_t_20 = PyBytes_AsString(__pyx_v_text); if (unlikely((!__pyx_t_20) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_v_ctext = __pyx_t_20;
 
-        /* "pysam/csamtools.pyx":845
+        /* "pysam/csamtools.pyx":852
  *                     text = _force_bytes(text)
  *                     ctext = text
  *                     header_to_write.l_text = strlen(ctext)             # <<<<<<<<<<<<<<
@@ -9287,7 +10095,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  */
         __pyx_v_header_to_write->l_text = strlen(__pyx_v_ctext);
 
-        /* "pysam/csamtools.pyx":846
+        /* "pysam/csamtools.pyx":853
  *                     ctext = text
  *                     header_to_write.l_text = strlen(ctext)
  *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )             # <<<<<<<<<<<<<<
@@ -9296,7 +10104,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  */
         __pyx_v_header_to_write->text = ((char *)calloc(strlen(__pyx_v_ctext), (sizeof(char))));
 
-        /* "pysam/csamtools.pyx":847
+        /* "pysam/csamtools.pyx":854
  *                     header_to_write.l_text = strlen(ctext)
  *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )
  *                     memcpy( header_to_write.text, ctext, strlen(ctext) )             # <<<<<<<<<<<<<<
@@ -9304,11 +10112,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  *                 header_to_write.hash = NULL
  */
         memcpy(__pyx_v_header_to_write->text, __pyx_v_ctext, strlen(__pyx_v_ctext));
-        goto __pyx_L27;
+        goto __pyx_L26;
       }
-      __pyx_L27:;
+      __pyx_L26:;
 
-      /* "pysam/csamtools.pyx":849
+      /* "pysam/csamtools.pyx":856
  *                     memcpy( header_to_write.text, ctext, strlen(ctext) )
  * 
  *                 header_to_write.hash = NULL             # <<<<<<<<<<<<<<
@@ -9317,7 +10125,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  */
       __pyx_v_header_to_write->hash = NULL;
 
-      /* "pysam/csamtools.pyx":850
+      /* "pysam/csamtools.pyx":857
  * 
  *                 header_to_write.hash = NULL
  *                 header_to_write.rg2lib = NULL             # <<<<<<<<<<<<<<
@@ -9326,66 +10134,66 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  */
       __pyx_v_header_to_write->rg2lib = NULL;
     }
-    __pyx_L17:;
+    __pyx_L16:;
 
-    /* "pysam/csamtools.pyx":854
+    /* "pysam/csamtools.pyx":861
  *             # open file. Header gets written to file at the same time for bam files
  *             # and sam files (in the latter case, the mode needs to be wh)
  *             store = StderrStore()             # <<<<<<<<<<<<<<
  *             self.samfile = samopen( filename, bmode, header_to_write )
  *             store.release()
  */
-    __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_8);
-    __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
-    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-    __pyx_v_store = __pyx_t_7;
-    __pyx_t_7 = 0;
+    __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_8);
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __pyx_v_store = __pyx_t_8;
+    __pyx_t_8 = 0;
 
-    /* "pysam/csamtools.pyx":855
+    /* "pysam/csamtools.pyx":862
  *             # and sam files (in the latter case, the mode needs to be wh)
  *             store = StderrStore()
  *             self.samfile = samopen( filename, bmode, header_to_write )             # <<<<<<<<<<<<<<
  *             store.release()
  * 
  */
-    __pyx_t_21 = PyBytes_AsString(__pyx_v_filename); if (unlikely((__pyx_t_21 == (const char*)NULL) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_12 = PyBytes_AsString(((PyObject *)__pyx_v_bmode)); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_v_self->samfile = samopen(__pyx_t_21, __pyx_t_12, __pyx_v_header_to_write);
+    __pyx_t_21 = PyBytes_AsString(__pyx_v_filename); if (unlikely((__pyx_t_21 == (const char*)NULL) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_20 = PyBytes_AsString(((PyObject *)__pyx_v_bmode)); if (unlikely((!__pyx_t_20) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_v_self->samfile = samopen(__pyx_t_21, __pyx_t_20, __pyx_v_header_to_write);
 
-    /* "pysam/csamtools.pyx":856
+    /* "pysam/csamtools.pyx":863
  *             store = StderrStore()
  *             self.samfile = samopen( filename, bmode, header_to_write )
  *             store.release()             # <<<<<<<<<<<<<<
  * 
  *             # bam_header_destroy takes care of cleaning up of all the members
  */
-    __pyx_t_7 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_7);
-    __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
-    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_7);
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 
-    /* "pysam/csamtools.pyx":859
+    /* "pysam/csamtools.pyx":866
  * 
  *             # bam_header_destroy takes care of cleaning up of all the members
  *             if not template and header_to_write != NULL:             # <<<<<<<<<<<<<<
  *                 bam_header_destroy( header_to_write )
  * 
  */
-    __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_10 = (!__pyx_t_1);
-    if (__pyx_t_10) {
-      __pyx_t_1 = (__pyx_v_header_to_write != NULL);
-      __pyx_t_11 = __pyx_t_1;
+    __pyx_t_10 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_11 = (!__pyx_t_10);
+    if (__pyx_t_11) {
+      __pyx_t_10 = (__pyx_v_header_to_write != NULL);
+      __pyx_t_1 = __pyx_t_10;
     } else {
-      __pyx_t_11 = __pyx_t_10;
+      __pyx_t_1 = __pyx_t_11;
     }
-    if (__pyx_t_11) {
+    if (__pyx_t_1) {
 
-      /* "pysam/csamtools.pyx":860
+      /* "pysam/csamtools.pyx":867
  *             # bam_header_destroy takes care of cleaning up of all the members
  *             if not template and header_to_write != NULL:
  *                 bam_header_destroy( header_to_write )             # <<<<<<<<<<<<<<
@@ -9393,155 +10201,140 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  *         elif mode[0] == "r":
  */
       bam_header_destroy(__pyx_v_header_to_write);
-      goto __pyx_L28;
+      goto __pyx_L27;
     }
-    __pyx_L28:;
-    goto __pyx_L16;
+    __pyx_L27:;
+    goto __pyx_L15;
   }
 
-  /* "pysam/csamtools.pyx":862
+  /* "pysam/csamtools.pyx":869
  *                 bam_header_destroy( header_to_write )
  * 
  *         elif mode[0] == "r":             # <<<<<<<<<<<<<<
  *             # open file for reading
- *             if strncmp( filename, "-", 1) != 0 and \
+ *             if filename != b"-" and not self.isremote and not os.path.exists( filename ):
  */
-  __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_8);
-  __pyx_t_7 = PyObject_RichCompare(__pyx_t_8, ((PyObject *)__pyx_n_s__r), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 869; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_7);
+  __pyx_t_8 = PyObject_RichCompare(__pyx_t_7, ((PyObject *)__pyx_n_s__r), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 869; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-  if (__pyx_t_11) {
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 869; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+  if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":864
+    /* "pysam/csamtools.pyx":871
  *         elif mode[0] == "r":
  *             # open file for reading
- *             if strncmp( filename, "-", 1) != 0 and \             # <<<<<<<<<<<<<<
- *                     not self.isremote and \
- *                     not os.path.exists( filename ):
- */
-    __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_11 = (strncmp(__pyx_t_12, __pyx_k_34, 1) != 0);
-    if (__pyx_t_11) {
-
-      /* "pysam/csamtools.pyx":865
- *             # open file for reading
- *             if strncmp( filename, "-", 1) != 0 and \
- *                     not self.isremote and \             # <<<<<<<<<<<<<<
- *                     not os.path.exists( filename ):
- *                 raise IOError( "file `%s` not found" % filename)
- */
-      __pyx_t_10 = (!__pyx_v_self->isremote);
-      if (__pyx_t_10) {
-
-        /* "pysam/csamtools.pyx":866
- *             if strncmp( filename, "-", 1) != 0 and \
- *                     not self.isremote and \
- *                     not os.path.exists( filename ):             # <<<<<<<<<<<<<<
+ *             if filename != b"-" and not self.isremote and not os.path.exists( filename ):             # <<<<<<<<<<<<<<
  *                 raise IOError( "file `%s` not found" % filename)
  * 
  */
-        __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_GOTREF(__pyx_t_7);
-        __pyx_t_8 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__path); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_RichCompare(__pyx_v_filename, ((PyObject *)__pyx_kp_b_32), Py_NE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    if (__pyx_t_1) {
+      __pyx_t_11 = (!__pyx_v_self->isremote);
+      if (__pyx_t_11) {
+        __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-        __pyx_t_7 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__exists); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__path); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__exists); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_7);
         __Pyx_INCREF(__pyx_v_filename);
-        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_filename);
+        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_filename);
         __Pyx_GIVEREF(__pyx_v_filename);
-        __pyx_t_5 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_5);
-        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-        __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
-        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+        __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
+        __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-        __pyx_t_22 = (!__pyx_t_1);
-        __pyx_t_1 = __pyx_t_22;
+        __pyx_t_22 = (!__pyx_t_10);
+        __pyx_t_10 = __pyx_t_22;
       } else {
-        __pyx_t_1 = __pyx_t_10;
+        __pyx_t_10 = __pyx_t_11;
       }
-      __pyx_t_10 = __pyx_t_1;
+      __pyx_t_11 = __pyx_t_10;
     } else {
-      __pyx_t_10 = __pyx_t_11;
+      __pyx_t_11 = __pyx_t_1;
     }
-    if (__pyx_t_10) {
+    if (__pyx_t_11) {
 
-      /* "pysam/csamtools.pyx":867
- *                     not self.isremote and \
- *                     not os.path.exists( filename ):
+      /* "pysam/csamtools.pyx":872
+ *             # open file for reading
+ *             if filename != b"-" and not self.isremote and not os.path.exists( filename ):
  *                 raise IOError( "file `%s` not found" % filename)             # <<<<<<<<<<<<<<
  * 
  *             # try to detect errors
  */
-      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_40), __pyx_v_filename); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_40), __pyx_v_filename); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_5));
-      __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_8);
-      PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_5));
+      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_7);
+      PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_5));
       __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
       __pyx_t_5 = 0;
-      __pyx_t_5 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
+      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
       __Pyx_Raise(__pyx_t_5, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      goto __pyx_L29;
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      goto __pyx_L28;
     }
-    __pyx_L29:;
+    __pyx_L28:;
 
-    /* "pysam/csamtools.pyx":870
+    /* "pysam/csamtools.pyx":875
  * 
  *             # try to detect errors
  *             self.samfile = samopen( filename, bmode, NULL )             # <<<<<<<<<<<<<<
  *             if self.samfile == NULL:
  *                 raise ValueError( "could not open file (mode='%s') - is it SAM/BAM format?" % mode)
  */
-    __pyx_t_21 = PyBytes_AsString(__pyx_v_filename); if (unlikely((__pyx_t_21 == (const char*)NULL) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_12 = PyBytes_AsString(((PyObject *)__pyx_v_bmode)); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_v_self->samfile = samopen(__pyx_t_21, __pyx_t_12, NULL);
+    __pyx_t_21 = PyBytes_AsString(__pyx_v_filename); if (unlikely((__pyx_t_21 == (const char*)NULL) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_20 = PyBytes_AsString(((PyObject *)__pyx_v_bmode)); if (unlikely((!__pyx_t_20) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_v_self->samfile = samopen(__pyx_t_21, __pyx_t_20, NULL);
 
-    /* "pysam/csamtools.pyx":871
+    /* "pysam/csamtools.pyx":876
  *             # try to detect errors
  *             self.samfile = samopen( filename, bmode, NULL )
  *             if self.samfile == NULL:             # <<<<<<<<<<<<<<
  *                 raise ValueError( "could not open file (mode='%s') - is it SAM/BAM format?" % mode)
  * 
  */
-    __pyx_t_10 = (__pyx_v_self->samfile == NULL);
-    if (__pyx_t_10) {
+    __pyx_t_11 = (__pyx_v_self->samfile == NULL);
+    if (__pyx_t_11) {
 
-      /* "pysam/csamtools.pyx":872
+      /* "pysam/csamtools.pyx":877
  *             self.samfile = samopen( filename, bmode, NULL )
  *             if self.samfile == NULL:
  *                 raise ValueError( "could not open file (mode='%s') - is it SAM/BAM format?" % mode)             # <<<<<<<<<<<<<<
  * 
  *             # bam files require a valid header
  */
-      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_41), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_41), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_5));
-      __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_8);
-      PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_5));
+      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_7);
+      PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_5));
       __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
       __pyx_t_5 = 0;
-      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
+      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
       __Pyx_Raise(__pyx_t_5, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      goto __pyx_L30;
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      goto __pyx_L29;
     }
-    __pyx_L30:;
+    __pyx_L29:;
 
-    /* "pysam/csamtools.pyx":875
+    /* "pysam/csamtools.pyx":880
  * 
  *             # bam files require a valid header
  *             if self.isbam:             # <<<<<<<<<<<<<<
@@ -9550,262 +10343,262 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  */
     if (__pyx_v_self->isbam) {
 
-      /* "pysam/csamtools.pyx":876
+      /* "pysam/csamtools.pyx":881
  *             # bam files require a valid header
  *             if self.isbam:
  *                 if self.samfile.header == NULL:             # <<<<<<<<<<<<<<
  *                     raise ValueError( "file does not have valid header (mode='%s') - is it BAM format?" % mode )
  *             else:
  */
-      __pyx_t_10 = (__pyx_v_self->samfile->header == NULL);
-      if (__pyx_t_10) {
+      __pyx_t_11 = (__pyx_v_self->samfile->header == NULL);
+      if (__pyx_t_11) {
 
-        /* "pysam/csamtools.pyx":877
+        /* "pysam/csamtools.pyx":882
  *             if self.isbam:
  *                 if self.samfile.header == NULL:
  *                     raise ValueError( "file does not have valid header (mode='%s') - is it BAM format?" % mode )             # <<<<<<<<<<<<<<
  *             else:
  *                 # in sam files it is optional (samfile full of unmapped reads)
  */
-        __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_42), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_42), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_5));
-        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_GOTREF(__pyx_t_8);
-        PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_5));
+        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_7);
+        PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_5));
         __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
         __pyx_t_5 = 0;
-        __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_5);
-        __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
+        __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
         __Pyx_Raise(__pyx_t_5, 0, 0, 0);
         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        goto __pyx_L32;
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        goto __pyx_L31;
       }
-      __pyx_L32:;
-      goto __pyx_L31;
+      __pyx_L31:;
+      goto __pyx_L30;
     }
     /*else*/ {
 
-      /* "pysam/csamtools.pyx":880
+      /* "pysam/csamtools.pyx":885
  *             else:
  *                 # in sam files it is optional (samfile full of unmapped reads)
  *                 if check_header and self.samfile.header == NULL:             # <<<<<<<<<<<<<<
  *                     raise ValueError( "file does not have valid header (mode='%s') - is it SAM format?" % mode )
  * 
  */
-      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_check_header); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      if (__pyx_t_10) {
-        __pyx_t_11 = (__pyx_v_self->samfile->header == NULL);
-        __pyx_t_1 = __pyx_t_11;
+      __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_check_header); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (__pyx_t_11) {
+        __pyx_t_1 = (__pyx_v_self->samfile->header == NULL);
+        __pyx_t_10 = __pyx_t_1;
       } else {
-        __pyx_t_1 = __pyx_t_10;
+        __pyx_t_10 = __pyx_t_11;
       }
-      if (__pyx_t_1) {
+      if (__pyx_t_10) {
 
-        /* "pysam/csamtools.pyx":881
+        /* "pysam/csamtools.pyx":886
  *                 # in sam files it is optional (samfile full of unmapped reads)
  *                 if check_header and self.samfile.header == NULL:
  *                     raise ValueError( "file does not have valid header (mode='%s') - is it SAM format?" % mode )             # <<<<<<<<<<<<<<
  * 
  *             # disabled for autodetection to work
  */
-        __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_43), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_43), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_5));
-        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_GOTREF(__pyx_t_8);
-        PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_5));
+        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_7);
+        PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_5));
         __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
         __pyx_t_5 = 0;
-        __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_5);
-        __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
+        __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
         __Pyx_Raise(__pyx_t_5, 0, 0, 0);
         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        goto __pyx_L33;
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        goto __pyx_L32;
       }
-      __pyx_L33:;
+      __pyx_L32:;
     }
-    __pyx_L31:;
+    __pyx_L30:;
 
-    /* "pysam/csamtools.pyx":885
+    /* "pysam/csamtools.pyx":890
  *             # disabled for autodetection to work
  *             # needs to be disabled so that reading from sam-files without headers works
  *             if check_sq and self.samfile.header.n_targets == 0:             # <<<<<<<<<<<<<<
  *                 raise ValueError( "file header is empty (mode='%s') - is it SAM/BAM format?" % mode)
  * 
  */
-    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_check_sq); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    if (__pyx_t_1) {
-      __pyx_t_10 = (__pyx_v_self->samfile->header->n_targets == 0);
-      __pyx_t_11 = __pyx_t_10;
+    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_check_sq); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (__pyx_t_10) {
+      __pyx_t_11 = (__pyx_v_self->samfile->header->n_targets == 0);
+      __pyx_t_1 = __pyx_t_11;
     } else {
-      __pyx_t_11 = __pyx_t_1;
+      __pyx_t_1 = __pyx_t_10;
     }
-    if (__pyx_t_11) {
+    if (__pyx_t_1) {
 
-      /* "pysam/csamtools.pyx":886
+      /* "pysam/csamtools.pyx":891
  *             # needs to be disabled so that reading from sam-files without headers works
  *             if check_sq and self.samfile.header.n_targets == 0:
  *                 raise ValueError( "file header is empty (mode='%s') - is it SAM/BAM format?" % mode)             # <<<<<<<<<<<<<<
  * 
  *         if self.samfile == NULL:
  */
-      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_44), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_44), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_5));
-      __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_8);
-      PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_5));
+      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_7);
+      PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_5));
       __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
       __pyx_t_5 = 0;
-      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
+      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
       __Pyx_Raise(__pyx_t_5, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      goto __pyx_L34;
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      goto __pyx_L33;
     }
-    __pyx_L34:;
-    goto __pyx_L16;
+    __pyx_L33:;
+    goto __pyx_L15;
   }
-  __pyx_L16:;
+  __pyx_L15:;
 
-  /* "pysam/csamtools.pyx":888
+  /* "pysam/csamtools.pyx":893
  *                 raise ValueError( "file header is empty (mode='%s') - is it SAM/BAM format?" % mode)
  * 
  *         if self.samfile == NULL:             # <<<<<<<<<<<<<<
  *             raise IOError("could not open file `%s`" % filename )
  * 
  */
-  __pyx_t_11 = (__pyx_v_self->samfile == NULL);
-  if (__pyx_t_11) {
+  __pyx_t_1 = (__pyx_v_self->samfile == NULL);
+  if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":889
+    /* "pysam/csamtools.pyx":894
  * 
  *         if self.samfile == NULL:
  *             raise IOError("could not open file `%s`" % filename )             # <<<<<<<<<<<<<<
  * 
  *         # check for index and open if present
  */
-    __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), __pyx_v_filename); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), __pyx_v_filename); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_5));
-    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_8);
-    PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_5));
+    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_7);
+    PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_5));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
     __pyx_t_5 = 0;
-    __pyx_t_5 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
-    __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
+    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
     __Pyx_Raise(__pyx_t_5, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    goto __pyx_L35;
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    goto __pyx_L34;
   }
-  __pyx_L35:;
+  __pyx_L34:;
 
-  /* "pysam/csamtools.pyx":892
+  /* "pysam/csamtools.pyx":897
  * 
  *         # check for index and open if present
  *         if mode[0] == "r" and self.isbam:             # <<<<<<<<<<<<<<
  * 
  *             if not self.isremote:
  */
-  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
-  __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__r), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_n_s__r), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-  if (__pyx_t_11) {
-    __pyx_t_1 = __pyx_v_self->isbam;
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+  if (__pyx_t_1) {
+    __pyx_t_10 = __pyx_v_self->isbam;
   } else {
-    __pyx_t_1 = __pyx_t_11;
+    __pyx_t_10 = __pyx_t_1;
   }
-  if (__pyx_t_1) {
+  if (__pyx_t_10) {
 
-    /* "pysam/csamtools.pyx":894
+    /* "pysam/csamtools.pyx":899
  *         if mode[0] == "r" and self.isbam:
  * 
  *             if not self.isremote:             # <<<<<<<<<<<<<<
  *                 if not os.path.exists(filename + b".bai") \
  *                         and not os.path.exists( filename[:-4] + b".bai"):
  */
-    __pyx_t_1 = (!__pyx_v_self->isremote);
-    if (__pyx_t_1) {
+    __pyx_t_10 = (!__pyx_v_self->isremote);
+    if (__pyx_t_10) {
 
-      /* "pysam/csamtools.pyx":895
+      /* "pysam/csamtools.pyx":900
  * 
  *             if not self.isremote:
  *                 if not os.path.exists(filename + b".bai") \             # <<<<<<<<<<<<<<
  *                         and not os.path.exists( filename[:-4] + b".bai"):
  *                     self.index = NULL
  */
-      __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_8);
-      __pyx_t_5 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__path); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_7);
+      __pyx_t_5 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__path); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-      __pyx_t_8 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__exists); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __pyx_t_7 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__exists); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-      __pyx_t_5 = PyNumber_Add(__pyx_v_filename, ((PyObject *)__pyx_kp_b_45)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyNumber_Add(__pyx_v_filename, ((PyObject *)__pyx_kp_b_45)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_7);
-      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
+      __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_8);
+      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5);
       __Pyx_GIVEREF(__pyx_t_5);
       __pyx_t_5 = 0;
-      __pyx_t_5 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
+      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-      __pyx_t_11 = (!__pyx_t_1);
-      if (__pyx_t_11) {
+      __pyx_t_1 = (!__pyx_t_10);
+      if (__pyx_t_1) {
 
-        /* "pysam/csamtools.pyx":896
+        /* "pysam/csamtools.pyx":901
  *             if not self.isremote:
  *                 if not os.path.exists(filename + b".bai") \
  *                         and not os.path.exists( filename[:-4] + b".bai"):             # <<<<<<<<<<<<<<
  *                     self.index = NULL
  *                 else:
  */
-        __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_5);
-        __pyx_t_7 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__path); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_GOTREF(__pyx_t_7);
+        __pyx_t_8 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__path); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_8);
         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-        __pyx_t_5 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__exists); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__exists); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_5);
-        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-        __pyx_t_7 = __Pyx_PySequence_GetSlice(__pyx_v_filename, 0, -4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_GOTREF(__pyx_t_7);
-        __pyx_t_8 = PyNumber_Add(__pyx_t_7, ((PyObject *)__pyx_kp_b_45)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+        __pyx_t_8 = __Pyx_PySequence_GetSlice(__pyx_v_filename, 0, -4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyNumber_Add(__pyx_t_8, ((PyObject *)__pyx_kp_b_45)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
-        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
-        __Pyx_GIVEREF(__pyx_t_8);
-        __pyx_t_8 = 0;
-        __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
+        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
+        __Pyx_GIVEREF(__pyx_t_7);
+        __pyx_t_7 = 0;
+        __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_7);
         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-        __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-        __pyx_t_10 = (!__pyx_t_1);
-        __pyx_t_1 = __pyx_t_10;
+        __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
+        __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __pyx_t_11 = (!__pyx_t_10);
+        __pyx_t_10 = __pyx_t_11;
       } else {
-        __pyx_t_1 = __pyx_t_11;
+        __pyx_t_10 = __pyx_t_1;
       }
-      if (__pyx_t_1) {
+      if (__pyx_t_10) {
 
-        /* "pysam/csamtools.pyx":897
+        /* "pysam/csamtools.pyx":902
  *                 if not os.path.exists(filename + b".bai") \
  *                         and not os.path.exists( filename[:-4] + b".bai"):
  *                     self.index = NULL             # <<<<<<<<<<<<<<
@@ -9813,116 +10606,116 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  *                     # returns NULL if there is no index or index could not be opened
  */
         __pyx_v_self->index = NULL;
-        goto __pyx_L38;
+        goto __pyx_L37;
       }
       /*else*/ {
 
-        /* "pysam/csamtools.pyx":900
+        /* "pysam/csamtools.pyx":905
  *                 else:
  *                     # returns NULL if there is no index or index could not be opened
  *                     self.index = bam_index_load(filename)             # <<<<<<<<<<<<<<
  *                     if self.index == NULL:
  *                         raise IOError("error while opening index `%s` " % filename )
  */
-        __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_v_self->index = bam_index_load(__pyx_t_12);
+        __pyx_t_20 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_20) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_v_self->index = bam_index_load(__pyx_t_20);
 
-        /* "pysam/csamtools.pyx":901
+        /* "pysam/csamtools.pyx":906
  *                     # returns NULL if there is no index or index could not be opened
  *                     self.index = bam_index_load(filename)
  *                     if self.index == NULL:             # <<<<<<<<<<<<<<
  *                         raise IOError("error while opening index `%s` " % filename )
  *             else:
  */
-        __pyx_t_1 = (__pyx_v_self->index == NULL);
-        if (__pyx_t_1) {
+        __pyx_t_10 = (__pyx_v_self->index == NULL);
+        if (__pyx_t_10) {
 
-          /* "pysam/csamtools.pyx":902
+          /* "pysam/csamtools.pyx":907
  *                     self.index = bam_index_load(filename)
  *                     if self.index == NULL:
  *                         raise IOError("error while opening index `%s` " % filename )             # <<<<<<<<<<<<<<
  *             else:
  *                 self.index = bam_index_load(filename)
  */
-          __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_46), __pyx_v_filename); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __Pyx_GOTREF(((PyObject *)__pyx_t_8));
-          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __Pyx_GOTREF(__pyx_t_7);
-          PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_8));
-          __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
-          __pyx_t_8 = 0;
-          __pyx_t_8 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_46), __pyx_v_filename); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_GOTREF(((PyObject *)__pyx_t_7));
+          __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_8);
-          __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-          __Pyx_Raise(__pyx_t_8, 0, 0, 0);
-          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          goto __pyx_L39;
+          PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_7));
+          __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
+          __pyx_t_7 = 0;
+          __pyx_t_7 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_GOTREF(__pyx_t_7);
+          __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
+          __Pyx_Raise(__pyx_t_7, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          goto __pyx_L38;
         }
-        __pyx_L39:;
+        __pyx_L38:;
       }
-      __pyx_L38:;
-      goto __pyx_L37;
+      __pyx_L37:;
+      goto __pyx_L36;
     }
     /*else*/ {
 
-      /* "pysam/csamtools.pyx":904
+      /* "pysam/csamtools.pyx":909
  *                         raise IOError("error while opening index `%s` " % filename )
  *             else:
  *                 self.index = bam_index_load(filename)             # <<<<<<<<<<<<<<
  *                 if self.index == NULL:
  *                     raise IOError("error while opening index `%s` " % filename )
  */
-      __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_v_self->index = bam_index_load(__pyx_t_12);
+      __pyx_t_20 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_20) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 909; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_v_self->index = bam_index_load(__pyx_t_20);
 
-      /* "pysam/csamtools.pyx":905
+      /* "pysam/csamtools.pyx":910
  *             else:
  *                 self.index = bam_index_load(filename)
  *                 if self.index == NULL:             # <<<<<<<<<<<<<<
  *                     raise IOError("error while opening index `%s` " % filename )
  * 
  */
-      __pyx_t_1 = (__pyx_v_self->index == NULL);
-      if (__pyx_t_1) {
+      __pyx_t_10 = (__pyx_v_self->index == NULL);
+      if (__pyx_t_10) {
 
-        /* "pysam/csamtools.pyx":906
+        /* "pysam/csamtools.pyx":911
  *                 self.index = bam_index_load(filename)
  *                 if self.index == NULL:
  *                     raise IOError("error while opening index `%s` " % filename )             # <<<<<<<<<<<<<<
  * 
  *             if not self.isstream:
  */
-        __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_46), __pyx_v_filename); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_GOTREF(((PyObject *)__pyx_t_8));
-        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_GOTREF(__pyx_t_7);
-        PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_8));
-        __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
-        __pyx_t_8 = 0;
-        __pyx_t_8 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_46), __pyx_v_filename); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(((PyObject *)__pyx_t_7));
+        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-        __Pyx_Raise(__pyx_t_8, 0, 0, 0);
-        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        goto __pyx_L40;
+        PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_7));
+        __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
+        __pyx_t_7 = 0;
+        __pyx_t_7 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
+        __Pyx_Raise(__pyx_t_7, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        goto __pyx_L39;
       }
-      __pyx_L40:;
+      __pyx_L39:;
     }
-    __pyx_L37:;
+    __pyx_L36:;
 
-    /* "pysam/csamtools.pyx":908
+    /* "pysam/csamtools.pyx":913
  *                     raise IOError("error while opening index `%s` " % filename )
  * 
  *             if not self.isstream:             # <<<<<<<<<<<<<<
  *                 self.start_offset = bam_tell( self.samfile.x.bam )
  * 
  */
-    __pyx_t_1 = (!__pyx_v_self->isstream);
-    if (__pyx_t_1) {
+    __pyx_t_10 = (!__pyx_v_self->isstream);
+    if (__pyx_t_10) {
 
-      /* "pysam/csamtools.pyx":909
+      /* "pysam/csamtools.pyx":914
  * 
  *             if not self.isstream:
  *                 self.start_offset = bam_tell( self.samfile.x.bam )             # <<<<<<<<<<<<<<
@@ -9930,12 +10723,12 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6_open(struct __pyx_obj_5py
  *     def gettid( self, reference ):
  */
       __pyx_v_self->start_offset = bam_tell(__pyx_v_self->samfile->x.bam);
-      goto __pyx_L41;
+      goto __pyx_L40;
     }
-    __pyx_L41:;
-    goto __pyx_L36;
+    __pyx_L40:;
+    goto __pyx_L35;
   }
-  __pyx_L36:;
+  __pyx_L35:;
 
   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
   goto __pyx_L0;
@@ -9975,7 +10768,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_9gettid(PyObject *__pyx_v_s
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":911
+/* "pysam/csamtools.pyx":916
  *                 self.start_offset = bam_tell( self.samfile.x.bam )
  * 
  *     def gettid( self, reference ):             # <<<<<<<<<<<<<<
@@ -9996,48 +10789,48 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_8gettid(struct __pyx_obj_5p
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("gettid", 0);
-  __Pyx_TraceCall("gettid", __pyx_f[0], 911);
+  __Pyx_TraceCall("gettid", __pyx_f[0], 916);
   __Pyx_INCREF(__pyx_v_reference);
 
-  /* "pysam/csamtools.pyx":917
+  /* "pysam/csamtools.pyx":922
  *         returns -1 if reference is not known.
  *         '''
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         reference = _force_bytes(reference)
  *         return pysam_reference2tid( self.samfile.header, reference )
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_47), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_47), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __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 = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":918
+  /* "pysam/csamtools.pyx":923
  *         '''
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *         reference = _force_bytes(reference)             # <<<<<<<<<<<<<<
  *         return pysam_reference2tid( self.samfile.header, reference )
  * 
  */
-  __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_reference)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 918; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_reference)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_v_reference);
   __pyx_v_reference = __pyx_t_2;
   __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":919
+  /* "pysam/csamtools.pyx":924
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *         reference = _force_bytes(reference)
  *         return pysam_reference2tid( self.samfile.header, reference )             # <<<<<<<<<<<<<<
@@ -10045,8 +10838,8 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_8gettid(struct __pyx_obj_5p
  *     def getrname( self, tid ):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_5 = PyBytes_AsString(__pyx_v_reference); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = PyInt_FromLong(pysam_reference2tid(__pyx_v_self->samfile->header, __pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyBytes_AsString(__pyx_v_reference); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyInt_FromLong(pysam_reference2tid(__pyx_v_self->samfile->header, __pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
@@ -10079,7 +10872,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_11getrname(PyObject *__pyx_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":921
+/* "pysam/csamtools.pyx":926
  *         return pysam_reference2tid( self.samfile.header, reference )
  * 
  *     def getrname( self, tid ):             # <<<<<<<<<<<<<<
@@ -10100,63 +10893,63 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_10getrname(struct __pyx_obj
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("getrname", 0);
-  __Pyx_TraceCall("getrname", __pyx_f[0], 921);
+  __Pyx_TraceCall("getrname", __pyx_f[0], 926);
 
-  /* "pysam/csamtools.pyx":924
+  /* "pysam/csamtools.pyx":929
  *         '''
  *         convert numerical :term:`tid` into :term:`reference` name.'''
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         if not 0 <= tid < self.samfile.header.n_targets:
  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_48), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_48), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 929; __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 = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":925
+  /* "pysam/csamtools.pyx":930
  *         convert numerical :term:`tid` into :term:`reference` name.'''
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *         if not 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
  *         return _charptr_to_str(self.samfile.header.target_name[tid])
  */
-  __pyx_t_2 = PyObject_RichCompare(__pyx_int_0, __pyx_v_tid, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_RichCompare(__pyx_int_0, __pyx_v_tid, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__Pyx_PyObject_IsTrue(__pyx_t_2)) {
     __Pyx_DECREF(__pyx_t_2);
-    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->samfile->header->n_targets); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->samfile->header->n_targets); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyObject_RichCompare(__pyx_v_tid, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_RichCompare(__pyx_v_tid, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   }
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 925; __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 = 930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_3 = (!__pyx_t_4);
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":926
+    /* "pysam/csamtools.pyx":931
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *         if not 0 <= tid < self.samfile.header.n_targets:
  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )             # <<<<<<<<<<<<<<
  *         return _charptr_to_str(self.samfile.header.target_name[tid])
  * 
  */
-    __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->samfile->header->n_targets); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->samfile->header->n_targets); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_INCREF(__pyx_v_tid);
     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_tid);
@@ -10164,25 +10957,25 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_10getrname(struct __pyx_obj
     PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
     __Pyx_GIVEREF(__pyx_t_2);
     __pyx_t_2 = 0;
-    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
     __Pyx_DECREF(((PyObject *)__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 = 926; __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 = 931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
     __pyx_t_2 = 0;
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":927
+  /* "pysam/csamtools.pyx":932
  *         if not 0 <= tid < self.samfile.header.n_targets:
  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
  *         return _charptr_to_str(self.samfile.header.target_name[tid])             # <<<<<<<<<<<<<<
@@ -10190,8 +10983,8 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_10getrname(struct __pyx_obj
  *     cdef char * _getrname( self, int tid ): # TODO unused
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_tid); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = __pyx_f_5pysam_9csamtools__charptr_to_str((__pyx_v_self->samfile->header->target_name[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_tid); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __pyx_f_5pysam_9csamtools__charptr_to_str((__pyx_v_self->samfile->header->target_name[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
@@ -10211,7 +11004,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_10getrname(struct __pyx_obj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":929
+/* "pysam/csamtools.pyx":934
  *         return _charptr_to_str(self.samfile.header.target_name[tid])
  * 
  *     cdef char * _getrname( self, int tid ): # TODO unused             # <<<<<<<<<<<<<<
@@ -10232,34 +11025,34 @@ static char *__pyx_f_5pysam_9csamtools_7Samfile__getrname(struct __pyx_obj_5pysa
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_getrname", 0);
-  __Pyx_TraceCall("_getrname", __pyx_f[0], 929);
+  __Pyx_TraceCall("_getrname", __pyx_f[0], 934);
 
-  /* "pysam/csamtools.pyx":932
+  /* "pysam/csamtools.pyx":937
  *         '''
  *         convert numerical :term:`tid` into :term:`reference` name.'''
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         if not 0 <= tid < self.samfile.header.n_targets:
  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_50), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_50), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __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 = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":933
+  /* "pysam/csamtools.pyx":938
  *         convert numerical :term:`tid` into :term:`reference` name.'''
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *         if not 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
@@ -10273,18 +11066,18 @@ static char *__pyx_f_5pysam_9csamtools_7Samfile__getrname(struct __pyx_obj_5pysa
   __pyx_t_3 = (!__pyx_t_4);
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":934
+    /* "pysam/csamtools.pyx":939
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *         if not 0 <= tid < self.samfile.header.n_targets:
  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )             # <<<<<<<<<<<<<<
  *         return self.samfile.header.target_name[tid]
  * 
  */
-    __pyx_t_2 = PyInt_FromLong(__pyx_v_tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyInt_FromLong(__pyx_v_tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->samfile->header->n_targets); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->samfile->header->n_targets); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
     __Pyx_GIVEREF(__pyx_t_2);
@@ -10292,25 +11085,25 @@ static char *__pyx_f_5pysam_9csamtools_7Samfile__getrname(struct __pyx_obj_5pysa
     __Pyx_GIVEREF(__pyx_t_1);
     __pyx_t_2 = 0;
     __pyx_t_1 = 0;
-    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
-    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
     __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":935
+  /* "pysam/csamtools.pyx":940
  *         if not 0 <= tid < self.samfile.header.n_targets:
  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
  *         return self.samfile.header.target_name[tid]             # <<<<<<<<<<<<<<
@@ -10349,7 +11142,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_13_parseRegion(PyObject *__
     static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,0};
     PyObject* values[4] = {0,0,0,0};
 
-    /* "pysam/csamtools.pyx":938
+    /* "pysam/csamtools.pyx":943
  * 
  *     def _parseRegion( self,
  *                       reference = None,             # <<<<<<<<<<<<<<
@@ -10358,7 +11151,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_13_parseRegion(PyObject *__
  */
     values[0] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":939
+    /* "pysam/csamtools.pyx":944
  *     def _parseRegion( self,
  *                       reference = None,
  *                       start = None,             # <<<<<<<<<<<<<<
@@ -10367,7 +11160,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_13_parseRegion(PyObject *__
  */
     values[1] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":940
+    /* "pysam/csamtools.pyx":945
  *                       reference = None,
  *                       start = None,
  *                       end = None,             # <<<<<<<<<<<<<<
@@ -10376,7 +11169,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_13_parseRegion(PyObject *__
  */
     values[2] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":941
+    /* "pysam/csamtools.pyx":946
  *                       start = None,
  *                       end = None,
  *                       region = None ):             # <<<<<<<<<<<<<<
@@ -10419,7 +11212,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_13_parseRegion(PyObject *__
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_parseRegion") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_parseRegion") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 942; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -10438,7 +11231,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_13_parseRegion(PyObject *__
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("_parseRegion", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("_parseRegion", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 942; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.Samfile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -10449,7 +11242,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_13_parseRegion(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":937
+/* "pysam/csamtools.pyx":942
  *         return self.samfile.header.target_name[tid]
  * 
  *     def _parseRegion( self,             # <<<<<<<<<<<<<<
@@ -10482,11 +11275,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_parseRegion", 0);
-  __Pyx_TraceCall("_parseRegion", __pyx_f[0], 937);
+  __Pyx_TraceCall("_parseRegion", __pyx_f[0], 942);
   __Pyx_INCREF(__pyx_v_reference);
   __Pyx_INCREF(__pyx_v_region);
 
-  /* "pysam/csamtools.pyx":960
+  /* "pysam/csamtools.pyx":965
  *         cdef long long rend
  * 
  *         rtid = -1             # <<<<<<<<<<<<<<
@@ -10495,7 +11288,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
  */
   __pyx_v_rtid = -1;
 
-  /* "pysam/csamtools.pyx":961
+  /* "pysam/csamtools.pyx":966
  * 
  *         rtid = -1
  *         rstart = 0             # <<<<<<<<<<<<<<
@@ -10504,7 +11297,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
  */
   __pyx_v_rstart = 0;
 
-  /* "pysam/csamtools.pyx":962
+  /* "pysam/csamtools.pyx":967
  *         rtid = -1
  *         rstart = 0
  *         rend = max_pos             # <<<<<<<<<<<<<<
@@ -10513,19 +11306,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
  */
   __pyx_v_rend = __pyx_v_5pysam_9csamtools_max_pos;
 
-  /* "pysam/csamtools.pyx":963
+  /* "pysam/csamtools.pyx":968
  *         rstart = 0
  *         rend = max_pos
  *         if start != None:             # <<<<<<<<<<<<<<
  *             try:
  *                 rstart = start
  */
-  __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":964
+    /* "pysam/csamtools.pyx":969
  *         rend = max_pos
  *         if start != None:
  *             try:             # <<<<<<<<<<<<<<
@@ -10539,14 +11332,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
       __Pyx_XGOTREF(__pyx_t_5);
       /*try:*/ {
 
-        /* "pysam/csamtools.pyx":965
+        /* "pysam/csamtools.pyx":970
  *         if start != None:
  *             try:
  *                 rstart = start             # <<<<<<<<<<<<<<
  *             except OverflowError:
  *                 raise ValueError( 'start out of range (%i)' % start )
  */
-        __pyx_t_6 = __Pyx_PyInt_AsLongLong(__pyx_v_start); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
+        __pyx_t_6 = __Pyx_PyInt_AsLongLong(__pyx_v_start); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 970; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
         __pyx_v_rstart = __pyx_t_6;
       }
       __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
@@ -10556,7 +11349,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
       __pyx_L4_error:;
       __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-      /* "pysam/csamtools.pyx":966
+      /* "pysam/csamtools.pyx":971
  *             try:
  *                 rstart = start
  *             except OverflowError:             # <<<<<<<<<<<<<<
@@ -10566,31 +11359,31 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
       __pyx_t_7 = PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
       if (__pyx_t_7) {
         __Pyx_AddTraceback("pysam.csamtools.Samfile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
-        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_8, &__pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 966; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
+        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_8, &__pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
         __Pyx_GOTREF(__pyx_t_1);
         __Pyx_GOTREF(__pyx_t_8);
         __Pyx_GOTREF(__pyx_t_9);
 
-        /* "pysam/csamtools.pyx":967
+        /* "pysam/csamtools.pyx":972
  *                 rstart = start
  *             except OverflowError:
  *                 raise ValueError( 'start out of range (%i)' % start )             # <<<<<<<<<<<<<<
  * 
  *         if end != None:
  */
-        __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_17), __pyx_v_start); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
+        __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_v_start); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_10));
-        __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
+        __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
         __Pyx_GOTREF(__pyx_t_11);
         PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_t_10));
         __Pyx_GIVEREF(((PyObject *)__pyx_t_10));
         __pyx_t_10 = 0;
-        __pyx_t_10 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
+        __pyx_t_10 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
         __Pyx_GOTREF(__pyx_t_10);
         __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
         __Pyx_Raise(__pyx_t_10, 0, 0, 0);
         __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
@@ -10613,19 +11406,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":969
+  /* "pysam/csamtools.pyx":974
  *                 raise ValueError( 'start out of range (%i)' % start )
  * 
  *         if end != None:             # <<<<<<<<<<<<<<
  *             try:
  *                 rend = end
  */
-  __pyx_t_9 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":970
+    /* "pysam/csamtools.pyx":975
  * 
  *         if end != None:
  *             try:             # <<<<<<<<<<<<<<
@@ -10639,14 +11432,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
       __Pyx_XGOTREF(__pyx_t_3);
       /*try:*/ {
 
-        /* "pysam/csamtools.pyx":971
+        /* "pysam/csamtools.pyx":976
  *         if end != None:
  *             try:
  *                 rend = end             # <<<<<<<<<<<<<<
  *             except OverflowError:
  *                 raise ValueError( 'end out of range (%i)' % end )
  */
-        __pyx_t_6 = __Pyx_PyInt_AsLongLong(__pyx_v_end); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L15_error;}
+        __pyx_t_6 = __Pyx_PyInt_AsLongLong(__pyx_v_end); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 976; __pyx_clineno = __LINE__; goto __pyx_L15_error;}
         __pyx_v_rend = __pyx_t_6;
       }
       __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
@@ -10660,7 +11453,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
       __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
       __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
 
-      /* "pysam/csamtools.pyx":972
+      /* "pysam/csamtools.pyx":977
  *             try:
  *                 rend = end
  *             except OverflowError:             # <<<<<<<<<<<<<<
@@ -10670,31 +11463,31 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
       __pyx_t_7 = PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
       if (__pyx_t_7) {
         __Pyx_AddTraceback("pysam.csamtools.Samfile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
-        if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_8, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
+        if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_8, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
         __Pyx_GOTREF(__pyx_t_9);
         __Pyx_GOTREF(__pyx_t_8);
         __Pyx_GOTREF(__pyx_t_1);
 
-        /* "pysam/csamtools.pyx":973
+        /* "pysam/csamtools.pyx":978
  *                 rend = end
  *             except OverflowError:
  *                 raise ValueError( 'end out of range (%i)' % end )             # <<<<<<<<<<<<<<
  * 
  *         if region:
  */
-        __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_end); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
+        __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), __pyx_v_end); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_10));
-        __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
+        __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
         __Pyx_GOTREF(__pyx_t_11);
         PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_t_10));
         __Pyx_GIVEREF(((PyObject *)__pyx_t_10));
         __pyx_t_10 = 0;
-        __pyx_t_10 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
+        __pyx_t_10 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
         __Pyx_GOTREF(__pyx_t_10);
         __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
         __Pyx_Raise(__pyx_t_10, 0, 0, 0);
         __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -10717,42 +11510,42 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
   }
   __pyx_L14:;
 
-  /* "pysam/csamtools.pyx":975
+  /* "pysam/csamtools.pyx":980
  *                 raise ValueError( 'end out of range (%i)' % end )
  * 
  *         if region:             # <<<<<<<<<<<<<<
  *             region = _force_str(region)
  *             parts = re.split( "[:-]", region )
  */
-  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":976
+    /* "pysam/csamtools.pyx":981
  * 
  *         if region:
  *             region = _force_str(region)             # <<<<<<<<<<<<<<
  *             parts = re.split( "[:-]", region )
  *             reference = parts[0]
  */
-    __pyx_t_1 = __pyx_f_5pysam_9csamtools__force_str(__pyx_v_region); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __pyx_f_5pysam_9csamtools__force_str(__pyx_v_region); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_v_region);
     __pyx_v_region = __pyx_t_1;
     __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":977
+    /* "pysam/csamtools.pyx":982
  *         if region:
  *             region = _force_str(region)
  *             parts = re.split( "[:-]", region )             # <<<<<<<<<<<<<<
  *             reference = parts[0]
  *             if len(parts) >= 2: rstart = int(parts[1]) - 1
  */
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__re); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__re); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_8 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__split); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__split); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
     __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 = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_INCREF(((PyObject *)__pyx_kp_s_51));
     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_51));
@@ -10760,77 +11553,77 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
     __Pyx_INCREF(__pyx_v_region);
     PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_region);
     __Pyx_GIVEREF(__pyx_v_region);
-    __pyx_t_9 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
     __pyx_v_parts = __pyx_t_9;
     __pyx_t_9 = 0;
 
-    /* "pysam/csamtools.pyx":978
+    /* "pysam/csamtools.pyx":983
  *             region = _force_str(region)
  *             parts = re.split( "[:-]", region )
  *             reference = parts[0]             # <<<<<<<<<<<<<<
  *             if len(parts) >= 2: rstart = int(parts[1]) - 1
  *             if len(parts) >= 3: rend = int(parts[2])
  */
-    __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_parts, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_parts, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __Pyx_DECREF(__pyx_v_reference);
     __pyx_v_reference = __pyx_t_9;
     __pyx_t_9 = 0;
 
-    /* "pysam/csamtools.pyx":979
+    /* "pysam/csamtools.pyx":984
  *             parts = re.split( "[:-]", region )
  *             reference = parts[0]
  *             if len(parts) >= 2: rstart = int(parts[1]) - 1             # <<<<<<<<<<<<<<
  *             if len(parts) >= 3: rend = int(parts[2])
  * 
  */
-    __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_2 = (__pyx_t_12 >= 2);
     if (__pyx_t_2) {
-      __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_parts, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_parts, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
-      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 979; __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 = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9);
       __Pyx_GIVEREF(__pyx_t_9);
       __pyx_t_9 = 0;
-      __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
       __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
-      __pyx_t_1 = PyNumber_Subtract(__pyx_t_9, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyNumber_Subtract(__pyx_t_9, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-      __pyx_t_6 = __Pyx_PyInt_AsLongLong(__pyx_t_1); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = __Pyx_PyInt_AsLongLong(__pyx_t_1); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v_rstart = __pyx_t_6;
       goto __pyx_L26;
     }
     __pyx_L26:;
 
-    /* "pysam/csamtools.pyx":980
+    /* "pysam/csamtools.pyx":985
  *             reference = parts[0]
  *             if len(parts) >= 2: rstart = int(parts[1]) - 1
  *             if len(parts) >= 3: rend = int(parts[2])             # <<<<<<<<<<<<<<
  * 
  *         if not reference: return 0, 0, 0, 0
  */
-    __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_2 = (__pyx_t_12 >= 3);
     if (__pyx_t_2) {
-      __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
       PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
       __Pyx_GIVEREF(__pyx_t_1);
       __pyx_t_1 = 0;
-      __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
-      __pyx_t_6 = __Pyx_PyInt_AsLongLong(__pyx_t_1); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = __Pyx_PyInt_AsLongLong(__pyx_t_1); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v_rend = __pyx_t_6;
       goto __pyx_L27;
@@ -10840,14 +11633,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
   }
   __pyx_L25:;
 
-  /* "pysam/csamtools.pyx":982
+  /* "pysam/csamtools.pyx":987
  *             if len(parts) >= 3: rend = int(parts[2])
  * 
  *         if not reference: return 0, 0, 0, 0             # <<<<<<<<<<<<<<
  * 
  *         rtid = self.gettid( reference )
  */
-  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_t_13 = (!__pyx_t_2);
   if (__pyx_t_13) {
     __Pyx_XDECREF(__pyx_r);
@@ -10858,29 +11651,29 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
   }
   __pyx_L28:;
 
-  /* "pysam/csamtools.pyx":984
+  /* "pysam/csamtools.pyx":989
  *         if not reference: return 0, 0, 0, 0
  * 
  *         rtid = self.gettid( reference )             # <<<<<<<<<<<<<<
  *         if rtid < 0: raise ValueError( "invalid reference `%s`" % reference )
  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__gettid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__gettid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_9);
   __Pyx_INCREF(__pyx_v_reference);
   PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_reference);
   __Pyx_GIVEREF(__pyx_v_reference);
-  __pyx_t_8 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
-  __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_t_8); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_t_8); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
   __pyx_v_rtid = __pyx_t_7;
 
-  /* "pysam/csamtools.pyx":985
+  /* "pysam/csamtools.pyx":990
  * 
  *         rtid = self.gettid( reference )
  *         if rtid < 0: raise ValueError( "invalid reference `%s`" % reference )             # <<<<<<<<<<<<<<
@@ -10889,24 +11682,24 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
  */
   __pyx_t_13 = (__pyx_v_rtid < 0);
   if (__pyx_t_13) {
-    __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_53), __pyx_v_reference); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_53), __pyx_v_reference); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_8));
-    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_8));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
     __pyx_t_8 = 0;
-    __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
     __Pyx_Raise(__pyx_t_8, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L29;
   }
   __pyx_L29:;
 
-  /* "pysam/csamtools.pyx":986
+  /* "pysam/csamtools.pyx":991
  *         rtid = self.gettid( reference )
  *         if rtid < 0: raise ValueError( "invalid reference `%s`" % reference )
  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )             # <<<<<<<<<<<<<<
@@ -10915,11 +11708,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
  */
   __pyx_t_13 = (__pyx_v_rstart > __pyx_v_rend);
   if (__pyx_t_13) {
-    __pyx_t_8 = PyLong_FromLongLong(__pyx_v_rstart); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyLong_FromLongLong(__pyx_v_rstart); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
-    __pyx_t_9 = PyLong_FromLongLong(__pyx_v_rend); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyLong_FromLongLong(__pyx_v_rend); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
-    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
     __Pyx_GIVEREF(__pyx_t_8);
@@ -10927,25 +11720,25 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
     __Pyx_GIVEREF(__pyx_t_9);
     __pyx_t_8 = 0;
     __pyx_t_9 = 0;
-    __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_54), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_54), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_9));
     __Pyx_DECREF(((PyObject *)__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 = 986; __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 = 991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_9));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
     __pyx_t_9 = 0;
-    __pyx_t_9 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
     __Pyx_Raise(__pyx_t_9, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L30;
   }
   __pyx_L30:;
 
-  /* "pysam/csamtools.pyx":987
+  /* "pysam/csamtools.pyx":992
  *         if rtid < 0: raise ValueError( "invalid reference `%s`" % reference )
  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )
  *         if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )             # <<<<<<<<<<<<<<
@@ -10958,27 +11751,27 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
   }
   __pyx_t_2 = (!__pyx_t_13);
   if (__pyx_t_2) {
-    __pyx_t_9 = PyLong_FromLongLong(__pyx_v_rstart); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyLong_FromLongLong(__pyx_v_rstart); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
-    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_17), __pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_1));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
     __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L31;
   }
   __pyx_L31:;
 
-  /* "pysam/csamtools.pyx":988
+  /* "pysam/csamtools.pyx":993
  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )
  *         if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
  *         if not 0 <= rend <= max_pos: raise ValueError( 'end out of range (%i)' % rend )             # <<<<<<<<<<<<<<
@@ -10991,27 +11784,27 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
   }
   __pyx_t_13 = (!__pyx_t_2);
   if (__pyx_t_13) {
-    __pyx_t_1 = PyLong_FromLongLong(__pyx_v_rend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyLong_FromLongLong(__pyx_v_rend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), __pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_9));
     __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 = 988; __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 = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_9));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
     __pyx_t_9 = 0;
-    __pyx_t_9 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
     __Pyx_Raise(__pyx_t_9, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L32;
   }
   __pyx_L32:;
 
-  /* "pysam/csamtools.pyx":990
+  /* "pysam/csamtools.pyx":995
  *         if not 0 <= rend <= max_pos: raise ValueError( 'end out of range (%i)' % rend )
  * 
  *         return 1, rtid, rstart, rend             # <<<<<<<<<<<<<<
@@ -11019,13 +11812,13 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_12_parseRegion(struct __pyx
  *     def reset( self ):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_9 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_9);
-  __pyx_t_1 = PyLong_FromLongLong(__pyx_v_rstart); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyLong_FromLongLong(__pyx_v_rstart); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_8 = PyLong_FromLongLong(__pyx_v_rend); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = PyLong_FromLongLong(__pyx_v_rend); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
-  __pyx_t_10 = PyTuple_New(4); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_10 = PyTuple_New(4); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_10);
   __Pyx_INCREF(__pyx_int_1);
   PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_int_1);
@@ -11075,7 +11868,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_15reset(PyObject *__pyx_v_s
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":992
+/* "pysam/csamtools.pyx":997
  *         return 1, rtid, rstart, rend
  * 
  *     def reset( self ):             # <<<<<<<<<<<<<<
@@ -11094,9 +11887,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_14reset(struct __pyx_obj_5p
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("reset", 0);
-  __Pyx_TraceCall("reset", __pyx_f[0], 992);
+  __Pyx_TraceCall("reset", __pyx_f[0], 997);
 
-  /* "pysam/csamtools.pyx":994
+  /* "pysam/csamtools.pyx":999
  *     def reset( self ):
  *         '''reset file position to beginning of read section.'''
  *         return self.seek( self.start_offset, 0 )             # <<<<<<<<<<<<<<
@@ -11104,11 +11897,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_14reset(struct __pyx_obj_5p
  *     def seek( self, uint64_t offset, int where = 0):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__seek); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__seek); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = __Pyx_PyInt_to_py_int64_t(__pyx_v_self->start_offset); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_to_py_int64_t(__pyx_v_self->start_offset); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
   __Pyx_GIVEREF(__pyx_t_2);
@@ -11116,7 +11909,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_14reset(struct __pyx_obj_5p
   PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
   __Pyx_GIVEREF(__pyx_int_0);
   __pyx_t_2 = 0;
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
@@ -11172,7 +11965,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_17seek(PyObject *__pyx_v_se
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "seek") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 996; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "seek") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -11182,16 +11975,16 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_17seek(PyObject *__pyx_v_se
         default: goto __pyx_L5_argtuple_error;
       }
     }
-    __pyx_v_offset = __Pyx_PyInt_from_py_uint64_t(values[0]); if (unlikely((__pyx_v_offset == (uint64_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 996; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_offset = __Pyx_PyInt_from_py_uint64_t(values[0]); if (unlikely((__pyx_v_offset == (uint64_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     if (values[1]) {
-      __pyx_v_where = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_where == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 996; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_where = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_where == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
       __pyx_v_where = ((int)0);
     }
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("seek", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 996; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("seek", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.Samfile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -11202,7 +11995,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_17seek(PyObject *__pyx_v_se
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":996
+/* "pysam/csamtools.pyx":1001
  *         return self.seek( self.start_offset, 0 )
  * 
  *     def seek( self, uint64_t offset, int where = 0):             # <<<<<<<<<<<<<<
@@ -11222,42 +12015,42 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_16seek(struct __pyx_obj_5py
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("seek", 0);
-  __Pyx_TraceCall("seek", __pyx_f[0], 996);
+  __Pyx_TraceCall("seek", __pyx_f[0], 1001);
 
-  /* "pysam/csamtools.pyx":1001
+  /* "pysam/csamtools.pyx":1006
  *         '''
  * 
  *         if not self._isOpen():             # <<<<<<<<<<<<<<
  *             raise ValueError( "I/O operation on closed file" )
  *         if not self.isbam:
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":1002
+    /* "pysam/csamtools.pyx":1007
  * 
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         if not self.isbam:
  *             raise NotImplementedError("seek only available in bam files")
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_55), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_55), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1007; __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 = 1002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1003
+  /* "pysam/csamtools.pyx":1008
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )
  *         if not self.isbam:             # <<<<<<<<<<<<<<
@@ -11267,23 +12060,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_16seek(struct __pyx_obj_5py
   __pyx_t_4 = (!__pyx_v_self->isbam);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":1004
+    /* "pysam/csamtools.pyx":1009
  *             raise ValueError( "I/O operation on closed file" )
  *         if not self.isbam:
  *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
  *         if self.isstream:
  *             raise OSError("seek no available in streams")
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_57), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_57), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1009; __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 = 1004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":1005
+  /* "pysam/csamtools.pyx":1010
  *         if not self.isbam:
  *             raise NotImplementedError("seek only available in bam files")
  *         if self.isstream:             # <<<<<<<<<<<<<<
@@ -11292,23 +12085,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_16seek(struct __pyx_obj_5py
  */
   if (__pyx_v_self->isstream) {
 
-    /* "pysam/csamtools.pyx":1006
+    /* "pysam/csamtools.pyx":1011
  *             raise NotImplementedError("seek only available in bam files")
  *         if self.isstream:
  *             raise OSError("seek no available in streams")             # <<<<<<<<<<<<<<
  * 
  *         return bam_seek( self.samfile.x.bam, offset, where )
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_OSError, ((PyObject *)__pyx_k_tuple_59), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_OSError, ((PyObject *)__pyx_k_tuple_59), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __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 = 1006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L5;
   }
   __pyx_L5:;
 
-  /* "pysam/csamtools.pyx":1008
+  /* "pysam/csamtools.pyx":1013
  *             raise OSError("seek no available in streams")
  * 
  *         return bam_seek( self.samfile.x.bam, offset, where )             # <<<<<<<<<<<<<<
@@ -11316,7 +12109,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_16seek(struct __pyx_obj_5py
  *     def tell( self ):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = __Pyx_PyInt_to_py_int64_t(bam_seek(__pyx_v_self->samfile->x.bam, __pyx_v_offset, __pyx_v_where)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_to_py_int64_t(bam_seek(__pyx_v_self->samfile->x.bam, __pyx_v_offset, __pyx_v_where)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
@@ -11348,7 +12141,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_19tell(PyObject *__pyx_v_se
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1010
+/* "pysam/csamtools.pyx":1015
  *         return bam_seek( self.samfile.x.bam, offset, where )
  * 
  *     def tell( self ):             # <<<<<<<<<<<<<<
@@ -11368,42 +12161,42 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_18tell(struct __pyx_obj_5py
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("tell", 0);
-  __Pyx_TraceCall("tell", __pyx_f[0], 1010);
+  __Pyx_TraceCall("tell", __pyx_f[0], 1015);
 
-  /* "pysam/csamtools.pyx":1014
+  /* "pysam/csamtools.pyx":1019
  *         return current file position
  *         '''
  *         if not self._isOpen():             # <<<<<<<<<<<<<<
  *             raise ValueError( "I/O operation on closed file" )
  *         if not self.isbam:
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":1015
+    /* "pysam/csamtools.pyx":1020
  *         '''
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         if not self.isbam:
  *             raise NotImplementedError("seek only available in bam files")
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_60), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_60), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __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 = 1015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1016
+  /* "pysam/csamtools.pyx":1021
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )
  *         if not self.isbam:             # <<<<<<<<<<<<<<
@@ -11413,23 +12206,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_18tell(struct __pyx_obj_5py
   __pyx_t_4 = (!__pyx_v_self->isbam);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":1017
+    /* "pysam/csamtools.pyx":1022
  *             raise ValueError( "I/O operation on closed file" )
  *         if not self.isbam:
  *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
  * 
  *         return bam_tell( self.samfile.x.bam )
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_61), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_61), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __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 = 1017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":1019
+  /* "pysam/csamtools.pyx":1024
  *             raise NotImplementedError("seek only available in bam files")
  * 
  *         return bam_tell( self.samfile.x.bam )             # <<<<<<<<<<<<<<
@@ -11437,7 +12230,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_18tell(struct __pyx_obj_5py
  *     def fetch( self,
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = __Pyx_PyInt_to_py_int64_t(bam_tell(__pyx_v_self->samfile->x.bam)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_to_py_int64_t(bam_tell(__pyx_v_self->samfile->x.bam)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
@@ -11474,7 +12267,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_21fetch(PyObject *__pyx_v_s
     static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,&__pyx_n_s__callback,&__pyx_n_s__until_eof,0};
     PyObject* values[6] = {0,0,0,0,0,0};
 
-    /* "pysam/csamtools.pyx":1022
+    /* "pysam/csamtools.pyx":1027
  * 
  *     def fetch( self,
  *                reference = None,             # <<<<<<<<<<<<<<
@@ -11483,7 +12276,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_21fetch(PyObject *__pyx_v_s
  */
     values[0] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":1023
+    /* "pysam/csamtools.pyx":1028
  *     def fetch( self,
  *                reference = None,
  *                start = None,             # <<<<<<<<<<<<<<
@@ -11492,7 +12285,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_21fetch(PyObject *__pyx_v_s
  */
     values[1] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":1024
+    /* "pysam/csamtools.pyx":1029
  *                reference = None,
  *                start = None,
  *                end = None,             # <<<<<<<<<<<<<<
@@ -11501,7 +12294,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_21fetch(PyObject *__pyx_v_s
  */
     values[2] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":1025
+    /* "pysam/csamtools.pyx":1030
  *                start = None,
  *                end = None,
  *                region = None,             # <<<<<<<<<<<<<<
@@ -11510,7 +12303,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_21fetch(PyObject *__pyx_v_s
  */
     values[3] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":1026
+    /* "pysam/csamtools.pyx":1031
  *                end = None,
  *                region = None,
  *                callback = None,             # <<<<<<<<<<<<<<
@@ -11566,7 +12359,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_21fetch(PyObject *__pyx_v_s
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1026; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -11589,7 +12382,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_21fetch(PyObject *__pyx_v_s
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1026; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.Samfile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -11600,7 +12393,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_21fetch(PyObject *__pyx_v_s
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1021
+/* "pysam/csamtools.pyx":1026
  *         return bam_tell( self.samfile.x.bam )
  * 
  *     def fetch( self,             # <<<<<<<<<<<<<<
@@ -11636,51 +12429,51 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("fetch", 0);
-  __Pyx_TraceCall("fetch", __pyx_f[0], 1021);
+  __Pyx_TraceCall("fetch", __pyx_f[0], 1026);
 
-  /* "pysam/csamtools.pyx":1051
+  /* "pysam/csamtools.pyx":1056
  *         cdef int rtid, rstart, rend, has_coord
  * 
  *         if not self._isOpen():             # <<<<<<<<<<<<<<
  *             raise ValueError( "I/O operation on closed file" )
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":1052
+    /* "pysam/csamtools.pyx":1057
  * 
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_63), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_63), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1057; __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 = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1054
+  /* "pysam/csamtools.pyx":1059
  *             raise ValueError( "I/O operation on closed file" )
  * 
  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )             # <<<<<<<<<<<<<<
  * 
  *         if self.isstream: reopen = False
  */
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__pyx_v_reference);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
@@ -11694,7 +12487,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
   __Pyx_INCREF(__pyx_v_region);
   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_region);
   __Pyx_GIVEREF(__pyx_v_region);
-  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
@@ -11708,7 +12501,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
     if (unlikely(size != 4)) {
       if (size > 4) __Pyx_RaiseTooManyValuesError(4);
       else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     #if CYTHON_COMPILING_IN_CPYTHON
     if (likely(PyTuple_CheckExact(sequence))) {
@@ -11730,7 +12523,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
     Py_ssize_t i;
     PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7};
     for (i=0; i < 4; i++) {
-      PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(item);
       *(temps[i]) = item;
     }
@@ -11740,7 +12533,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
   {
     Py_ssize_t index = -1;
     PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7};
-    __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
@@ -11749,7 +12542,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
       __Pyx_GOTREF(item);
       *(temps[index]) = item;
     }
-    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_9 = NULL;
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     goto __pyx_L5_unpacking_done;
@@ -11757,23 +12550,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     __pyx_t_9 = NULL;
     if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_L5_unpacking_done:;
   }
-  __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_12 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_12 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-  __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
   __pyx_v_has_coord = __pyx_t_10;
   __pyx_v_rtid = __pyx_t_11;
   __pyx_v_rstart = __pyx_t_12;
   __pyx_v_rend = __pyx_t_13;
 
-  /* "pysam/csamtools.pyx":1056
+  /* "pysam/csamtools.pyx":1061
  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
  * 
  *         if self.isstream: reopen = False             # <<<<<<<<<<<<<<
@@ -11786,7 +12579,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1057
+    /* "pysam/csamtools.pyx":1062
  * 
  *         if self.isstream: reopen = False
  *         else: reopen = True             # <<<<<<<<<<<<<<
@@ -11797,7 +12590,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
   }
   __pyx_L6:;
 
-  /* "pysam/csamtools.pyx":1059
+  /* "pysam/csamtools.pyx":1064
  *         else: reopen = True
  * 
  *         if self.isbam:             # <<<<<<<<<<<<<<
@@ -11806,22 +12599,22 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
  */
   if (__pyx_v_self->isbam) {
 
-    /* "pysam/csamtools.pyx":1060
+    /* "pysam/csamtools.pyx":1065
  * 
  *         if self.isbam:
  *             if not until_eof and not self._hasIndex() and not self.isremote:             # <<<<<<<<<<<<<<
  *                 raise ValueError( "fetch called on bamfile without index" )
  * 
  */
-    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_3 = (!__pyx_t_4);
     if (__pyx_t_3) {
-      __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       __pyx_t_14 = (!__pyx_t_4);
       if (__pyx_t_14) {
@@ -11836,33 +12629,33 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
     }
     if (__pyx_t_14) {
 
-      /* "pysam/csamtools.pyx":1061
+      /* "pysam/csamtools.pyx":1066
  *         if self.isbam:
  *             if not until_eof and not self._hasIndex() and not self.isremote:
  *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
  * 
  *             if callback:
  */
-      __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_65), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_65), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_Raise(__pyx_t_7, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L8;
     }
     __pyx_L8:;
 
-    /* "pysam/csamtools.pyx":1063
+    /* "pysam/csamtools.pyx":1068
  *                 raise ValueError( "fetch called on bamfile without index" )
  * 
  *             if callback:             # <<<<<<<<<<<<<<
  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
  */
-    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (__pyx_t_14) {
 
-      /* "pysam/csamtools.pyx":1064
+      /* "pysam/csamtools.pyx":1069
  * 
  *             if callback:
  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
@@ -11871,41 +12664,41 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
  */
       __pyx_t_14 = (!__pyx_v_has_coord);
       if (__pyx_t_14) {
-        __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_67), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_67), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_Raise(__pyx_t_7, 0, 0, 0);
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         goto __pyx_L10;
       }
       __pyx_L10:;
 
-      /* "pysam/csamtools.pyx":1065
+      /* "pysam/csamtools.pyx":1070
  *             if callback:
  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
  *                 return bam_fetch(self.samfile.x.bam,
  *                                  self.index,
  */
-      __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
-      __pyx_t_5 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
       __pyx_t_3 = (!__pyx_t_14);
       if (__pyx_t_3) {
-        __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_69), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_69), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __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 = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         goto __pyx_L11;
       }
       __pyx_L11:;
 
-      /* "pysam/csamtools.pyx":1066
+      /* "pysam/csamtools.pyx":1071
  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
  *                 return bam_fetch(self.samfile.x.bam,             # <<<<<<<<<<<<<<
@@ -11914,14 +12707,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
  */
       __Pyx_XDECREF(__pyx_r);
 
-      /* "pysam/csamtools.pyx":1072
+      /* "pysam/csamtools.pyx":1077
  *                                  rend,
  *                                  <void*>callback,
  *                                  fetch_callback )             # <<<<<<<<<<<<<<
  *             else:
  *                 if has_coord:
  */
-      __pyx_t_5 = PyInt_FromLong(bam_fetch(__pyx_v_self->samfile->x.bam, __pyx_v_self->index, __pyx_v_rtid, __pyx_v_rstart, __pyx_v_rend, ((void *)__pyx_v_callback), __pyx_f_5pysam_9csamtools_fetch_callback)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyInt_FromLong(bam_fetch(__pyx_v_self->samfile->x.bam, __pyx_v_self->index, __pyx_v_rtid, __pyx_v_rstart, __pyx_v_rend, ((void *)__pyx_v_callback), __pyx_f_5pysam_9csamtools_fetch_callback)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
       __pyx_r = __pyx_t_5;
       __pyx_t_5 = 0;
@@ -11930,7 +12723,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
     }
     /*else*/ {
 
-      /* "pysam/csamtools.pyx":1074
+      /* "pysam/csamtools.pyx":1079
  *                                  fetch_callback )
  *             else:
  *                 if has_coord:             # <<<<<<<<<<<<<<
@@ -11939,7 +12732,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
  */
       if (__pyx_v_has_coord) {
 
-        /* "pysam/csamtools.pyx":1075
+        /* "pysam/csamtools.pyx":1080
  *             else:
  *                 if has_coord:
  *                     return IteratorRowRegion( self, rtid, rstart, rend,             # <<<<<<<<<<<<<<
@@ -11947,13 +12740,13 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
  *                 else:
  */
         __Pyx_XDECREF(__pyx_r);
-        __pyx_t_5 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_5);
-        __pyx_t_7 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
-        __pyx_t_6 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_6 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
-        __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
         __Pyx_INCREF(((PyObject *)__pyx_v_self));
         PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
@@ -11967,21 +12760,21 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
         __pyx_t_5 = 0;
         __pyx_t_7 = 0;
         __pyx_t_6 = 0;
-        __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_6));
 
-        /* "pysam/csamtools.pyx":1076
+        /* "pysam/csamtools.pyx":1081
  *                 if has_coord:
  *                     return IteratorRowRegion( self, rtid, rstart, rend,
  *                                               reopen=reopen )             # <<<<<<<<<<<<<<
  *                 else:
  *                     if until_eof:
  */
-        __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
-        if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__reopen), __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__reopen), __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-        __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowRegion)), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowRegion)), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
@@ -11992,17 +12785,17 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
       }
       /*else*/ {
 
-        /* "pysam/csamtools.pyx":1078
+        /* "pysam/csamtools.pyx":1083
  *                                               reopen=reopen )
  *                 else:
  *                     if until_eof:             # <<<<<<<<<<<<<<
  *                         return IteratorRowAll( self, reopen=reopen )
  *                     else:
  */
-        __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         if (__pyx_t_3) {
 
-          /* "pysam/csamtools.pyx":1079
+          /* "pysam/csamtools.pyx":1084
  *                 else:
  *                     if until_eof:
  *                         return IteratorRowAll( self, reopen=reopen )             # <<<<<<<<<<<<<<
@@ -12010,18 +12803,18 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
  *                         # AH: check - reason why no reopen for AllRefs?
  */
           __Pyx_XDECREF(__pyx_r);
-          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_7);
           __Pyx_INCREF(((PyObject *)__pyx_v_self));
           PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self));
           __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
-          __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(((PyObject *)__pyx_t_6));
-          __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_2);
-          if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__reopen), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__reopen), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-          __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowAll)), ((PyObject *)__pyx_t_7), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowAll)), ((PyObject *)__pyx_t_7), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_2);
           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
@@ -12032,7 +12825,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
         }
         /*else*/ {
 
-          /* "pysam/csamtools.pyx":1082
+          /* "pysam/csamtools.pyx":1087
  *                     else:
  *                         # AH: check - reason why no reopen for AllRefs?
  *                         return IteratorRowAllRefs(self ) # , reopen=reopen )             # <<<<<<<<<<<<<<
@@ -12040,12 +12833,12 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
  *             if has_coord:
  */
           __Pyx_XDECREF(__pyx_r);
-          __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_2);
           __Pyx_INCREF(((PyObject *)__pyx_v_self));
           PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
           __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
-          __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowAllRefs)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowAllRefs)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_6);
           __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
           __pyx_r = __pyx_t_6;
@@ -12061,7 +12854,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1084
+    /* "pysam/csamtools.pyx":1089
  *                         return IteratorRowAllRefs(self ) # , reopen=reopen )
  *         else:
  *             if has_coord:             # <<<<<<<<<<<<<<
@@ -12070,49 +12863,49 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
  */
     if (__pyx_v_has_coord) {
 
-      /* "pysam/csamtools.pyx":1085
+      /* "pysam/csamtools.pyx":1090
  *         else:
  *             if has_coord:
  *                 raise ValueError ("fetching by region is not available for sam files" )             # <<<<<<<<<<<<<<
  * 
  *             if callback:
  */
-      __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_71), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_71), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       __Pyx_Raise(__pyx_t_6, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L14;
     }
     __pyx_L14:;
 
-    /* "pysam/csamtools.pyx":1087
+    /* "pysam/csamtools.pyx":1092
  *                 raise ValueError ("fetching by region is not available for sam files" )
  * 
  *             if callback:             # <<<<<<<<<<<<<<
  *                 raise NotImplementedError( "callback not implemented yet" )
  * 
  */
-    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (__pyx_t_3) {
 
-      /* "pysam/csamtools.pyx":1088
+      /* "pysam/csamtools.pyx":1093
  * 
  *             if callback:
  *                 raise NotImplementedError( "callback not implemented yet" )             # <<<<<<<<<<<<<<
  * 
  *             if self.samfile.header == NULL:
  */
-      __pyx_t_6 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_73), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_73), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       __Pyx_Raise(__pyx_t_6, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L15;
     }
     __pyx_L15:;
 
-    /* "pysam/csamtools.pyx":1090
+    /* "pysam/csamtools.pyx":1095
  *                 raise NotImplementedError( "callback not implemented yet" )
  * 
  *             if self.samfile.header == NULL:             # <<<<<<<<<<<<<<
@@ -12122,23 +12915,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
     __pyx_t_3 = (__pyx_v_self->samfile->header == NULL);
     if (__pyx_t_3) {
 
-      /* "pysam/csamtools.pyx":1091
+      /* "pysam/csamtools.pyx":1096
  * 
  *             if self.samfile.header == NULL:
  *                 raise ValueError( "fetch called for samfile without header")             # <<<<<<<<<<<<<<
  * 
  *             # check if targets are defined
  */
-      __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_75), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_75), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       __Pyx_Raise(__pyx_t_6, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L16;
     }
     __pyx_L16:;
 
-    /* "pysam/csamtools.pyx":1095
+    /* "pysam/csamtools.pyx":1100
  *             # check if targets are defined
  *             # give warning, sam_read1 segfaults
  *             if self.samfile.header.n_targets == 0:             # <<<<<<<<<<<<<<
@@ -12148,19 +12941,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
     __pyx_t_3 = (__pyx_v_self->samfile->header->n_targets == 0);
     if (__pyx_t_3) {
 
-      /* "pysam/csamtools.pyx":1096
+      /* "pysam/csamtools.pyx":1101
  *             # give warning, sam_read1 segfaults
  *             if self.samfile.header.n_targets == 0:
  *                 warnings.warn( "fetch called for samfile without header")             # <<<<<<<<<<<<<<
  * 
  *             return IteratorRowAll( self, reopen=reopen )
  */
-      __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__warnings); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__warnings); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
-      __pyx_t_2 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__warn); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__warn); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-      __pyx_t_6 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_76), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_76), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1101; __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_6); __pyx_t_6 = 0;
@@ -12168,7 +12961,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
     }
     __pyx_L17:;
 
-    /* "pysam/csamtools.pyx":1098
+    /* "pysam/csamtools.pyx":1103
  *                 warnings.warn( "fetch called for samfile without header")
  * 
  *             return IteratorRowAll( self, reopen=reopen )             # <<<<<<<<<<<<<<
@@ -12176,18 +12969,18 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_20fetch(struct __pyx_obj_5p
  *     def mate( self,
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
     __Pyx_INCREF(((PyObject *)__pyx_v_self));
     PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_self));
     __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
-    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-    __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
-    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reopen), __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reopen), __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-    __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowAll)), ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowAll)), ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
     __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
@@ -12222,7 +13015,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_23mate(PyObject *__pyx_v_se
   PyObject *__pyx_r = 0;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("mate (wrapper)", 0);
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_9csamtools_AlignedRead, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_9csamtools_AlignedRead, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_7Samfile_22mate(((struct __pyx_obj_5pysam_9csamtools_Samfile *)__pyx_v_self), ((struct __pyx_obj_5pysam_9csamtools_AlignedRead *)__pyx_v_read));
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -12232,7 +13025,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_23mate(PyObject *__pyx_v_se
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1100
+/* "pysam/csamtools.pyx":1105
  *             return IteratorRowAll( self, reopen=reopen )
  * 
  *     def mate( self,             # <<<<<<<<<<<<<<
@@ -12257,9 +13050,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_22mate(struct __pyx_obj_5py
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("mate", 0);
-  __Pyx_TraceCall("mate", __pyx_f[0], 1100);
+  __Pyx_TraceCall("mate", __pyx_f[0], 1105);
 
-  /* "pysam/csamtools.pyx":1113
+  /* "pysam/csamtools.pyx":1118
  * 
  *         '''
  *         cdef uint32_t flag = read._delegate.core.flag             # <<<<<<<<<<<<<<
@@ -12269,7 +13062,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_22mate(struct __pyx_obj_5py
   __pyx_t_1 = __pyx_v_read->_delegate->core.flag;
   __pyx_v_flag = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":1115
+  /* "pysam/csamtools.pyx":1120
  *         cdef uint32_t flag = read._delegate.core.flag
  * 
  *         if flag & BAM_FPAIRED == 0:             # <<<<<<<<<<<<<<
@@ -12279,34 +13072,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_22mate(struct __pyx_obj_5py
   __pyx_t_2 = ((__pyx_v_flag & 1) == 0);
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":1116
+    /* "pysam/csamtools.pyx":1121
  * 
  *         if flag & BAM_FPAIRED == 0:
  *             raise ValueError( "read %s: is unpaired" % (read.qname))             # <<<<<<<<<<<<<<
  *         if flag & BAM_FMUNMAP != 0:
  *             raise ValueError( "mate %s: is unmapped" % (read.qname))
  */
-    __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_read), __pyx_n_s__qname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_read), __pyx_n_s__qname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_77), __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_77), __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_4));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
     __pyx_t_4 = 0;
-    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
     __Pyx_Raise(__pyx_t_4, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1117
+  /* "pysam/csamtools.pyx":1122
  *         if flag & BAM_FPAIRED == 0:
  *             raise ValueError( "read %s: is unpaired" % (read.qname))
  *         if flag & BAM_FMUNMAP != 0:             # <<<<<<<<<<<<<<
@@ -12316,34 +13109,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_22mate(struct __pyx_obj_5py
   __pyx_t_2 = ((__pyx_v_flag & 8) != 0);
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":1118
+    /* "pysam/csamtools.pyx":1123
  *             raise ValueError( "read %s: is unpaired" % (read.qname))
  *         if flag & BAM_FMUNMAP != 0:
  *             raise ValueError( "mate %s: is unmapped" % (read.qname))             # <<<<<<<<<<<<<<
  * 
  *         cdef MateData mate_data
  */
-    __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_read), __pyx_n_s__qname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_read), __pyx_n_s__qname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
-    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_78), __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_78), __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
     __pyx_t_3 = 0;
-    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
     __Pyx_Raise(__pyx_t_3, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":1122
+  /* "pysam/csamtools.pyx":1127
  *         cdef MateData mate_data
  * 
  *         mate_data.name = <char *>bam1_qname(read._delegate)             # <<<<<<<<<<<<<<
@@ -12352,7 +13145,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_22mate(struct __pyx_obj_5py
  */
   __pyx_v_mate_data.name = ((char *)bam1_qname(__pyx_v_read->_delegate));
 
-  /* "pysam/csamtools.pyx":1123
+  /* "pysam/csamtools.pyx":1128
  * 
  *         mate_data.name = <char *>bam1_qname(read._delegate)
  *         mate_data.mate = NULL             # <<<<<<<<<<<<<<
@@ -12361,7 +13154,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_22mate(struct __pyx_obj_5py
  */
   __pyx_v_mate_data.mate = NULL;
 
-  /* "pysam/csamtools.pyx":1125
+  /* "pysam/csamtools.pyx":1130
  *         mate_data.mate = NULL
  *         # xor flags to get the other mate
  *         cdef int x = BAM_FREAD1 + BAM_FREAD2             # <<<<<<<<<<<<<<
@@ -12370,7 +13163,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_22mate(struct __pyx_obj_5py
  */
   __pyx_v_x = 192;
 
-  /* "pysam/csamtools.pyx":1126
+  /* "pysam/csamtools.pyx":1131
  *         # xor flags to get the other mate
  *         cdef int x = BAM_FREAD1 + BAM_FREAD2
  *         mate_data.flag = ( flag ^ x) & x             # <<<<<<<<<<<<<<
@@ -12379,7 +13172,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_22mate(struct __pyx_obj_5py
  */
   __pyx_v_mate_data.flag = ((__pyx_v_flag ^ __pyx_v_x) & __pyx_v_x);
 
-  /* "pysam/csamtools.pyx":1134
+  /* "pysam/csamtools.pyx":1139
  *                   read._delegate.core.mpos + 1,
  *                   <void*>&mate_data,
  *                   mate_callback )             # <<<<<<<<<<<<<<
@@ -12388,7 +13181,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_22mate(struct __pyx_obj_5py
  */
   bam_fetch(__pyx_v_self->samfile->x.bam, __pyx_v_self->index, __pyx_v_read->_delegate->core.mtid, __pyx_v_read->_delegate->core.mpos, (__pyx_v_read->_delegate->core.mpos + 1), ((void *)(&__pyx_v_mate_data)), __pyx_f_5pysam_9csamtools_mate_callback);
 
-  /* "pysam/csamtools.pyx":1136
+  /* "pysam/csamtools.pyx":1141
  *                   mate_callback )
  * 
  *         if mate_data.mate == NULL:             # <<<<<<<<<<<<<<
@@ -12398,36 +13191,36 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_22mate(struct __pyx_obj_5py
   __pyx_t_2 = (__pyx_v_mate_data.mate == NULL);
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":1137
+    /* "pysam/csamtools.pyx":1142
  * 
  *         if mate_data.mate == NULL:
  *             raise ValueError( "mate not found" )             # <<<<<<<<<<<<<<
  * 
  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
  */
-    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_80), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_80), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_Raise(__pyx_t_3, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L5;
   }
   __pyx_L5:;
 
-  /* "pysam/csamtools.pyx":1139
+  /* "pysam/csamtools.pyx":1144
  *             raise ValueError( "mate not found" )
  * 
  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)             # <<<<<<<<<<<<<<
  *         dest._delegate = mate_data.mate
  *         return dest
  */
-  __pyx_t_3 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5pysam_9csamtools_AlignedRead)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5pysam_9csamtools_AlignedRead)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  if (!(likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5pysam_9csamtools_AlignedRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5pysam_9csamtools_AlignedRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_dest = ((struct __pyx_obj_5pysam_9csamtools_AlignedRead *)__pyx_t_3);
   __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":1140
+  /* "pysam/csamtools.pyx":1145
  * 
  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
  *         dest._delegate = mate_data.mate             # <<<<<<<<<<<<<<
@@ -12437,7 +13230,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_22mate(struct __pyx_obj_5py
   __pyx_t_5 = __pyx_v_mate_data.mate;
   __pyx_v_dest->_delegate = __pyx_t_5;
 
-  /* "pysam/csamtools.pyx":1141
+  /* "pysam/csamtools.pyx":1146
  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
  *         dest._delegate = mate_data.mate
  *         return dest             # <<<<<<<<<<<<<<
@@ -12480,7 +13273,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_25count(PyObject *__pyx_v_s
     static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,&__pyx_n_s__until_eof,0};
     PyObject* values[5] = {0,0,0,0,0};
 
-    /* "pysam/csamtools.pyx":1144
+    /* "pysam/csamtools.pyx":1149
  * 
  *     def count( self,
  *                reference = None,             # <<<<<<<<<<<<<<
@@ -12489,7 +13282,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_25count(PyObject *__pyx_v_s
  */
     values[0] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":1145
+    /* "pysam/csamtools.pyx":1150
  *     def count( self,
  *                reference = None,
  *                start = None,             # <<<<<<<<<<<<<<
@@ -12498,7 +13291,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_25count(PyObject *__pyx_v_s
  */
     values[1] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":1146
+    /* "pysam/csamtools.pyx":1151
  *                reference = None,
  *                start = None,
  *                end = None,             # <<<<<<<<<<<<<<
@@ -12507,7 +13300,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_25count(PyObject *__pyx_v_s
  */
     values[2] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":1147
+    /* "pysam/csamtools.pyx":1152
  *                start = None,
  *                end = None,
  *                region = None,             # <<<<<<<<<<<<<<
@@ -12557,7 +13350,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_25count(PyObject *__pyx_v_s
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1143; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1148; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -12578,7 +13371,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_25count(PyObject *__pyx_v_s
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("count", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1143; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("count", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1148; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.Samfile.count", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -12589,7 +13382,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_25count(PyObject *__pyx_v_s
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1143
+/* "pysam/csamtools.pyx":1148
  *         return dest
  * 
  *     def count( self,             # <<<<<<<<<<<<<<
@@ -12623,52 +13416,52 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("count", 0);
-  __Pyx_TraceCall("count", __pyx_f[0], 1143);
+  __Pyx_TraceCall("count", __pyx_f[0], 1148);
   __Pyx_INCREF(__pyx_v_region);
 
-  /* "pysam/csamtools.pyx":1161
+  /* "pysam/csamtools.pyx":1166
  *         cdef int rend
  * 
  *         if not self._isOpen():             # <<<<<<<<<<<<<<
  *             raise ValueError( "I/O operation on closed file" )
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":1162
+    /* "pysam/csamtools.pyx":1167
  * 
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_82), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_82), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1167; __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 = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1164
+  /* "pysam/csamtools.pyx":1169
  *             raise ValueError( "I/O operation on closed file" )
  * 
  *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )             # <<<<<<<<<<<<<<
  * 
  *         cdef int counter
  */
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__pyx_v_reference);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
@@ -12682,7 +13475,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
   __Pyx_INCREF(__pyx_v_region);
   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_region);
   __Pyx_GIVEREF(__pyx_v_region);
-  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
@@ -12696,7 +13489,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
     if (unlikely(size != 4)) {
       if (size > 4) __Pyx_RaiseTooManyValuesError(4);
       else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     #if CYTHON_COMPILING_IN_CPYTHON
     if (likely(PyTuple_CheckExact(sequence))) {
@@ -12718,7 +13511,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
     Py_ssize_t i;
     PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7};
     for (i=0; i < 4; i++) {
-      PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(item);
       *(temps[i]) = item;
     }
@@ -12728,7 +13521,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
   {
     Py_ssize_t index = -1;
     PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7};
-    __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
@@ -12737,7 +13530,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
       __Pyx_GOTREF(item);
       *(temps[index]) = item;
     }
-    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_9 = NULL;
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     goto __pyx_L5_unpacking_done;
@@ -12745,14 +13538,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     __pyx_t_9 = NULL;
     if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_L5_unpacking_done:;
   }
-  __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-  __pyx_t_12 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_12 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
   __Pyx_DECREF(__pyx_v_region);
   __pyx_v_region = __pyx_t_1;
@@ -12761,7 +13554,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
   __pyx_v_rstart = __pyx_t_11;
   __pyx_v_rend = __pyx_t_12;
 
-  /* "pysam/csamtools.pyx":1167
+  /* "pysam/csamtools.pyx":1172
  * 
  *         cdef int counter
  *         counter = 0;             # <<<<<<<<<<<<<<
@@ -12770,7 +13563,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
  */
   __pyx_v_counter = 0;
 
-  /* "pysam/csamtools.pyx":1169
+  /* "pysam/csamtools.pyx":1174
  *         counter = 0;
  * 
  *         if self.isbam:             # <<<<<<<<<<<<<<
@@ -12779,22 +13572,22 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
  */
   if (__pyx_v_self->isbam) {
 
-    /* "pysam/csamtools.pyx":1170
+    /* "pysam/csamtools.pyx":1175
  * 
  *         if self.isbam:
  *             if not until_eof and not self._hasIndex() and not self.isremote:             # <<<<<<<<<<<<<<
  *                 raise ValueError( "fetch called on bamfile without index" )
  * 
  */
-    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_3 = (!__pyx_t_4);
     if (__pyx_t_3) {
-      __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       __pyx_t_13 = (!__pyx_t_4);
       if (__pyx_t_13) {
@@ -12809,75 +13602,75 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
     }
     if (__pyx_t_13) {
 
-      /* "pysam/csamtools.pyx":1171
+      /* "pysam/csamtools.pyx":1176
  *         if self.isbam:
  *             if not until_eof and not self._hasIndex() and not self.isremote:
  *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
  * 
  *             if not region:
  */
-      __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_83), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_83), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_Raise(__pyx_t_7, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L7;
     }
     __pyx_L7:;
 
-    /* "pysam/csamtools.pyx":1173
+    /* "pysam/csamtools.pyx":1178
  *                 raise ValueError( "fetch called on bamfile without index" )
  * 
  *             if not region:             # <<<<<<<<<<<<<<
  *                 raise ValueError( "counting functionality requires a region/reference" )
  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )
  */
-    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_3 = (!__pyx_t_13);
     if (__pyx_t_3) {
 
-      /* "pysam/csamtools.pyx":1174
+      /* "pysam/csamtools.pyx":1179
  * 
  *             if not region:
  *                 raise ValueError( "counting functionality requires a region/reference" )             # <<<<<<<<<<<<<<
  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )
  *             bam_fetch(self.samfile.x.bam,
  */
-      __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_85), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_85), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_Raise(__pyx_t_7, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L8;
     }
     __pyx_L8:;
 
-    /* "pysam/csamtools.pyx":1175
+    /* "pysam/csamtools.pyx":1180
  *             if not region:
  *                 raise ValueError( "counting functionality requires a region/reference" )
  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
  *             bam_fetch(self.samfile.x.bam,
  *                              self.index,
  */
-    __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
-    __pyx_t_5 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     __pyx_t_13 = (!__pyx_t_3);
     if (__pyx_t_13) {
-      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_86), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_86), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __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 = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L9;
     }
     __pyx_L9:;
 
-    /* "pysam/csamtools.pyx":1182
+    /* "pysam/csamtools.pyx":1187
  *                              rend,
  *                              <void*>&counter,
  *                              count_callback )             # <<<<<<<<<<<<<<
@@ -12886,7 +13679,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
  */
     bam_fetch(__pyx_v_self->samfile->x.bam, __pyx_v_self->index, __pyx_v_rtid, __pyx_v_rstart, __pyx_v_rend, ((void *)(&__pyx_v_counter)), __pyx_f_5pysam_9csamtools_count_callback);
 
-    /* "pysam/csamtools.pyx":1183
+    /* "pysam/csamtools.pyx":1188
  *                              <void*>&counter,
  *                              count_callback )
  *             return counter             # <<<<<<<<<<<<<<
@@ -12894,7 +13687,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
  *             raise ValueError ("count for a region is not available for sam files" )
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_5 = PyInt_FromLong(__pyx_v_counter); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyInt_FromLong(__pyx_v_counter); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     __pyx_r = __pyx_t_5;
     __pyx_t_5 = 0;
@@ -12903,18 +13696,18 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_24count(struct __pyx_obj_5p
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1185
+    /* "pysam/csamtools.pyx":1190
  *             return counter
  *         else:
  *             raise ValueError ("count for a region is not available for sam files" )             # <<<<<<<<<<<<<<
  * 
  *     def pileup( self,
  */
-    __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_88), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_88), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __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 = 1185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L6:;
 
@@ -12956,7 +13749,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_27pileup(PyObject *__pyx_v_
     static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,&__pyx_n_s__callback,0};
     PyObject* values[5] = {0,0,0,0,0};
 
-    /* "pysam/csamtools.pyx":1188
+    /* "pysam/csamtools.pyx":1193
  * 
  *     def pileup( self,
  *                 reference = None,             # <<<<<<<<<<<<<<
@@ -12965,7 +13758,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_27pileup(PyObject *__pyx_v_
  */
     values[0] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":1189
+    /* "pysam/csamtools.pyx":1194
  *     def pileup( self,
  *                 reference = None,
  *                 start = None,             # <<<<<<<<<<<<<<
@@ -12974,7 +13767,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_27pileup(PyObject *__pyx_v_
  */
     values[1] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":1190
+    /* "pysam/csamtools.pyx":1195
  *                 reference = None,
  *                 start = None,
  *                 end = None,             # <<<<<<<<<<<<<<
@@ -12983,7 +13776,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_27pileup(PyObject *__pyx_v_
  */
     values[2] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":1191
+    /* "pysam/csamtools.pyx":1196
  *                 start = None,
  *                 end = None,
  *                 region = None,             # <<<<<<<<<<<<<<
@@ -12992,7 +13785,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_27pileup(PyObject *__pyx_v_
  */
     values[3] = ((PyObject *)Py_None);
 
-    /* "pysam/csamtools.pyx":1192
+    /* "pysam/csamtools.pyx":1197
  *                 end = None,
  *                 region = None,
  *                 callback = None,             # <<<<<<<<<<<<<<
@@ -13041,7 +13834,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_27pileup(PyObject *__pyx_v_
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "pileup") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1187; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "pileup") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -13062,7 +13855,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_27pileup(PyObject *__pyx_v_
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("pileup", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1187; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("pileup", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
   __Pyx_AddTraceback("pysam.csamtools.Samfile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
@@ -13075,7 +13868,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_27pileup(PyObject *__pyx_v_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1187
+/* "pysam/csamtools.pyx":1192
  *             raise ValueError ("count for a region is not available for sam files" )
  * 
  *     def pileup( self,             # <<<<<<<<<<<<<<
@@ -13109,51 +13902,51 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("pileup", 0);
-  __Pyx_TraceCall("pileup", __pyx_f[0], 1187);
+  __Pyx_TraceCall("pileup", __pyx_f[0], 1192);
 
-  /* "pysam/csamtools.pyx":1243
+  /* "pysam/csamtools.pyx":1248
  *         cdef bam_plbuf_t *buf
  * 
  *         if not self._isOpen():             # <<<<<<<<<<<<<<
  *             raise ValueError( "I/O operation on closed file" )
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":1244
+    /* "pysam/csamtools.pyx":1249
  * 
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_89), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_89), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __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 = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1246
+  /* "pysam/csamtools.pyx":1251
  *             raise ValueError( "I/O operation on closed file" )
  * 
  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )             # <<<<<<<<<<<<<<
  * 
  *         if self.isbam:
  */
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__pyx_v_reference);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
@@ -13167,7 +13960,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
   __Pyx_INCREF(__pyx_v_region);
   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_region);
   __Pyx_GIVEREF(__pyx_v_region);
-  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
@@ -13181,7 +13974,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
     if (unlikely(size != 4)) {
       if (size > 4) __Pyx_RaiseTooManyValuesError(4);
       else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     #if CYTHON_COMPILING_IN_CPYTHON
     if (likely(PyTuple_CheckExact(sequence))) {
@@ -13203,7 +13996,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
     Py_ssize_t i;
     PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7};
     for (i=0; i < 4; i++) {
-      PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(item);
       *(temps[i]) = item;
     }
@@ -13213,7 +14006,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
   {
     Py_ssize_t index = -1;
     PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7};
-    __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
@@ -13222,7 +14015,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
       __Pyx_GOTREF(item);
       *(temps[index]) = item;
     }
-    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_9 = NULL;
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     goto __pyx_L5_unpacking_done;
@@ -13230,23 +14023,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     __pyx_t_9 = NULL;
     if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_L5_unpacking_done:;
   }
-  __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_12 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_12 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-  __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
   __pyx_v_has_coord = __pyx_t_10;
   __pyx_v_rtid = __pyx_t_11;
   __pyx_v_rstart = __pyx_t_12;
   __pyx_v_rend = __pyx_t_13;
 
-  /* "pysam/csamtools.pyx":1248
+  /* "pysam/csamtools.pyx":1253
  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
  * 
  *         if self.isbam:             # <<<<<<<<<<<<<<
@@ -13255,42 +14048,42 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
  */
   if (__pyx_v_self->isbam) {
 
-    /* "pysam/csamtools.pyx":1249
+    /* "pysam/csamtools.pyx":1254
  * 
  *         if self.isbam:
  *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )             # <<<<<<<<<<<<<<
  * 
  *             if callback:
  */
-    __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
-    __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
     __pyx_t_3 = (!__pyx_t_4);
     if (__pyx_t_3) {
-      __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_91), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_91), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_Raise(__pyx_t_7, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L7;
     }
     __pyx_L7:;
 
-    /* "pysam/csamtools.pyx":1251
+    /* "pysam/csamtools.pyx":1256
  *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )
  * 
  *             if callback:             # <<<<<<<<<<<<<<
  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
  * 
  */
-    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (__pyx_t_3) {
 
-      /* "pysam/csamtools.pyx":1252
+      /* "pysam/csamtools.pyx":1257
  * 
  *             if callback:
  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
@@ -13299,16 +14092,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
  */
       __pyx_t_3 = (!__pyx_v_has_coord);
       if (__pyx_t_3) {
-        __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_92), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_92), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_Raise(__pyx_t_7, 0, 0, 0);
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         goto __pyx_L9;
       }
       __pyx_L9:;
 
-      /* "pysam/csamtools.pyx":1254
+      /* "pysam/csamtools.pyx":1259
  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
  * 
  *                 buf = bam_plbuf_init( <bam_pileup_f>pileup_callback, <void*>callback )             # <<<<<<<<<<<<<<
@@ -13317,7 +14110,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
  */
       __pyx_v_buf = bam_plbuf_init(((bam_pileup_f)__pyx_f_5pysam_9csamtools_pileup_callback), ((void *)__pyx_v_callback));
 
-      /* "pysam/csamtools.pyx":1257
+      /* "pysam/csamtools.pyx":1262
  *                 bam_fetch(self.samfile.x.bam,
  *                           self.index, rtid, rstart, rend,
  *                           buf, pileup_fetch_callback )             # <<<<<<<<<<<<<<
@@ -13326,7 +14119,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
  */
       bam_fetch(__pyx_v_self->samfile->x.bam, __pyx_v_self->index, __pyx_v_rtid, __pyx_v_rstart, __pyx_v_rend, __pyx_v_buf, __pyx_f_5pysam_9csamtools_pileup_fetch_callback);
 
-      /* "pysam/csamtools.pyx":1260
+      /* "pysam/csamtools.pyx":1265
  * 
  *                 # finalize pileup
  *                 bam_plbuf_push( NULL, buf)             # <<<<<<<<<<<<<<
@@ -13335,7 +14128,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
  */
       bam_plbuf_push(NULL, __pyx_v_buf);
 
-      /* "pysam/csamtools.pyx":1261
+      /* "pysam/csamtools.pyx":1266
  *                 # finalize pileup
  *                 bam_plbuf_push( NULL, buf)
  *                 bam_plbuf_destroy(buf)             # <<<<<<<<<<<<<<
@@ -13347,7 +14140,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
     }
     /*else*/ {
 
-      /* "pysam/csamtools.pyx":1263
+      /* "pysam/csamtools.pyx":1268
  *                 bam_plbuf_destroy(buf)
  *             else:
  *                 if has_coord:             # <<<<<<<<<<<<<<
@@ -13356,7 +14149,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
  */
       if (__pyx_v_has_coord) {
 
-        /* "pysam/csamtools.pyx":1264
+        /* "pysam/csamtools.pyx":1269
  *             else:
  *                 if has_coord:
  *                     return IteratorColumnRegion( self,             # <<<<<<<<<<<<<<
@@ -13364,67 +14157,67 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
  *                                                  start = rstart,
  */
         __Pyx_XDECREF(__pyx_r);
-        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_INCREF(((PyObject *)__pyx_v_self));
         PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self));
         __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
 
-        /* "pysam/csamtools.pyx":1268
+        /* "pysam/csamtools.pyx":1273
  *                                                  start = rstart,
  *                                                  end = rend,
  *                                                  **kwargs )             # <<<<<<<<<<<<<<
  *                 else:
  *                     return IteratorColumnAllRefs(self, **kwargs )
  */
-        __pyx_t_5 = PyDict_Copy(((PyObject *)__pyx_v_kwargs)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = PyDict_Copy(((PyObject *)__pyx_v_kwargs)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_5));
 
-        /* "pysam/csamtools.pyx":1265
+        /* "pysam/csamtools.pyx":1270
  *                 if has_coord:
  *                     return IteratorColumnRegion( self,
  *                                                  tid = rtid,             # <<<<<<<<<<<<<<
  *                                                  start = rstart,
  *                                                  end = rend,
  */
-        __pyx_t_6 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_6 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
         if (unlikely(PyDict_GetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__tid)))) {
-          __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__tid)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__tid)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
-        if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__tid), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__tid), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
 
-        /* "pysam/csamtools.pyx":1266
+        /* "pysam/csamtools.pyx":1271
  *                     return IteratorColumnRegion( self,
  *                                                  tid = rtid,
  *                                                  start = rstart,             # <<<<<<<<<<<<<<
  *                                                  end = rend,
  *                                                  **kwargs )
  */
-        __pyx_t_6 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_6 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
         if (unlikely(PyDict_GetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__start)))) {
-          __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__start)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__start)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
-        if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__start), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__start), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
 
-        /* "pysam/csamtools.pyx":1267
+        /* "pysam/csamtools.pyx":1272
  *                                                  tid = rtid,
  *                                                  start = rstart,
  *                                                  end = rend,             # <<<<<<<<<<<<<<
  *                                                  **kwargs )
  *                 else:
  */
-        __pyx_t_6 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_6 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
         if (unlikely(PyDict_GetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__end)))) {
-          __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__end)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__end)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
-        if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__end), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__end), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-        __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorColumnRegion)), ((PyObject *)__pyx_t_7), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorColumnRegion)), ((PyObject *)__pyx_t_7), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
         __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
@@ -13435,7 +14228,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
       }
       /*else*/ {
 
-        /* "pysam/csamtools.pyx":1270
+        /* "pysam/csamtools.pyx":1275
  *                                                  **kwargs )
  *                 else:
  *                     return IteratorColumnAllRefs(self, **kwargs )             # <<<<<<<<<<<<<<
@@ -13443,14 +14236,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
  *         else:
  */
         __Pyx_XDECREF(__pyx_r);
-        __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
         __Pyx_INCREF(((PyObject *)__pyx_v_self));
         PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_self));
         __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
         __pyx_t_5 = ((PyObject *)__pyx_v_kwargs);
         __Pyx_INCREF(__pyx_t_5);
-        __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorColumnAllRefs)), ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorColumnAllRefs)), ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
         __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
@@ -13465,18 +14258,18 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_26pileup(struct __pyx_obj_5
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1273
+    /* "pysam/csamtools.pyx":1278
  * 
  *         else:
  *             raise NotImplementedError( "pileup of samfiles not implemented yet" )             # <<<<<<<<<<<<<<
  * 
  *     def close( self ):
  */
-    __pyx_t_7 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_94), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_94), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
     __Pyx_Raise(__pyx_t_7, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L6:;
 
@@ -13510,7 +14303,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_29close(PyObject *__pyx_v_s
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1275
+/* "pysam/csamtools.pyx":1280
  *             raise NotImplementedError( "pileup of samfiles not implemented yet" )
  * 
  *     def close( self ):             # <<<<<<<<<<<<<<
@@ -13524,9 +14317,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_28close(struct __pyx_obj_5p
   int __pyx_t_1;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("close", 0);
-  __Pyx_TraceCall("close", __pyx_f[0], 1275);
+  __Pyx_TraceCall("close", __pyx_f[0], 1280);
 
-  /* "pysam/csamtools.pyx":1278
+  /* "pysam/csamtools.pyx":1283
  *         '''
  *         closes the :class:`pysam.Samfile`.'''
  *         if self.samfile != NULL:             # <<<<<<<<<<<<<<
@@ -13536,7 +14329,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_28close(struct __pyx_obj_5p
   __pyx_t_1 = (__pyx_v_self->samfile != NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":1279
+    /* "pysam/csamtools.pyx":1284
  *         closes the :class:`pysam.Samfile`.'''
  *         if self.samfile != NULL:
  *             samclose( self.samfile )             # <<<<<<<<<<<<<<
@@ -13545,7 +14338,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_28close(struct __pyx_obj_5p
  */
     samclose(__pyx_v_self->samfile);
 
-    /* "pysam/csamtools.pyx":1280
+    /* "pysam/csamtools.pyx":1285
  *         if self.samfile != NULL:
  *             samclose( self.samfile )
  *             bam_index_destroy(self.index);             # <<<<<<<<<<<<<<
@@ -13554,7 +14347,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_28close(struct __pyx_obj_5p
  */
     bam_index_destroy(__pyx_v_self->index);
 
-    /* "pysam/csamtools.pyx":1281
+    /* "pysam/csamtools.pyx":1286
  *             samclose( self.samfile )
  *             bam_index_destroy(self.index);
  *             self.samfile = NULL             # <<<<<<<<<<<<<<
@@ -13582,7 +14375,7 @@ static void __pyx_pw_5pysam_9csamtools_7Samfile_31__dealloc__(PyObject *__pyx_v_
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/csamtools.pyx":1283
+/* "pysam/csamtools.pyx":1288
  *             self.samfile = NULL
  * 
  *     def __dealloc__( self ):             # <<<<<<<<<<<<<<
@@ -13594,50 +14387,35 @@ static void __pyx_pf_5pysam_9csamtools_7Samfile_30__dealloc__(struct __pyx_obj_5
   __Pyx_RefNannyDeclarations
   PyObject *__pyx_t_1 = NULL;
   PyObject *__pyx_t_2 = NULL;
-  int __pyx_t_3;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__dealloc__", 0);
-  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1283);
+  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1288);
 
-  /* "pysam/csamtools.pyx":1287
+  /* "pysam/csamtools.pyx":1292
  *         # note: no doc string
  *         # note: __del__ is not called.
  *         self.close()             # <<<<<<<<<<<<<<
  *         bam_destroy1(self.b)
- *         if self._filename != NULL: free( self._filename )
+ * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":1288
+  /* "pysam/csamtools.pyx":1293
  *         # note: __del__ is not called.
  *         self.close()
  *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
- *         if self._filename != NULL: free( self._filename )
- * 
- */
-  bam_destroy1(__pyx_v_self->b);
-
-  /* "pysam/csamtools.pyx":1289
- *         self.close()
- *         bam_destroy1(self.b)
- *         if self._filename != NULL: free( self._filename )             # <<<<<<<<<<<<<<
  * 
  *     cpdef int write( self, AlignedRead read ) except -1:
  */
-  __pyx_t_3 = (__pyx_v_self->_filename != NULL);
-  if (__pyx_t_3) {
-    free(__pyx_v_self->_filename);
-    goto __pyx_L3;
-  }
-  __pyx_L3:;
+  bam_destroy1(__pyx_v_self->b);
 
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -13649,8 +14427,8 @@ static void __pyx_pf_5pysam_9csamtools_7Samfile_30__dealloc__(struct __pyx_obj_5
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/csamtools.pyx":1291
- *         if self._filename != NULL: free( self._filename )
+/* "pysam/csamtools.pyx":1295
+ *         bam_destroy1(self.b)
  * 
  *     cpdef int write( self, AlignedRead read ) except -1:             # <<<<<<<<<<<<<<
  *         '''
@@ -13672,23 +14450,23 @@ static int __pyx_f_5pysam_9csamtools_7Samfile_write(struct __pyx_obj_5pysam_9csa
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("write", 0);
-  __Pyx_TraceCall("write", __pyx_f[0], 1291);
+  __Pyx_TraceCall("write", __pyx_f[0], 1295);
   /* Check if called by wrapper */
   if (unlikely(__pyx_skip_dispatch)) ;
   /* Check if overridden in Python */
   else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
-    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_9csamtools_7Samfile_33write)) {
-      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_INCREF(((PyObject *)__pyx_v_read));
       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_read));
       __Pyx_GIVEREF(((PyObject *)__pyx_v_read));
-      __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 = 1291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __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 = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_DECREF(((PyObject *)__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 = 1291; __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 = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
       __pyx_r = __pyx_t_4;
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -13697,24 +14475,24 @@ static int __pyx_f_5pysam_9csamtools_7Samfile_write(struct __pyx_obj_5pysam_9csa
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   }
 
-  /* "pysam/csamtools.pyx":1297
+  /* "pysam/csamtools.pyx":1301
  *         returns the number of bytes written.
  *         '''
  *         if not self._isOpen():             # <<<<<<<<<<<<<<
  *             return 0
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   __pyx_t_6 = (!__pyx_t_5);
   if (__pyx_t_6) {
 
-    /* "pysam/csamtools.pyx":1298
+    /* "pysam/csamtools.pyx":1302
  *         '''
  *         if not self._isOpen():
  *             return 0             # <<<<<<<<<<<<<<
@@ -13727,7 +14505,7 @@ static int __pyx_f_5pysam_9csamtools_7Samfile_write(struct __pyx_obj_5pysam_9csa
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1300
+  /* "pysam/csamtools.pyx":1304
  *             return 0
  * 
  *         return samwrite( self.samfile, read._delegate )             # <<<<<<<<<<<<<<
@@ -13758,7 +14536,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_33write(PyObject *__pyx_v_s
   PyObject *__pyx_r = 0;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("write (wrapper)", 0);
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_9csamtools_AlignedRead, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_9csamtools_AlignedRead, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_7Samfile_32write(((struct __pyx_obj_5pysam_9csamtools_Samfile *)__pyx_v_self), ((struct __pyx_obj_5pysam_9csamtools_AlignedRead *)__pyx_v_read));
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -13768,8 +14546,8 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_33write(PyObject *__pyx_v_s
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1291
- *         if self._filename != NULL: free( self._filename )
+/* "pysam/csamtools.pyx":1295
+ *         bam_destroy1(self.b)
  * 
  *     cpdef int write( self, AlignedRead read ) except -1:             # <<<<<<<<<<<<<<
  *         '''
@@ -13785,9 +14563,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_32write(struct __pyx_obj_5p
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("write", 0);
-  __Pyx_TraceCall("write", __pyx_f[0], 1291);
+  __Pyx_TraceCall("write", __pyx_f[0], 1295);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(((struct __pyx_vtabstruct_5pysam_9csamtools_Samfile *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, __pyx_v_read, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(((struct __pyx_vtabstruct_5pysam_9csamtools_Samfile *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, __pyx_v_read, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -13818,7 +14596,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_35__enter__(PyObject *__pyx
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1302
+/* "pysam/csamtools.pyx":1306
  *         return samwrite( self.samfile, read._delegate )
  * 
  *     def __enter__(self):             # <<<<<<<<<<<<<<
@@ -13831,9 +14609,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_34__enter__(struct __pyx_ob
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__enter__", 0);
-  __Pyx_TraceCall("__enter__", __pyx_f[0], 1302);
+  __Pyx_TraceCall("__enter__", __pyx_f[0], 1306);
 
-  /* "pysam/csamtools.pyx":1303
+  /* "pysam/csamtools.pyx":1307
  * 
  *     def __enter__(self):
  *         return self             # <<<<<<<<<<<<<<
@@ -13884,16 +14662,16 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_37__exit__(PyObject *__pyx_
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__exc_value)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  2:
         if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__traceback)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
       goto __pyx_L5_argtuple_error;
@@ -13908,7 +14686,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_37__exit__(PyObject *__pyx_
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.Samfile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -13919,7 +14697,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_37__exit__(PyObject *__pyx_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1305
+/* "pysam/csamtools.pyx":1309
  *         return self
  * 
  *     def __exit__(self, exc_type, exc_value, traceback):             # <<<<<<<<<<<<<<
@@ -13937,23 +14715,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_36__exit__(struct __pyx_obj
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__exit__", 0);
-  __Pyx_TraceCall("__exit__", __pyx_f[0], 1305);
+  __Pyx_TraceCall("__exit__", __pyx_f[0], 1309);
 
-  /* "pysam/csamtools.pyx":1306
+  /* "pysam/csamtools.pyx":1310
  * 
  *     def __exit__(self, exc_type, exc_value, traceback):
  *         self.close()             # <<<<<<<<<<<<<<
  *         return False
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":1307
+  /* "pysam/csamtools.pyx":1311
  *     def __exit__(self, exc_type, exc_value, traceback):
  *         self.close()
  *         return False             # <<<<<<<<<<<<<<
@@ -13961,7 +14739,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_36__exit__(struct __pyx_obj
  *     ###############################################################
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
@@ -13992,74 +14770,34 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_8filename_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1316
+/* "pysam/csamtools.pyx":1320
  *     property filename:
  *         '''number of :term:`filename` associated with this object.'''
  *         def __get__(self):             # <<<<<<<<<<<<<<
- *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             return self._filename
+ * 
  */
 
 static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_8filename___get__(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_self) {
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
-  PyObject *__pyx_t_1 = NULL;
-  PyObject *__pyx_t_2 = NULL;
-  int __pyx_t_3;
-  int __pyx_t_4;
-  int __pyx_lineno = 0;
-  const char *__pyx_filename = NULL;
-  int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 1316);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 1320);
 
-  /* "pysam/csamtools.pyx":1317
+  /* "pysam/csamtools.pyx":1321
  *         '''number of :term:`filename` associated with this object.'''
  *         def __get__(self):
- *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
- *             return self._filename
- * 
- */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_2);
-  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_4 = (!__pyx_t_3);
-  if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_95), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __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 = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    goto __pyx_L3;
-  }
-  __pyx_L3:;
-
-  /* "pysam/csamtools.pyx":1318
- *         def __get__(self):
- *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             return self._filename             # <<<<<<<<<<<<<<
  * 
  *     property nreferences:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = PyBytes_FromString(__pyx_v_self->_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-  __pyx_r = ((PyObject *)__pyx_t_2);
-  __pyx_t_2 = 0;
+  __Pyx_INCREF(__pyx_v_self->_filename);
+  __pyx_r = __pyx_v_self->_filename;
   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_AddTraceback("pysam.csamtools.Samfile.filename.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
   __pyx_L0:;
   __Pyx_XGIVEREF(__pyx_r);
   __Pyx_TraceReturn(__pyx_r);
@@ -14078,7 +14816,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_11nreferences_1__get__(PyOb
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1322
+/* "pysam/csamtools.pyx":1325
  *     property nreferences:
  *         '''number of :term:`reference` sequences in the file.'''
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -14098,34 +14836,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_11nreferences___get__(struc
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 1322);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 1325);
 
-  /* "pysam/csamtools.pyx":1323
+  /* "pysam/csamtools.pyx":1326
  *         '''number of :term:`reference` sequences in the file.'''
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             return self.samfile.header.n_targets
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_96), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_95), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __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 = 1323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1324
+  /* "pysam/csamtools.pyx":1327
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             return self.samfile.header.n_targets             # <<<<<<<<<<<<<<
@@ -14133,7 +14871,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_11nreferences___get__(struc
  *     property references:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->samfile->header->n_targets); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->samfile->header->n_targets); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
@@ -14164,7 +14902,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_10references_1__get__(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1328
+/* "pysam/csamtools.pyx":1331
  *     property references:
  *         """tuple with the names of :term:`reference` sequences."""
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -14188,46 +14926,46 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_10references___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 1328);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 1331);
 
-  /* "pysam/csamtools.pyx":1329
+  /* "pysam/csamtools.pyx":1332
  *         """tuple with the names of :term:`reference` sequences."""
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             t = []
  *             for x from 0 <= x < self.samfile.header.n_targets:
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_97), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_96), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __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 = 1329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1330
+  /* "pysam/csamtools.pyx":1333
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             t = []             # <<<<<<<<<<<<<<
  *             for x from 0 <= x < self.samfile.header.n_targets:
  *                 t.append( _charptr_to_str(self.samfile.header.target_name[x]) )
  */
-  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_v_t = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":1331
+  /* "pysam/csamtools.pyx":1334
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             t = []
  *             for x from 0 <= x < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
@@ -14237,20 +14975,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_10references___get__(struct
   __pyx_t_5 = __pyx_v_self->samfile->header->n_targets;
   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {
 
-    /* "pysam/csamtools.pyx":1332
+    /* "pysam/csamtools.pyx":1335
  *             t = []
  *             for x from 0 <= x < self.samfile.header.n_targets:
  *                 t.append( _charptr_to_str(self.samfile.header.target_name[x]) )             # <<<<<<<<<<<<<<
  *             return tuple(t)
  * 
  */
-    __pyx_t_2 = __pyx_f_5pysam_9csamtools__charptr_to_str((__pyx_v_self->samfile->header->target_name[__pyx_v_x])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __pyx_f_5pysam_9csamtools__charptr_to_str((__pyx_v_self->samfile->header->target_name[__pyx_v_x])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_6 = PyList_Append(__pyx_v_t, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyList_Append(__pyx_v_t, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   }
 
-  /* "pysam/csamtools.pyx":1333
+  /* "pysam/csamtools.pyx":1336
  *             for x from 0 <= x < self.samfile.header.n_targets:
  *                 t.append( _charptr_to_str(self.samfile.header.target_name[x]) )
  *             return tuple(t)             # <<<<<<<<<<<<<<
@@ -14258,7 +14996,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_10references___get__(struct
  *     property lengths:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = ((PyObject *)PyList_AsTuple(__pyx_v_t)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = ((PyObject *)PyList_AsTuple(__pyx_v_t)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
   __pyx_r = ((PyObject *)__pyx_t_2);
   __pyx_t_2 = 0;
@@ -14290,7 +15028,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_7lengths_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1339
+/* "pysam/csamtools.pyx":1342
  *         :attr:`pysam.Samfile.references`
  *         """
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -14314,46 +15052,46 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_7lengths___get__(struct __p
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 1339);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 1342);
 
-  /* "pysam/csamtools.pyx":1340
+  /* "pysam/csamtools.pyx":1343
  *         """
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             t = []
  *             for x from 0 <= x < self.samfile.header.n_targets:
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_98), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_97), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __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 = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1341
+  /* "pysam/csamtools.pyx":1344
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             t = []             # <<<<<<<<<<<<<<
  *             for x from 0 <= x < self.samfile.header.n_targets:
  *                 t.append( self.samfile.header.target_len[x] )
  */
-  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_v_t = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":1342
+  /* "pysam/csamtools.pyx":1345
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             t = []
  *             for x from 0 <= x < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
@@ -14363,20 +15101,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_7lengths___get__(struct __p
   __pyx_t_5 = __pyx_v_self->samfile->header->n_targets;
   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {
 
-    /* "pysam/csamtools.pyx":1343
+    /* "pysam/csamtools.pyx":1346
  *             t = []
  *             for x from 0 <= x < self.samfile.header.n_targets:
  *                 t.append( self.samfile.header.target_len[x] )             # <<<<<<<<<<<<<<
  *             return tuple(t)
  * 
  */
-    __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t((__pyx_v_self->samfile->header->target_len[__pyx_v_x])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t((__pyx_v_self->samfile->header->target_len[__pyx_v_x])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_6 = PyList_Append(__pyx_v_t, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyList_Append(__pyx_v_t, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   }
 
-  /* "pysam/csamtools.pyx":1344
+  /* "pysam/csamtools.pyx":1347
  *             for x from 0 <= x < self.samfile.header.n_targets:
  *                 t.append( self.samfile.header.target_len[x] )
  *             return tuple(t)             # <<<<<<<<<<<<<<
@@ -14384,7 +15122,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_7lengths___get__(struct __p
  *     property mapped:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = ((PyObject *)PyList_AsTuple(__pyx_v_t)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = ((PyObject *)PyList_AsTuple(__pyx_v_t)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
   __pyx_r = ((PyObject *)__pyx_t_2);
   __pyx_t_2 = 0;
@@ -14416,7 +15154,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_6mapped_1__get__(PyObject *
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1349
+/* "pysam/csamtools.pyx":1352
  *         """total number of mapped reads in file.
  *         """
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -14439,34 +15177,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6mapped___get__(struct __py
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 1349);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 1352);
 
-  /* "pysam/csamtools.pyx":1350
+  /* "pysam/csamtools.pyx":1353
  *         """
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )
  *             if self.index == NULL:
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_99), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_98), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __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 = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1351
+  /* "pysam/csamtools.pyx":1354
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )             # <<<<<<<<<<<<<<
@@ -14475,16 +15213,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6mapped___get__(struct __py
  */
   __pyx_t_4 = (!__pyx_v_self->isbam);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_AttributeError, ((PyObject *)__pyx_k_tuple_101), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_AttributeError, ((PyObject *)__pyx_k_tuple_100), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1354; __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 = 1351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":1352
+  /* "pysam/csamtools.pyx":1355
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )
  *             if self.index == NULL:             # <<<<<<<<<<<<<<
@@ -14494,23 +15232,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6mapped___get__(struct __py
   __pyx_t_4 = (__pyx_v_self->index == NULL);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":1353
+    /* "pysam/csamtools.pyx":1356
  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )
  *             if self.index == NULL:
  *                 raise ValueError( "mapping information not recorded in index or index not available")             # <<<<<<<<<<<<<<
  * 
  *             cdef int tid
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_103), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_102), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __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 = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L5;
   }
   __pyx_L5:;
 
-  /* "pysam/csamtools.pyx":1356
+  /* "pysam/csamtools.pyx":1359
  * 
  *             cdef int tid
  *             cdef uint32_t total = 0             # <<<<<<<<<<<<<<
@@ -14519,7 +15257,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6mapped___get__(struct __py
  */
   __pyx_v_total = 0;
 
-  /* "pysam/csamtools.pyx":1357
+  /* "pysam/csamtools.pyx":1360
  *             cdef int tid
  *             cdef uint32_t total = 0
  *             for tid from 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
@@ -14529,7 +15267,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6mapped___get__(struct __py
   __pyx_t_5 = __pyx_v_self->samfile->header->n_targets;
   for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_5; __pyx_v_tid++) {
 
-    /* "pysam/csamtools.pyx":1358
+    /* "pysam/csamtools.pyx":1361
  *             cdef uint32_t total = 0
  *             for tid from 0 <= tid < self.samfile.header.n_targets:
  *                 total += pysam_get_mapped( self.index, tid )             # <<<<<<<<<<<<<<
@@ -14539,7 +15277,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6mapped___get__(struct __py
     __pyx_v_total = (__pyx_v_total + pysam_get_mapped(__pyx_v_self->index, __pyx_v_tid));
   }
 
-  /* "pysam/csamtools.pyx":1359
+  /* "pysam/csamtools.pyx":1362
  *             for tid from 0 <= tid < self.samfile.header.n_targets:
  *                 total += pysam_get_mapped( self.index, tid )
  *             return total             # <<<<<<<<<<<<<<
@@ -14547,7 +15285,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6mapped___get__(struct __py
  *     property unmapped:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_total); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_total); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
@@ -14578,7 +15316,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_8unmapped_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1364
+/* "pysam/csamtools.pyx":1367
  *         """total number of unmapped reads in file.
  *         """
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -14601,34 +15339,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_8unmapped___get__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 1364);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 1367);
 
-  /* "pysam/csamtools.pyx":1365
+  /* "pysam/csamtools.pyx":1368
  *         """
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )
  *             cdef int tid
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_104), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_103), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __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 = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1366
+  /* "pysam/csamtools.pyx":1369
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )             # <<<<<<<<<<<<<<
@@ -14637,16 +15375,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_8unmapped___get__(struct __
  */
   __pyx_t_4 = (!__pyx_v_self->isbam);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_AttributeError, ((PyObject *)__pyx_k_tuple_106), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_AttributeError, ((PyObject *)__pyx_k_tuple_105), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __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 = 1366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":1368
+  /* "pysam/csamtools.pyx":1371
  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )
  *             cdef int tid
  *             cdef uint32_t total = 0             # <<<<<<<<<<<<<<
@@ -14655,7 +15393,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_8unmapped___get__(struct __
  */
   __pyx_v_total = 0;
 
-  /* "pysam/csamtools.pyx":1369
+  /* "pysam/csamtools.pyx":1372
  *             cdef int tid
  *             cdef uint32_t total = 0
  *             for tid from 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
@@ -14665,7 +15403,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_8unmapped___get__(struct __
   __pyx_t_5 = __pyx_v_self->samfile->header->n_targets;
   for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_5; __pyx_v_tid++) {
 
-    /* "pysam/csamtools.pyx":1370
+    /* "pysam/csamtools.pyx":1373
  *             cdef uint32_t total = 0
  *             for tid from 0 <= tid < self.samfile.header.n_targets:
  *                 total += pysam_get_unmapped( self.index, tid )             # <<<<<<<<<<<<<<
@@ -14675,7 +15413,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_8unmapped___get__(struct __
     __pyx_v_total = (__pyx_v_total + pysam_get_unmapped(__pyx_v_self->index, __pyx_v_tid));
   }
 
-  /* "pysam/csamtools.pyx":1372
+  /* "pysam/csamtools.pyx":1375
  *                 total += pysam_get_unmapped( self.index, tid )
  *             # get unmapped reads without coordinates
  *             total += pysam_get_unmapped( self.index, -1 )             # <<<<<<<<<<<<<<
@@ -14684,7 +15422,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_8unmapped___get__(struct __
  */
   __pyx_v_total = (__pyx_v_total + pysam_get_unmapped(__pyx_v_self->index, -1));
 
-  /* "pysam/csamtools.pyx":1373
+  /* "pysam/csamtools.pyx":1376
  *             # get unmapped reads without coordinates
  *             total += pysam_get_unmapped( self.index, -1 )
  *             return total             # <<<<<<<<<<<<<<
@@ -14692,7 +15430,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_8unmapped___get__(struct __
  *     property text:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_total); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_total); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
@@ -14723,7 +15461,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_4text_1__get__(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1377
+/* "pysam/csamtools.pyx":1380
  *     property text:
  *         '''full contents of the :term:`sam file` header as a string.'''
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -14743,34 +15481,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_4text___get__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 1377);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 1380);
 
-  /* "pysam/csamtools.pyx":1378
+  /* "pysam/csamtools.pyx":1381
  *         '''full contents of the :term:`sam file` header as a string.'''
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             return from_string_and_size(self.samfile.header.text, self.samfile.header.l_text)
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_107), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_106), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1381; __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 = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1379
+  /* "pysam/csamtools.pyx":1382
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             return from_string_and_size(self.samfile.header.text, self.samfile.header.l_text)             # <<<<<<<<<<<<<<
@@ -14778,7 +15516,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_4text___get__(struct __pyx_
  *     property header:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = __pyx_f_5pysam_9csamtools_from_string_and_size(__pyx_v_self->samfile->header->text, __pyx_v_self->samfile->header->l_text); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __pyx_f_5pysam_9csamtools_from_string_and_size(__pyx_v_self->samfile->header->text, __pyx_v_self->samfile->header->l_text); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
@@ -14809,7 +15547,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_6header_1__get__(PyObject *
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1385
+/* "pysam/csamtools.pyx":1388
  *         a two-level dictionary.
  *         '''
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -14851,46 +15589,46 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 1385);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 1388);
 
-  /* "pysam/csamtools.pyx":1386
+  /* "pysam/csamtools.pyx":1389
  *         '''
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *             result = {}
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_108), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_107), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1389; __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 = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1388
+  /* "pysam/csamtools.pyx":1391
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  * 
  *             result = {}             # <<<<<<<<<<<<<<
  * 
  *             if self.samfile.header.text != NULL:
  */
-  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
   __pyx_v_result = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":1390
+  /* "pysam/csamtools.pyx":1393
  *             result = {}
  * 
  *             if self.samfile.header.text != NULL:             # <<<<<<<<<<<<<<
@@ -14900,35 +15638,35 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
   __pyx_t_4 = (__pyx_v_self->samfile->header->text != NULL);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":1392
+    /* "pysam/csamtools.pyx":1395
  *             if self.samfile.header.text != NULL:
  *                 # convert to python string (note: call self.text to create 0-terminated string)
  *                 t = self.text             # <<<<<<<<<<<<<<
  *                 for line in t.split("\n"):
  *                     if not line.strip(): continue
  */
-    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__text); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__text); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __pyx_v_t = __pyx_t_2;
     __pyx_t_2 = 0;
 
-    /* "pysam/csamtools.pyx":1393
+    /* "pysam/csamtools.pyx":1396
  *                 # convert to python string (note: call self.text to create 0-terminated string)
  *                 t = self.text
  *                 for line in t.split("\n"):             # <<<<<<<<<<<<<<
  *                     if not line.strip(): continue
  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
  */
-    __pyx_t_2 = PyObject_GetAttr(__pyx_v_t, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_v_t, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_109), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_108), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
       __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
       __pyx_t_6 = NULL;
     } else {
-      __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext;
     }
@@ -14937,23 +15675,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
       if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_2)) {
         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_2)) {
         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else {
         __pyx_t_1 = __pyx_t_6(__pyx_t_2);
         if (unlikely(!__pyx_t_1)) {
           if (PyErr_Occurred()) {
             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           }
           break;
         }
@@ -14963,19 +15701,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
       __pyx_v_line = __pyx_t_1;
       __pyx_t_1 = 0;
 
-      /* "pysam/csamtools.pyx":1394
+      /* "pysam/csamtools.pyx":1397
  *                 t = self.text
  *                 for line in t.split("\n"):
  *                     if not line.strip(): continue             # <<<<<<<<<<<<<<
  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
  *                     fields = line[1:].split("\t")
  */
-      __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       __pyx_t_3 = (!__pyx_t_4);
       if (__pyx_t_3) {
@@ -14984,7 +15722,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
       }
       __pyx_L7:;
 
-      /* "pysam/csamtools.pyx":1395
+      /* "pysam/csamtools.pyx":1398
  *                 for line in t.split("\n"):
  *                     if not line.strip(): continue
  *                     assert line.startswith("@"), "header line without '@': '%s'" % line             # <<<<<<<<<<<<<<
@@ -14992,55 +15730,55 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
  *                     record = fields[0]
  */
       #ifndef CYTHON_WITHOUT_ASSERTIONS
-      __pyx_t_7 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__startswith); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__startswith); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
-      __pyx_t_1 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_k_tuple_111), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_k_tuple_110), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       if (unlikely(!__pyx_t_3)) {
-        __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_112), __pyx_v_line); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_111), __pyx_v_line); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_1));
         PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_1));
         __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
       #endif
 
-      /* "pysam/csamtools.pyx":1396
+      /* "pysam/csamtools.pyx":1399
  *                     if not line.strip(): continue
  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
  *                     fields = line[1:].split("\t")             # <<<<<<<<<<<<<<
  *                     record = fields[0]
  *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)
  */
-      __pyx_t_1 = __Pyx_PySequence_GetSlice(__pyx_v_line, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_PySequence_GetSlice(__pyx_v_line, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_7 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__split); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__split); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-      __pyx_t_1 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_k_tuple_113), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_k_tuple_112), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       __Pyx_XDECREF(__pyx_v_fields);
       __pyx_v_fields = __pyx_t_1;
       __pyx_t_1 = 0;
 
-      /* "pysam/csamtools.pyx":1397
+      /* "pysam/csamtools.pyx":1400
  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
  *                     fields = line[1:].split("\t")
  *                     record = fields[0]             # <<<<<<<<<<<<<<
  *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)
  * 
  */
-      __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_fields, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_fields, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_XDECREF(__pyx_v_record);
       __pyx_v_record = __pyx_t_1;
       __pyx_t_1 = 0;
 
-      /* "pysam/csamtools.pyx":1398
+      /* "pysam/csamtools.pyx":1401
  *                     fields = line[1:].split("\t")
  *                     record = fields[0]
  *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)             # <<<<<<<<<<<<<<
@@ -15048,12 +15786,12 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
  *                     # treat comments
  */
       #ifndef CYTHON_WITHOUT_ASSERTIONS
-      __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_3 = (__Pyx_PySequence_Contains(__pyx_v_record, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = (__Pyx_PySequence_Contains(__pyx_v_record, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       if (unlikely(!__pyx_t_3)) {
-        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
         __Pyx_INCREF(__pyx_v_record);
         PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_record);
@@ -15061,73 +15799,73 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
         __Pyx_INCREF(__pyx_v_line);
         PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_line);
         __Pyx_GIVEREF(__pyx_v_line);
-        __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_114), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_113), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_7));
         __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
         PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_7));
         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
       #endif
 
-      /* "pysam/csamtools.pyx":1401
+      /* "pysam/csamtools.pyx":1404
  * 
  *                     # treat comments
  *                     if record == "CO":             # <<<<<<<<<<<<<<
  *                         if record not in result: result[record] = []
  *                         result[record].append( "\t".join( fields[1:] ) )
  */
-      __pyx_t_7 = PyObject_RichCompare(__pyx_v_record, ((PyObject *)__pyx_n_s__CO), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_RichCompare(__pyx_v_record, ((PyObject *)__pyx_n_s__CO), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       if (__pyx_t_3) {
 
-        /* "pysam/csamtools.pyx":1402
+        /* "pysam/csamtools.pyx":1405
  *                     # treat comments
  *                     if record == "CO":
  *                         if record not in result: result[record] = []             # <<<<<<<<<<<<<<
  *                         result[record].append( "\t".join( fields[1:] ) )
  *                         continue
  */
-        __pyx_t_3 = (__Pyx_PyDict_Contains(__pyx_v_record, ((PyObject *)__pyx_v_result), Py_NE)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_3 = (__Pyx_PyDict_Contains(__pyx_v_record, ((PyObject *)__pyx_v_result), Py_NE)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         if (__pyx_t_3) {
-          __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_7);
-          if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_t_7)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_t_7)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
           goto __pyx_L9;
         }
         __pyx_L9:;
 
-        /* "pysam/csamtools.pyx":1403
+        /* "pysam/csamtools.pyx":1406
  *                     if record == "CO":
  *                         if record not in result: result[record] = []
  *                         result[record].append( "\t".join( fields[1:] ) )             # <<<<<<<<<<<<<<
  *                         continue
  *                     # the following is clumsy as generators do not work?
  */
-        __pyx_t_7 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_result), __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_result), __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
-        __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
-        __pyx_t_8 = __Pyx_PySequence_GetSlice(__pyx_v_fields, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = __Pyx_PySequence_GetSlice(__pyx_v_fields, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_9);
         PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
         __Pyx_GIVEREF(__pyx_t_8);
         __pyx_t_8 = 0;
-        __pyx_t_8 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
         __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
-        __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_9);
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
 
-        /* "pysam/csamtools.pyx":1404
+        /* "pysam/csamtools.pyx":1407
  *                         if record not in result: result[record] = []
  *                         result[record].append( "\t".join( fields[1:] ) )
  *                         continue             # <<<<<<<<<<<<<<
@@ -15139,33 +15877,33 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
       }
       __pyx_L8:;
 
-      /* "pysam/csamtools.pyx":1406
+      /* "pysam/csamtools.pyx":1409
  *                         continue
  *                     # the following is clumsy as generators do not work?
  *                     x = {}             # <<<<<<<<<<<<<<
  *                     for field in fields[1:]:
  *                         if ":" not in field:
  */
-      __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_9));
       __Pyx_XDECREF(((PyObject *)__pyx_v_x));
       __pyx_v_x = ((PyObject*)__pyx_t_9);
       __pyx_t_9 = 0;
 
-      /* "pysam/csamtools.pyx":1407
+      /* "pysam/csamtools.pyx":1410
  *                     # the following is clumsy as generators do not work?
  *                     x = {}
  *                     for field in fields[1:]:             # <<<<<<<<<<<<<<
  *                         if ":" not in field:
  *                             raise ValueError("malformatted header: no ':' in field" )
  */
-      __pyx_t_9 = __Pyx_PySequence_GetSlice(__pyx_v_fields, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = __Pyx_PySequence_GetSlice(__pyx_v_fields, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
       if (PyList_CheckExact(__pyx_t_9) || PyTuple_CheckExact(__pyx_t_9)) {
         __pyx_t_8 = __pyx_t_9; __Pyx_INCREF(__pyx_t_8); __pyx_t_10 = 0;
         __pyx_t_11 = NULL;
       } else {
-        __pyx_t_10 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_10 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
         __pyx_t_11 = Py_TYPE(__pyx_t_8)->tp_iternext;
       }
@@ -15174,23 +15912,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
         if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_8)) {
           if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_8)) break;
           #if CYTHON_COMPILING_IN_CPYTHON
-          __pyx_t_9 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_10); __Pyx_INCREF(__pyx_t_9); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_10); __Pyx_INCREF(__pyx_t_9); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #else
-          __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #endif
         } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_8)) {
           if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
           #if CYTHON_COMPILING_IN_CPYTHON
-          __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_10); __Pyx_INCREF(__pyx_t_9); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_10); __Pyx_INCREF(__pyx_t_9); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #else
-          __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #endif
         } else {
           __pyx_t_9 = __pyx_t_11(__pyx_t_8);
           if (unlikely(!__pyx_t_9)) {
             if (PyErr_Occurred()) {
               if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             }
             break;
           }
@@ -15200,42 +15938,42 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
         __pyx_v_field = __pyx_t_9;
         __pyx_t_9 = 0;
 
-        /* "pysam/csamtools.pyx":1408
+        /* "pysam/csamtools.pyx":1411
  *                     x = {}
  *                     for field in fields[1:]:
  *                         if ":" not in field:             # <<<<<<<<<<<<<<
  *                             raise ValueError("malformatted header: no ':' in field" )
  *                         key, value = field.split(":",1)
  */
-        __pyx_t_3 = (__Pyx_PySequence_Contains(((PyObject *)__pyx_kp_s_115), __pyx_v_field, Py_NE)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_3 = (__Pyx_PySequence_Contains(((PyObject *)__pyx_kp_s_114), __pyx_v_field, Py_NE)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         if (__pyx_t_3) {
 
-          /* "pysam/csamtools.pyx":1409
+          /* "pysam/csamtools.pyx":1412
  *                     for field in fields[1:]:
  *                         if ":" not in field:
  *                             raise ValueError("malformatted header: no ':' in field" )             # <<<<<<<<<<<<<<
  *                         key, value = field.split(":",1)
  *                         # uppercase keys must be valid
  */
-          __pyx_t_9 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_117), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_116), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_9);
           __Pyx_Raise(__pyx_t_9, 0, 0, 0);
           __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           goto __pyx_L12;
         }
         __pyx_L12:;
 
-        /* "pysam/csamtools.pyx":1410
+        /* "pysam/csamtools.pyx":1413
  *                         if ":" not in field:
  *                             raise ValueError("malformatted header: no ':' in field" )
  *                         key, value = field.split(":",1)             # <<<<<<<<<<<<<<
  *                         # uppercase keys must be valid
  *                         # lowercase are permitted for user fields
  */
-        __pyx_t_9 = PyObject_GetAttr(__pyx_v_field, __pyx_n_s__split); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = PyObject_GetAttr(__pyx_v_field, __pyx_n_s__split); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_9);
-        __pyx_t_7 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_k_tuple_118), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_k_tuple_117), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
         if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
@@ -15248,7 +15986,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
           if (unlikely(size != 2)) {
             if (size > 2) __Pyx_RaiseTooManyValuesError(2);
             else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           }
           #if CYTHON_COMPILING_IN_CPYTHON
           if (likely(PyTuple_CheckExact(sequence))) {
@@ -15261,16 +15999,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
           __Pyx_INCREF(__pyx_t_9);
           __Pyx_INCREF(__pyx_t_1);
           #else
-          __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_9);
-          __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_1);
           #endif
           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         } else
         {
           Py_ssize_t index = -1;
-          __pyx_t_12 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_12 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_12);
           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
           __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext;
@@ -15278,7 +16016,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
           __Pyx_GOTREF(__pyx_t_9);
           index = 1; __pyx_t_1 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_1)) goto __pyx_L13_unpacking_failed;
           __Pyx_GOTREF(__pyx_t_1);
-          if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __pyx_t_13 = NULL;
           __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
           goto __pyx_L14_unpacking_done;
@@ -15286,7 +16024,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
           __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
           __pyx_t_13 = NULL;
           if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __pyx_L14_unpacking_done:;
         }
         __Pyx_XDECREF(__pyx_v_key);
@@ -15296,88 +16034,88 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
         __pyx_v_value = __pyx_t_1;
         __pyx_t_1 = 0;
 
-        /* "pysam/csamtools.pyx":1413
+        /* "pysam/csamtools.pyx":1416
  *                         # uppercase keys must be valid
  *                         # lowercase are permitted for user fields
  *                         if key in VALID_HEADER_FIELDS[record]:             # <<<<<<<<<<<<<<
  *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
  *                         elif not key.isupper():
  */
-        __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_FIELDS); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_FIELDS); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
-        __pyx_t_1 = PyObject_GetItem(__pyx_t_7, __pyx_v_record); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyObject_GetItem(__pyx_t_7, __pyx_v_record); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-        __pyx_t_3 = (__Pyx_PySequence_Contains(__pyx_v_key, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_3 = (__Pyx_PySequence_Contains(__pyx_v_key, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
         if (__pyx_t_3) {
 
-          /* "pysam/csamtools.pyx":1414
+          /* "pysam/csamtools.pyx":1417
  *                         # lowercase are permitted for user fields
  *                         if key in VALID_HEADER_FIELDS[record]:
  *                             x[key] = VALID_HEADER_FIELDS[record][key](value)             # <<<<<<<<<<<<<<
  *                         elif not key.isupper():
  *                             x[key] = value
  */
-          __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_FIELDS); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_FIELDS); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_1);
-          __pyx_t_7 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_7);
           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-          __pyx_t_1 = PyObject_GetItem(__pyx_t_7, __pyx_v_key); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_1 = PyObject_GetItem(__pyx_t_7, __pyx_v_key); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_1);
           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_7);
           __Pyx_INCREF(__pyx_v_value);
           PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_value);
           __Pyx_GIVEREF(__pyx_v_value);
-          __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_9);
           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-          if (PyDict_SetItem(((PyObject *)__pyx_v_x), __pyx_v_key, __pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          if (PyDict_SetItem(((PyObject *)__pyx_v_x), __pyx_v_key, __pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
           goto __pyx_L15;
         }
 
-        /* "pysam/csamtools.pyx":1415
+        /* "pysam/csamtools.pyx":1418
  *                         if key in VALID_HEADER_FIELDS[record]:
  *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
  *                         elif not key.isupper():             # <<<<<<<<<<<<<<
  *                             x[key] = value
  *                         else:
  */
-        __pyx_t_9 = PyObject_GetAttr(__pyx_v_key, __pyx_n_s__isupper); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = PyObject_GetAttr(__pyx_v_key, __pyx_n_s__isupper); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_9);
-        __pyx_t_7 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-        __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         __pyx_t_4 = (!__pyx_t_3);
         if (__pyx_t_4) {
 
-          /* "pysam/csamtools.pyx":1416
+          /* "pysam/csamtools.pyx":1419
  *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
  *                         elif not key.isupper():
  *                             x[key] = value             # <<<<<<<<<<<<<<
  *                         else:
  *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )
  */
-          if (PyDict_SetItem(((PyObject *)__pyx_v_x), __pyx_v_key, __pyx_v_value) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          if (PyDict_SetItem(((PyObject *)__pyx_v_x), __pyx_v_key, __pyx_v_value) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           goto __pyx_L15;
         }
         /*else*/ {
 
-          /* "pysam/csamtools.pyx":1418
+          /* "pysam/csamtools.pyx":1421
  *                             x[key] = value
  *                         else:
  *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )             # <<<<<<<<<<<<<<
  * 
  *                     if VALID_HEADER_TYPES[record] == dict:
  */
-          __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_7);
           __Pyx_INCREF(__pyx_v_key);
           PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_key);
@@ -15385,133 +16123,133 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
           __Pyx_INCREF(__pyx_v_record);
           PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_record);
           __Pyx_GIVEREF(__pyx_v_record);
-          __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_119), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_118), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(((PyObject *)__pyx_t_9));
           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_7);
           PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_9));
           __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
           __pyx_t_9 = 0;
-          __pyx_t_9 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_9);
           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
           __Pyx_Raise(__pyx_t_9, 0, 0, 0);
           __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         __pyx_L15:;
       }
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
 
-      /* "pysam/csamtools.pyx":1420
+      /* "pysam/csamtools.pyx":1423
  *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )
  * 
  *                     if VALID_HEADER_TYPES[record] == dict:             # <<<<<<<<<<<<<<
  *                         if record in result:
  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
  */
-      __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
-      __pyx_t_9 = PyObject_GetItem(__pyx_t_8, __pyx_v_record); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyObject_GetItem(__pyx_t_8, __pyx_v_record); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-      __pyx_t_8 = PyObject_RichCompare(__pyx_t_9, ((PyObject *)((PyObject*)(&PyDict_Type))), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyObject_RichCompare(__pyx_t_9, ((PyObject *)((PyObject*)(&PyDict_Type))), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
       if (__pyx_t_4) {
 
-        /* "pysam/csamtools.pyx":1421
+        /* "pysam/csamtools.pyx":1424
  * 
  *                     if VALID_HEADER_TYPES[record] == dict:
  *                         if record in result:             # <<<<<<<<<<<<<<
  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
  *                         result[record] = x
  */
-        __pyx_t_4 = (__Pyx_PyDict_Contains(__pyx_v_record, ((PyObject *)__pyx_v_result), Py_EQ)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_4 = (__Pyx_PyDict_Contains(__pyx_v_record, ((PyObject *)__pyx_v_result), Py_EQ)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         if (__pyx_t_4) {
 
-          /* "pysam/csamtools.pyx":1422
+          /* "pysam/csamtools.pyx":1425
  *                     if VALID_HEADER_TYPES[record] == dict:
  *                         if record in result:
  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )             # <<<<<<<<<<<<<<
  *                         result[record] = x
  *                     elif VALID_HEADER_TYPES[record] == list:
  */
-          __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_120), __pyx_v_record); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_119), __pyx_v_record); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(((PyObject *)__pyx_t_8));
-          __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_9);
           PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_8));
           __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
           __pyx_t_8 = 0;
-          __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_8);
           __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
           __Pyx_Raise(__pyx_t_8, 0, 0, 0);
           __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           goto __pyx_L17;
         }
         __pyx_L17:;
 
-        /* "pysam/csamtools.pyx":1423
+        /* "pysam/csamtools.pyx":1426
  *                         if record in result:
  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
  *                         result[record] = x             # <<<<<<<<<<<<<<
  *                     elif VALID_HEADER_TYPES[record] == list:
  *                         if record not in result: result[record] = []
  */
-        if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_v_x)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_v_x)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         goto __pyx_L16;
       }
 
-      /* "pysam/csamtools.pyx":1424
+      /* "pysam/csamtools.pyx":1427
  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
  *                         result[record] = x
  *                     elif VALID_HEADER_TYPES[record] == list:             # <<<<<<<<<<<<<<
  *                         if record not in result: result[record] = []
  *                         result[record].append( x )
  */
-      __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
-      __pyx_t_9 = PyObject_GetItem(__pyx_t_8, __pyx_v_record); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyObject_GetItem(__pyx_t_8, __pyx_v_record); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-      __pyx_t_8 = PyObject_RichCompare(__pyx_t_9, ((PyObject *)((PyObject*)(&PyList_Type))), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyObject_RichCompare(__pyx_t_9, ((PyObject *)((PyObject*)(&PyList_Type))), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
       if (__pyx_t_4) {
 
-        /* "pysam/csamtools.pyx":1425
+        /* "pysam/csamtools.pyx":1428
  *                         result[record] = x
  *                     elif VALID_HEADER_TYPES[record] == list:
  *                         if record not in result: result[record] = []             # <<<<<<<<<<<<<<
  *                         result[record].append( x )
  * 
  */
-        __pyx_t_4 = (__Pyx_PyDict_Contains(__pyx_v_record, ((PyObject *)__pyx_v_result), Py_NE)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_4 = (__Pyx_PyDict_Contains(__pyx_v_record, ((PyObject *)__pyx_v_result), Py_NE)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         if (__pyx_t_4) {
-          __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_8);
-          if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_t_8)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_t_8)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
           goto __pyx_L18;
         }
         __pyx_L18:;
 
-        /* "pysam/csamtools.pyx":1426
+        /* "pysam/csamtools.pyx":1429
  *                     elif VALID_HEADER_TYPES[record] == list:
  *                         if record not in result: result[record] = []
  *                         result[record].append( x )             # <<<<<<<<<<<<<<
  * 
  *                 # if there are no SQ lines in the header, add the reference names
  */
-        __pyx_t_8 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_result), __pyx_v_record); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_result), __pyx_v_record); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_8, ((PyObject *)__pyx_v_x)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_8, ((PyObject *)__pyx_v_x)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_9);
         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
@@ -15522,40 +16260,40 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
     }
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-    /* "pysam/csamtools.pyx":1434
+    /* "pysam/csamtools.pyx":1437
  *                 # SQ lines, the SQ information is not part of the textual header and thus
  *                 # are missing from the output. See issue 84.
  *                 if "SQ" not in result:             # <<<<<<<<<<<<<<
  *                     sq = []
  *                     for ref, length in zip( self.references, self.lengths ):
  */
-    __pyx_t_4 = (__Pyx_PyDict_Contains(((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_v_result), Py_NE)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = (__Pyx_PyDict_Contains(((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_v_result), Py_NE)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (__pyx_t_4) {
 
-      /* "pysam/csamtools.pyx":1435
+      /* "pysam/csamtools.pyx":1438
  *                 # are missing from the output. See issue 84.
  *                 if "SQ" not in result:
  *                     sq = []             # <<<<<<<<<<<<<<
  *                     for ref, length in zip( self.references, self.lengths ):
  *                         sq.append( {'LN': length, 'SN': ref } )
  */
-      __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __pyx_v_sq = ((PyObject*)__pyx_t_2);
       __pyx_t_2 = 0;
 
-      /* "pysam/csamtools.pyx":1436
+      /* "pysam/csamtools.pyx":1439
  *                 if "SQ" not in result:
  *                     sq = []
  *                     for ref, length in zip( self.references, self.lengths ):             # <<<<<<<<<<<<<<
  *                         sq.append( {'LN': length, 'SN': ref } )
  *                     result["SQ"] = sq
  */
-      __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__references); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__references); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
-      __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__lengths); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__lengths); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
-      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
       PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
       __Pyx_GIVEREF(__pyx_t_2);
@@ -15563,14 +16301,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
       __Pyx_GIVEREF(__pyx_t_9);
       __pyx_t_2 = 0;
       __pyx_t_9 = 0;
-      __pyx_t_9 = PyObject_Call(__pyx_builtin_zip, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyObject_Call(__pyx_builtin_zip, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
       __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
       if (PyList_CheckExact(__pyx_t_9) || PyTuple_CheckExact(__pyx_t_9)) {
         __pyx_t_8 = __pyx_t_9; __Pyx_INCREF(__pyx_t_8); __pyx_t_5 = 0;
         __pyx_t_6 = NULL;
       } else {
-        __pyx_t_5 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_5 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
         __pyx_t_6 = Py_TYPE(__pyx_t_8)->tp_iternext;
       }
@@ -15579,23 +16317,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
         if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_8)) {
           if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_8)) break;
           #if CYTHON_COMPILING_IN_CPYTHON
-          __pyx_t_9 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_9); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_9); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #else
-          __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #endif
         } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_8)) {
           if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
           #if CYTHON_COMPILING_IN_CPYTHON
-          __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_9); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_9); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #else
-          __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #endif
         } else {
           __pyx_t_9 = __pyx_t_6(__pyx_t_8);
           if (unlikely(!__pyx_t_9)) {
             if (PyErr_Occurred()) {
               if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             }
             break;
           }
@@ -15611,7 +16349,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
           if (unlikely(size != 2)) {
             if (size > 2) __Pyx_RaiseTooManyValuesError(2);
             else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           }
           #if CYTHON_COMPILING_IN_CPYTHON
           if (likely(PyTuple_CheckExact(sequence))) {
@@ -15624,16 +16362,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
           __Pyx_INCREF(__pyx_t_2);
           __Pyx_INCREF(__pyx_t_7);
           #else
-          __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_2);
-          __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_7);
           #endif
           __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
         } else
         {
           Py_ssize_t index = -1;
-          __pyx_t_1 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_1 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_1);
           __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
           __pyx_t_13 = Py_TYPE(__pyx_t_1)->tp_iternext;
@@ -15641,7 +16379,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
           __Pyx_GOTREF(__pyx_t_2);
           index = 1; __pyx_t_7 = __pyx_t_13(__pyx_t_1); if (unlikely(!__pyx_t_7)) goto __pyx_L22_unpacking_failed;
           __Pyx_GOTREF(__pyx_t_7);
-          if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_1), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_1), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __pyx_t_13 = NULL;
           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
           goto __pyx_L23_unpacking_done;
@@ -15649,7 +16387,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
           __pyx_t_13 = NULL;
           if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __pyx_L23_unpacking_done:;
         }
         __Pyx_XDECREF(__pyx_v_ref);
@@ -15659,30 +16397,30 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
         __pyx_v_length = __pyx_t_7;
         __pyx_t_7 = 0;
 
-        /* "pysam/csamtools.pyx":1437
+        /* "pysam/csamtools.pyx":1440
  *                     sq = []
  *                     for ref, length in zip( self.references, self.lengths ):
  *                         sq.append( {'LN': length, 'SN': ref } )             # <<<<<<<<<<<<<<
  *                     result["SQ"] = sq
  * 
  */
-        __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_9));
-        if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__LN), __pyx_v_length) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__SN), __pyx_v_ref) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_t_14 = PyList_Append(__pyx_v_sq, ((PyObject *)__pyx_t_9)); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__LN), __pyx_v_length) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__SN), __pyx_v_ref) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_14 = PyList_Append(__pyx_v_sq, ((PyObject *)__pyx_t_9)); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
       }
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
 
-      /* "pysam/csamtools.pyx":1438
+      /* "pysam/csamtools.pyx":1441
  *                     for ref, length in zip( self.references, self.lengths ):
  *                         sq.append( {'LN': length, 'SN': ref } )
  *                     result["SQ"] = sq             # <<<<<<<<<<<<<<
  * 
  *             return result
  */
-      if (PyDict_SetItem(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_v_sq)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (PyDict_SetItem(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_v_sq)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L19;
     }
     __pyx_L19:;
@@ -15690,7 +16428,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_6header___get__(struct __py
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":1440
+  /* "pysam/csamtools.pyx":1443
  *                     result["SQ"] = sq
  * 
  *             return result             # <<<<<<<<<<<<<<
@@ -15761,11 +16499,11 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_39_buildLine(PyObject *__py
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__record)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1445; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_buildLine") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_buildLine") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1445; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
       goto __pyx_L5_argtuple_error;
@@ -15778,7 +16516,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_39_buildLine(PyObject *__py
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1445; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.Samfile._buildLine", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -15789,7 +16527,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_39_buildLine(PyObject *__py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1442
+/* "pysam/csamtools.pyx":1445
  *             return result
  * 
  *     def _buildLine( self, fields, record ):             # <<<<<<<<<<<<<<
@@ -15815,18 +16553,18 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_buildLine", 0);
-  __Pyx_TraceCall("_buildLine", __pyx_f[0], 1442);
+  __Pyx_TraceCall("_buildLine", __pyx_f[0], 1445);
 
-  /* "pysam/csamtools.pyx":1446
+  /* "pysam/csamtools.pyx":1449
  * 
  *         # TODO: add checking for field and sort order
  *         line = ["@%s" % record ]             # <<<<<<<<<<<<<<
  *         # comment
  *         if record == "CO":
  */
-  __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_121), __pyx_v_record); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_120), __pyx_v_record); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
   __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
@@ -15834,65 +16572,65 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
   __pyx_v_line = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":1448
+  /* "pysam/csamtools.pyx":1451
  *         line = ["@%s" % record ]
  *         # comment
  *         if record == "CO":             # <<<<<<<<<<<<<<
  *             line.append( fields )
  *         # user tags
  */
-  __pyx_t_2 = PyObject_RichCompare(__pyx_v_record, ((PyObject *)__pyx_n_s__CO), Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_RichCompare(__pyx_v_record, ((PyObject *)__pyx_n_s__CO), Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":1449
+    /* "pysam/csamtools.pyx":1452
  *         # comment
  *         if record == "CO":
  *             line.append( fields )             # <<<<<<<<<<<<<<
  *         # user tags
  *         elif record.islower():
  */
-    __pyx_t_4 = PyList_Append(__pyx_v_line, __pyx_v_fields); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyList_Append(__pyx_v_line, __pyx_v_fields); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
 
-  /* "pysam/csamtools.pyx":1451
+  /* "pysam/csamtools.pyx":1454
  *             line.append( fields )
  *         # user tags
  *         elif record.islower():             # <<<<<<<<<<<<<<
  *             for key in sorted(fields):
  *                 line.append( "%s:%s" % (key, str(fields[key])))
  */
-  __pyx_t_2 = PyObject_GetAttr(__pyx_v_record, __pyx_n_s__islower); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_v_record, __pyx_n_s__islower); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":1452
+    /* "pysam/csamtools.pyx":1455
  *         # user tags
  *         elif record.islower():
  *             for key in sorted(fields):             # <<<<<<<<<<<<<<
  *                 line.append( "%s:%s" % (key, str(fields[key])))
  *         # defined tags
  */
-    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __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 = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_INCREF(__pyx_v_fields);
     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fields);
     __Pyx_GIVEREF(__pyx_v_fields);
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_sorted, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_sorted, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
     if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
       __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
       __pyx_t_6 = NULL;
     } else {
-      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
     }
@@ -15901,23 +16639,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
       if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) {
         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) {
         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else {
         __pyx_t_2 = __pyx_t_6(__pyx_t_1);
         if (unlikely(!__pyx_t_2)) {
           if (PyErr_Occurred()) {
             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           }
           break;
         }
@@ -15927,24 +16665,24 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
       __pyx_v_key = __pyx_t_2;
       __pyx_t_2 = 0;
 
-      /* "pysam/csamtools.pyx":1453
+      /* "pysam/csamtools.pyx":1456
  *         elif record.islower():
  *             for key in sorted(fields):
  *                 line.append( "%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
  *         # defined tags
  *         else:
  */
-      __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
-      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
       __Pyx_GIVEREF(__pyx_t_2);
       __pyx_t_2 = 0;
-      __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_INCREF(__pyx_v_key);
       PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_key);
@@ -15952,10 +16690,10 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
       PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_2);
       __Pyx_GIVEREF(__pyx_t_2);
       __pyx_t_2 = 0;
-      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_122), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_121), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-      __pyx_t_4 = PyList_Append(__pyx_v_line, ((PyObject *)__pyx_t_2)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyList_Append(__pyx_v_line, ((PyObject *)__pyx_t_2)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
     }
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -15963,23 +16701,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1457
+    /* "pysam/csamtools.pyx":1460
  *         else:
  *             # write fields of the specification
  *             for key in VALID_HEADER_ORDER[record]:             # <<<<<<<<<<<<<<
  *                 if key in fields:
  *                     line.append( "%s:%s" % (key, str(fields[key])))
  */
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_ORDER); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_ORDER); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
       __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
       __pyx_t_6 = NULL;
     } else {
-      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
     }
@@ -15988,23 +16726,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
       if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) {
         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) {
         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else {
         __pyx_t_2 = __pyx_t_6(__pyx_t_1);
         if (unlikely(!__pyx_t_2)) {
           if (PyErr_Occurred()) {
             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           }
           break;
         }
@@ -16014,34 +16752,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
       __pyx_v_key = __pyx_t_2;
       __pyx_t_2 = 0;
 
-      /* "pysam/csamtools.pyx":1458
+      /* "pysam/csamtools.pyx":1461
  *             # write fields of the specification
  *             for key in VALID_HEADER_ORDER[record]:
  *                 if key in fields:             # <<<<<<<<<<<<<<
  *                     line.append( "%s:%s" % (key, str(fields[key])))
  *             # write user fields
  */
-      __pyx_t_3 = (__Pyx_PySequence_Contains(__pyx_v_key, __pyx_v_fields, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = (__Pyx_PySequence_Contains(__pyx_v_key, __pyx_v_fields, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       if (__pyx_t_3) {
 
-        /* "pysam/csamtools.pyx":1459
+        /* "pysam/csamtools.pyx":1462
  *             for key in VALID_HEADER_ORDER[record]:
  *                 if key in fields:
  *                     line.append( "%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
  *             # write user fields
  *             for key in fields:
  */
-        __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
-        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
         __Pyx_GIVEREF(__pyx_t_2);
         __pyx_t_2 = 0;
-        __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-        __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_INCREF(__pyx_v_key);
         PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_key);
@@ -16049,10 +16787,10 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
         PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_2);
         __Pyx_GIVEREF(__pyx_t_2);
         __pyx_t_2 = 0;
-        __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_122), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_121), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_2));
         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-        __pyx_t_4 = PyList_Append(__pyx_v_line, ((PyObject *)__pyx_t_2)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_4 = PyList_Append(__pyx_v_line, ((PyObject *)__pyx_t_2)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
         goto __pyx_L8;
       }
@@ -16060,7 +16798,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
     }
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":1461
+    /* "pysam/csamtools.pyx":1464
  *                     line.append( "%s:%s" % (key, str(fields[key])))
  *             # write user fields
  *             for key in fields:             # <<<<<<<<<<<<<<
@@ -16071,7 +16809,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
       __pyx_t_1 = __pyx_v_fields; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
       __pyx_t_6 = NULL;
     } else {
-      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_fields); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_fields); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
     }
@@ -16079,23 +16817,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
       if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) {
         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) {
         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else {
         __pyx_t_2 = __pyx_t_6(__pyx_t_1);
         if (unlikely(!__pyx_t_2)) {
           if (PyErr_Occurred()) {
             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           }
           break;
         }
@@ -16105,41 +16843,41 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
       __pyx_v_key = __pyx_t_2;
       __pyx_t_2 = 0;
 
-      /* "pysam/csamtools.pyx":1462
+      /* "pysam/csamtools.pyx":1465
  *             # write user fields
  *             for key in fields:
  *                 if not key.isupper():             # <<<<<<<<<<<<<<
  *                     line.append( "%s:%s" % (key, str(fields[key])))
  * 
  */
-      __pyx_t_2 = PyObject_GetAttr(__pyx_v_key, __pyx_n_s__isupper); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_GetAttr(__pyx_v_key, __pyx_n_s__isupper); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
-      __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       __pyx_t_8 = (!__pyx_t_3);
       if (__pyx_t_8) {
 
-        /* "pysam/csamtools.pyx":1463
+        /* "pysam/csamtools.pyx":1466
  *             for key in fields:
  *                 if not key.isupper():
  *                     line.append( "%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
  * 
  *         return "\t".join( line )
  */
-        __pyx_t_7 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
-        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
         PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7);
         __Pyx_GIVEREF(__pyx_t_7);
         __pyx_t_7 = 0;
-        __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __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 = 1463; __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 = 1466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
         __Pyx_INCREF(__pyx_v_key);
         PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
@@ -16147,10 +16885,10 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
         PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7);
         __Pyx_GIVEREF(__pyx_t_7);
         __pyx_t_7 = 0;
-        __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_122), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_121), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_7));
         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
-        __pyx_t_4 = PyList_Append(__pyx_v_line, ((PyObject *)__pyx_t_7)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_4 = PyList_Append(__pyx_v_line, ((PyObject *)__pyx_t_7)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
         goto __pyx_L11;
       }
@@ -16160,7 +16898,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1465
+  /* "pysam/csamtools.pyx":1468
  *                     line.append( "%s:%s" % (key, str(fields[key])))
  * 
  *         return "\t".join( line )             # <<<<<<<<<<<<<<
@@ -16168,14 +16906,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
  *     cdef bam_header_t * _buildHeader( self, new_header ):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_7);
   __Pyx_INCREF(((PyObject *)__pyx_v_line));
   PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_line));
   __Pyx_GIVEREF(((PyObject *)__pyx_v_line));
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
@@ -16200,7 +16938,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1467
+/* "pysam/csamtools.pyx":1470
  *         return "\t".join( line )
  * 
  *     cdef bam_header_t * _buildHeader( self, new_header ):             # <<<<<<<<<<<<<<
@@ -16249,21 +16987,21 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_buildHeader", 0);
-  __Pyx_TraceCall("_buildHeader", __pyx_f[0], 1467);
+  __Pyx_TraceCall("_buildHeader", __pyx_f[0], 1470);
 
-  /* "pysam/csamtools.pyx":1473
+  /* "pysam/csamtools.pyx":1476
  *         '''
  * 
  *         lines = []             # <<<<<<<<<<<<<<
  * 
  *         # check if hash exists
  */
-  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_lines = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":1480
+  /* "pysam/csamtools.pyx":1483
  *         cdef bam_header_t * dest
  * 
  *         dest = bam_header_init()             # <<<<<<<<<<<<<<
@@ -16272,20 +17010,20 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
  */
   __pyx_v_dest = bam_header_init();
 
-  /* "pysam/csamtools.pyx":1483
+  /* "pysam/csamtools.pyx":1486
  * 
  *         # first: defined tags
  *         for record in VALID_HEADERS:             # <<<<<<<<<<<<<<
  *             if record in new_header:
  *                 ttype = VALID_HEADER_TYPES[record]
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADERS); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADERS); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
     __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
     __pyx_t_4 = NULL;
   } else {
-    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext;
   }
@@ -16294,23 +17032,23 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
     if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) {
       if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
       #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #else
-      __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
     } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) {
       if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
       #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #else
-      __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
     } else {
       __pyx_t_1 = __pyx_t_4(__pyx_t_2);
       if (unlikely(!__pyx_t_1)) {
         if (PyErr_Occurred()) {
           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         break;
       }
@@ -16320,70 +17058,70 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
     __pyx_v_record = __pyx_t_1;
     __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":1484
+    /* "pysam/csamtools.pyx":1487
  *         # first: defined tags
  *         for record in VALID_HEADERS:
  *             if record in new_header:             # <<<<<<<<<<<<<<
  *                 ttype = VALID_HEADER_TYPES[record]
  *                 data = new_header[record]
  */
-    __pyx_t_5 = (__Pyx_PySequence_Contains(__pyx_v_record, __pyx_v_new_header, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = (__Pyx_PySequence_Contains(__pyx_v_record, __pyx_v_new_header, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (__pyx_t_5) {
 
-      /* "pysam/csamtools.pyx":1485
+      /* "pysam/csamtools.pyx":1488
  *         for record in VALID_HEADERS:
  *             if record in new_header:
  *                 ttype = VALID_HEADER_TYPES[record]             # <<<<<<<<<<<<<<
  *                 data = new_header[record]
  *                 if type( data ) != type( ttype() ):
  */
-      __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_6 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __Pyx_XDECREF(__pyx_v_ttype);
       __pyx_v_ttype = __pyx_t_6;
       __pyx_t_6 = 0;
 
-      /* "pysam/csamtools.pyx":1486
+      /* "pysam/csamtools.pyx":1489
  *             if record in new_header:
  *                 ttype = VALID_HEADER_TYPES[record]
  *                 data = new_header[record]             # <<<<<<<<<<<<<<
  *                 if type( data ) != type( ttype() ):
  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
  */
-      __pyx_t_6 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       __Pyx_XDECREF(__pyx_v_data);
       __pyx_v_data = __pyx_t_6;
       __pyx_t_6 = 0;
 
-      /* "pysam/csamtools.pyx":1487
+      /* "pysam/csamtools.pyx":1490
  *                 ttype = VALID_HEADER_TYPES[record]
  *                 data = new_header[record]
  *                 if type( data ) != type( ttype() ):             # <<<<<<<<<<<<<<
  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
  *                 if type( data ) is dict:
  */
-      __pyx_t_6 = PyObject_Call(__pyx_v_ttype, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyObject_Call(__pyx_v_ttype, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
-      __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_data)), ((PyObject *)Py_TYPE(__pyx_t_6)), Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_data)), ((PyObject *)Py_TYPE(__pyx_t_6)), Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       if (__pyx_t_5) {
 
-        /* "pysam/csamtools.pyx":1488
+        /* "pysam/csamtools.pyx":1491
  *                 data = new_header[record]
  *                 if type( data ) != type( ttype() ):
  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )             # <<<<<<<<<<<<<<
  *                 if type( data ) is dict:
  *                     lines.append( self._buildLine( data, record ) )
  */
-        __pyx_t_1 = PyObject_Call(__pyx_v_ttype, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyObject_Call(__pyx_v_ttype, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
-        __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
         __Pyx_INCREF(__pyx_v_record);
         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_record);
@@ -16395,25 +17133,25 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
         PyTuple_SET_ITEM(__pyx_t_6, 2, ((PyObject *)Py_TYPE(__pyx_t_1)));
         __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_t_1)));
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-        __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_123), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_122), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_1));
         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
-        __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
         PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1));
         __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
         __pyx_t_1 = 0;
-        __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
         __Pyx_Raise(__pyx_t_1, 0, 0, 0);
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         goto __pyx_L6;
       }
       __pyx_L6:;
 
-      /* "pysam/csamtools.pyx":1489
+      /* "pysam/csamtools.pyx":1492
  *                 if type( data ) != type( ttype() ):
  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
  *                 if type( data ) is dict:             # <<<<<<<<<<<<<<
@@ -16423,16 +17161,16 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
       __pyx_t_5 = (((PyObject *)Py_TYPE(__pyx_v_data)) == ((PyObject *)((PyObject*)(&PyDict_Type))));
       if (__pyx_t_5) {
 
-        /* "pysam/csamtools.pyx":1490
+        /* "pysam/csamtools.pyx":1493
  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
  *                 if type( data ) is dict:
  *                     lines.append( self._buildLine( data, record ) )             # <<<<<<<<<<<<<<
  *                 else:
  *                     for fields in new_header[record]:
  */
-        __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___buildLine); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___buildLine); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
-        __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1490; __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 = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
         __Pyx_INCREF(__pyx_v_data);
         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_data);
@@ -16440,30 +17178,30 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
         __Pyx_INCREF(__pyx_v_record);
         PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_record);
         __Pyx_GIVEREF(__pyx_v_record);
-        __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
-        __pyx_t_8 = PyList_Append(__pyx_v_lines, __pyx_t_7); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyList_Append(__pyx_v_lines, __pyx_t_7); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         goto __pyx_L7;
       }
       /*else*/ {
 
-        /* "pysam/csamtools.pyx":1492
+        /* "pysam/csamtools.pyx":1495
  *                     lines.append( self._buildLine( data, record ) )
  *                 else:
  *                     for fields in new_header[record]:             # <<<<<<<<<<<<<<
  *                         lines.append( self._buildLine( fields, record ) )
  * 
  */
-        __pyx_t_7 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         if (PyList_CheckExact(__pyx_t_7) || PyTuple_CheckExact(__pyx_t_7)) {
           __pyx_t_6 = __pyx_t_7; __Pyx_INCREF(__pyx_t_6); __pyx_t_9 = 0;
           __pyx_t_10 = NULL;
         } else {
-          __pyx_t_9 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_6);
           __pyx_t_10 = Py_TYPE(__pyx_t_6)->tp_iternext;
         }
@@ -16472,23 +17210,23 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
           if (!__pyx_t_10 && PyList_CheckExact(__pyx_t_6)) {
             if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_6)) break;
             #if CYTHON_COMPILING_IN_CPYTHON
-            __pyx_t_7 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_9); __Pyx_INCREF(__pyx_t_7); __pyx_t_9++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_7 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_9); __Pyx_INCREF(__pyx_t_7); __pyx_t_9++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             #else
-            __pyx_t_7 = PySequence_ITEM(__pyx_t_6, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_7 = PySequence_ITEM(__pyx_t_6, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             #endif
           } else if (!__pyx_t_10 && PyTuple_CheckExact(__pyx_t_6)) {
             if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
             #if CYTHON_COMPILING_IN_CPYTHON
-            __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_9); __Pyx_INCREF(__pyx_t_7); __pyx_t_9++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_9); __Pyx_INCREF(__pyx_t_7); __pyx_t_9++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             #else
-            __pyx_t_7 = PySequence_ITEM(__pyx_t_6, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_7 = PySequence_ITEM(__pyx_t_6, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             #endif
           } else {
             __pyx_t_7 = __pyx_t_10(__pyx_t_6);
             if (unlikely(!__pyx_t_7)) {
               if (PyErr_Occurred()) {
                 if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-                else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+                else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
               }
               break;
             }
@@ -16498,16 +17236,16 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
           __pyx_v_fields = __pyx_t_7;
           __pyx_t_7 = 0;
 
-          /* "pysam/csamtools.pyx":1493
+          /* "pysam/csamtools.pyx":1496
  *                 else:
  *                     for fields in new_header[record]:
  *                         lines.append( self._buildLine( fields, record ) )             # <<<<<<<<<<<<<<
  * 
  *         # then: user tags (lower case), sorted alphabetically
  */
-          __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___buildLine); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___buildLine); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_7);
-          __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_1);
           __Pyx_INCREF(__pyx_v_fields);
           PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fields);
@@ -16515,11 +17253,11 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
           __Pyx_INCREF(__pyx_v_record);
           PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_record);
           __Pyx_GIVEREF(__pyx_v_record);
-          __pyx_t_11 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_11 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_11);
           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
           __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
-          __pyx_t_8 = PyList_Append(__pyx_v_lines, __pyx_t_11); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_8 = PyList_Append(__pyx_v_lines, __pyx_t_11); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
         }
         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
@@ -16531,31 +17269,31 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
   }
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":1496
+  /* "pysam/csamtools.pyx":1499
  * 
  *         # then: user tags (lower case), sorted alphabetically
  *         for record, data in sorted(new_header.items()):             # <<<<<<<<<<<<<<
  *             if record in VALID_HEADERS: continue
  *             if type( data ) is dict:
  */
-  __pyx_t_2 = PyObject_GetAttr(__pyx_v_new_header, __pyx_n_s__items); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_v_new_header, __pyx_n_s__items); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_6 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_6 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_6);
   __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 = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
   __Pyx_GIVEREF(__pyx_t_6);
   __pyx_t_6 = 0;
-  __pyx_t_6 = PyObject_Call(__pyx_builtin_sorted, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_6 = PyObject_Call(__pyx_builtin_sorted, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_6);
   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
   if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) {
     __pyx_t_2 = __pyx_t_6; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
     __pyx_t_4 = NULL;
   } else {
-    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext;
   }
@@ -16564,23 +17302,23 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
     if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) {
       if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
       #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #else
-      __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
     } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) {
       if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
       #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #else
-      __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
     } else {
       __pyx_t_6 = __pyx_t_4(__pyx_t_2);
       if (unlikely(!__pyx_t_6)) {
         if (PyErr_Occurred()) {
           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         break;
       }
@@ -16596,7 +17334,7 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
       if (unlikely(size != 2)) {
         if (size > 2) __Pyx_RaiseTooManyValuesError(2);
         else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
       #if CYTHON_COMPILING_IN_CPYTHON
       if (likely(PyTuple_CheckExact(sequence))) {
@@ -16609,16 +17347,16 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
       __Pyx_INCREF(__pyx_t_11);
       __Pyx_INCREF(__pyx_t_1);
       #else
-      __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_11);
-      __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       #endif
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     } else
     {
       Py_ssize_t index = -1;
-      __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
       __pyx_t_12 = Py_TYPE(__pyx_t_7)->tp_iternext;
@@ -16626,7 +17364,7 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
       __Pyx_GOTREF(__pyx_t_11);
       index = 1; __pyx_t_1 = __pyx_t_12(__pyx_t_7); if (unlikely(!__pyx_t_1)) goto __pyx_L12_unpacking_failed;
       __Pyx_GOTREF(__pyx_t_1);
-      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_t_12 = NULL;
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       goto __pyx_L13_unpacking_done;
@@ -16634,7 +17372,7 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       __pyx_t_12 = NULL;
       if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_L13_unpacking_done:;
     }
     __Pyx_XDECREF(__pyx_v_record);
@@ -16644,16 +17382,16 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
     __pyx_v_data = __pyx_t_1;
     __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":1497
+    /* "pysam/csamtools.pyx":1500
  *         # then: user tags (lower case), sorted alphabetically
  *         for record, data in sorted(new_header.items()):
  *             if record in VALID_HEADERS: continue             # <<<<<<<<<<<<<<
  *             if type( data ) is dict:
  *                 lines.append( self._buildLine( data, record ) )
  */
-    __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADERS); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADERS); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
-    __pyx_t_5 = (__Pyx_PySequence_Contains(__pyx_v_record, __pyx_t_6, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = (__Pyx_PySequence_Contains(__pyx_v_record, __pyx_t_6, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     if (__pyx_t_5) {
       goto __pyx_L10_continue;
@@ -16661,7 +17399,7 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
     }
     __pyx_L14:;
 
-    /* "pysam/csamtools.pyx":1498
+    /* "pysam/csamtools.pyx":1501
  *         for record, data in sorted(new_header.items()):
  *             if record in VALID_HEADERS: continue
  *             if type( data ) is dict:             # <<<<<<<<<<<<<<
@@ -16671,16 +17409,16 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
     __pyx_t_5 = (((PyObject *)Py_TYPE(__pyx_v_data)) == ((PyObject *)((PyObject*)(&PyDict_Type))));
     if (__pyx_t_5) {
 
-      /* "pysam/csamtools.pyx":1499
+      /* "pysam/csamtools.pyx":1502
  *             if record in VALID_HEADERS: continue
  *             if type( data ) is dict:
  *                 lines.append( self._buildLine( data, record ) )             # <<<<<<<<<<<<<<
  *             else:
  *                 for fields in new_header[record]:
  */
-      __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___buildLine); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___buildLine); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
-      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_INCREF(__pyx_v_data);
       PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_data);
@@ -16688,30 +17426,30 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
       __Pyx_INCREF(__pyx_v_record);
       PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_record);
       __Pyx_GIVEREF(__pyx_v_record);
-      __pyx_t_11 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_11 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_11);
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
       __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
-      __pyx_t_8 = PyList_Append(__pyx_v_lines, __pyx_t_11); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyList_Append(__pyx_v_lines, __pyx_t_11); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
       goto __pyx_L15;
     }
     /*else*/ {
 
-      /* "pysam/csamtools.pyx":1501
+      /* "pysam/csamtools.pyx":1504
  *                 lines.append( self._buildLine( data, record ) )
  *             else:
  *                 for fields in new_header[record]:             # <<<<<<<<<<<<<<
  *                     lines.append( self._buildLine( fields, record ) )
  * 
  */
-      __pyx_t_11 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_11 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_11);
       if (PyList_CheckExact(__pyx_t_11) || PyTuple_CheckExact(__pyx_t_11)) {
         __pyx_t_1 = __pyx_t_11; __Pyx_INCREF(__pyx_t_1); __pyx_t_9 = 0;
         __pyx_t_10 = NULL;
       } else {
-        __pyx_t_9 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
         __pyx_t_10 = Py_TYPE(__pyx_t_1)->tp_iternext;
       }
@@ -16720,23 +17458,23 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
         if (!__pyx_t_10 && PyList_CheckExact(__pyx_t_1)) {
           if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_1)) break;
           #if CYTHON_COMPILING_IN_CPYTHON
-          __pyx_t_11 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_11); __pyx_t_9++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_11 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_11); __pyx_t_9++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #else
-          __pyx_t_11 = PySequence_ITEM(__pyx_t_1, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_11 = PySequence_ITEM(__pyx_t_1, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #endif
         } else if (!__pyx_t_10 && PyTuple_CheckExact(__pyx_t_1)) {
           if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
           #if CYTHON_COMPILING_IN_CPYTHON
-          __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_11); __pyx_t_9++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_11); __pyx_t_9++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #else
-          __pyx_t_11 = PySequence_ITEM(__pyx_t_1, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_11 = PySequence_ITEM(__pyx_t_1, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           #endif
         } else {
           __pyx_t_11 = __pyx_t_10(__pyx_t_1);
           if (unlikely(!__pyx_t_11)) {
             if (PyErr_Occurred()) {
               if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             }
             break;
           }
@@ -16746,16 +17484,16 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
         __pyx_v_fields = __pyx_t_11;
         __pyx_t_11 = 0;
 
-        /* "pysam/csamtools.pyx":1502
+        /* "pysam/csamtools.pyx":1505
  *             else:
  *                 for fields in new_header[record]:
  *                     lines.append( self._buildLine( fields, record ) )             # <<<<<<<<<<<<<<
  * 
  *         text = "\n".join(lines) + "\n"
  */
-        __pyx_t_11 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___buildLine); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_11 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___buildLine); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_11);
-        __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __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 = 1505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
         __Pyx_INCREF(__pyx_v_fields);
         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_fields);
@@ -16763,11 +17501,11 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
         __Pyx_INCREF(__pyx_v_record);
         PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_record);
         __Pyx_GIVEREF(__pyx_v_record);
-        __pyx_t_7 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
         __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
-        __pyx_t_8 = PyList_Append(__pyx_v_lines, __pyx_t_7); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyList_Append(__pyx_v_lines, __pyx_t_7); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       }
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -16777,31 +17515,31 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
   }
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":1504
+  /* "pysam/csamtools.pyx":1507
  *                     lines.append( self._buildLine( fields, record ) )
  * 
  *         text = "\n".join(lines) + "\n"             # <<<<<<<<<<<<<<
  *         if dest.text != NULL: free( dest.text )
  *         dest.text = <char*>calloc( len(text), sizeof(char))
  */
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_6), __pyx_n_s__join); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_6), __pyx_n_s__join); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __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 = 1507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(((PyObject *)__pyx_v_lines));
   PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_lines));
   __Pyx_GIVEREF(((PyObject *)__pyx_v_lines));
-  __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_7);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
-  __pyx_t_1 = PyNumber_Add(__pyx_t_7, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyNumber_Add(__pyx_t_7, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
   __pyx_v_text = __pyx_t_1;
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":1505
+  /* "pysam/csamtools.pyx":1508
  * 
  *         text = "\n".join(lines) + "\n"
  *         if dest.text != NULL: free( dest.text )             # <<<<<<<<<<<<<<
@@ -16815,88 +17553,88 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
   }
   __pyx_L18:;
 
-  /* "pysam/csamtools.pyx":1506
+  /* "pysam/csamtools.pyx":1509
  *         text = "\n".join(lines) + "\n"
  *         if dest.text != NULL: free( dest.text )
  *         dest.text = <char*>calloc( len(text), sizeof(char))             # <<<<<<<<<<<<<<
  *         dest.l_text = len(text)
  *         cdef bytes btext = text.encode('ascii')
  */
-  __pyx_t_3 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_dest->text = ((char *)calloc(__pyx_t_3, (sizeof(char))));
 
-  /* "pysam/csamtools.pyx":1507
+  /* "pysam/csamtools.pyx":1510
  *         if dest.text != NULL: free( dest.text )
  *         dest.text = <char*>calloc( len(text), sizeof(char))
  *         dest.l_text = len(text)             # <<<<<<<<<<<<<<
  *         cdef bytes btext = text.encode('ascii')
  *         strncpy( dest.text, btext, dest.l_text )
  */
-  __pyx_t_3 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_dest->l_text = __pyx_t_3;
 
-  /* "pysam/csamtools.pyx":1508
+  /* "pysam/csamtools.pyx":1511
  *         dest.text = <char*>calloc( len(text), sizeof(char))
  *         dest.l_text = len(text)
  *         cdef bytes btext = text.encode('ascii')             # <<<<<<<<<<<<<<
  *         strncpy( dest.text, btext, dest.l_text )
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(__pyx_v_text, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_v_text, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_124), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_123), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_7);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  if (!(likely(PyBytes_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_7)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyBytes_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_7)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_btext = ((PyObject*)__pyx_t_7);
   __pyx_t_7 = 0;
 
-  /* "pysam/csamtools.pyx":1509
+  /* "pysam/csamtools.pyx":1512
  *         dest.l_text = len(text)
  *         cdef bytes btext = text.encode('ascii')
  *         strncpy( dest.text, btext, dest.l_text )             # <<<<<<<<<<<<<<
  * 
  *         cdef bytes bseqname
  */
-  __pyx_t_13 = PyBytes_AsString(((PyObject *)__pyx_v_btext)); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_13 = PyBytes_AsString(((PyObject *)__pyx_v_btext)); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   strncpy(__pyx_v_dest->text, __pyx_t_13, __pyx_v_dest->l_text);
 
-  /* "pysam/csamtools.pyx":1513
+  /* "pysam/csamtools.pyx":1516
  *         cdef bytes bseqname
  *         # collect targets
  *         if "SQ" in new_header:             # <<<<<<<<<<<<<<
  *             seqs = []
  *             for fields in new_header["SQ"]:
  */
-  __pyx_t_5 = (__Pyx_PySequence_Contains(((PyObject *)__pyx_n_s__SQ), __pyx_v_new_header, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = (__Pyx_PySequence_Contains(((PyObject *)__pyx_n_s__SQ), __pyx_v_new_header, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_5) {
 
-    /* "pysam/csamtools.pyx":1514
+    /* "pysam/csamtools.pyx":1517
  *         # collect targets
  *         if "SQ" in new_header:
  *             seqs = []             # <<<<<<<<<<<<<<
  *             for fields in new_header["SQ"]:
  *                 try:
  */
-    __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
     __pyx_v_seqs = ((PyObject*)__pyx_t_7);
     __pyx_t_7 = 0;
 
-    /* "pysam/csamtools.pyx":1515
+    /* "pysam/csamtools.pyx":1518
  *         if "SQ" in new_header:
  *             seqs = []
  *             for fields in new_header["SQ"]:             # <<<<<<<<<<<<<<
  *                 try:
  *                     seqs.append( (fields["SN"], fields["LN"] ) )
  */
-    __pyx_t_7 = PyObject_GetItem(__pyx_v_new_header, ((PyObject *)__pyx_n_s__SQ)); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyObject_GetItem(__pyx_v_new_header, ((PyObject *)__pyx_n_s__SQ)); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
     if (PyList_CheckExact(__pyx_t_7) || PyTuple_CheckExact(__pyx_t_7)) {
       __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
       __pyx_t_4 = NULL;
     } else {
-      __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext;
     }
@@ -16905,23 +17643,23 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
       if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_1)) {
         if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_1)) {
         if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else {
         __pyx_t_7 = __pyx_t_4(__pyx_t_1);
         if (unlikely(!__pyx_t_7)) {
           if (PyErr_Occurred()) {
             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           }
           break;
         }
@@ -16931,7 +17669,7 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
       __pyx_v_fields = __pyx_t_7;
       __pyx_t_7 = 0;
 
-      /* "pysam/csamtools.pyx":1516
+      /* "pysam/csamtools.pyx":1519
  *             seqs = []
  *             for fields in new_header["SQ"]:
  *                 try:             # <<<<<<<<<<<<<<
@@ -16945,18 +17683,18 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
         __Pyx_XGOTREF(__pyx_t_16);
         /*try:*/ {
 
-          /* "pysam/csamtools.pyx":1517
+          /* "pysam/csamtools.pyx":1520
  *             for fields in new_header["SQ"]:
  *                 try:
  *                     seqs.append( (fields["SN"], fields["LN"] ) )             # <<<<<<<<<<<<<<
  *                 except KeyError:
  *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
  */
-          __pyx_t_7 = PyObject_GetItem(__pyx_v_fields, ((PyObject *)__pyx_n_s__SN)); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1517; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
+          __pyx_t_7 = PyObject_GetItem(__pyx_v_fields, ((PyObject *)__pyx_n_s__SN)); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1520; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
           __Pyx_GOTREF(__pyx_t_7);
-          __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, ((PyObject *)__pyx_n_s__LN)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1517; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
+          __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, ((PyObject *)__pyx_n_s__LN)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1520; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
           __Pyx_GOTREF(__pyx_t_2);
-          __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1517; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
+          __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1520; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
           __Pyx_GOTREF(__pyx_t_6);
           PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
           __Pyx_GIVEREF(__pyx_t_7);
@@ -16964,7 +17702,7 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
           __Pyx_GIVEREF(__pyx_t_2);
           __pyx_t_7 = 0;
           __pyx_t_2 = 0;
-          __pyx_t_8 = PyList_Append(__pyx_v_seqs, ((PyObject *)__pyx_t_6)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1517; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
+          __pyx_t_8 = PyList_Append(__pyx_v_seqs, ((PyObject *)__pyx_t_6)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1520; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
         }
         __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
@@ -16977,7 +17715,7 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
         __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
         __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
 
-        /* "pysam/csamtools.pyx":1518
+        /* "pysam/csamtools.pyx":1521
  *                 try:
  *                     seqs.append( (fields["SN"], fields["LN"] ) )
  *                 except KeyError:             # <<<<<<<<<<<<<<
@@ -16987,40 +17725,40 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
         __pyx_t_17 = PyErr_ExceptionMatches(__pyx_builtin_KeyError);
         if (__pyx_t_17) {
           __Pyx_AddTraceback("pysam.csamtools.Samfile._buildHeader", __pyx_clineno, __pyx_lineno, __pyx_filename);
-          if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_2, &__pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
+          if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_2, &__pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1521; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
           __Pyx_GOTREF(__pyx_t_6);
           __Pyx_GOTREF(__pyx_t_2);
           __Pyx_GOTREF(__pyx_t_7);
 
-          /* "pysam/csamtools.pyx":1519
+          /* "pysam/csamtools.pyx":1522
  *                     seqs.append( (fields["SN"], fields["LN"] ) )
  *                 except KeyError:
  *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))             # <<<<<<<<<<<<<<
  * 
  *             dest.n_targets = len(seqs)
  */
-          __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1519; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
+          __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1522; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
           __Pyx_GOTREF(__pyx_t_11);
           __Pyx_INCREF(__pyx_v_fields);
           PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_fields);
           __Pyx_GIVEREF(__pyx_v_fields);
-          __pyx_t_18 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1519; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
+          __pyx_t_18 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1522; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
           __Pyx_GOTREF(__pyx_t_18);
           __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
-          __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_125), __pyx_t_18); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1519; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
+          __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_124), __pyx_t_18); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1522; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
           __Pyx_GOTREF(((PyObject *)__pyx_t_11));
           __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
-          __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1519; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
+          __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1522; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
           __Pyx_GOTREF(__pyx_t_18);
           PyTuple_SET_ITEM(__pyx_t_18, 0, ((PyObject *)__pyx_t_11));
           __Pyx_GIVEREF(((PyObject *)__pyx_t_11));
           __pyx_t_11 = 0;
-          __pyx_t_11 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_18), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1519; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
+          __pyx_t_11 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_18), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1522; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
           __Pyx_GOTREF(__pyx_t_11);
           __Pyx_DECREF(((PyObject *)__pyx_t_18)); __pyx_t_18 = 0;
           __Pyx_Raise(__pyx_t_11, 0, 0, 0);
           __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1519; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1522; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
           __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
@@ -17042,17 +17780,17 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
     }
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":1521
+    /* "pysam/csamtools.pyx":1524
  *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
  * 
  *             dest.n_targets = len(seqs)             # <<<<<<<<<<<<<<
  *             dest.target_name = <char**>calloc( dest.n_targets, sizeof(char*) )
  *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )
  */
-    __pyx_t_3 = PyList_GET_SIZE(((PyObject *)__pyx_v_seqs)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyList_GET_SIZE(((PyObject *)__pyx_v_seqs)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_v_dest->n_targets = __pyx_t_3;
 
-    /* "pysam/csamtools.pyx":1522
+    /* "pysam/csamtools.pyx":1525
  * 
  *             dest.n_targets = len(seqs)
  *             dest.target_name = <char**>calloc( dest.n_targets, sizeof(char*) )             # <<<<<<<<<<<<<<
@@ -17061,7 +17799,7 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
  */
     __pyx_v_dest->target_name = ((char **)calloc(__pyx_v_dest->n_targets, (sizeof(char *))));
 
-    /* "pysam/csamtools.pyx":1523
+    /* "pysam/csamtools.pyx":1526
  *             dest.n_targets = len(seqs)
  *             dest.target_name = <char**>calloc( dest.n_targets, sizeof(char*) )
  *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )             # <<<<<<<<<<<<<<
@@ -17070,7 +17808,7 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
  */
     __pyx_v_dest->target_len = ((uint32_t *)calloc(__pyx_v_dest->n_targets, (sizeof(uint32_t))));
 
-    /* "pysam/csamtools.pyx":1525
+    /* "pysam/csamtools.pyx":1528
  *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )
  * 
  *             for x from 0 <= x < dest.n_targets:             # <<<<<<<<<<<<<<
@@ -17080,14 +17818,14 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
     __pyx_t_19 = __pyx_v_dest->n_targets;
     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_19; __pyx_v_x++) {
 
-      /* "pysam/csamtools.pyx":1526
+      /* "pysam/csamtools.pyx":1529
  * 
  *             for x from 0 <= x < dest.n_targets:
  *                 seqname, seqlen = seqs[x]             # <<<<<<<<<<<<<<
  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
  *                 bseqname = seqname.encode('ascii')
  */
-      __pyx_t_1 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_seqs), __pyx_v_x, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_seqs), __pyx_v_x, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
         PyObject* sequence = __pyx_t_1;
@@ -17099,7 +17837,7 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
         if (unlikely(size != 2)) {
           if (size > 2) __Pyx_RaiseTooManyValuesError(2);
           else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         #if CYTHON_COMPILING_IN_CPYTHON
         if (likely(PyTuple_CheckExact(sequence))) {
@@ -17112,16 +17850,16 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
         __Pyx_INCREF(__pyx_t_7);
         __Pyx_INCREF(__pyx_t_2);
         #else
-        __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
-        __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
         #endif
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       } else
       {
         Py_ssize_t index = -1;
-        __pyx_t_6 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_6 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
         __pyx_t_12 = Py_TYPE(__pyx_t_6)->tp_iternext;
@@ -17129,7 +17867,7 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
         __Pyx_GOTREF(__pyx_t_7);
         index = 1; __pyx_t_2 = __pyx_t_12(__pyx_t_6); if (unlikely(!__pyx_t_2)) goto __pyx_L34_unpacking_failed;
         __Pyx_GOTREF(__pyx_t_2);
-        if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __pyx_t_12 = NULL;
         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
         goto __pyx_L35_unpacking_done;
@@ -17137,7 +17875,7 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
         __pyx_t_12 = NULL;
         if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __pyx_L35_unpacking_done:;
       }
       __Pyx_XDECREF(__pyx_v_seqname);
@@ -17147,59 +17885,59 @@ static bam_header_t *__pyx_f_5pysam_9csamtools_7Samfile__buildHeader(struct __py
       __pyx_v_seqlen = __pyx_t_2;
       __pyx_t_2 = 0;
 
-      /* "pysam/csamtools.pyx":1527
+      /* "pysam/csamtools.pyx":1530
  *             for x from 0 <= x < dest.n_targets:
  *                 seqname, seqlen = seqs[x]
  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )             # <<<<<<<<<<<<<<
  *                 bseqname = seqname.encode('ascii')
  *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )
  */
-      __pyx_t_3 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       (__pyx_v_dest->target_name[__pyx_v_x]) = ((char *)calloc((__pyx_t_3 + 1), (sizeof(char))));
 
-      /* "pysam/csamtools.pyx":1528
+      /* "pysam/csamtools.pyx":1531
  *                 seqname, seqlen = seqs[x]
  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
  *                 bseqname = seqname.encode('ascii')             # <<<<<<<<<<<<<<
  *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )
  *                 dest.target_len[x] = seqlen
  */
-      __pyx_t_1 = PyObject_GetAttr(__pyx_v_seqname, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_GetAttr(__pyx_v_seqname, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_126), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_125), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-      if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_XDECREF(((PyObject *)__pyx_v_bseqname));
       __pyx_v_bseqname = ((PyObject*)__pyx_t_2);
       __pyx_t_2 = 0;
 
-      /* "pysam/csamtools.pyx":1529
+      /* "pysam/csamtools.pyx":1532
  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
  *                 bseqname = seqname.encode('ascii')
  *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )             # <<<<<<<<<<<<<<
  *                 dest.target_len[x] = seqlen
  * 
  */
-      __pyx_t_13 = PyBytes_AsString(((PyObject *)__pyx_v_bseqname)); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_3 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_13 = PyBytes_AsString(((PyObject *)__pyx_v_bseqname)); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       strncpy((__pyx_v_dest->target_name[__pyx_v_x]), __pyx_t_13, (__pyx_t_3 + 1));
 
-      /* "pysam/csamtools.pyx":1530
+      /* "pysam/csamtools.pyx":1533
  *                 bseqname = seqname.encode('ascii')
  *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )
  *                 dest.target_len[x] = seqlen             # <<<<<<<<<<<<<<
  * 
  *         return dest
  */
-      __pyx_t_20 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_seqlen); if (unlikely((__pyx_t_20 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_20 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_seqlen); if (unlikely((__pyx_t_20 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       (__pyx_v_dest->target_len[__pyx_v_x]) = __pyx_t_20;
     }
     goto __pyx_L19;
   }
   __pyx_L19:;
 
-  /* "pysam/csamtools.pyx":1532
+  /* "pysam/csamtools.pyx":1535
  *                 dest.target_len[x] = seqlen
  * 
  *         return dest             # <<<<<<<<<<<<<<
@@ -17248,7 +17986,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_41__iter__(PyObject *__pyx_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1542
+/* "pysam/csamtools.pyx":1545
  *     ## Possible solutions: deprecate or open new file handle
  *     ###############################################################
  *     def __iter__(self):             # <<<<<<<<<<<<<<
@@ -17269,34 +18007,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_40__iter__(struct __pyx_obj
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__iter__", 0);
-  __Pyx_TraceCall("__iter__", __pyx_f[0], 1542);
+  __Pyx_TraceCall("__iter__", __pyx_f[0], 1545);
 
-  /* "pysam/csamtools.pyx":1543
+  /* "pysam/csamtools.pyx":1546
  *     ###############################################################
  *     def __iter__(self):
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         if not self.isbam and self.samfile.header.n_targets == 0:
  *                 raise NotImplementedError( "can not iterate over samfile without header")
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_127), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_126), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __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 = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1544
+  /* "pysam/csamtools.pyx":1547
  *     def __iter__(self):
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *         if not self.isbam and self.samfile.header.n_targets == 0:             # <<<<<<<<<<<<<<
@@ -17312,23 +18050,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_40__iter__(struct __pyx_obj
   }
   if (__pyx_t_5) {
 
-    /* "pysam/csamtools.pyx":1545
+    /* "pysam/csamtools.pyx":1548
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *         if not self.isbam and self.samfile.header.n_targets == 0:
  *                 raise NotImplementedError( "can not iterate over samfile without header")             # <<<<<<<<<<<<<<
  *         return self
  * 
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_129), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_128), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1548; __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 = 1545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":1546
+  /* "pysam/csamtools.pyx":1549
  *         if not self.isbam and self.samfile.header.n_targets == 0:
  *                 raise NotImplementedError( "can not iterate over samfile without header")
  *         return self             # <<<<<<<<<<<<<<
@@ -17354,7 +18092,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_40__iter__(struct __pyx_obj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1548
+/* "pysam/csamtools.pyx":1551
  *         return self
  * 
  *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
@@ -17367,9 +18105,9 @@ static bam1_t *__pyx_f_5pysam_9csamtools_7Samfile_getCurrent(struct __pyx_obj_5p
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("getCurrent", 0);
-  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1548);
+  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1551);
 
-  /* "pysam/csamtools.pyx":1549
+  /* "pysam/csamtools.pyx":1552
  * 
  *     cdef bam1_t * getCurrent( self ):
  *         return self.b             # <<<<<<<<<<<<<<
@@ -17386,7 +18124,7 @@ static bam1_t *__pyx_f_5pysam_9csamtools_7Samfile_getCurrent(struct __pyx_obj_5p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1551
+/* "pysam/csamtools.pyx":1554
  *         return self.b
  * 
  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
@@ -17399,9 +18137,9 @@ static int __pyx_f_5pysam_9csamtools_7Samfile_cnext(struct __pyx_obj_5pysam_9csa
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("cnext", 0);
-  __Pyx_TraceCall("cnext", __pyx_f[0], 1551);
+  __Pyx_TraceCall("cnext", __pyx_f[0], 1554);
 
-  /* "pysam/csamtools.pyx":1556
+  /* "pysam/csamtools.pyx":1559
  *         '''
  *         cdef int ret
  *         return samread(self.samfile, self.b)             # <<<<<<<<<<<<<<
@@ -17433,7 +18171,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7Samfile_43__next__(PyObject *__pyx_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1558
+/* "pysam/csamtools.pyx":1561
  *         return samread(self.samfile, self.b)
  * 
  *     def __next__(self):             # <<<<<<<<<<<<<<
@@ -17452,9 +18190,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_42__next__(struct __pyx_obj
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__next__", 0);
-  __Pyx_TraceCall("__next__", __pyx_f[0], 1558);
+  __Pyx_TraceCall("__next__", __pyx_f[0], 1561);
 
-  /* "pysam/csamtools.pyx":1563
+  /* "pysam/csamtools.pyx":1566
  *         """
  *         cdef int ret
  *         ret = samread(self.samfile, self.b)             # <<<<<<<<<<<<<<
@@ -17463,7 +18201,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_42__next__(struct __pyx_obj
  */
   __pyx_v_ret = samread(__pyx_v_self->samfile, __pyx_v_self->b);
 
-  /* "pysam/csamtools.pyx":1564
+  /* "pysam/csamtools.pyx":1567
  *         cdef int ret
  *         ret = samread(self.samfile, self.b)
  *         if (ret > 0):             # <<<<<<<<<<<<<<
@@ -17473,7 +18211,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_42__next__(struct __pyx_obj
   __pyx_t_1 = (__pyx_v_ret > 0);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":1565
+    /* "pysam/csamtools.pyx":1568
  *         ret = samread(self.samfile, self.b)
  *         if (ret > 0):
  *             return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
@@ -17481,7 +18219,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_42__next__(struct __pyx_obj
  *             raise StopIteration
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __pyx_r = __pyx_t_2;
     __pyx_t_2 = 0;
@@ -17490,7 +18228,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_42__next__(struct __pyx_obj
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1567
+    /* "pysam/csamtools.pyx":1570
  *             return makeAlignedRead( self.b )
  *         else:
  *             raise StopIteration             # <<<<<<<<<<<<<<
@@ -17498,7 +18236,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7Samfile_42__next__(struct __pyx_obj
  * ##-------------------------------------------------------------------
  */
     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L3:;
 
@@ -17549,17 +18287,17 @@ static int __pyx_pw_5pysam_9csamtools_17IteratorRowRegion_1__cinit__(PyObject *_
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tid)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  2:
         if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__beg)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  3:
         if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  4:
         if (kw_args > 0) {
@@ -17568,7 +18306,7 @@ static int __pyx_pw_5pysam_9csamtools_17IteratorRowRegion_1__cinit__(PyObject *_
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -17582,14 +18320,14 @@ static int __pyx_pw_5pysam_9csamtools_17IteratorRowRegion_1__cinit__(PyObject *_
       }
     }
     __pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)values[0]);
-    __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    __pyx_v_beg = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_beg = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     if (values[4]) {
-      __pyx_v_reopen = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_reopen = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
 
-      /* "pysam/csamtools.pyx":1622
+      /* "pysam/csamtools.pyx":1625
  *     """
  * 
  *     def __cinit__(self, Samfile samfile, int tid, int beg, int end, int reopen = True ):             # <<<<<<<<<<<<<<
@@ -17601,13 +18339,13 @@ static int __pyx_pw_5pysam_9csamtools_17IteratorRowRegion_1__cinit__(PyObject *_
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.IteratorRowRegion.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_17IteratorRowRegion___cinit__(((struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_beg, __pyx_v_end, __pyx_v_reopen);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -17626,82 +18364,83 @@ static int __pyx_pf_5pysam_9csamtools_17IteratorRowRegion___cinit__(struct __pyx
   PyObject *__pyx_t_2 = NULL;
   int __pyx_t_3;
   int __pyx_t_4;
-  char *__pyx_t_5;
-  samfile_t *__pyx_t_6;
+  const char* __pyx_t_5;
+  char *__pyx_t_6;
+  samfile_t *__pyx_t_7;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__cinit__", 0);
-  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1622);
+  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1625);
 
-  /* "pysam/csamtools.pyx":1624
+  /* "pysam/csamtools.pyx":1627
  *     def __cinit__(self, Samfile samfile, int tid, int beg, int end, int reopen = True ):
  * 
  *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
  *             raise ValueError( "I/O operation on closed file" )
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":1625
+    /* "pysam/csamtools.pyx":1628
  * 
  *         if not samfile._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         if not samfile._hasIndex():
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_130), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_129), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1628; __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 = 1625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1627
+  /* "pysam/csamtools.pyx":1630
  *             raise ValueError( "I/O operation on closed file" )
  * 
  *         if not samfile._hasIndex():             # <<<<<<<<<<<<<<
  *             raise ValueError( "no index available for iteration" )
  * 
  */
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __pyx_t_3 = (!__pyx_t_4);
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":1628
+    /* "pysam/csamtools.pyx":1631
  * 
  *         if not samfile._hasIndex():
  *             raise ValueError( "no index available for iteration" )             # <<<<<<<<<<<<<<
  * 
  *         # makes sure that samfile stays alive as long as the
  */
-    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_132), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_131), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":1632
+  /* "pysam/csamtools.pyx":1635
  *         # makes sure that samfile stays alive as long as the
  *         # iterator is alive
  *         self.samfile = samfile             # <<<<<<<<<<<<<<
@@ -17714,7 +18453,7 @@ static int __pyx_pf_5pysam_9csamtools_17IteratorRowRegion___cinit__(struct __pyx
   __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
   __pyx_v_self->samfile = __pyx_v_samfile;
 
-  /* "pysam/csamtools.pyx":1634
+  /* "pysam/csamtools.pyx":1637
  *         self.samfile = samfile
  * 
  *         if samfile.isbam: mode = b"rb"             # <<<<<<<<<<<<<<
@@ -17728,7 +18467,7 @@ static int __pyx_pf_5pysam_9csamtools_17IteratorRowRegion___cinit__(struct __pyx
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1635
+    /* "pysam/csamtools.pyx":1638
  * 
  *         if samfile.isbam: mode = b"rb"
  *         else: mode = b"r"             # <<<<<<<<<<<<<<
@@ -17740,7 +18479,7 @@ static int __pyx_pf_5pysam_9csamtools_17IteratorRowRegion___cinit__(struct __pyx
   }
   __pyx_L5:;
 
-  /* "pysam/csamtools.pyx":1639
+  /* "pysam/csamtools.pyx":1642
  *         # reopen the file - note that this makes the iterator
  *         # slow and causes pileup to slow down significantly.
  *         if reopen:             # <<<<<<<<<<<<<<
@@ -17749,46 +18488,47 @@ static int __pyx_pf_5pysam_9csamtools_17IteratorRowRegion___cinit__(struct __pyx
  */
   if (__pyx_v_reopen) {
 
-    /* "pysam/csamtools.pyx":1640
+    /* "pysam/csamtools.pyx":1643
  *         # slow and causes pileup to slow down significantly.
  *         if reopen:
  *             store = StderrStore()             # <<<<<<<<<<<<<<
  *             self.fp = samopen( samfile._filename, mode, NULL )
  *             store.release()
  */
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __pyx_v_store = __pyx_t_2;
     __pyx_t_2 = 0;
 
-    /* "pysam/csamtools.pyx":1641
+    /* "pysam/csamtools.pyx":1644
  *         if reopen:
  *             store = StderrStore()
  *             self.fp = samopen( samfile._filename, mode, NULL )             # <<<<<<<<<<<<<<
  *             store.release()
  *             assert self.fp != NULL
  */
-    __pyx_t_5 = PyBytes_AsString(((PyObject *)__pyx_v_mode)); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_v_self->fp = samopen(__pyx_v_samfile->_filename, __pyx_t_5, NULL);
+    __pyx_t_5 = PyBytes_AsString(__pyx_v_samfile->_filename); if (unlikely((__pyx_t_5 == (const char*)NULL) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyBytes_AsString(((PyObject *)__pyx_v_mode)); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_v_self->fp = samopen(__pyx_t_5, __pyx_t_6, NULL);
 
-    /* "pysam/csamtools.pyx":1642
+    /* "pysam/csamtools.pyx":1645
  *             store = StderrStore()
  *             self.fp = samopen( samfile._filename, mode, NULL )
  *             store.release()             # <<<<<<<<<<<<<<
  *             assert self.fp != NULL
  *             self.owns_samfile = True
  */
-    __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":1643
+    /* "pysam/csamtools.pyx":1646
  *             self.fp = samopen( samfile._filename, mode, NULL )
  *             store.release()
  *             assert self.fp != NULL             # <<<<<<<<<<<<<<
@@ -17798,11 +18538,11 @@ static int __pyx_pf_5pysam_9csamtools_17IteratorRowRegion___cinit__(struct __pyx
     #ifndef CYTHON_WITHOUT_ASSERTIONS
     if (unlikely(!(__pyx_v_self->fp != NULL))) {
       PyErr_SetNone(PyExc_AssertionError);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     #endif
 
-    /* "pysam/csamtools.pyx":1644
+    /* "pysam/csamtools.pyx":1647
  *             store.release()
  *             assert self.fp != NULL
  *             self.owns_samfile = True             # <<<<<<<<<<<<<<
@@ -17814,17 +18554,17 @@ static int __pyx_pf_5pysam_9csamtools_17IteratorRowRegion___cinit__(struct __pyx
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1646
+    /* "pysam/csamtools.pyx":1649
  *             self.owns_samfile = True
  *         else:
  *             self.fp = self.samfile.samfile             # <<<<<<<<<<<<<<
  *             self.owns_samfile = False
  * 
  */
-    __pyx_t_6 = __pyx_v_self->samfile->samfile;
-    __pyx_v_self->fp = __pyx_t_6;
+    __pyx_t_7 = __pyx_v_self->samfile->samfile;
+    __pyx_v_self->fp = __pyx_t_7;
 
-    /* "pysam/csamtools.pyx":1647
+    /* "pysam/csamtools.pyx":1650
  *         else:
  *             self.fp = self.samfile.samfile
  *             self.owns_samfile = False             # <<<<<<<<<<<<<<
@@ -17835,7 +18575,7 @@ static int __pyx_pf_5pysam_9csamtools_17IteratorRowRegion___cinit__(struct __pyx
   }
   __pyx_L6:;
 
-  /* "pysam/csamtools.pyx":1649
+  /* "pysam/csamtools.pyx":1652
  *             self.owns_samfile = False
  * 
  *         self.retval = 0             # <<<<<<<<<<<<<<
@@ -17844,7 +18584,7 @@ static int __pyx_pf_5pysam_9csamtools_17IteratorRowRegion___cinit__(struct __pyx
  */
   __pyx_v_self->retval = 0;
 
-  /* "pysam/csamtools.pyx":1651
+  /* "pysam/csamtools.pyx":1654
  *         self.retval = 0
  * 
  *         self.iter = bam_iter_query(self.samfile.index,             # <<<<<<<<<<<<<<
@@ -17853,7 +18593,7 @@ static int __pyx_pf_5pysam_9csamtools_17IteratorRowRegion___cinit__(struct __pyx
  */
   __pyx_v_self->iter = bam_iter_query(__pyx_v_self->samfile->index, __pyx_v_tid, __pyx_v_beg, __pyx_v_end);
 
-  /* "pysam/csamtools.pyx":1655
+  /* "pysam/csamtools.pyx":1658
  *                                    beg,
  *                                    end)
  *         self.b = bam_init1()             # <<<<<<<<<<<<<<
@@ -17888,7 +18628,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_17IteratorRowRegion_3__iter__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1657
+/* "pysam/csamtools.pyx":1660
  *         self.b = bam_init1()
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
@@ -17901,9 +18641,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_17IteratorRowRegion_2__iter__(struct
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__iter__", 0);
-  __Pyx_TraceCall("__iter__", __pyx_f[0], 1657);
+  __Pyx_TraceCall("__iter__", __pyx_f[0], 1660);
 
-  /* "pysam/csamtools.pyx":1658
+  /* "pysam/csamtools.pyx":1661
  * 
  *     def __iter__(self):
  *         return self             # <<<<<<<<<<<<<<
@@ -17923,7 +18663,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_17IteratorRowRegion_2__iter__(struct
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1660
+/* "pysam/csamtools.pyx":1663
  *         return self
  * 
  *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
@@ -17936,9 +18676,9 @@ static bam1_t *__pyx_f_5pysam_9csamtools_17IteratorRowRegion_getCurrent(struct _
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("getCurrent", 0);
-  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1660);
+  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1663);
 
-  /* "pysam/csamtools.pyx":1661
+  /* "pysam/csamtools.pyx":1664
  * 
  *     cdef bam1_t * getCurrent( self ):
  *         return self.b             # <<<<<<<<<<<<<<
@@ -17955,7 +18695,7 @@ static bam1_t *__pyx_f_5pysam_9csamtools_17IteratorRowRegion_getCurrent(struct _
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1663
+/* "pysam/csamtools.pyx":1666
  *         return self.b
  * 
  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
@@ -17968,9 +18708,9 @@ static int __pyx_f_5pysam_9csamtools_17IteratorRowRegion_cnext(struct __pyx_obj_
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("cnext", 0);
-  __Pyx_TraceCall("cnext", __pyx_f[0], 1663);
+  __Pyx_TraceCall("cnext", __pyx_f[0], 1666);
 
-  /* "pysam/csamtools.pyx":1665
+  /* "pysam/csamtools.pyx":1668
  *     cdef int cnext(self):
  *         '''cversion of iterator. Used by IteratorColumn'''
  *         self.retval = bam_iter_read( self.fp.x.bam,             # <<<<<<<<<<<<<<
@@ -18000,7 +18740,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_17IteratorRowRegion_5__next__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1669
+/* "pysam/csamtools.pyx":1672
  *                                      self.b)
  * 
  *     def __next__(self):             # <<<<<<<<<<<<<<
@@ -18018,9 +18758,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_17IteratorRowRegion_4__next__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__next__", 0);
-  __Pyx_TraceCall("__next__", __pyx_f[0], 1669);
+  __Pyx_TraceCall("__next__", __pyx_f[0], 1672);
 
-  /* "pysam/csamtools.pyx":1672
+  /* "pysam/csamtools.pyx":1675
  *         """python version of next().
  *         """
  *         self.cnext()             # <<<<<<<<<<<<<<
@@ -18029,7 +18769,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_17IteratorRowRegion_4__next__(struct
  */
   ((struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowRegion *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);
 
-  /* "pysam/csamtools.pyx":1673
+  /* "pysam/csamtools.pyx":1676
  *         """
  *         self.cnext()
  *         if self.retval < 0: raise StopIteration             # <<<<<<<<<<<<<<
@@ -18039,12 +18779,12 @@ static PyObject *__pyx_pf_5pysam_9csamtools_17IteratorRowRegion_4__next__(struct
   __pyx_t_1 = (__pyx_v_self->retval < 0);
   if (__pyx_t_1) {
     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1674
+  /* "pysam/csamtools.pyx":1677
  *         self.cnext()
  *         if self.retval < 0: raise StopIteration
  *         return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
@@ -18052,7 +18792,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_17IteratorRowRegion_4__next__(struct
  *     def __dealloc__(self):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
@@ -18080,7 +18820,7 @@ static void __pyx_pw_5pysam_9csamtools_17IteratorRowRegion_7__dealloc__(PyObject
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/csamtools.pyx":1676
+/* "pysam/csamtools.pyx":1679
  *         return makeAlignedRead( self.b )
  * 
  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
@@ -18092,9 +18832,9 @@ static void __pyx_pf_5pysam_9csamtools_17IteratorRowRegion_6__dealloc__(struct _
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__dealloc__", 0);
-  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1676);
+  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1679);
 
-  /* "pysam/csamtools.pyx":1677
+  /* "pysam/csamtools.pyx":1680
  * 
  *     def __dealloc__(self):
  *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
@@ -18103,7 +18843,7 @@ static void __pyx_pf_5pysam_9csamtools_17IteratorRowRegion_6__dealloc__(struct _
  */
   bam_destroy1(__pyx_v_self->b);
 
-  /* "pysam/csamtools.pyx":1678
+  /* "pysam/csamtools.pyx":1681
  *     def __dealloc__(self):
  *         bam_destroy1(self.b)
  *         bam_iter_destroy( self.iter )             # <<<<<<<<<<<<<<
@@ -18112,7 +18852,7 @@ static void __pyx_pf_5pysam_9csamtools_17IteratorRowRegion_6__dealloc__(struct _
  */
   bam_iter_destroy(__pyx_v_self->iter);
 
-  /* "pysam/csamtools.pyx":1679
+  /* "pysam/csamtools.pyx":1682
  *         bam_destroy1(self.b)
  *         bam_iter_destroy( self.iter )
  *         if self.owns_samfile: samclose( self.fp )             # <<<<<<<<<<<<<<
@@ -18161,7 +18901,7 @@ static int __pyx_pw_5pysam_9csamtools_14IteratorRowAll_1__cinit__(PyObject *__py
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -18173,10 +18913,10 @@ static int __pyx_pw_5pysam_9csamtools_14IteratorRowAll_1__cinit__(PyObject *__py
     }
     __pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)values[0]);
     if (values[1]) {
-      __pyx_v_reopen = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_reopen = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
 
-      /* "pysam/csamtools.pyx":1697
+      /* "pysam/csamtools.pyx":1700
  *     """
  * 
  *     def __cinit__(self, Samfile samfile, int reopen = True ):             # <<<<<<<<<<<<<<
@@ -18188,13 +18928,13 @@ static int __pyx_pw_5pysam_9csamtools_14IteratorRowAll_1__cinit__(PyObject *__py
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.IteratorRowAll.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_14IteratorRowAll___cinit__(((struct __pyx_obj_5pysam_9csamtools_IteratorRowAll *)__pyx_v_self), __pyx_v_samfile, __pyx_v_reopen);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -18213,49 +18953,50 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorRowAll___cinit__(struct __pyx_ob
   PyObject *__pyx_t_2 = NULL;
   int __pyx_t_3;
   int __pyx_t_4;
-  char *__pyx_t_5;
-  samfile_t *__pyx_t_6;
+  const char* __pyx_t_5;
+  char *__pyx_t_6;
+  samfile_t *__pyx_t_7;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__cinit__", 0);
-  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1697);
+  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1700);
 
-  /* "pysam/csamtools.pyx":1699
+  /* "pysam/csamtools.pyx":1702
  *     def __cinit__(self, Samfile samfile, int reopen = True ):
  * 
  *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
  *             raise ValueError( "I/O operation on closed file" )
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":1700
+    /* "pysam/csamtools.pyx":1703
  * 
  *         if not samfile._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         if samfile.isbam: mode = b"rb"
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_133), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_132), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __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 = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1702
+  /* "pysam/csamtools.pyx":1705
  *             raise ValueError( "I/O operation on closed file" )
  * 
  *         if samfile.isbam: mode = b"rb"             # <<<<<<<<<<<<<<
@@ -18269,7 +19010,7 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorRowAll___cinit__(struct __pyx_ob
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1703
+    /* "pysam/csamtools.pyx":1706
  * 
  *         if samfile.isbam: mode = b"rb"
  *         else: mode = b"r"             # <<<<<<<<<<<<<<
@@ -18281,7 +19022,7 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorRowAll___cinit__(struct __pyx_ob
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":1706
+  /* "pysam/csamtools.pyx":1709
  * 
  *         # reopen the file to avoid iterator conflict
  *         if reopen:             # <<<<<<<<<<<<<<
@@ -18290,46 +19031,47 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorRowAll___cinit__(struct __pyx_ob
  */
   if (__pyx_v_reopen) {
 
-    /* "pysam/csamtools.pyx":1707
+    /* "pysam/csamtools.pyx":1710
  *         # reopen the file to avoid iterator conflict
  *         if reopen:
  *             store = StderrStore()             # <<<<<<<<<<<<<<
  *             self.fp = samopen( samfile._filename, mode, NULL )
  *             store.release()
  */
-    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __pyx_v_store = __pyx_t_1;
     __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":1708
+    /* "pysam/csamtools.pyx":1711
  *         if reopen:
  *             store = StderrStore()
  *             self.fp = samopen( samfile._filename, mode, NULL )             # <<<<<<<<<<<<<<
  *             store.release()
  *             assert self.fp != NULL
  */
-    __pyx_t_5 = PyBytes_AsString(((PyObject *)__pyx_v_mode)); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_v_self->fp = samopen(__pyx_v_samfile->_filename, __pyx_t_5, NULL);
+    __pyx_t_5 = PyBytes_AsString(__pyx_v_samfile->_filename); if (unlikely((__pyx_t_5 == (const char*)NULL) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyBytes_AsString(((PyObject *)__pyx_v_mode)); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_v_self->fp = samopen(__pyx_t_5, __pyx_t_6, NULL);
 
-    /* "pysam/csamtools.pyx":1709
+    /* "pysam/csamtools.pyx":1712
  *             store = StderrStore()
  *             self.fp = samopen( samfile._filename, mode, NULL )
  *             store.release()             # <<<<<<<<<<<<<<
  *             assert self.fp != NULL
  *             self.owns_samfile = True
  */
-    __pyx_t_1 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-    /* "pysam/csamtools.pyx":1710
+    /* "pysam/csamtools.pyx":1713
  *             self.fp = samopen( samfile._filename, mode, NULL )
  *             store.release()
  *             assert self.fp != NULL             # <<<<<<<<<<<<<<
@@ -18339,11 +19081,11 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorRowAll___cinit__(struct __pyx_ob
     #ifndef CYTHON_WITHOUT_ASSERTIONS
     if (unlikely(!(__pyx_v_self->fp != NULL))) {
       PyErr_SetNone(PyExc_AssertionError);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     #endif
 
-    /* "pysam/csamtools.pyx":1711
+    /* "pysam/csamtools.pyx":1714
  *             store.release()
  *             assert self.fp != NULL
  *             self.owns_samfile = True             # <<<<<<<<<<<<<<
@@ -18355,17 +19097,17 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorRowAll___cinit__(struct __pyx_ob
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1713
+    /* "pysam/csamtools.pyx":1716
  *             self.owns_samfile = True
  *         else:
  *             self.fp = samfile.samfile             # <<<<<<<<<<<<<<
  *             self.owns_samfile = False
  * 
  */
-    __pyx_t_6 = __pyx_v_samfile->samfile;
-    __pyx_v_self->fp = __pyx_t_6;
+    __pyx_t_7 = __pyx_v_samfile->samfile;
+    __pyx_v_self->fp = __pyx_t_7;
 
-    /* "pysam/csamtools.pyx":1714
+    /* "pysam/csamtools.pyx":1717
  *         else:
  *             self.fp = samfile.samfile
  *             self.owns_samfile = False             # <<<<<<<<<<<<<<
@@ -18376,7 +19118,7 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorRowAll___cinit__(struct __pyx_ob
   }
   __pyx_L5:;
 
-  /* "pysam/csamtools.pyx":1717
+  /* "pysam/csamtools.pyx":1720
  * 
  *         # allocate memory for alignment
  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
@@ -18411,7 +19153,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_14IteratorRowAll_3__iter__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1719
+/* "pysam/csamtools.pyx":1722
  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
@@ -18424,9 +19166,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorRowAll_2__iter__(struct __
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__iter__", 0);
-  __Pyx_TraceCall("__iter__", __pyx_f[0], 1719);
+  __Pyx_TraceCall("__iter__", __pyx_f[0], 1722);
 
-  /* "pysam/csamtools.pyx":1720
+  /* "pysam/csamtools.pyx":1723
  * 
  *     def __iter__(self):
  *         return self             # <<<<<<<<<<<<<<
@@ -18446,7 +19188,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorRowAll_2__iter__(struct __
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1722
+/* "pysam/csamtools.pyx":1725
  *         return self
  * 
  *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
@@ -18459,9 +19201,9 @@ static bam1_t *__pyx_f_5pysam_9csamtools_14IteratorRowAll_getCurrent(struct __py
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("getCurrent", 0);
-  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1722);
+  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1725);
 
-  /* "pysam/csamtools.pyx":1723
+  /* "pysam/csamtools.pyx":1726
  * 
  *     cdef bam1_t * getCurrent( self ):
  *         return self.b             # <<<<<<<<<<<<<<
@@ -18478,7 +19220,7 @@ static bam1_t *__pyx_f_5pysam_9csamtools_14IteratorRowAll_getCurrent(struct __py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1725
+/* "pysam/csamtools.pyx":1728
  *         return self.b
  * 
  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
@@ -18491,9 +19233,9 @@ static int __pyx_f_5pysam_9csamtools_14IteratorRowAll_cnext(struct __pyx_obj_5py
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("cnext", 0);
-  __Pyx_TraceCall("cnext", __pyx_f[0], 1725);
+  __Pyx_TraceCall("cnext", __pyx_f[0], 1728);
 
-  /* "pysam/csamtools.pyx":1727
+  /* "pysam/csamtools.pyx":1730
  *     cdef int cnext(self):
  *         '''cversion of iterator. Used by IteratorColumn'''
  *         return samread(self.fp, self.b)             # <<<<<<<<<<<<<<
@@ -18525,7 +19267,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_14IteratorRowAll_5__next__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1729
+/* "pysam/csamtools.pyx":1732
  *         return samread(self.fp, self.b)
  * 
  *     def __next__(self):             # <<<<<<<<<<<<<<
@@ -18544,9 +19286,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorRowAll_4__next__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__next__", 0);
-  __Pyx_TraceCall("__next__", __pyx_f[0], 1729);
+  __Pyx_TraceCall("__next__", __pyx_f[0], 1732);
 
-  /* "pysam/csamtools.pyx":1735
+  /* "pysam/csamtools.pyx":1738
  *         """
  *         cdef int ret
  *         ret = samread(self.fp, self.b)             # <<<<<<<<<<<<<<
@@ -18555,7 +19297,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorRowAll_4__next__(struct __
  */
   __pyx_v_ret = samread(__pyx_v_self->fp, __pyx_v_self->b);
 
-  /* "pysam/csamtools.pyx":1736
+  /* "pysam/csamtools.pyx":1739
  *         cdef int ret
  *         ret = samread(self.fp, self.b)
  *         if (ret > 0):             # <<<<<<<<<<<<<<
@@ -18565,7 +19307,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorRowAll_4__next__(struct __
   __pyx_t_1 = (__pyx_v_ret > 0);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":1737
+    /* "pysam/csamtools.pyx":1740
  *         ret = samread(self.fp, self.b)
  *         if (ret > 0):
  *             return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
@@ -18573,7 +19315,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorRowAll_4__next__(struct __
  *             raise StopIteration
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __pyx_r = __pyx_t_2;
     __pyx_t_2 = 0;
@@ -18582,7 +19324,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorRowAll_4__next__(struct __
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1739
+    /* "pysam/csamtools.pyx":1742
  *             return makeAlignedRead( self.b )
  *         else:
  *             raise StopIteration             # <<<<<<<<<<<<<<
@@ -18590,7 +19332,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorRowAll_4__next__(struct __
  *     def __dealloc__(self):
  */
     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L3:;
 
@@ -18616,7 +19358,7 @@ static void __pyx_pw_5pysam_9csamtools_14IteratorRowAll_7__dealloc__(PyObject *_
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/csamtools.pyx":1741
+/* "pysam/csamtools.pyx":1744
  *             raise StopIteration
  * 
  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
@@ -18628,9 +19370,9 @@ static void __pyx_pf_5pysam_9csamtools_14IteratorRowAll_6__dealloc__(struct __py
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__dealloc__", 0);
-  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1741);
+  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1744);
 
-  /* "pysam/csamtools.pyx":1742
+  /* "pysam/csamtools.pyx":1745
  * 
  *     def __dealloc__(self):
  *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
@@ -18639,7 +19381,7 @@ static void __pyx_pf_5pysam_9csamtools_14IteratorRowAll_6__dealloc__(struct __py
  */
   bam_destroy1(__pyx_v_self->b);
 
-  /* "pysam/csamtools.pyx":1743
+  /* "pysam/csamtools.pyx":1746
  *     def __dealloc__(self):
  *         bam_destroy1(self.b)
  *         if self.owns_samfile: samclose( self.fp )             # <<<<<<<<<<<<<<
@@ -18681,7 +19423,7 @@ static int __pyx_pw_5pysam_9csamtools_18IteratorRowAllRefs_1__cinit__(PyObject *
         else goto __pyx_L5_argtuple_error;
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1753; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1756; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
       goto __pyx_L5_argtuple_error;
@@ -18692,13 +19434,13 @@ static int __pyx_pw_5pysam_9csamtools_18IteratorRowAllRefs_1__cinit__(PyObject *
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1753; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1756; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.IteratorRowAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs___cinit__(((struct __pyx_obj_5pysam_9csamtools_IteratorRowAllRefs *)__pyx_v_self), __pyx_v_samfile);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -18708,7 +19450,7 @@ static int __pyx_pw_5pysam_9csamtools_18IteratorRowAllRefs_1__cinit__(PyObject *
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1753
+/* "pysam/csamtools.pyx":1756
  *     """
  * 
  *     def __cinit__(self, Samfile samfile):             # <<<<<<<<<<<<<<
@@ -18728,9 +19470,9 @@ static int __pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs___cinit__(struct __py
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__cinit__", 0);
-  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1753);
+  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1756);
 
-  /* "pysam/csamtools.pyx":1754
+  /* "pysam/csamtools.pyx":1757
  * 
  *     def __cinit__(self, Samfile samfile):
  *         assert samfile._isOpen()             # <<<<<<<<<<<<<<
@@ -18738,45 +19480,45 @@ static int __pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs___cinit__(struct __py
  *         self.samfile = samfile
  */
   #ifndef CYTHON_WITHOUT_ASSERTIONS
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   if (unlikely(!__pyx_t_3)) {
     PyErr_SetNone(PyExc_AssertionError);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #endif
 
-  /* "pysam/csamtools.pyx":1755
+  /* "pysam/csamtools.pyx":1758
  *     def __cinit__(self, Samfile samfile):
  *         assert samfile._isOpen()
  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
  *         self.samfile = samfile
  *         self.tid = -1
  */
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_134), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_133), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1756
+  /* "pysam/csamtools.pyx":1759
  *         assert samfile._isOpen()
  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")
  *         self.samfile = samfile             # <<<<<<<<<<<<<<
@@ -18789,7 +19531,7 @@ static int __pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs___cinit__(struct __py
   __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
   __pyx_v_self->samfile = __pyx_v_samfile;
 
-  /* "pysam/csamtools.pyx":1757
+  /* "pysam/csamtools.pyx":1760
  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")
  *         self.samfile = samfile
  *         self.tid = -1             # <<<<<<<<<<<<<<
@@ -18823,7 +19565,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_18IteratorRowAllRefs_3nextiter(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1759
+/* "pysam/csamtools.pyx":1762
  *         self.tid = -1
  * 
  *     def nextiter(self):             # <<<<<<<<<<<<<<
@@ -18841,18 +19583,18 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_2nextiter(struc
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("nextiter", 0);
-  __Pyx_TraceCall("nextiter", __pyx_f[0], 1759);
+  __Pyx_TraceCall("nextiter", __pyx_f[0], 1762);
 
-  /* "pysam/csamtools.pyx":1760
+  /* "pysam/csamtools.pyx":1763
  * 
  *     def nextiter(self):
  *         self.rowiter = IteratorRowRegion(self.samfile, self.tid, 0, 1<<29)             # <<<<<<<<<<<<<<
  * 
  *     def __iter__(self):
  */
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
   PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self->samfile));
@@ -18866,7 +19608,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_2nextiter(struc
   PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_int_536870912);
   __Pyx_GIVEREF(__pyx_int_536870912);
   __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowRegion)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowRegion)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
   __Pyx_GIVEREF(__pyx_t_1);
@@ -18900,7 +19642,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_18IteratorRowAllRefs_5__iter__(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1762
+/* "pysam/csamtools.pyx":1765
  *         self.rowiter = IteratorRowRegion(self.samfile, self.tid, 0, 1<<29)
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
@@ -18913,9 +19655,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_4__iter__(struc
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__iter__", 0);
-  __Pyx_TraceCall("__iter__", __pyx_f[0], 1762);
+  __Pyx_TraceCall("__iter__", __pyx_f[0], 1765);
 
-  /* "pysam/csamtools.pyx":1763
+  /* "pysam/csamtools.pyx":1766
  * 
  *     def __iter__(self):
  *         return self             # <<<<<<<<<<<<<<
@@ -18950,7 +19692,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_18IteratorRowAllRefs_7__next__(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1765
+/* "pysam/csamtools.pyx":1768
  *         return self
  * 
  *     def __next__(self):             # <<<<<<<<<<<<<<
@@ -18971,9 +19713,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__next__", 0);
-  __Pyx_TraceCall("__next__", __pyx_f[0], 1765);
+  __Pyx_TraceCall("__next__", __pyx_f[0], 1768);
 
-  /* "pysam/csamtools.pyx":1771
+  /* "pysam/csamtools.pyx":1774
  *         """
  *         # Create an initial iterator
  *         if self.tid==-1:             # <<<<<<<<<<<<<<
@@ -18983,21 +19725,21 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
   __pyx_t_1 = (__pyx_v_self->tid == -1);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":1772
+    /* "pysam/csamtools.pyx":1775
  *         # Create an initial iterator
  *         if self.tid==-1:
  *             if not self.samfile.nreferences:             # <<<<<<<<<<<<<<
  *                 raise StopIteration
  *             self.tid = 0
  */
-    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self->samfile), __pyx_n_s__nreferences); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self->samfile), __pyx_n_s__nreferences); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __pyx_t_3 = (!__pyx_t_1);
     if (__pyx_t_3) {
 
-      /* "pysam/csamtools.pyx":1773
+      /* "pysam/csamtools.pyx":1776
  *         if self.tid==-1:
  *             if not self.samfile.nreferences:
  *                 raise StopIteration             # <<<<<<<<<<<<<<
@@ -19005,12 +19747,12 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
  *             self.nextiter()
  */
       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L4;
     }
     __pyx_L4:;
 
-    /* "pysam/csamtools.pyx":1774
+    /* "pysam/csamtools.pyx":1777
  *             if not self.samfile.nreferences:
  *                 raise StopIteration
  *             self.tid = 0             # <<<<<<<<<<<<<<
@@ -19019,16 +19761,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
  */
     __pyx_v_self->tid = 0;
 
-    /* "pysam/csamtools.pyx":1775
+    /* "pysam/csamtools.pyx":1778
  *                 raise StopIteration
  *             self.tid = 0
  *             self.nextiter()             # <<<<<<<<<<<<<<
  * 
  *         while 1:
  */
-    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__nextiter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__nextiter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
@@ -19036,7 +19778,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1777
+  /* "pysam/csamtools.pyx":1780
  *             self.nextiter()
  * 
  *         while 1:             # <<<<<<<<<<<<<<
@@ -19046,7 +19788,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
   while (1) {
     if (!1) break;
 
-    /* "pysam/csamtools.pyx":1778
+    /* "pysam/csamtools.pyx":1781
  * 
  *         while 1:
  *             self.rowiter.cnext()             # <<<<<<<<<<<<<<
@@ -19055,7 +19797,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
  */
     ((struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowRegion *)__pyx_v_self->rowiter->__pyx_vtab)->cnext(__pyx_v_self->rowiter);
 
-    /* "pysam/csamtools.pyx":1781
+    /* "pysam/csamtools.pyx":1784
  * 
  *             # If current iterator is not exhausted, return aligned read
  *             if self.rowiter.retval>0:             # <<<<<<<<<<<<<<
@@ -19065,7 +19807,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
     __pyx_t_3 = (__pyx_v_self->rowiter->retval > 0);
     if (__pyx_t_3) {
 
-      /* "pysam/csamtools.pyx":1782
+      /* "pysam/csamtools.pyx":1785
  *             # If current iterator is not exhausted, return aligned read
  *             if self.rowiter.retval>0:
  *                 return makeAlignedRead(self.rowiter.b)             # <<<<<<<<<<<<<<
@@ -19073,7 +19815,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
  *             self.tid += 1
  */
       __Pyx_XDECREF(__pyx_r);
-      __pyx_t_4 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_self->rowiter->b); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_self->rowiter->b); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_4);
       __pyx_r = __pyx_t_4;
       __pyx_t_4 = 0;
@@ -19082,7 +19824,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
     }
     __pyx_L7:;
 
-    /* "pysam/csamtools.pyx":1784
+    /* "pysam/csamtools.pyx":1787
  *                 return makeAlignedRead(self.rowiter.b)
  * 
  *             self.tid += 1             # <<<<<<<<<<<<<<
@@ -19091,34 +19833,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
  */
     __pyx_v_self->tid = (__pyx_v_self->tid + 1);
 
-    /* "pysam/csamtools.pyx":1787
+    /* "pysam/csamtools.pyx":1790
  * 
  *             # Otherwise, proceed to next reference or stop
  *             if self.tid<self.samfile.nreferences:             # <<<<<<<<<<<<<<
  *                 self.nextiter()
  *             else:
  */
-    __pyx_t_4 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
-    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self->samfile), __pyx_n_s__nreferences); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self->samfile), __pyx_n_s__nreferences); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     if (__pyx_t_3) {
 
-      /* "pysam/csamtools.pyx":1788
+      /* "pysam/csamtools.pyx":1791
  *             # Otherwise, proceed to next reference or stop
  *             if self.tid<self.samfile.nreferences:
  *                 self.nextiter()             # <<<<<<<<<<<<<<
  *             else:
  *                 raise StopIteration
  */
-      __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__nextiter); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__nextiter); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
@@ -19126,7 +19868,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
     }
     /*else*/ {
 
-      /* "pysam/csamtools.pyx":1790
+      /* "pysam/csamtools.pyx":1793
  *                 self.nextiter()
  *             else:
  *                 raise StopIteration             # <<<<<<<<<<<<<<
@@ -19134,7 +19876,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_18IteratorRowAllRefs_6__next__(struc
  * cdef class IteratorRowSelection(IteratorRow):
  */
       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     __pyx_L8:;
   }
@@ -19184,7 +19926,7 @@ static int __pyx_pw_5pysam_9csamtools_20IteratorRowSelection_1__cinit__(PyObject
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__positions)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1802; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  2:
         if (kw_args > 0) {
@@ -19193,7 +19935,7 @@ static int __pyx_pw_5pysam_9csamtools_20IteratorRowSelection_1__cinit__(PyObject
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1802; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -19207,10 +19949,10 @@ static int __pyx_pw_5pysam_9csamtools_20IteratorRowSelection_1__cinit__(PyObject
     __pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)values[0]);
     __pyx_v_positions = values[1];
     if (values[2]) {
-      __pyx_v_reopen = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1802; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_reopen = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
 
-      /* "pysam/csamtools.pyx":1802
+      /* "pysam/csamtools.pyx":1805
  *     """
  * 
  *     def __cinit__(self, Samfile samfile, positions, int reopen = True ):             # <<<<<<<<<<<<<<
@@ -19222,13 +19964,13 @@ static int __pyx_pw_5pysam_9csamtools_20IteratorRowSelection_1__cinit__(PyObject
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1802; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.IteratorRowSelection.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_20IteratorRowSelection___cinit__(((struct __pyx_obj_5pysam_9csamtools_IteratorRowSelection *)__pyx_v_self), __pyx_v_samfile, __pyx_v_positions, __pyx_v_reopen);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -19247,82 +19989,83 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorRowSelection___cinit__(struct __
   PyObject *__pyx_t_2 = NULL;
   int __pyx_t_3;
   int __pyx_t_4;
-  char *__pyx_t_5;
-  samfile_t *__pyx_t_6;
+  const char* __pyx_t_5;
+  char *__pyx_t_6;
+  samfile_t *__pyx_t_7;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__cinit__", 0);
-  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1802);
+  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1805);
 
-  /* "pysam/csamtools.pyx":1804
+  /* "pysam/csamtools.pyx":1807
  *     def __cinit__(self, Samfile samfile, positions, int reopen = True ):
  * 
  *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
  *             raise ValueError( "I/O operation on closed file" )
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":1805
+    /* "pysam/csamtools.pyx":1808
  * 
  *         if not samfile._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         if not samfile._isOpen():
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_135), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_134), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1807
+  /* "pysam/csamtools.pyx":1810
  *             raise ValueError( "I/O operation on closed file" )
  * 
  *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
  *             raise ValueError( "I/O operation on closed file" )
  * 
  */
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __pyx_t_3 = (!__pyx_t_4);
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":1808
+    /* "pysam/csamtools.pyx":1811
  * 
  *         if not samfile._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         assert samfile.isbam, "can only use this iterator on bam files"
  */
-    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_136), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_135), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":1810
+  /* "pysam/csamtools.pyx":1813
  *             raise ValueError( "I/O operation on closed file" )
  * 
  *         assert samfile.isbam, "can only use this iterator on bam files"             # <<<<<<<<<<<<<<
@@ -19331,12 +20074,12 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorRowSelection___cinit__(struct __
  */
   #ifndef CYTHON_WITHOUT_ASSERTIONS
   if (unlikely(!__pyx_v_samfile->isbam)) {
-    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_137));
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_136));
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #endif
 
-  /* "pysam/csamtools.pyx":1811
+  /* "pysam/csamtools.pyx":1814
  * 
  *         assert samfile.isbam, "can only use this iterator on bam files"
  *         mode = b"rb"             # <<<<<<<<<<<<<<
@@ -19346,7 +20089,7 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorRowSelection___cinit__(struct __
   __Pyx_INCREF(((PyObject *)__pyx_n_b__rb));
   __pyx_v_mode = __pyx_n_b__rb;
 
-  /* "pysam/csamtools.pyx":1814
+  /* "pysam/csamtools.pyx":1817
  * 
  *         # reopen the file to avoid iterator conflict
  *         if reopen:             # <<<<<<<<<<<<<<
@@ -19355,46 +20098,47 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorRowSelection___cinit__(struct __
  */
   if (__pyx_v_reopen) {
 
-    /* "pysam/csamtools.pyx":1815
+    /* "pysam/csamtools.pyx":1818
  *         # reopen the file to avoid iterator conflict
  *         if reopen:
  *             store = StderrStore()             # <<<<<<<<<<<<<<
  *             self.fp = samopen( samfile._filename, mode, NULL )
  *             store.release()
  */
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __pyx_v_store = __pyx_t_2;
     __pyx_t_2 = 0;
 
-    /* "pysam/csamtools.pyx":1816
+    /* "pysam/csamtools.pyx":1819
  *         if reopen:
  *             store = StderrStore()
  *             self.fp = samopen( samfile._filename, mode, NULL )             # <<<<<<<<<<<<<<
  *             store.release()
  *             assert self.fp != NULL
  */
-    __pyx_t_5 = PyBytes_AsString(((PyObject *)__pyx_v_mode)); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_v_self->fp = samopen(__pyx_v_samfile->_filename, __pyx_t_5, NULL);
+    __pyx_t_5 = PyBytes_AsString(__pyx_v_samfile->_filename); if (unlikely((__pyx_t_5 == (const char*)NULL) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyBytes_AsString(((PyObject *)__pyx_v_mode)); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_v_self->fp = samopen(__pyx_t_5, __pyx_t_6, NULL);
 
-    /* "pysam/csamtools.pyx":1817
+    /* "pysam/csamtools.pyx":1820
  *             store = StderrStore()
  *             self.fp = samopen( samfile._filename, mode, NULL )
  *             store.release()             # <<<<<<<<<<<<<<
  *             assert self.fp != NULL
  *             self.owns_samfile = True
  */
-    __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":1818
+    /* "pysam/csamtools.pyx":1821
  *             self.fp = samopen( samfile._filename, mode, NULL )
  *             store.release()
  *             assert self.fp != NULL             # <<<<<<<<<<<<<<
@@ -19404,11 +20148,11 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorRowSelection___cinit__(struct __
     #ifndef CYTHON_WITHOUT_ASSERTIONS
     if (unlikely(!(__pyx_v_self->fp != NULL))) {
       PyErr_SetNone(PyExc_AssertionError);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     #endif
 
-    /* "pysam/csamtools.pyx":1819
+    /* "pysam/csamtools.pyx":1822
  *             store.release()
  *             assert self.fp != NULL
  *             self.owns_samfile = True             # <<<<<<<<<<<<<<
@@ -19420,17 +20164,17 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorRowSelection___cinit__(struct __
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1821
+    /* "pysam/csamtools.pyx":1824
  *             self.owns_samfile = True
  *         else:
  *             self.fp = samfile.samfile             # <<<<<<<<<<<<<<
  *             self.owns_samfile = False
  * 
  */
-    __pyx_t_6 = __pyx_v_samfile->samfile;
-    __pyx_v_self->fp = __pyx_t_6;
+    __pyx_t_7 = __pyx_v_samfile->samfile;
+    __pyx_v_self->fp = __pyx_t_7;
 
-    /* "pysam/csamtools.pyx":1822
+    /* "pysam/csamtools.pyx":1825
  *         else:
  *             self.fp = samfile.samfile
  *             self.owns_samfile = False             # <<<<<<<<<<<<<<
@@ -19441,7 +20185,7 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorRowSelection___cinit__(struct __
   }
   __pyx_L5:;
 
-  /* "pysam/csamtools.pyx":1825
+  /* "pysam/csamtools.pyx":1828
  * 
  *         # allocate memory for alignment
  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
@@ -19450,7 +20194,7 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorRowSelection___cinit__(struct __
  */
   __pyx_v_self->b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
 
-  /* "pysam/csamtools.pyx":1827
+  /* "pysam/csamtools.pyx":1830
  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
  * 
  *         self.positions = positions             # <<<<<<<<<<<<<<
@@ -19463,7 +20207,7 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorRowSelection___cinit__(struct __
   __Pyx_DECREF(__pyx_v_self->positions);
   __pyx_v_self->positions = __pyx_v_positions;
 
-  /* "pysam/csamtools.pyx":1828
+  /* "pysam/csamtools.pyx":1831
  * 
  *         self.positions = positions
  *         self.current_pos = 0             # <<<<<<<<<<<<<<
@@ -19498,7 +20242,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_20IteratorRowSelection_3__iter__(PyO
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1830
+/* "pysam/csamtools.pyx":1833
  *         self.current_pos = 0
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
@@ -19511,9 +20255,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorRowSelection_2__iter__(str
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__iter__", 0);
-  __Pyx_TraceCall("__iter__", __pyx_f[0], 1830);
+  __Pyx_TraceCall("__iter__", __pyx_f[0], 1833);
 
-  /* "pysam/csamtools.pyx":1831
+  /* "pysam/csamtools.pyx":1834
  * 
  *     def __iter__(self):
  *         return self             # <<<<<<<<<<<<<<
@@ -19533,7 +20277,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorRowSelection_2__iter__(str
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1833
+/* "pysam/csamtools.pyx":1836
  *         return self
  * 
  *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
@@ -19546,9 +20290,9 @@ static bam1_t *__pyx_f_5pysam_9csamtools_20IteratorRowSelection_getCurrent(struc
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("getCurrent", 0);
-  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1833);
+  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1836);
 
-  /* "pysam/csamtools.pyx":1834
+  /* "pysam/csamtools.pyx":1837
  * 
  *     cdef bam1_t * getCurrent( self ):
  *         return self.b             # <<<<<<<<<<<<<<
@@ -19565,7 +20309,7 @@ static bam1_t *__pyx_f_5pysam_9csamtools_20IteratorRowSelection_getCurrent(struc
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1836
+/* "pysam/csamtools.pyx":1839
  *         return self.b
  * 
  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
@@ -19585,9 +20329,9 @@ static int __pyx_f_5pysam_9csamtools_20IteratorRowSelection_cnext(struct __pyx_o
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("cnext", 0);
-  __Pyx_TraceCall("cnext", __pyx_f[0], 1836);
+  __Pyx_TraceCall("cnext", __pyx_f[0], 1839);
 
-  /* "pysam/csamtools.pyx":1840
+  /* "pysam/csamtools.pyx":1843
  * 
  *         # end iteration if out of positions
  *         if self.current_pos >= len(self.positions): return -1             # <<<<<<<<<<<<<<
@@ -19596,7 +20340,7 @@ static int __pyx_f_5pysam_9csamtools_20IteratorRowSelection_cnext(struct __pyx_o
  */
   __pyx_t_1 = __pyx_v_self->positions;
   __Pyx_INCREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __pyx_t_3 = (__pyx_v_self->current_pos >= __pyx_t_2);
   if (__pyx_t_3) {
@@ -19606,20 +20350,20 @@ static int __pyx_f_5pysam_9csamtools_20IteratorRowSelection_cnext(struct __pyx_o
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1842
+  /* "pysam/csamtools.pyx":1845
  *         if self.current_pos >= len(self.positions): return -1
  * 
  *         bam_seek( self.fp.x.bam, self.positions[self.current_pos], 0 )             # <<<<<<<<<<<<<<
  *         self.current_pos += 1
  *         return samread(self.fp, self.b)
  */
-  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->positions, __pyx_v_self->current_pos, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->positions, __pyx_v_self->current_pos, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_4 = __Pyx_PyInt_from_py_uint64_t(__pyx_t_1); if (unlikely((__pyx_t_4 == (uint64_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyInt_from_py_uint64_t(__pyx_t_1); if (unlikely((__pyx_t_4 == (uint64_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   bam_seek(__pyx_v_self->fp->x.bam, __pyx_t_4, 0);
 
-  /* "pysam/csamtools.pyx":1843
+  /* "pysam/csamtools.pyx":1846
  * 
  *         bam_seek( self.fp.x.bam, self.positions[self.current_pos], 0 )
  *         self.current_pos += 1             # <<<<<<<<<<<<<<
@@ -19628,7 +20372,7 @@ static int __pyx_f_5pysam_9csamtools_20IteratorRowSelection_cnext(struct __pyx_o
  */
   __pyx_v_self->current_pos = (__pyx_v_self->current_pos + 1);
 
-  /* "pysam/csamtools.pyx":1844
+  /* "pysam/csamtools.pyx":1847
  *         bam_seek( self.fp.x.bam, self.positions[self.current_pos], 0 )
  *         self.current_pos += 1
  *         return samread(self.fp, self.b)             # <<<<<<<<<<<<<<
@@ -19665,7 +20409,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_20IteratorRowSelection_5__next__(PyO
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1846
+/* "pysam/csamtools.pyx":1849
  *         return samread(self.fp, self.b)
  * 
  *     def __next__(self):             # <<<<<<<<<<<<<<
@@ -19684,9 +20428,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorRowSelection_4__next__(str
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__next__", 0);
-  __Pyx_TraceCall("__next__", __pyx_f[0], 1846);
+  __Pyx_TraceCall("__next__", __pyx_f[0], 1849);
 
-  /* "pysam/csamtools.pyx":1852
+  /* "pysam/csamtools.pyx":1855
  *         """
  * 
  *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
@@ -19695,7 +20439,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorRowSelection_4__next__(str
  */
   __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowSelection *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);
 
-  /* "pysam/csamtools.pyx":1853
+  /* "pysam/csamtools.pyx":1856
  * 
  *         cdef int ret = self.cnext()
  *         if (ret > 0):             # <<<<<<<<<<<<<<
@@ -19705,7 +20449,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorRowSelection_4__next__(str
   __pyx_t_1 = (__pyx_v_ret > 0);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":1854
+    /* "pysam/csamtools.pyx":1857
  *         cdef int ret = self.cnext()
  *         if (ret > 0):
  *             return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
@@ -19713,7 +20457,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorRowSelection_4__next__(str
  *             raise StopIteration
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __pyx_f_5pysam_9csamtools_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __pyx_r = __pyx_t_2;
     __pyx_t_2 = 0;
@@ -19722,7 +20466,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorRowSelection_4__next__(str
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":1856
+    /* "pysam/csamtools.pyx":1859
  *             return makeAlignedRead( self.b )
  *         else:
  *             raise StopIteration             # <<<<<<<<<<<<<<
@@ -19730,7 +20474,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorRowSelection_4__next__(str
  *     def __dealloc__(self):
  */
     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L3:;
 
@@ -19756,7 +20500,7 @@ static void __pyx_pw_5pysam_9csamtools_20IteratorRowSelection_7__dealloc__(PyObj
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/csamtools.pyx":1858
+/* "pysam/csamtools.pyx":1861
  *             raise StopIteration
  * 
  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
@@ -19768,9 +20512,9 @@ static void __pyx_pf_5pysam_9csamtools_20IteratorRowSelection_6__dealloc__(struc
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__dealloc__", 0);
-  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1858);
+  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1861);
 
-  /* "pysam/csamtools.pyx":1859
+  /* "pysam/csamtools.pyx":1862
  * 
  *     def __dealloc__(self):
  *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
@@ -19779,7 +20523,7 @@ static void __pyx_pf_5pysam_9csamtools_20IteratorRowSelection_6__dealloc__(struc
  */
   bam_destroy1(__pyx_v_self->b);
 
-  /* "pysam/csamtools.pyx":1860
+  /* "pysam/csamtools.pyx":1863
  *     def __dealloc__(self):
  *         bam_destroy1(self.b)
  *         if self.owns_samfile: samclose( self.fp )             # <<<<<<<<<<<<<<
@@ -19796,7 +20540,7 @@ static void __pyx_pf_5pysam_9csamtools_20IteratorRowSelection_6__dealloc__(struc
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/csamtools.pyx":1865
+/* "pysam/csamtools.pyx":1868
  * ##-------------------------------------------------------------------
  * ##-------------------------------------------------------------------
  * cdef int __advance_all( void * data, bam1_t * b ):             # <<<<<<<<<<<<<<
@@ -19810,9 +20554,9 @@ static int __pyx_f_5pysam_9csamtools___advance_all(void *__pyx_v_data, bam1_t *_
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__advance_all", 0);
-  __Pyx_TraceCall("__advance_all", __pyx_f[0], 1865);
+  __Pyx_TraceCall("__advance_all", __pyx_f[0], 1868);
 
-  /* "pysam/csamtools.pyx":1869
+  /* "pysam/csamtools.pyx":1872
  *     '''
  *     cdef __iterdata * d
  *     d = <__iterdata*>data             # <<<<<<<<<<<<<<
@@ -19821,7 +20565,7 @@ static int __pyx_f_5pysam_9csamtools___advance_all(void *__pyx_v_data, bam1_t *_
  */
   __pyx_v_d = ((__pyx_t_5pysam_9csamtools___iterdata *)__pyx_v_data);
 
-  /* "pysam/csamtools.pyx":1870
+  /* "pysam/csamtools.pyx":1873
  *     cdef __iterdata * d
  *     d = <__iterdata*>data
  *     return bam_iter_read( d.samfile.x.bam, d.iter, b )             # <<<<<<<<<<<<<<
@@ -19838,7 +20582,7 @@ static int __pyx_f_5pysam_9csamtools___advance_all(void *__pyx_v_data, bam1_t *_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1872
+/* "pysam/csamtools.pyx":1875
  *     return bam_iter_read( d.samfile.x.bam, d.iter, b )
  * 
  * cdef int __advance_snpcalls( void * data, bam1_t * b ):             # <<<<<<<<<<<<<<
@@ -19869,9 +20613,9 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__advance_snpcalls", 0);
-  __Pyx_TraceCall("__advance_snpcalls", __pyx_f[0], 1872);
+  __Pyx_TraceCall("__advance_snpcalls", __pyx_f[0], 1875);
 
-  /* "pysam/csamtools.pyx":1877
+  /* "pysam/csamtools.pyx":1880
  *     '''
  *     cdef __iterdata * d
  *     d = <__iterdata*>data             # <<<<<<<<<<<<<<
@@ -19880,7 +20624,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
  */
   __pyx_v_d = ((__pyx_t_5pysam_9csamtools___iterdata *)__pyx_v_data);
 
-  /* "pysam/csamtools.pyx":1879
+  /* "pysam/csamtools.pyx":1882
  *     d = <__iterdata*>data
  * 
  *     cdef int ret = bam_iter_read( d.samfile.x.bam, d.iter, b )             # <<<<<<<<<<<<<<
@@ -19889,7 +20633,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
  */
   __pyx_v_ret = bam_iter_read(__pyx_v_d->samfile->x.bam, __pyx_v_d->iter, __pyx_v_b);
 
-  /* "pysam/csamtools.pyx":1880
+  /* "pysam/csamtools.pyx":1883
  * 
  *     cdef int ret = bam_iter_read( d.samfile.x.bam, d.iter, b )
  *     cdef int skip = 0             # <<<<<<<<<<<<<<
@@ -19898,7 +20642,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
  */
   __pyx_v_skip = 0;
 
-  /* "pysam/csamtools.pyx":1882
+  /* "pysam/csamtools.pyx":1885
  *     cdef int skip = 0
  *     cdef int q
  *     cdef int is_cns = 1             # <<<<<<<<<<<<<<
@@ -19907,7 +20651,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
  */
   __pyx_v_is_cns = 1;
 
-  /* "pysam/csamtools.pyx":1883
+  /* "pysam/csamtools.pyx":1886
  *     cdef int q
  *     cdef int is_cns = 1
  *     cdef int is_nobaq = 0             # <<<<<<<<<<<<<<
@@ -19916,7 +20660,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
  */
   __pyx_v_is_nobaq = 0;
 
-  /* "pysam/csamtools.pyx":1884
+  /* "pysam/csamtools.pyx":1887
  *     cdef int is_cns = 1
  *     cdef int is_nobaq = 0
  *     cdef int capQ_thres = 0             # <<<<<<<<<<<<<<
@@ -19925,7 +20669,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
  */
   __pyx_v_capQ_thres = 0;
 
-  /* "pysam/csamtools.pyx":1887
+  /* "pysam/csamtools.pyx":1890
  * 
  *     # reload sequence
  *     if d.fastafile != NULL and b.core.tid != d.tid:             # <<<<<<<<<<<<<<
@@ -19941,7 +20685,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
   }
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":1888
+    /* "pysam/csamtools.pyx":1891
  *     # reload sequence
  *     if d.fastafile != NULL and b.core.tid != d.tid:
  *         if d.seq != NULL: free(d.seq)             # <<<<<<<<<<<<<<
@@ -19955,7 +20699,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
     }
     __pyx_L4:;
 
-    /* "pysam/csamtools.pyx":1889
+    /* "pysam/csamtools.pyx":1892
  *     if d.fastafile != NULL and b.core.tid != d.tid:
  *         if d.seq != NULL: free(d.seq)
  *         d.tid = b.core.tid             # <<<<<<<<<<<<<<
@@ -19965,7 +20709,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
     __pyx_t_4 = __pyx_v_b->core.tid;
     __pyx_v_d->tid = __pyx_t_4;
 
-    /* "pysam/csamtools.pyx":1890
+    /* "pysam/csamtools.pyx":1893
  *         if d.seq != NULL: free(d.seq)
  *         d.tid = b.core.tid
  *         d.seq = faidx_fetch_seq(d.fastafile,             # <<<<<<<<<<<<<<
@@ -19974,7 +20718,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
  */
     __pyx_v_d->seq = faidx_fetch_seq(__pyx_v_d->fastafile, (__pyx_v_d->samfile->header->target_name[__pyx_v_d->tid]), 0, __pyx_v_5pysam_9csamtools_max_pos, (&__pyx_v_d->seq_len));
 
-    /* "pysam/csamtools.pyx":1894
+    /* "pysam/csamtools.pyx":1897
  *                                 0, max_pos,
  *                                 &d.seq_len)
  *         if d.seq == NULL:             # <<<<<<<<<<<<<<
@@ -19984,26 +20728,26 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
     __pyx_t_3 = (__pyx_v_d->seq == NULL);
     if (__pyx_t_3) {
 
-      /* "pysam/csamtools.pyx":1896
+      /* "pysam/csamtools.pyx":1899
  *         if d.seq == NULL:
  *             raise ValueError( "reference sequence for '%s' (tid=%i) not found" % \
  *                                   (d.samfile.header.target_name[d.tid],             # <<<<<<<<<<<<<<
  *                                    d.tid))
  * 
  */
-      __pyx_t_5 = PyBytes_FromString((__pyx_v_d->samfile->header->target_name[__pyx_v_d->tid])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyBytes_FromString((__pyx_v_d->samfile->header->target_name[__pyx_v_d->tid])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_5));
 
-      /* "pysam/csamtools.pyx":1897
+      /* "pysam/csamtools.pyx":1900
  *             raise ValueError( "reference sequence for '%s' (tid=%i) not found" % \
  *                                   (d.samfile.header.target_name[d.tid],
  *                                    d.tid))             # <<<<<<<<<<<<<<
  * 
  * 
  */
-      __pyx_t_6 = PyInt_FromLong(__pyx_v_d->tid); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyInt_FromLong(__pyx_v_d->tid); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
-      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_5));
       __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
@@ -20011,20 +20755,20 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
       __Pyx_GIVEREF(__pyx_t_6);
       __pyx_t_5 = 0;
       __pyx_t_6 = 0;
-      __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_138), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_137), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_6));
       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_6));
       __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
       __pyx_t_6 = 0;
-      __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
       __Pyx_Raise(__pyx_t_6, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L5;
     }
     __pyx_L5:;
@@ -20032,7 +20776,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":1900
+  /* "pysam/csamtools.pyx":1903
  * 
  * 
  *     while ret >= 0:             # <<<<<<<<<<<<<<
@@ -20043,7 +20787,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
     __pyx_t_3 = (__pyx_v_ret >= 0);
     if (!__pyx_t_3) break;
 
-    /* "pysam/csamtools.pyx":1902
+    /* "pysam/csamtools.pyx":1905
  *     while ret >= 0:
  * 
  *         skip = 0             # <<<<<<<<<<<<<<
@@ -20052,7 +20796,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
  */
     __pyx_v_skip = 0;
 
-    /* "pysam/csamtools.pyx":1905
+    /* "pysam/csamtools.pyx":1908
  * 
  *         # realign read - changes base qualities
  *         if d.seq != NULL and is_cns and not is_nobaq: bam_prob_realn( b, d.seq )             # <<<<<<<<<<<<<<
@@ -20077,7 +20821,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
     }
     __pyx_L8:;
 
-    /* "pysam/csamtools.pyx":1907
+    /* "pysam/csamtools.pyx":1910
  *         if d.seq != NULL and is_cns and not is_nobaq: bam_prob_realn( b, d.seq )
  * 
  *         if d.seq != NULL and capQ_thres > 10:             # <<<<<<<<<<<<<<
@@ -20093,7 +20837,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
     }
     if (__pyx_t_2) {
 
-      /* "pysam/csamtools.pyx":1908
+      /* "pysam/csamtools.pyx":1911
  * 
  *         if d.seq != NULL and capQ_thres > 10:
  *             q = bam_cap_mapQ(b, d.seq, capQ_thres)             # <<<<<<<<<<<<<<
@@ -20102,7 +20846,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
  */
       __pyx_v_q = bam_cap_mapQ(__pyx_v_b, __pyx_v_d->seq, __pyx_v_capQ_thres);
 
-      /* "pysam/csamtools.pyx":1909
+      /* "pysam/csamtools.pyx":1912
  *         if d.seq != NULL and capQ_thres > 10:
  *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
  *             if q < 0: skip = 1             # <<<<<<<<<<<<<<
@@ -20115,7 +20859,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
         goto __pyx_L10;
       }
 
-      /* "pysam/csamtools.pyx":1910
+      /* "pysam/csamtools.pyx":1913
  *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
  *             if q < 0: skip = 1
  *             elif b.core.qual > q: b.core.qual = q             # <<<<<<<<<<<<<<
@@ -20132,7 +20876,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
     }
     __pyx_L9:;
 
-    /* "pysam/csamtools.pyx":1911
+    /* "pysam/csamtools.pyx":1914
  *             if q < 0: skip = 1
  *             elif b.core.qual > q: b.core.qual = q
  *         if b.core.flag & BAM_FUNMAP: skip = 1             # <<<<<<<<<<<<<<
@@ -20145,7 +20889,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
       goto __pyx_L11;
     }
 
-    /* "pysam/csamtools.pyx":1912
+    /* "pysam/csamtools.pyx":1915
  *             elif b.core.qual > q: b.core.qual = q
  *         if b.core.flag & BAM_FUNMAP: skip = 1
  *         elif b.core.flag & 1 and not b.core.flag & 2: skip = 1             # <<<<<<<<<<<<<<
@@ -20164,7 +20908,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
     }
     __pyx_L11:;
 
-    /* "pysam/csamtools.pyx":1914
+    /* "pysam/csamtools.pyx":1917
  *         elif b.core.flag & 1 and not b.core.flag & 2: skip = 1
  * 
  *         if not skip: break             # <<<<<<<<<<<<<<
@@ -20178,7 +20922,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
     }
     __pyx_L12:;
 
-    /* "pysam/csamtools.pyx":1917
+    /* "pysam/csamtools.pyx":1920
  *         # additional filters
  * 
  *         ret = bam_iter_read( d.samfile.x.bam, d.iter, b )             # <<<<<<<<<<<<<<
@@ -20189,7 +20933,7 @@ static int __pyx_f_5pysam_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1
   }
   __pyx_L7_break:;
 
-  /* "pysam/csamtools.pyx":1919
+  /* "pysam/csamtools.pyx":1922
  *         ret = bam_iter_read( d.samfile.x.bam, d.iter, b )
  * 
  *     return ret             # <<<<<<<<<<<<<<
@@ -20241,7 +20985,7 @@ static int __pyx_pw_5pysam_9csamtools_14IteratorColumn_1__cinit__(PyObject *__py
         else goto __pyx_L5_argtuple_error;
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1968; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1971; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
       goto __pyx_L5_argtuple_error;
@@ -20252,14 +20996,14 @@ static int __pyx_pw_5pysam_9csamtools_14IteratorColumn_1__cinit__(PyObject *__py
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1968; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1971; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
   __Pyx_AddTraceback("pysam.csamtools.IteratorColumn.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_14IteratorColumn___cinit__(((struct __pyx_obj_5pysam_9csamtools_IteratorColumn *)__pyx_v_self), __pyx_v_samfile, __pyx_v_kwargs);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -20270,7 +21014,7 @@ static int __pyx_pw_5pysam_9csamtools_14IteratorColumn_1__cinit__(PyObject *__py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1968
+/* "pysam/csamtools.pyx":1971
  *     '''
  * 
  *     def __cinit__( self, Samfile samfile, **kwargs ):             # <<<<<<<<<<<<<<
@@ -20289,9 +21033,9 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorColumn___cinit__(struct __pyx_ob
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__cinit__", 0);
-  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1968);
+  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1971);
 
-  /* "pysam/csamtools.pyx":1969
+  /* "pysam/csamtools.pyx":1972
  * 
  *     def __cinit__( self, Samfile samfile, **kwargs ):
  *         self.samfile = samfile             # <<<<<<<<<<<<<<
@@ -20304,46 +21048,46 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorColumn___cinit__(struct __pyx_ob
   __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
   __pyx_v_self->samfile = __pyx_v_samfile;
 
-  /* "pysam/csamtools.pyx":1970
+  /* "pysam/csamtools.pyx":1973
  *     def __cinit__( self, Samfile samfile, **kwargs ):
  *         self.samfile = samfile
  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )             # <<<<<<<<<<<<<<
  *         self.fastafile = kwargs.get( "fastafile", None )
  *         self.stepper = kwargs.get( "stepper", None )
  */
-  __pyx_t_1 = PyInt_FromLong(BAM_DEF_MASK); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(BAM_DEF_MASK); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s__mask), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s__mask), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_v_self->mask = __pyx_t_3;
 
-  /* "pysam/csamtools.pyx":1971
+  /* "pysam/csamtools.pyx":1974
  *         self.samfile = samfile
  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )
  *         self.fastafile = kwargs.get( "fastafile", None )             # <<<<<<<<<<<<<<
  *         self.stepper = kwargs.get( "stepper", None )
  *         self.max_depth = kwargs.get( "max_depth", 8000 )
  */
-  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s__fastafile), Py_None); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s__fastafile), Py_None); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1974; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5pysam_9csamtools_Fastafile))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5pysam_9csamtools_Fastafile))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1974; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GIVEREF(__pyx_t_2);
   __Pyx_GOTREF(__pyx_v_self->fastafile);
   __Pyx_DECREF(((PyObject *)__pyx_v_self->fastafile));
   __pyx_v_self->fastafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":1972
+  /* "pysam/csamtools.pyx":1975
  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )
  *         self.fastafile = kwargs.get( "fastafile", None )
  *         self.stepper = kwargs.get( "stepper", None )             # <<<<<<<<<<<<<<
  *         self.max_depth = kwargs.get( "max_depth", 8000 )
  *         self.iterdata.seq = NULL
  */
-  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s__stepper), Py_None); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s__stepper), Py_None); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_GIVEREF(__pyx_t_2);
   __Pyx_GOTREF(__pyx_v_self->stepper);
@@ -20351,20 +21095,20 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorColumn___cinit__(struct __pyx_ob
   __pyx_v_self->stepper = __pyx_t_2;
   __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":1973
+  /* "pysam/csamtools.pyx":1976
  *         self.fastafile = kwargs.get( "fastafile", None )
  *         self.stepper = kwargs.get( "stepper", None )
  *         self.max_depth = kwargs.get( "max_depth", 8000 )             # <<<<<<<<<<<<<<
  *         self.iterdata.seq = NULL
  *         self.tid = 0
  */
-  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s__max_depth), __pyx_int_8000); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s__max_depth), __pyx_int_8000); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_v_self->max_depth = __pyx_t_3;
 
-  /* "pysam/csamtools.pyx":1974
+  /* "pysam/csamtools.pyx":1977
  *         self.stepper = kwargs.get( "stepper", None )
  *         self.max_depth = kwargs.get( "max_depth", 8000 )
  *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
@@ -20373,7 +21117,7 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorColumn___cinit__(struct __pyx_ob
  */
   __pyx_v_self->iterdata.seq = NULL;
 
-  /* "pysam/csamtools.pyx":1975
+  /* "pysam/csamtools.pyx":1978
  *         self.max_depth = kwargs.get( "max_depth", 8000 )
  *         self.iterdata.seq = NULL
  *         self.tid = 0             # <<<<<<<<<<<<<<
@@ -20382,7 +21126,7 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorColumn___cinit__(struct __pyx_ob
  */
   __pyx_v_self->tid = 0;
 
-  /* "pysam/csamtools.pyx":1976
+  /* "pysam/csamtools.pyx":1979
  *         self.iterdata.seq = NULL
  *         self.tid = 0
  *         self.pos = 0             # <<<<<<<<<<<<<<
@@ -20391,7 +21135,7 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorColumn___cinit__(struct __pyx_ob
  */
   __pyx_v_self->pos = 0;
 
-  /* "pysam/csamtools.pyx":1977
+  /* "pysam/csamtools.pyx":1980
  *         self.tid = 0
  *         self.pos = 0
  *         self.n_plp = 0             # <<<<<<<<<<<<<<
@@ -20400,7 +21144,7 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorColumn___cinit__(struct __pyx_ob
  */
   __pyx_v_self->n_plp = 0;
 
-  /* "pysam/csamtools.pyx":1978
+  /* "pysam/csamtools.pyx":1981
  *         self.pos = 0
  *         self.n_plp = 0
  *         self.plp = NULL             # <<<<<<<<<<<<<<
@@ -20409,7 +21153,7 @@ static int __pyx_pf_5pysam_9csamtools_14IteratorColumn___cinit__(struct __pyx_ob
  */
   __pyx_v_self->plp = NULL;
 
-  /* "pysam/csamtools.pyx":1979
+  /* "pysam/csamtools.pyx":1982
  *         self.n_plp = 0
  *         self.plp = NULL
  *         self.pileup_iter = <bam_plp_t>NULL             # <<<<<<<<<<<<<<
@@ -20442,7 +21186,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_14IteratorColumn_3__iter__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1981
+/* "pysam/csamtools.pyx":1984
  *         self.pileup_iter = <bam_plp_t>NULL
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
@@ -20455,9 +21199,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorColumn_2__iter__(struct __
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__iter__", 0);
-  __Pyx_TraceCall("__iter__", __pyx_f[0], 1981);
+  __Pyx_TraceCall("__iter__", __pyx_f[0], 1984);
 
-  /* "pysam/csamtools.pyx":1982
+  /* "pysam/csamtools.pyx":1985
  * 
  *     def __iter__(self):
  *         return self             # <<<<<<<<<<<<<<
@@ -20477,7 +21221,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorColumn_2__iter__(struct __
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1984
+/* "pysam/csamtools.pyx":1987
  *         return self
  * 
  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
@@ -20490,9 +21234,9 @@ static int __pyx_f_5pysam_9csamtools_14IteratorColumn_cnext(struct __pyx_obj_5py
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("cnext", 0);
-  __Pyx_TraceCall("cnext", __pyx_f[0], 1984);
+  __Pyx_TraceCall("cnext", __pyx_f[0], 1987);
 
-  /* "pysam/csamtools.pyx":1987
+  /* "pysam/csamtools.pyx":1990
  *         '''perform next iteration.
  *         '''
  *         self.plp = bam_plp_auto( self.pileup_iter,             # <<<<<<<<<<<<<<
@@ -20507,7 +21251,7 @@ static int __pyx_f_5pysam_9csamtools_14IteratorColumn_cnext(struct __pyx_obj_5py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1992
+/* "pysam/csamtools.pyx":1995
  *                                  &self.n_plp )
  * 
  *     cdef char * getSequence( self ):             # <<<<<<<<<<<<<<
@@ -20520,9 +21264,9 @@ static char *__pyx_f_5pysam_9csamtools_14IteratorColumn_getSequence(struct __pyx
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("getSequence", 0);
-  __Pyx_TraceCall("getSequence", __pyx_f[0], 1992);
+  __Pyx_TraceCall("getSequence", __pyx_f[0], 1995);
 
-  /* "pysam/csamtools.pyx":1995
+  /* "pysam/csamtools.pyx":1998
  *         '''return current reference sequence underlying the iterator.
  *         '''
  *         return self.iterdata.seq             # <<<<<<<<<<<<<<
@@ -20550,7 +21294,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_14IteratorColumn_7seq_len_1__get__(P
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":1999
+/* "pysam/csamtools.pyx":2002
  *     property seq_len:
  *         '''current sequence length.'''
  *         def __get__(self): return self.iterdata.seq_len             # <<<<<<<<<<<<<<
@@ -20567,9 +21311,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorColumn_7seq_len___get__(st
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 1999);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2002);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->iterdata.seq_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->iterdata.seq_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -20595,7 +21339,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_14IteratorColumn_5addReference(PyObj
   PyObject *__pyx_r = 0;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("addReference (wrapper)", 0);
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fastafile), __pyx_ptype_5pysam_9csamtools_Fastafile, 1, "fastafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fastafile), __pyx_ptype_5pysam_9csamtools_Fastafile, 1, "fastafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_14IteratorColumn_4addReference(((struct __pyx_obj_5pysam_9csamtools_IteratorColumn *)__pyx_v_self), ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)__pyx_v_fastafile));
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -20605,7 +21349,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_14IteratorColumn_5addReference(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2001
+/* "pysam/csamtools.pyx":2004
  *         def __get__(self): return self.iterdata.seq_len
  * 
  *     def addReference( self, Fastafile fastafile ):             # <<<<<<<<<<<<<<
@@ -20620,9 +21364,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorColumn_4addReference(struc
   faidx_t *__pyx_t_2;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("addReference", 0);
-  __Pyx_TraceCall("addReference", __pyx_f[0], 2001);
+  __Pyx_TraceCall("addReference", __pyx_f[0], 2004);
 
-  /* "pysam/csamtools.pyx":2004
+  /* "pysam/csamtools.pyx":2007
  *        '''
  *        add reference sequences in *fastafile* to iterator.'''
  *        self.fastafile = fastafile             # <<<<<<<<<<<<<<
@@ -20635,7 +21379,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorColumn_4addReference(struc
   __Pyx_DECREF(((PyObject *)__pyx_v_self->fastafile));
   __pyx_v_self->fastafile = __pyx_v_fastafile;
 
-  /* "pysam/csamtools.pyx":2005
+  /* "pysam/csamtools.pyx":2008
  *        add reference sequences in *fastafile* to iterator.'''
  *        self.fastafile = fastafile
  *        if self.iterdata.seq != NULL: free(self.iterdata.seq)             # <<<<<<<<<<<<<<
@@ -20649,7 +21393,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorColumn_4addReference(struc
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2006
+  /* "pysam/csamtools.pyx":2009
  *        self.fastafile = fastafile
  *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
  *        self.iterdata.tid = -1             # <<<<<<<<<<<<<<
@@ -20658,7 +21402,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorColumn_4addReference(struc
  */
   __pyx_v_self->iterdata.tid = -1;
 
-  /* "pysam/csamtools.pyx":2007
+  /* "pysam/csamtools.pyx":2010
  *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
  *        self.iterdata.tid = -1
  *        self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
@@ -20687,7 +21431,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_14IteratorColumn_7hasReference(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2009
+/* "pysam/csamtools.pyx":2012
  *        self.iterdata.fastafile = self.fastafile.fastafile
  * 
  *     def hasReference( self ):             # <<<<<<<<<<<<<<
@@ -20700,9 +21444,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorColumn_6hasReference(struc
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("hasReference", 0);
-  __Pyx_TraceCall("hasReference", __pyx_f[0], 2009);
+  __Pyx_TraceCall("hasReference", __pyx_f[0], 2012);
 
-  /* "pysam/csamtools.pyx":2012
+  /* "pysam/csamtools.pyx":2015
  *         '''
  *         return true if iterator is associated with a reference'''
  *         return self.fastafile             # <<<<<<<<<<<<<<
@@ -20722,7 +21466,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_14IteratorColumn_6hasReference(struc
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2014
+/* "pysam/csamtools.pyx":2017
  *         return self.fastafile
  * 
  *     cdef setMask( self, mask ):             # <<<<<<<<<<<<<<
@@ -20739,19 +21483,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setMask(struct __pyx
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("setMask", 0);
-  __Pyx_TraceCall("setMask", __pyx_f[0], 2014);
+  __Pyx_TraceCall("setMask", __pyx_f[0], 2017);
 
-  /* "pysam/csamtools.pyx":2019
+  /* "pysam/csamtools.pyx":2022
  *         reads with bits set in *mask* will be skipped.
  *         '''
  *         self.mask = mask             # <<<<<<<<<<<<<<
  *         bam_plp_set_mask( self.pileup_iter, self.mask )
  * 
  */
-  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_mask); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_mask); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->mask = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2020
+  /* "pysam/csamtools.pyx":2023
  *         '''
  *         self.mask = mask
  *         bam_plp_set_mask( self.pileup_iter, self.mask )             # <<<<<<<<<<<<<<
@@ -20772,7 +21516,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setMask(struct __pyx
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2022
+/* "pysam/csamtools.pyx":2025
  *         bam_plp_set_mask( self.pileup_iter, self.mask )
  * 
  *     cdef setupIteratorData( self,             # <<<<<<<<<<<<<<
@@ -20800,29 +21544,29 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("setupIteratorData", 0);
-  __Pyx_TraceCall("setupIteratorData", __pyx_f[0], 2022);
+  __Pyx_TraceCall("setupIteratorData", __pyx_f[0], 2025);
   if (__pyx_optional_args) {
     if (__pyx_optional_args->__pyx_n > 0) {
       __pyx_v_reopen = __pyx_optional_args->reopen;
     }
   }
 
-  /* "pysam/csamtools.pyx":2029
+  /* "pysam/csamtools.pyx":2032
  *         '''setup the iterator structure'''
  * 
  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen )             # <<<<<<<<<<<<<<
  *         self.iterdata.samfile = self.samfile.samfile
  *         self.iterdata.iter = self.iter.iter
  */
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyInt_FromLong(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyInt_FromLong(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = PyInt_FromLong(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyInt_FromLong(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_4 = PyInt_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyInt_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
   PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_self->samfile));
@@ -20839,7 +21583,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
   __pyx_t_2 = 0;
   __pyx_t_3 = 0;
   __pyx_t_4 = 0;
-  __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowRegion)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowRegion)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
   __Pyx_GIVEREF(__pyx_t_4);
@@ -20848,7 +21592,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
   __pyx_v_self->iter = ((struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *)__pyx_t_4);
   __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":2030
+  /* "pysam/csamtools.pyx":2033
  * 
  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen )
  *         self.iterdata.samfile = self.samfile.samfile             # <<<<<<<<<<<<<<
@@ -20858,7 +21602,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
   __pyx_t_6 = __pyx_v_self->samfile->samfile;
   __pyx_v_self->iterdata.samfile = __pyx_t_6;
 
-  /* "pysam/csamtools.pyx":2031
+  /* "pysam/csamtools.pyx":2034
  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen )
  *         self.iterdata.samfile = self.samfile.samfile
  *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
@@ -20868,7 +21612,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
   __pyx_t_7 = __pyx_v_self->iter->iter;
   __pyx_v_self->iterdata.iter = __pyx_t_7;
 
-  /* "pysam/csamtools.pyx":2032
+  /* "pysam/csamtools.pyx":2035
  *         self.iterdata.samfile = self.samfile.samfile
  *         self.iterdata.iter = self.iter.iter
  *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
@@ -20877,7 +21621,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
  */
   __pyx_v_self->iterdata.seq = NULL;
 
-  /* "pysam/csamtools.pyx":2033
+  /* "pysam/csamtools.pyx":2036
  *         self.iterdata.iter = self.iter.iter
  *         self.iterdata.seq = NULL
  *         self.iterdata.tid = -1             # <<<<<<<<<<<<<<
@@ -20886,19 +21630,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
  */
   __pyx_v_self->iterdata.tid = -1;
 
-  /* "pysam/csamtools.pyx":2035
+  /* "pysam/csamtools.pyx":2038
  *         self.iterdata.tid = -1
  * 
  *         if self.fastafile != None:             # <<<<<<<<<<<<<<
  *             self.iterdata.fastafile = self.fastafile.fastafile
  *         else:
  */
-  __pyx_t_4 = PyObject_RichCompare(((PyObject *)__pyx_v_self->fastafile), Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_RichCompare(((PyObject *)__pyx_v_self->fastafile), Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   if (__pyx_t_8) {
 
-    /* "pysam/csamtools.pyx":2036
+    /* "pysam/csamtools.pyx":2039
  * 
  *         if self.fastafile != None:
  *             self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
@@ -20911,7 +21655,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":2038
+    /* "pysam/csamtools.pyx":2041
  *             self.iterdata.fastafile = self.fastafile.fastafile
  *         else:
  *             self.iterdata.fastafile = NULL             # <<<<<<<<<<<<<<
@@ -20922,19 +21666,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2040
+  /* "pysam/csamtools.pyx":2043
  *             self.iterdata.fastafile = NULL
  * 
  *         if self.stepper == None or self.stepper == "all":             # <<<<<<<<<<<<<<
  *             self.pileup_iter = bam_plp_init( &__advance_all, &self.iterdata )
  *         elif self.stepper == "samtools":
  */
-  __pyx_t_4 = PyObject_RichCompare(__pyx_v_self->stepper, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_RichCompare(__pyx_v_self->stepper, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   if (!__pyx_t_8) {
-    __pyx_t_4 = PyObject_RichCompare(__pyx_v_self->stepper, ((PyObject *)__pyx_n_s__all), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_RichCompare(__pyx_v_self->stepper, ((PyObject *)__pyx_n_s__all), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
     __pyx_t_11 = __pyx_t_10;
   } else {
@@ -20942,7 +21686,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
   }
   if (__pyx_t_11) {
 
-    /* "pysam/csamtools.pyx":2041
+    /* "pysam/csamtools.pyx":2044
  * 
  *         if self.stepper == None or self.stepper == "all":
  *             self.pileup_iter = bam_plp_init( &__advance_all, &self.iterdata )             # <<<<<<<<<<<<<<
@@ -20953,19 +21697,19 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
     goto __pyx_L4;
   }
 
-  /* "pysam/csamtools.pyx":2042
+  /* "pysam/csamtools.pyx":2045
  *         if self.stepper == None or self.stepper == "all":
  *             self.pileup_iter = bam_plp_init( &__advance_all, &self.iterdata )
  *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
  *             self.pileup_iter = bam_plp_init( &__advance_snpcalls, &self.iterdata )
  *         else:
  */
-  __pyx_t_4 = PyObject_RichCompare(__pyx_v_self->stepper, ((PyObject *)__pyx_n_s__samtools), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_RichCompare(__pyx_v_self->stepper, ((PyObject *)__pyx_n_s__samtools), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   if (__pyx_t_11) {
 
-    /* "pysam/csamtools.pyx":2043
+    /* "pysam/csamtools.pyx":2046
  *             self.pileup_iter = bam_plp_init( &__advance_all, &self.iterdata )
  *         elif self.stepper == "samtools":
  *             self.pileup_iter = bam_plp_init( &__advance_snpcalls, &self.iterdata )             # <<<<<<<<<<<<<<
@@ -20977,30 +21721,30 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":2045
+    /* "pysam/csamtools.pyx":2048
  *             self.pileup_iter = bam_plp_init( &__advance_snpcalls, &self.iterdata )
  *         else:
  *             raise ValueError( "unknown stepper option `%s` in IteratorColumn" % self.stepper)             # <<<<<<<<<<<<<<
  * 
  *         if self.max_depth:
  */
-    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_139), __pyx_v_self->stepper); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_138), __pyx_v_self->stepper); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
-    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
     __pyx_t_4 = 0;
-    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
     __Pyx_Raise(__pyx_t_4, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":2047
+  /* "pysam/csamtools.pyx":2050
  *             raise ValueError( "unknown stepper option `%s` in IteratorColumn" % self.stepper)
  * 
  *         if self.max_depth:             # <<<<<<<<<<<<<<
@@ -21009,7 +21753,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
  */
   if (__pyx_v_self->max_depth) {
 
-    /* "pysam/csamtools.pyx":2048
+    /* "pysam/csamtools.pyx":2051
  * 
  *         if self.max_depth:
  *             bam_plp_set_maxcnt( self.pileup_iter, self.max_depth )             # <<<<<<<<<<<<<<
@@ -21021,7 +21765,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
   }
   __pyx_L5:;
 
-  /* "pysam/csamtools.pyx":2050
+  /* "pysam/csamtools.pyx":2053
  *             bam_plp_set_maxcnt( self.pileup_iter, self.max_depth )
  * 
  *         bam_plp_set_mask( self.pileup_iter, self.mask )             # <<<<<<<<<<<<<<
@@ -21047,7 +21791,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData(st
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2052
+/* "pysam/csamtools.pyx":2055
  *         bam_plp_set_mask( self.pileup_iter, self.mask )
  * 
  *     cdef reset( self, tid, start, end ):             # <<<<<<<<<<<<<<
@@ -21068,16 +21812,16 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_reset(struct __pyx_o
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("reset", 0);
-  __Pyx_TraceCall("reset", __pyx_f[0], 2052);
+  __Pyx_TraceCall("reset", __pyx_f[0], 2055);
 
-  /* "pysam/csamtools.pyx":2058
+  /* "pysam/csamtools.pyx":2061
  *         having to incur the full set-up costs.
  *         '''
  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen = 0 )             # <<<<<<<<<<<<<<
  *         self.iterdata.iter = self.iter.iter
  * 
  */
-  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
   PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->samfile));
@@ -21091,10 +21835,10 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_reset(struct __pyx_o
   __Pyx_INCREF(__pyx_v_end);
   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_end);
   __Pyx_GIVEREF(__pyx_v_end);
-  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reopen), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowRegion)), ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reopen), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowRegion)), ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
@@ -21104,7 +21848,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_reset(struct __pyx_o
   __pyx_v_self->iter = ((struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *)__pyx_t_3);
   __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":2059
+  /* "pysam/csamtools.pyx":2062
  *         '''
  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen = 0 )
  *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
@@ -21114,22 +21858,22 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_reset(struct __pyx_o
   __pyx_t_4 = __pyx_v_self->iter->iter;
   __pyx_v_self->iterdata.iter = __pyx_t_4;
 
-  /* "pysam/csamtools.pyx":2062
+  /* "pysam/csamtools.pyx":2065
  * 
  *         # invalidate sequence if different tid
  *         if self.tid != tid:             # <<<<<<<<<<<<<<
  *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
  *             self.iterdata.seq = NULL
  */
-  __pyx_t_3 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_v_tid, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_v_tid, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   if (__pyx_t_5) {
 
-    /* "pysam/csamtools.pyx":2063
+    /* "pysam/csamtools.pyx":2066
  *         # invalidate sequence if different tid
  *         if self.tid != tid:
  *             if self.iterdata.seq != NULL: free( self.iterdata.seq )             # <<<<<<<<<<<<<<
@@ -21143,7 +21887,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_reset(struct __pyx_o
     }
     __pyx_L4:;
 
-    /* "pysam/csamtools.pyx":2064
+    /* "pysam/csamtools.pyx":2067
  *         if self.tid != tid:
  *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
  *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
@@ -21152,7 +21896,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_reset(struct __pyx_o
  */
     __pyx_v_self->iterdata.seq = NULL;
 
-    /* "pysam/csamtools.pyx":2065
+    /* "pysam/csamtools.pyx":2068
  *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
  *             self.iterdata.seq = NULL
  *             self.iterdata.tid = -1             # <<<<<<<<<<<<<<
@@ -21164,7 +21908,7 @@ static PyObject *__pyx_f_5pysam_9csamtools_14IteratorColumn_reset(struct __pyx_o
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2068
+  /* "pysam/csamtools.pyx":2071
  * 
  *         # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata )
  *         bam_plp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
@@ -21197,7 +21941,7 @@ static void __pyx_pw_5pysam_9csamtools_14IteratorColumn_9__dealloc__(PyObject *_
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/csamtools.pyx":2070
+/* "pysam/csamtools.pyx":2073
  *         bam_plp_reset(self.pileup_iter)
  * 
  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
@@ -21210,9 +21954,9 @@ static void __pyx_pf_5pysam_9csamtools_14IteratorColumn_8__dealloc__(struct __py
   int __pyx_t_1;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__dealloc__", 0);
-  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2070);
+  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2073);
 
-  /* "pysam/csamtools.pyx":2073
+  /* "pysam/csamtools.pyx":2076
  *         # reset in order to avoid memory leak messages for iterators
  *         # that have not been fully consumed
  *         if self.pileup_iter != <bam_plp_t>NULL:             # <<<<<<<<<<<<<<
@@ -21222,7 +21966,7 @@ static void __pyx_pf_5pysam_9csamtools_14IteratorColumn_8__dealloc__(struct __py
   __pyx_t_1 = (__pyx_v_self->pileup_iter != NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":2074
+    /* "pysam/csamtools.pyx":2077
  *         # that have not been fully consumed
  *         if self.pileup_iter != <bam_plp_t>NULL:
  *             bam_plp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
@@ -21231,7 +21975,7 @@ static void __pyx_pf_5pysam_9csamtools_14IteratorColumn_8__dealloc__(struct __py
  */
     bam_plp_reset(__pyx_v_self->pileup_iter);
 
-    /* "pysam/csamtools.pyx":2075
+    /* "pysam/csamtools.pyx":2078
  *         if self.pileup_iter != <bam_plp_t>NULL:
  *             bam_plp_reset(self.pileup_iter)
  *             bam_plp_destroy(self.pileup_iter)             # <<<<<<<<<<<<<<
@@ -21240,7 +21984,7 @@ static void __pyx_pf_5pysam_9csamtools_14IteratorColumn_8__dealloc__(struct __py
  */
     bam_plp_destroy(__pyx_v_self->pileup_iter);
 
-    /* "pysam/csamtools.pyx":2076
+    /* "pysam/csamtools.pyx":2079
  *             bam_plp_reset(self.pileup_iter)
  *             bam_plp_destroy(self.pileup_iter)
  *             self.pileup_iter = <bam_plp_t>NULL             # <<<<<<<<<<<<<<
@@ -21249,7 +21993,7 @@ static void __pyx_pf_5pysam_9csamtools_14IteratorColumn_8__dealloc__(struct __py
  */
     __pyx_v_self->pileup_iter = NULL;
 
-    /* "pysam/csamtools.pyx":2077
+    /* "pysam/csamtools.pyx":2080
  *             bam_plp_destroy(self.pileup_iter)
  *             self.pileup_iter = <bam_plp_t>NULL
  *             self.plp = <const_bam_pileup1_t_ptr>NULL             # <<<<<<<<<<<<<<
@@ -21261,7 +22005,7 @@ static void __pyx_pf_5pysam_9csamtools_14IteratorColumn_8__dealloc__(struct __py
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2079
+  /* "pysam/csamtools.pyx":2082
  *             self.plp = <const_bam_pileup1_t_ptr>NULL
  * 
  *         if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
@@ -21271,7 +22015,7 @@ static void __pyx_pf_5pysam_9csamtools_14IteratorColumn_8__dealloc__(struct __py
   __pyx_t_1 = (__pyx_v_self->iterdata.seq != NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":2080
+    /* "pysam/csamtools.pyx":2083
  * 
  *         if self.iterdata.seq != NULL:
  *             free(self.iterdata.seq)             # <<<<<<<<<<<<<<
@@ -21280,7 +22024,7 @@ static void __pyx_pf_5pysam_9csamtools_14IteratorColumn_8__dealloc__(struct __py
  */
     free(__pyx_v_self->iterdata.seq);
 
-    /* "pysam/csamtools.pyx":2081
+    /* "pysam/csamtools.pyx":2084
  *         if self.iterdata.seq != NULL:
  *             free(self.iterdata.seq)
  *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
@@ -21352,7 +22096,7 @@ static int __pyx_pw_5pysam_9csamtools_20IteratorColumnRegion_1__cinit__(PyObject
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2086; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2089; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -21367,25 +22111,25 @@ static int __pyx_pw_5pysam_9csamtools_20IteratorColumnRegion_1__cinit__(PyObject
     }
     __pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)values[0]);
     if (values[1]) {
-      __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2087; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2090; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
       __pyx_v_tid = ((int)0);
     }
     if (values[2]) {
-      __pyx_v_start = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2088; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_start = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2091; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
       __pyx_v_start = ((int)0);
     }
     if (values[3]) {
-      __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2089; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2092; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
-      __pyx_v_end = __pyx_k_140;
+      __pyx_v_end = __pyx_k_139;
     }
     if (values[4]) {
-      __pyx_v_truncate = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_truncate == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2090; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_truncate = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_truncate == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2093; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
 
-      /* "pysam/csamtools.pyx":2090
+      /* "pysam/csamtools.pyx":2093
  *                   int start = 0,
  *                   int end = max_pos,
  *                   int truncate = False,             # <<<<<<<<<<<<<<
@@ -21397,14 +22141,14 @@ static int __pyx_pw_5pysam_9csamtools_20IteratorColumnRegion_1__cinit__(PyObject
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2086; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2089; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
   __Pyx_AddTraceback("pysam.csamtools.IteratorColumnRegion.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_20IteratorColumnRegion___cinit__(((struct __pyx_obj_5pysam_9csamtools_IteratorColumnRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_start, __pyx_v_end, __pyx_v_truncate, __pyx_v_kwargs);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -21415,7 +22159,7 @@ static int __pyx_pw_5pysam_9csamtools_20IteratorColumnRegion_1__cinit__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2086
+/* "pysam/csamtools.pyx":2089
  *     '''iterates over a region only.
  *     '''
  *     def __cinit__(self, Samfile samfile,             # <<<<<<<<<<<<<<
@@ -21433,9 +22177,9 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorColumnRegion___cinit__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__cinit__", 0);
-  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2086);
+  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2089);
 
-  /* "pysam/csamtools.pyx":2094
+  /* "pysam/csamtools.pyx":2097
  * 
  *         # initialize iterator
  *         self.setupIteratorData( tid, start, end, 1 )             # <<<<<<<<<<<<<<
@@ -21444,11 +22188,11 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorColumnRegion___cinit__(struct __
  */
   __pyx_t_2.__pyx_n = 1;
   __pyx_t_2.reopen = 1;
-  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_9csamtools_IteratorColumn *)__pyx_v_self), __pyx_v_tid, __pyx_v_start, __pyx_v_end, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2094; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_9csamtools_IteratorColumn *)__pyx_v_self), __pyx_v_tid, __pyx_v_start, __pyx_v_end, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":2095
+  /* "pysam/csamtools.pyx":2098
  *         # initialize iterator
  *         self.setupIteratorData( tid, start, end, 1 )
  *         self.start = start             # <<<<<<<<<<<<<<
@@ -21457,7 +22201,7 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorColumnRegion___cinit__(struct __
  */
   __pyx_v_self->start = __pyx_v_start;
 
-  /* "pysam/csamtools.pyx":2096
+  /* "pysam/csamtools.pyx":2099
  *         self.setupIteratorData( tid, start, end, 1 )
  *         self.start = start
  *         self.end = end             # <<<<<<<<<<<<<<
@@ -21466,7 +22210,7 @@ static int __pyx_pf_5pysam_9csamtools_20IteratorColumnRegion___cinit__(struct __
  */
   __pyx_v_self->end = __pyx_v_end;
 
-  /* "pysam/csamtools.pyx":2097
+  /* "pysam/csamtools.pyx":2100
  *         self.start = start
  *         self.end = end
  *         self.truncate = truncate             # <<<<<<<<<<<<<<
@@ -21502,7 +22246,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_20IteratorColumnRegion_3__next__(PyO
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2099
+/* "pysam/csamtools.pyx":2102
  *         self.truncate = truncate
  * 
  *     def __next__(self):             # <<<<<<<<<<<<<<
@@ -21520,9 +22264,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorColumnRegion_2__next__(str
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__next__", 0);
-  __Pyx_TraceCall("__next__", __pyx_f[0], 2099);
+  __Pyx_TraceCall("__next__", __pyx_f[0], 2102);
 
-  /* "pysam/csamtools.pyx":2103
+  /* "pysam/csamtools.pyx":2106
  *         """
  * 
  *         while 1:             # <<<<<<<<<<<<<<
@@ -21532,7 +22276,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorColumnRegion_2__next__(str
   while (1) {
     if (!1) break;
 
-    /* "pysam/csamtools.pyx":2104
+    /* "pysam/csamtools.pyx":2107
  * 
  *         while 1:
  *             self.cnext()             # <<<<<<<<<<<<<<
@@ -21541,7 +22285,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorColumnRegion_2__next__(str
  */
     ((struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_9csamtools_IteratorColumn *)__pyx_v_self));
 
-    /* "pysam/csamtools.pyx":2105
+    /* "pysam/csamtools.pyx":2108
  *         while 1:
  *             self.cnext()
  *             if self.n_plp < 0:             # <<<<<<<<<<<<<<
@@ -21551,23 +22295,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorColumnRegion_2__next__(str
     __pyx_t_1 = (__pyx_v_self->__pyx_base.n_plp < 0);
     if (__pyx_t_1) {
 
-      /* "pysam/csamtools.pyx":2106
+      /* "pysam/csamtools.pyx":2109
  *             self.cnext()
  *             if self.n_plp < 0:
  *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
  * 
  *             if self.plp == NULL:
  */
-      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_142), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_141), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2109; __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 = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L5;
     }
     __pyx_L5:;
 
-    /* "pysam/csamtools.pyx":2108
+    /* "pysam/csamtools.pyx":2111
  *                 raise ValueError("error during iteration" )
  * 
  *             if self.plp == NULL:             # <<<<<<<<<<<<<<
@@ -21577,7 +22321,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorColumnRegion_2__next__(str
     __pyx_t_1 = (__pyx_v_self->__pyx_base.plp == NULL);
     if (__pyx_t_1) {
 
-      /* "pysam/csamtools.pyx":2109
+      /* "pysam/csamtools.pyx":2112
  * 
  *             if self.plp == NULL:
  *                 raise StopIteration             # <<<<<<<<<<<<<<
@@ -21585,12 +22329,12 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorColumnRegion_2__next__(str
  *             if self.truncate:
  */
       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L6;
     }
     __pyx_L6:;
 
-    /* "pysam/csamtools.pyx":2111
+    /* "pysam/csamtools.pyx":2114
  *                 raise StopIteration
  * 
  *             if self.truncate:             # <<<<<<<<<<<<<<
@@ -21599,7 +22343,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorColumnRegion_2__next__(str
  */
     if (__pyx_v_self->truncate) {
 
-      /* "pysam/csamtools.pyx":2112
+      /* "pysam/csamtools.pyx":2115
  * 
  *             if self.truncate:
  *                 if self.start > self.pos: continue             # <<<<<<<<<<<<<<
@@ -21613,7 +22357,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorColumnRegion_2__next__(str
       }
       __pyx_L8:;
 
-      /* "pysam/csamtools.pyx":2113
+      /* "pysam/csamtools.pyx":2116
  *             if self.truncate:
  *                 if self.start > self.pos: continue
  *                 if self.pos >= self.end: raise StopIteration             # <<<<<<<<<<<<<<
@@ -21623,7 +22367,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorColumnRegion_2__next__(str
       __pyx_t_1 = (__pyx_v_self->__pyx_base.pos >= __pyx_v_self->end);
       if (__pyx_t_1) {
         __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         goto __pyx_L9;
       }
       __pyx_L9:;
@@ -21631,7 +22375,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorColumnRegion_2__next__(str
     }
     __pyx_L7:;
 
-    /* "pysam/csamtools.pyx":2115
+    /* "pysam/csamtools.pyx":2118
  *                 if self.pos >= self.end: raise StopIteration
  * 
  *             return makePileupProxy( &self.plp,             # <<<<<<<<<<<<<<
@@ -21640,14 +22384,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_20IteratorColumnRegion_2__next__(str
  */
     __Pyx_XDECREF(__pyx_r);
 
-    /* "pysam/csamtools.pyx":2118
+    /* "pysam/csamtools.pyx":2121
  *                                      self.tid,
  *                                      self.pos,
  *                                      self.n_plp )             # <<<<<<<<<<<<<<
  * 
  * cdef class IteratorColumnAllRefs(IteratorColumn):
  */
-    __pyx_t_2 = __pyx_f_5pysam_9csamtools_makePileupProxy((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __pyx_f_5pysam_9csamtools_makePileupProxy((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __pyx_r = __pyx_t_2;
     __pyx_t_2 = 0;
@@ -21696,7 +22440,7 @@ static int __pyx_pw_5pysam_9csamtools_21IteratorColumnAllRefs_1__cinit__(PyObjec
         else goto __pyx_L5_argtuple_error;
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2124; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2127; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
       goto __pyx_L5_argtuple_error;
@@ -21707,14 +22451,14 @@ static int __pyx_pw_5pysam_9csamtools_21IteratorColumnAllRefs_1__cinit__(PyObjec
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2124; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2127; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
   __Pyx_AddTraceback("pysam.csamtools.IteratorColumnAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs___cinit__(((struct __pyx_obj_5pysam_9csamtools_IteratorColumnAllRefs *)__pyx_v_self), __pyx_v_samfile, __pyx_v_kwargs);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -21725,7 +22469,7 @@ static int __pyx_pw_5pysam_9csamtools_21IteratorColumnAllRefs_1__cinit__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2124
+/* "pysam/csamtools.pyx":2127
  *     """
  * 
  *     def __cinit__(self,             # <<<<<<<<<<<<<<
@@ -21745,28 +22489,28 @@ static int __pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs___cinit__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__cinit__", 0);
-  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2124);
+  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2127);
 
-  /* "pysam/csamtools.pyx":2129
+  /* "pysam/csamtools.pyx":2132
  * 
  *         # no iteration over empty files
  *         if not samfile.nreferences: raise StopIteration             # <<<<<<<<<<<<<<
  * 
  *         # initialize iterator
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__nreferences); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__nreferences); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __pyx_t_3 = (!__pyx_t_2);
   if (__pyx_t_3) {
     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2132
+  /* "pysam/csamtools.pyx":2135
  * 
  *         # initialize iterator
  *         self.setupIteratorData( self.tid, 0, max_pos, 1 )             # <<<<<<<<<<<<<<
@@ -21775,7 +22519,7 @@ static int __pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs___cinit__(struct _
  */
   __pyx_t_4.__pyx_n = 1;
   __pyx_t_4.reopen = 1;
-  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_9csamtools_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_9csamtools_max_pos, &__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_9csamtools_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_9csamtools_max_pos, &__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
@@ -21806,7 +22550,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_21IteratorColumnAllRefs_3__next__(Py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2134
+/* "pysam/csamtools.pyx":2137
  *         self.setupIteratorData( self.tid, 0, max_pos, 1 )
  * 
  *     def __next__(self):             # <<<<<<<<<<<<<<
@@ -21827,9 +22571,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__(st
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__next__", 0);
-  __Pyx_TraceCall("__next__", __pyx_f[0], 2134);
+  __Pyx_TraceCall("__next__", __pyx_f[0], 2137);
 
-  /* "pysam/csamtools.pyx":2138
+  /* "pysam/csamtools.pyx":2141
  *         """
  * 
  *         while 1:             # <<<<<<<<<<<<<<
@@ -21839,7 +22583,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__(st
   while (1) {
     if (!1) break;
 
-    /* "pysam/csamtools.pyx":2139
+    /* "pysam/csamtools.pyx":2142
  * 
  *         while 1:
  *             self.cnext()             # <<<<<<<<<<<<<<
@@ -21848,7 +22592,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__(st
  */
     ((struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_9csamtools_IteratorColumn *)__pyx_v_self));
 
-    /* "pysam/csamtools.pyx":2141
+    /* "pysam/csamtools.pyx":2144
  *             self.cnext()
  * 
  *             if self.n_plp < 0:             # <<<<<<<<<<<<<<
@@ -21858,23 +22602,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__(st
     __pyx_t_1 = (__pyx_v_self->__pyx_base.n_plp < 0);
     if (__pyx_t_1) {
 
-      /* "pysam/csamtools.pyx":2142
+      /* "pysam/csamtools.pyx":2145
  * 
  *             if self.n_plp < 0:
  *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
  * 
  *             # return result, if within same reference
  */
-      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_143), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_142), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2145; __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 = 2142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L5;
     }
     __pyx_L5:;
 
-    /* "pysam/csamtools.pyx":2145
+    /* "pysam/csamtools.pyx":2148
  * 
  *             # return result, if within same reference
  *             if self.plp != NULL:             # <<<<<<<<<<<<<<
@@ -21884,7 +22628,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__(st
     __pyx_t_1 = (__pyx_v_self->__pyx_base.plp != NULL);
     if (__pyx_t_1) {
 
-      /* "pysam/csamtools.pyx":2146
+      /* "pysam/csamtools.pyx":2149
  *             # return result, if within same reference
  *             if self.plp != NULL:
  *                 return makePileupProxy( &self.plp,             # <<<<<<<<<<<<<<
@@ -21893,14 +22637,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__(st
  */
       __Pyx_XDECREF(__pyx_r);
 
-      /* "pysam/csamtools.pyx":2149
+      /* "pysam/csamtools.pyx":2152
  *                                          self.tid,
  *                                          self.pos,
  *                                          self.n_plp )             # <<<<<<<<<<<<<<
  * 
  *             # otherwise, proceed to next reference or stop
  */
-      __pyx_t_2 = __pyx_f_5pysam_9csamtools_makePileupProxy((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __pyx_f_5pysam_9csamtools_makePileupProxy((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __pyx_r = __pyx_t_2;
       __pyx_t_2 = 0;
@@ -21909,7 +22653,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__(st
     }
     __pyx_L6:;
 
-    /* "pysam/csamtools.pyx":2152
+    /* "pysam/csamtools.pyx":2155
  * 
  *             # otherwise, proceed to next reference or stop
  *             self.tid += 1             # <<<<<<<<<<<<<<
@@ -21918,25 +22662,25 @@ static PyObject *__pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__(st
  */
     __pyx_v_self->__pyx_base.tid = (__pyx_v_self->__pyx_base.tid + 1);
 
-    /* "pysam/csamtools.pyx":2153
+    /* "pysam/csamtools.pyx":2156
  *             # otherwise, proceed to next reference or stop
  *             self.tid += 1
  *             if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
  *                 self.setupIteratorData( self.tid, 0, max_pos, 0 )
  *             else:
  */
-    __pyx_t_2 = PyInt_FromLong(__pyx_v_self->__pyx_base.tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyInt_FromLong(__pyx_v_self->__pyx_base.tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s__nreferences); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s__nreferences); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
     if (__pyx_t_1) {
 
-      /* "pysam/csamtools.pyx":2154
+      /* "pysam/csamtools.pyx":2157
  *             self.tid += 1
  *             if self.tid < self.samfile.nreferences:
  *                 self.setupIteratorData( self.tid, 0, max_pos, 0 )             # <<<<<<<<<<<<<<
@@ -21945,14 +22689,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__(st
  */
       __pyx_t_5.__pyx_n = 1;
       __pyx_t_5.reopen = 0;
-      __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_9csamtools_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_9csamtools_max_pos, &__pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_9csamtools_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_9csamtools_max_pos, &__pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_4);
       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
       goto __pyx_L7;
     }
     /*else*/ {
 
-      /* "pysam/csamtools.pyx":2156
+      /* "pysam/csamtools.pyx":2159
  *                 self.setupIteratorData( self.tid, 0, max_pos, 0 )
  *             else:
  *                 raise StopIteration             # <<<<<<<<<<<<<<
@@ -21960,7 +22704,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__(st
  * ##-------------------------------------------------------------------
  */
       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     __pyx_L7:;
   }
@@ -21980,7 +22724,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__(st
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2161
+/* "pysam/csamtools.pyx":2164
  * ##-------------------------------------------------------------------
  * ##-------------------------------------------------------------------
  * cdef inline int32_t query_start(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
@@ -22001,9 +22745,9 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
   int __pyx_t_4;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("query_start", 0);
-  __Pyx_TraceCall("query_start", __pyx_f[0], 2161);
+  __Pyx_TraceCall("query_start", __pyx_f[0], 2164);
 
-  /* "pysam/csamtools.pyx":2164
+  /* "pysam/csamtools.pyx":2167
  *     cdef uint32_t * cigar_p, op
  *     cdef uint32_t k
  *     cdef uint32_t start_offset = 0             # <<<<<<<<<<<<<<
@@ -22012,7 +22756,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
  */
   __pyx_v_start_offset = 0;
 
-  /* "pysam/csamtools.pyx":2166
+  /* "pysam/csamtools.pyx":2169
  *     cdef uint32_t start_offset = 0
  * 
  *     if src.core.n_cigar:             # <<<<<<<<<<<<<<
@@ -22021,7 +22765,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
  */
   if (__pyx_v_src->core.n_cigar) {
 
-    /* "pysam/csamtools.pyx":2167
+    /* "pysam/csamtools.pyx":2170
  * 
  *     if src.core.n_cigar:
  *         cigar_p = bam1_cigar(src);             # <<<<<<<<<<<<<<
@@ -22030,7 +22774,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
  */
     __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
 
-    /* "pysam/csamtools.pyx":2168
+    /* "pysam/csamtools.pyx":2171
  *     if src.core.n_cigar:
  *         cigar_p = bam1_cigar(src);
  *         for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
@@ -22040,7 +22784,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
     __pyx_t_1 = __pyx_v_src->core.n_cigar;
     for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_1; __pyx_v_k++) {
 
-      /* "pysam/csamtools.pyx":2169
+      /* "pysam/csamtools.pyx":2172
  *         cigar_p = bam1_cigar(src);
  *         for k from 0 <= k < src.core.n_cigar:
  *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
@@ -22049,7 +22793,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
  */
       __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
 
-      /* "pysam/csamtools.pyx":2174
+      /* "pysam/csamtools.pyx":2177
  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
  *                     return -1
  *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
@@ -22058,7 +22802,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
  */
       switch (__pyx_v_op) {
 
-        /* "pysam/csamtools.pyx":2170
+        /* "pysam/csamtools.pyx":2173
  *         for k from 0 <= k < src.core.n_cigar:
  *             op = cigar_p[k] & BAM_CIGAR_MASK
  *             if op==BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
@@ -22067,7 +22811,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
  */
         case 5:
 
-        /* "pysam/csamtools.pyx":2171
+        /* "pysam/csamtools.pyx":2174
  *             op = cigar_p[k] & BAM_CIGAR_MASK
  *             if op==BAM_CHARD_CLIP:
  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:             # <<<<<<<<<<<<<<
@@ -22083,16 +22827,16 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
         }
         if (__pyx_t_4) {
 
-          /* "pysam/csamtools.pyx":2172
+          /* "pysam/csamtools.pyx":2175
  *             if op==BAM_CHARD_CLIP:
  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')             # <<<<<<<<<<<<<<
  *                     return -1
  *             elif op==BAM_CSOFT_CLIP:
  */
-          PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_144);
+          PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_143);
 
-          /* "pysam/csamtools.pyx":2173
+          /* "pysam/csamtools.pyx":2176
  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
  *                     return -1             # <<<<<<<<<<<<<<
@@ -22106,7 +22850,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
         __pyx_L6:;
         break;
 
-        /* "pysam/csamtools.pyx":2174
+        /* "pysam/csamtools.pyx":2177
  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
  *                     return -1
  *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
@@ -22115,7 +22859,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
  */
         case 4:
 
-        /* "pysam/csamtools.pyx":2175
+        /* "pysam/csamtools.pyx":2178
  *                     return -1
  *             elif op==BAM_CSOFT_CLIP:
  *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
@@ -22126,7 +22870,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
         break;
         default:
 
-        /* "pysam/csamtools.pyx":2177
+        /* "pysam/csamtools.pyx":2180
  *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
  *             else:
  *                 break             # <<<<<<<<<<<<<<
@@ -22142,7 +22886,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2179
+  /* "pysam/csamtools.pyx":2182
  *                 break
  * 
  *     return start_offset             # <<<<<<<<<<<<<<
@@ -22159,7 +22903,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_start(bam1_t *__pyx
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2184
+/* "pysam/csamtools.pyx":2187
  * ##-------------------------------------------------------------------
  * ##-------------------------------------------------------------------
  * cdef inline int32_t query_end(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
@@ -22180,9 +22924,9 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
   int __pyx_t_4;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("query_end", 0);
-  __Pyx_TraceCall("query_end", __pyx_f[0], 2184);
+  __Pyx_TraceCall("query_end", __pyx_f[0], 2187);
 
-  /* "pysam/csamtools.pyx":2187
+  /* "pysam/csamtools.pyx":2190
  *     cdef uint32_t * cigar_p, op
  *     cdef uint32_t k
  *     cdef uint32_t end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
@@ -22192,7 +22936,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
   __pyx_t_1 = __pyx_v_src->core.l_qseq;
   __pyx_v_end_offset = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2189
+  /* "pysam/csamtools.pyx":2192
  *     cdef uint32_t end_offset = src.core.l_qseq
  * 
  *     if src.core.n_cigar>1:             # <<<<<<<<<<<<<<
@@ -22202,7 +22946,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
   __pyx_t_2 = (__pyx_v_src->core.n_cigar > 1);
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":2190
+    /* "pysam/csamtools.pyx":2193
  * 
  *     if src.core.n_cigar>1:
  *         cigar_p = bam1_cigar(src);             # <<<<<<<<<<<<<<
@@ -22211,7 +22955,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
  */
     __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
 
-    /* "pysam/csamtools.pyx":2191
+    /* "pysam/csamtools.pyx":2194
  *     if src.core.n_cigar>1:
  *         cigar_p = bam1_cigar(src);
  *         for k from src.core.n_cigar > k >= 1:             # <<<<<<<<<<<<<<
@@ -22220,7 +22964,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
  */
     for (__pyx_v_k = __pyx_v_src->core.n_cigar-1; __pyx_v_k >= 1; __pyx_v_k--) {
 
-      /* "pysam/csamtools.pyx":2192
+      /* "pysam/csamtools.pyx":2195
  *         cigar_p = bam1_cigar(src);
  *         for k from src.core.n_cigar > k >= 1:
  *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
@@ -22229,7 +22973,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
  */
       __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
 
-      /* "pysam/csamtools.pyx":2197
+      /* "pysam/csamtools.pyx":2200
  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
  *                     return -1
  *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
@@ -22238,7 +22982,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
  */
       switch (__pyx_v_op) {
 
-        /* "pysam/csamtools.pyx":2193
+        /* "pysam/csamtools.pyx":2196
  *         for k from src.core.n_cigar > k >= 1:
  *             op = cigar_p[k] & BAM_CIGAR_MASK
  *             if op==BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
@@ -22247,7 +22991,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
  */
         case 5:
 
-        /* "pysam/csamtools.pyx":2194
+        /* "pysam/csamtools.pyx":2197
  *             op = cigar_p[k] & BAM_CIGAR_MASK
  *             if op==BAM_CHARD_CLIP:
  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:             # <<<<<<<<<<<<<<
@@ -22263,16 +23007,16 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
         }
         if (__pyx_t_4) {
 
-          /* "pysam/csamtools.pyx":2195
+          /* "pysam/csamtools.pyx":2198
  *             if op==BAM_CHARD_CLIP:
  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')             # <<<<<<<<<<<<<<
  *                     return -1
  *             elif op==BAM_CSOFT_CLIP:
  */
-          PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_144);
+          PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_143);
 
-          /* "pysam/csamtools.pyx":2196
+          /* "pysam/csamtools.pyx":2199
  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
  *                     return -1             # <<<<<<<<<<<<<<
@@ -22286,7 +23030,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
         __pyx_L6:;
         break;
 
-        /* "pysam/csamtools.pyx":2197
+        /* "pysam/csamtools.pyx":2200
  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
  *                     return -1
  *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
@@ -22295,7 +23039,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
  */
         case 4:
 
-        /* "pysam/csamtools.pyx":2198
+        /* "pysam/csamtools.pyx":2201
  *                     return -1
  *             elif op==BAM_CSOFT_CLIP:
  *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
@@ -22306,7 +23050,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
         break;
         default:
 
-        /* "pysam/csamtools.pyx":2200
+        /* "pysam/csamtools.pyx":2203
  *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
  *             else:
  *                 break             # <<<<<<<<<<<<<<
@@ -22322,7 +23066,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2202
+  /* "pysam/csamtools.pyx":2205
  *                 break
  * 
  *     if end_offset==0:             # <<<<<<<<<<<<<<
@@ -22332,7 +23076,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
   __pyx_t_4 = (__pyx_v_end_offset == 0);
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":2203
+    /* "pysam/csamtools.pyx":2206
  * 
  *     if end_offset==0:
  *         end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
@@ -22345,7 +23089,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
   }
   __pyx_L7:;
 
-  /* "pysam/csamtools.pyx":2205
+  /* "pysam/csamtools.pyx":2208
  *         end_offset = src.core.l_qseq
  * 
  *     return end_offset             # <<<<<<<<<<<<<<
@@ -22362,7 +23106,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_9csamtools_query_end(bam1_t *__pyx_v
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2208
+/* "pysam/csamtools.pyx":2211
  * 
  * 
  * cdef inline object get_seq_range(bam1_t *src, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
@@ -22386,9 +23130,9 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_seq_range(bam1_t *_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("get_seq_range", 0);
-  __Pyx_TraceCall("get_seq_range", __pyx_f[0], 2208);
+  __Pyx_TraceCall("get_seq_range", __pyx_f[0], 2211);
 
-  /* "pysam/csamtools.pyx":2213
+  /* "pysam/csamtools.pyx":2216
  *     cdef char * s
  * 
  *     if not src.core.l_qseq:             # <<<<<<<<<<<<<<
@@ -22398,7 +23142,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_seq_range(bam1_t *_
   __pyx_t_1 = (!__pyx_v_src->core.l_qseq);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":2214
+    /* "pysam/csamtools.pyx":2217
  * 
  *     if not src.core.l_qseq:
  *         return None             # <<<<<<<<<<<<<<
@@ -22413,29 +23157,29 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_seq_range(bam1_t *_
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2216
+  /* "pysam/csamtools.pyx":2219
  *         return None
  * 
  *     seq = PyBytes_FromStringAndSize(NULL, end - start)             # <<<<<<<<<<<<<<
  *     s   = <char*>seq
  *     p   = bam1_seq(src)
  */
-  __pyx_t_2 = ((PyObject *)PyBytes_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = ((PyObject *)PyBytes_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_v_seq = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":2217
+  /* "pysam/csamtools.pyx":2220
  * 
  *     seq = PyBytes_FromStringAndSize(NULL, end - start)
  *     s   = <char*>seq             # <<<<<<<<<<<<<<
  *     p   = bam1_seq(src)
  * 
  */
-  __pyx_t_3 = PyBytes_AsString(((PyObject *)__pyx_v_seq)); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyBytes_AsString(((PyObject *)__pyx_v_seq)); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_s = ((char *)__pyx_t_3);
 
-  /* "pysam/csamtools.pyx":2218
+  /* "pysam/csamtools.pyx":2221
  *     seq = PyBytes_FromStringAndSize(NULL, end - start)
  *     s   = <char*>seq
  *     p   = bam1_seq(src)             # <<<<<<<<<<<<<<
@@ -22444,7 +23188,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_seq_range(bam1_t *_
  */
   __pyx_v_p = bam1_seq(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":2220
+  /* "pysam/csamtools.pyx":2223
  *     p   = bam1_seq(src)
  * 
  *     for k from start <= k < end:             # <<<<<<<<<<<<<<
@@ -22454,7 +23198,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_seq_range(bam1_t *_
   __pyx_t_4 = __pyx_v_end;
   for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {
 
-    /* "pysam/csamtools.pyx":2223
+    /* "pysam/csamtools.pyx":2226
  *         # equivalent to bam_nt16_rev_table[bam1_seqi(s, i)] (see bam.c)
  *         # note: do not use string literal as it will be a python string
  *         s[k-start] = bam_nt16_rev_table[p[k/2] >> 4 * (1 - k%2) & 0xf]             # <<<<<<<<<<<<<<
@@ -22464,7 +23208,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_seq_range(bam1_t *_
     (__pyx_v_s[(__pyx_v_k - __pyx_v_start)]) = (__pyx_v_5pysam_9csamtools_bam_nt16_rev_table[(((__pyx_v_p[__Pyx_div_long(__pyx_v_k, 2)]) >> (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2)))) & 0xf)]);
   }
 
-  /* "pysam/csamtools.pyx":2225
+  /* "pysam/csamtools.pyx":2228
  *         s[k-start] = bam_nt16_rev_table[p[k/2] >> 4 * (1 - k%2) & 0xf]
  * 
  *     return seq             # <<<<<<<<<<<<<<
@@ -22490,7 +23234,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_seq_range(bam1_t *_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2228
+/* "pysam/csamtools.pyx":2231
  * 
  * 
  * cdef inline object get_qual_range(bam1_t *src, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
@@ -22514,9 +23258,9 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_qual_range(bam1_t *
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("get_qual_range", 0);
-  __Pyx_TraceCall("get_qual_range", __pyx_f[0], 2228);
+  __Pyx_TraceCall("get_qual_range", __pyx_f[0], 2231);
 
-  /* "pysam/csamtools.pyx":2233
+  /* "pysam/csamtools.pyx":2236
  *     cdef char * q
  * 
  *     p = bam1_qual(src)             # <<<<<<<<<<<<<<
@@ -22525,7 +23269,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_qual_range(bam1_t *
  */
   __pyx_v_p = bam1_qual(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":2234
+  /* "pysam/csamtools.pyx":2237
  * 
  *     p = bam1_qual(src)
  *     if p[0] == 0xff:             # <<<<<<<<<<<<<<
@@ -22535,7 +23279,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_qual_range(bam1_t *
   __pyx_t_1 = ((__pyx_v_p[0]) == 0xff);
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":2235
+    /* "pysam/csamtools.pyx":2238
  *     p = bam1_qual(src)
  *     if p[0] == 0xff:
  *         return None             # <<<<<<<<<<<<<<
@@ -22550,29 +23294,29 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_qual_range(bam1_t *
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2237
+  /* "pysam/csamtools.pyx":2240
  *         return None
  * 
  *     qual = PyBytes_FromStringAndSize(NULL, end - start)             # <<<<<<<<<<<<<<
  *     q    = <char*>qual
  * 
  */
-  __pyx_t_2 = ((PyObject *)PyBytes_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = ((PyObject *)PyBytes_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_v_qual = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":2238
+  /* "pysam/csamtools.pyx":2241
  * 
  *     qual = PyBytes_FromStringAndSize(NULL, end - start)
  *     q    = <char*>qual             # <<<<<<<<<<<<<<
  * 
  *     for k from start <= k < end:
  */
-  __pyx_t_3 = PyBytes_AsString(((PyObject *)__pyx_v_qual)); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyBytes_AsString(((PyObject *)__pyx_v_qual)); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_q = ((char *)__pyx_t_3);
 
-  /* "pysam/csamtools.pyx":2240
+  /* "pysam/csamtools.pyx":2243
  *     q    = <char*>qual
  * 
  *     for k from start <= k < end:             # <<<<<<<<<<<<<<
@@ -22582,7 +23326,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_qual_range(bam1_t *
   __pyx_t_4 = __pyx_v_end;
   for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {
 
-    /* "pysam/csamtools.pyx":2242
+    /* "pysam/csamtools.pyx":2245
  *     for k from start <= k < end:
  *         ## equivalent to t[i] + 33 (see bam.c)
  *         q[k-start] = p[k] + 33             # <<<<<<<<<<<<<<
@@ -22592,7 +23336,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_9csamtools_get_qual_range(bam1_t *
     (__pyx_v_q[(__pyx_v_k - __pyx_v_start)]) = ((__pyx_v_p[__pyx_v_k]) + 33);
   }
 
-  /* "pysam/csamtools.pyx":2244
+  /* "pysam/csamtools.pyx":2247
  *         q[k-start] = p[k] + 33
  * 
  *     return qual             # <<<<<<<<<<<<<<
@@ -22632,7 +23376,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_1__init__(PyObject *__pyx_v_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2276
+/* "pysam/csamtools.pyx":2279
  * 
  *     # Now only called when instances are created from Python
  *     def __init__(self):             # <<<<<<<<<<<<<<
@@ -22645,9 +23389,9 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead___init__(struct __pyx_obj_5p
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__init__", 0);
-  __Pyx_TraceCall("__init__", __pyx_f[0], 2276);
+  __Pyx_TraceCall("__init__", __pyx_f[0], 2279);
 
-  /* "pysam/csamtools.pyx":2278
+  /* "pysam/csamtools.pyx":2281
  *     def __init__(self):
  *         # see bam_init1
  *         self._delegate = <bam1_t*>calloc( 1, sizeof( bam1_t) )             # <<<<<<<<<<<<<<
@@ -22656,7 +23400,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead___init__(struct __pyx_obj_5p
  */
   __pyx_v_self->_delegate = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
 
-  /* "pysam/csamtools.pyx":2282
+  /* "pysam/csamtools.pyx":2285
  *         # If size is 0, calloc does not return a pointer that can be passed to free()
  *         # so allocate 40 bytes for a new read
  *         self._delegate.m_data = 40             # <<<<<<<<<<<<<<
@@ -22665,7 +23409,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead___init__(struct __pyx_obj_5p
  */
   __pyx_v_self->_delegate->m_data = 40;
 
-  /* "pysam/csamtools.pyx":2283
+  /* "pysam/csamtools.pyx":2286
  *         # so allocate 40 bytes for a new read
  *         self._delegate.m_data = 40
  *         self._delegate.data = <uint8_t *>calloc( self._delegate.m_data, 1 )             # <<<<<<<<<<<<<<
@@ -22674,7 +23418,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead___init__(struct __pyx_obj_5p
  */
   __pyx_v_self->_delegate->data = ((uint8_t *)calloc(__pyx_v_self->_delegate->m_data, 1));
 
-  /* "pysam/csamtools.pyx":2284
+  /* "pysam/csamtools.pyx":2287
  *         self._delegate.m_data = 40
  *         self._delegate.data = <uint8_t *>calloc( self._delegate.m_data, 1 )
  *         self._delegate.data_len = 0             # <<<<<<<<<<<<<<
@@ -22698,7 +23442,7 @@ static void __pyx_pw_5pysam_9csamtools_11AlignedRead_3__dealloc__(PyObject *__py
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/csamtools.pyx":2286
+/* "pysam/csamtools.pyx":2289
  *         self._delegate.data_len = 0
  * 
  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
@@ -22710,9 +23454,9 @@ static void __pyx_pf_5pysam_9csamtools_11AlignedRead_2__dealloc__(struct __pyx_o
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__dealloc__", 0);
-  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2286);
+  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2289);
 
-  /* "pysam/csamtools.pyx":2287
+  /* "pysam/csamtools.pyx":2290
  * 
  *     def __dealloc__(self):
  *         bam_destroy1(self._delegate)             # <<<<<<<<<<<<<<
@@ -22740,7 +23484,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_5__str__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2289
+/* "pysam/csamtools.pyx":2292
  *         bam_destroy1(self._delegate)
  * 
  *     def __str__(self):             # <<<<<<<<<<<<<<
@@ -22771,49 +23515,49 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4__str__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__str__", 0);
-  __Pyx_TraceCall("__str__", __pyx_f[0], 2289);
+  __Pyx_TraceCall("__str__", __pyx_f[0], 2292);
 
-  /* "pysam/csamtools.pyx":2301
+  /* "pysam/csamtools.pyx":2304
  *         # sam-parsing is done in sam.c/bam_format1_core which
  *         # requires a valid header.
  *         if sys.version_info[0] < 3:             # <<<<<<<<<<<<<<
  *             seq = self.seq
  *             qual = self.qual
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__version_info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__version_info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":2302
+    /* "pysam/csamtools.pyx":2305
  *         # requires a valid header.
  *         if sys.version_info[0] < 3:
  *             seq = self.seq             # <<<<<<<<<<<<<<
  *             qual = self.qual
  *         else:
  */
-    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__seq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__seq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __pyx_v_seq = __pyx_t_2;
     __pyx_t_2 = 0;
 
-    /* "pysam/csamtools.pyx":2303
+    /* "pysam/csamtools.pyx":2306
  *         if sys.version_info[0] < 3:
  *             seq = self.seq
  *             qual = self.qual             # <<<<<<<<<<<<<<
  *         else:
  *             seq = self.seq.decode('ascii')
  */
-    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__qual); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__qual); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __pyx_v_qual = __pyx_t_2;
     __pyx_t_2 = 0;
@@ -22821,37 +23565,37 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4__str__(struct __pyx_
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":2305
+    /* "pysam/csamtools.pyx":2308
  *             qual = self.qual
  *         else:
  *             seq = self.seq.decode('ascii')             # <<<<<<<<<<<<<<
  *             qual = self.qual.decode('ascii')
  *         return "\t".join(map(str, (self.qname,
  */
-    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__seq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__seq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_145), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_144), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __pyx_v_seq = __pyx_t_2;
     __pyx_t_2 = 0;
 
-    /* "pysam/csamtools.pyx":2306
+    /* "pysam/csamtools.pyx":2309
  *         else:
  *             seq = self.seq.decode('ascii')
  *             qual = self.qual.decode('ascii')             # <<<<<<<<<<<<<<
  *         return "\t".join(map(str, (self.qname,
  *                                    self.flag,
  */
-    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__qual); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__qual); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_146), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_145), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __pyx_v_qual = __pyx_t_2;
@@ -22859,7 +23603,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4__str__(struct __pyx_
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2307
+  /* "pysam/csamtools.pyx":2310
  *             seq = self.seq.decode('ascii')
  *             qual = self.qual.decode('ascii')
  *         return "\t".join(map(str, (self.qname,             # <<<<<<<<<<<<<<
@@ -22867,101 +23611,101 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4__str__(struct __pyx_
  *                                    self.rname,
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__qname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__qname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
 
-  /* "pysam/csamtools.pyx":2308
+  /* "pysam/csamtools.pyx":2311
  *             qual = self.qual.decode('ascii')
  *         return "\t".join(map(str, (self.qname,
  *                                    self.flag,             # <<<<<<<<<<<<<<
  *                                    self.rname,
  *                                    self.pos,
  */
-  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
 
-  /* "pysam/csamtools.pyx":2309
+  /* "pysam/csamtools.pyx":2312
  *         return "\t".join(map(str, (self.qname,
  *                                    self.flag,
  *                                    self.rname,             # <<<<<<<<<<<<<<
  *                                    self.pos,
  *                                    self.mapq,
  */
-  __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__rname); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__rname); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
 
-  /* "pysam/csamtools.pyx":2310
+  /* "pysam/csamtools.pyx":2313
  *                                    self.flag,
  *                                    self.rname,
  *                                    self.pos,             # <<<<<<<<<<<<<<
  *                                    self.mapq,
  *                                    self.cigar,
  */
-  __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pos); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pos); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_6);
 
-  /* "pysam/csamtools.pyx":2311
+  /* "pysam/csamtools.pyx":2314
  *                                    self.rname,
  *                                    self.pos,
  *                                    self.mapq,             # <<<<<<<<<<<<<<
  *                                    self.cigar,
  *                                    self.mrnm,
  */
-  __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__mapq); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__mapq); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_7);
 
-  /* "pysam/csamtools.pyx":2312
+  /* "pysam/csamtools.pyx":2315
  *                                    self.pos,
  *                                    self.mapq,
  *                                    self.cigar,             # <<<<<<<<<<<<<<
  *                                    self.mrnm,
  *                                    self.mpos,
  */
-  __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__cigar); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__cigar); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
 
-  /* "pysam/csamtools.pyx":2313
+  /* "pysam/csamtools.pyx":2316
  *                                    self.mapq,
  *                                    self.cigar,
  *                                    self.mrnm,             # <<<<<<<<<<<<<<
  *                                    self.mpos,
  *                                    self.rlen,
  */
-  __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__mrnm); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__mrnm); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_9);
 
-  /* "pysam/csamtools.pyx":2314
+  /* "pysam/csamtools.pyx":2317
  *                                    self.cigar,
  *                                    self.mrnm,
  *                                    self.mpos,             # <<<<<<<<<<<<<<
  *                                    self.rlen,
  *                                    seq,
  */
-  __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__mpos); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__mpos); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_10);
 
-  /* "pysam/csamtools.pyx":2315
+  /* "pysam/csamtools.pyx":2318
  *                                    self.mrnm,
  *                                    self.mpos,
  *                                    self.rlen,             # <<<<<<<<<<<<<<
  *                                    seq,
  *                                    qual,
  */
-  __pyx_t_11 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__rlen); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_11 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__rlen); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_11);
 
-  /* "pysam/csamtools.pyx":2318
+  /* "pysam/csamtools.pyx":2321
  *                                    seq,
  *                                    qual,
  *                                    self.tags )))             # <<<<<<<<<<<<<<
  * 
  *     def compare(self, AlignedRead other):
  */
-  __pyx_t_12 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__tags); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_12 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__tags); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_12);
-  __pyx_t_13 = PyTuple_New(12); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_13 = PyTuple_New(12); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_13);
   PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1);
   __Pyx_GIVEREF(__pyx_t_1);
@@ -22999,7 +23743,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4__str__(struct __pyx_
   __pyx_t_10 = 0;
   __pyx_t_11 = 0;
   __pyx_t_12 = 0;
-  __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_12);
   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
   PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
@@ -23007,15 +23751,15 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4__str__(struct __pyx_
   PyTuple_SET_ITEM(__pyx_t_12, 1, ((PyObject *)__pyx_t_13));
   __Pyx_GIVEREF(((PyObject *)__pyx_t_13));
   __pyx_t_13 = 0;
-  __pyx_t_13 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_13 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_13);
   __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0;
-  __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_12);
   PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_13);
   __Pyx_GIVEREF(__pyx_t_13);
   __pyx_t_13 = 0;
-  __pyx_t_13 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_13 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_13);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0;
@@ -23056,7 +23800,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_7compare(PyObject *__p
   PyObject *__pyx_r = 0;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("compare (wrapper)", 0);
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_9csamtools_AlignedRead, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_9csamtools_AlignedRead, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(((struct __pyx_obj_5pysam_9csamtools_AlignedRead *)__pyx_v_self), ((struct __pyx_obj_5pysam_9csamtools_AlignedRead *)__pyx_v_other));
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -23066,7 +23810,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_7compare(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2320
+/* "pysam/csamtools.pyx":2323
  *                                    self.tags )))
  * 
  *     def compare(self, AlignedRead other):             # <<<<<<<<<<<<<<
@@ -23088,9 +23832,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("compare", 0);
-  __Pyx_TraceCall("compare", __pyx_f[0], 2320);
+  __Pyx_TraceCall("compare", __pyx_f[0], 2323);
 
-  /* "pysam/csamtools.pyx":2326
+  /* "pysam/csamtools.pyx":2329
  *         cdef bam1_t *t, *o
  * 
  *         t = self._delegate             # <<<<<<<<<<<<<<
@@ -23100,7 +23844,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(struct __pyx_
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_t = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2327
+  /* "pysam/csamtools.pyx":2330
  * 
  *         t = self._delegate
  *         o = other._delegate             # <<<<<<<<<<<<<<
@@ -23110,7 +23854,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(struct __pyx_
   __pyx_t_1 = __pyx_v_other->_delegate;
   __pyx_v_o = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2339
+  /* "pysam/csamtools.pyx":2342
  * 
  *         # Fast-path test for object identity
  *         if t==o:             # <<<<<<<<<<<<<<
@@ -23120,7 +23864,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(struct __pyx_
   __pyx_t_2 = (__pyx_v_t == __pyx_v_o);
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":2340
+    /* "pysam/csamtools.pyx":2343
  *         # Fast-path test for object identity
  *         if t==o:
  *             return 0             # <<<<<<<<<<<<<<
@@ -23135,7 +23879,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(struct __pyx_
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2342
+  /* "pysam/csamtools.pyx":2345
  *             return 0
  * 
  *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))             # <<<<<<<<<<<<<<
@@ -23144,7 +23888,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(struct __pyx_
  */
   __pyx_v_retval = memcmp((&__pyx_v_t->core), (&__pyx_v_o->core), (sizeof(bam1_core_t)));
 
-  /* "pysam/csamtools.pyx":2344
+  /* "pysam/csamtools.pyx":2347
  *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
  * 
  *         if retval: return retval             # <<<<<<<<<<<<<<
@@ -23153,7 +23897,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(struct __pyx_
  */
   if (__pyx_v_retval) {
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_3 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __pyx_r = __pyx_t_3;
     __pyx_t_3 = 0;
@@ -23162,7 +23906,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(struct __pyx_
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":2345
+  /* "pysam/csamtools.pyx":2348
  * 
  *         if retval: return retval
  *         retval = (t.data_len > o.data_len) - (t.data_len < o.data_len) # cmp(t.data_len, o.data_len)             # <<<<<<<<<<<<<<
@@ -23171,7 +23915,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(struct __pyx_
  */
   __pyx_v_retval = ((__pyx_v_t->data_len > __pyx_v_o->data_len) - (__pyx_v_t->data_len < __pyx_v_o->data_len));
 
-  /* "pysam/csamtools.pyx":2346
+  /* "pysam/csamtools.pyx":2349
  *         if retval: return retval
  *         retval = (t.data_len > o.data_len) - (t.data_len < o.data_len) # cmp(t.data_len, o.data_len)
  *         if retval: return retval             # <<<<<<<<<<<<<<
@@ -23180,7 +23924,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(struct __pyx_
  */
   if (__pyx_v_retval) {
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_3 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __pyx_r = __pyx_t_3;
     __pyx_t_3 = 0;
@@ -23189,7 +23933,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(struct __pyx_
   }
   __pyx_L5:;
 
-  /* "pysam/csamtools.pyx":2347
+  /* "pysam/csamtools.pyx":2350
  *         retval = (t.data_len > o.data_len) - (t.data_len < o.data_len) # cmp(t.data_len, o.data_len)
  *         if retval: return retval
  *         return memcmp(t.data, o.data, t.data_len)             # <<<<<<<<<<<<<<
@@ -23197,7 +23941,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6compare(struct __pyx_
  *     # Disabled so long as __cmp__ is a special method
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_3 = PyInt_FromLong(memcmp(__pyx_v_t->data, __pyx_v_o->data, __pyx_v_t->data_len)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyInt_FromLong(memcmp(__pyx_v_t->data, __pyx_v_o->data, __pyx_v_t->data_len)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_r = __pyx_t_3;
   __pyx_t_3 = 0;
@@ -23227,7 +23971,7 @@ static Py_hash_t __pyx_pw_5pysam_9csamtools_11AlignedRead_9__hash__(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2350
+/* "pysam/csamtools.pyx":2353
  * 
  *     # Disabled so long as __cmp__ is a special method
  *     def __hash__(self):             # <<<<<<<<<<<<<<
@@ -23240,9 +23984,9 @@ static Py_hash_t __pyx_pf_5pysam_9csamtools_11AlignedRead_8__hash__(struct __pyx
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__hash__", 0);
-  __Pyx_TraceCall("__hash__", __pyx_f[0], 2350);
+  __Pyx_TraceCall("__hash__", __pyx_f[0], 2353);
 
-  /* "pysam/csamtools.pyx":2351
+  /* "pysam/csamtools.pyx":2354
  *     # Disabled so long as __cmp__ is a special method
  *     def __hash__(self):
  *         return _Py_HashPointer(<void *>self)             # <<<<<<<<<<<<<<
@@ -23271,7 +24015,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_5qname_1__get__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2359
+/* "pysam/csamtools.pyx":2362
  *     property qname:
  *         """the query name (None if not present)"""
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -23291,9 +24035,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5qname___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2359);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2362);
 
-  /* "pysam/csamtools.pyx":2361
+  /* "pysam/csamtools.pyx":2364
  *         def __get__(self):
  *             cdef bam1_t * src
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -23303,7 +24047,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5qname___get__(struct
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2362
+  /* "pysam/csamtools.pyx":2365
  *             cdef bam1_t * src
  *             src = self._delegate
  *             if src.core.l_qname == 0: return None             # <<<<<<<<<<<<<<
@@ -23320,7 +24064,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5qname___get__(struct
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2363
+  /* "pysam/csamtools.pyx":2366
  *             src = self._delegate
  *             if src.core.l_qname == 0: return None
  *             return _charptr_to_str(<char *>bam1_qname( src ))             # <<<<<<<<<<<<<<
@@ -23328,7 +24072,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5qname___get__(struct
  *         def __set__(self, qname ):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_3 = __pyx_f_5pysam_9csamtools__charptr_to_str(((char *)bam1_qname(__pyx_v_src))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __pyx_f_5pysam_9csamtools__charptr_to_str(((char *)bam1_qname(__pyx_v_src))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_r = __pyx_t_3;
   __pyx_t_3 = 0;
@@ -23358,7 +24102,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_5qname_3__set__(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2365
+/* "pysam/csamtools.pyx":2368
  *             return _charptr_to_str(<char *>bam1_qname( src ))
  * 
  *         def __set__(self, qname ):             # <<<<<<<<<<<<<<
@@ -23384,21 +24128,21 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5qname_2__set__(struct __pyx
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2365);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2368);
   __Pyx_INCREF(__pyx_v_qname);
 
-  /* "pysam/csamtools.pyx":2366
+  /* "pysam/csamtools.pyx":2369
  * 
  *         def __set__(self, qname ):
  *             if qname == None or len(qname) == 0: return             # <<<<<<<<<<<<<<
  *             qname = _force_bytes(qname)
  *             cdef bam1_t * src
  */
-  __pyx_t_1 = PyObject_RichCompare(__pyx_v_qname, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_qname, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (!__pyx_t_2) {
-    __pyx_t_3 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_4 = (__pyx_t_3 == 0);
     __pyx_t_5 = __pyx_t_4;
   } else {
@@ -23411,20 +24155,20 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5qname_2__set__(struct __pyx
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2367
+  /* "pysam/csamtools.pyx":2370
  *         def __set__(self, qname ):
  *             if qname == None or len(qname) == 0: return
  *             qname = _force_bytes(qname)             # <<<<<<<<<<<<<<
  *             cdef bam1_t * src
  *             cdef int l
  */
-  __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_qname)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_qname)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_v_qname);
   __pyx_v_qname = __pyx_t_1;
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":2372
+  /* "pysam/csamtools.pyx":2375
  *             cdef char * p
  * 
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -23434,7 +24178,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5qname_2__set__(struct __pyx
   __pyx_t_6 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_6;
 
-  /* "pysam/csamtools.pyx":2373
+  /* "pysam/csamtools.pyx":2376
  * 
  *             src = self._delegate
  *             p = bam1_qname( src )             # <<<<<<<<<<<<<<
@@ -23443,17 +24187,17 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5qname_2__set__(struct __pyx
  */
   __pyx_v_p = bam1_qname(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":2376
+  /* "pysam/csamtools.pyx":2379
  * 
  *             # the qname is \0 terminated
  *             l = len(qname) + 1             # <<<<<<<<<<<<<<
  *             pysam_bam_update( src,
  *                               src.core.l_qname,
  */
-  __pyx_t_3 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_l = (__pyx_t_3 + 1);
 
-  /* "pysam/csamtools.pyx":2380
+  /* "pysam/csamtools.pyx":2383
  *                               src.core.l_qname,
  *                               l,
  *                               <uint8_t*>p )             # <<<<<<<<<<<<<<
@@ -23462,7 +24206,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5qname_2__set__(struct __pyx
  */
   pysam_bam_update(__pyx_v_src, __pyx_v_src->core.l_qname, __pyx_v_l, ((uint8_t *)__pyx_v_p));
 
-  /* "pysam/csamtools.pyx":2382
+  /* "pysam/csamtools.pyx":2385
  *                               <uint8_t*>p )
  * 
  *             src.core.l_qname = l             # <<<<<<<<<<<<<<
@@ -23471,7 +24215,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5qname_2__set__(struct __pyx
  */
   __pyx_v_src->core.l_qname = __pyx_v_l;
 
-  /* "pysam/csamtools.pyx":2386
+  /* "pysam/csamtools.pyx":2389
  *             # re-acquire pointer to location in memory
  *             # as it might have moved
  *             p = bam1_qname(src)             # <<<<<<<<<<<<<<
@@ -23480,14 +24224,14 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5qname_2__set__(struct __pyx
  */
   __pyx_v_p = bam1_qname(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":2388
+  /* "pysam/csamtools.pyx":2391
  *             p = bam1_qname(src)
  * 
  *             strncpy( p, qname, l )             # <<<<<<<<<<<<<<
  * 
  *     property cigar:
  */
-  __pyx_t_7 = PyBytes_AsString(__pyx_v_qname); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = PyBytes_AsString(__pyx_v_qname); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   strncpy(__pyx_v_p, __pyx_t_7, __pyx_v_l);
 
   __pyx_r = 0;
@@ -23514,7 +24258,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_5cigar_1__get__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2423
+/* "pysam/csamtools.pyx":2426
  * 
  *         """
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -23541,9 +24285,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2423);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2426);
 
-  /* "pysam/csamtools.pyx":2429
+  /* "pysam/csamtools.pyx":2432
  *             cdef int k
  * 
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -23553,7 +24297,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar___get__(struct
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2430
+  /* "pysam/csamtools.pyx":2433
  * 
  *             src = self._delegate
  *             if src.core.n_cigar == 0: return None             # <<<<<<<<<<<<<<
@@ -23570,19 +24314,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar___get__(struct
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2432
+  /* "pysam/csamtools.pyx":2435
  *             if src.core.n_cigar == 0: return None
  * 
  *             cigar = []             # <<<<<<<<<<<<<<
  *             cigar_p = bam1_cigar(src);
  *             for k from 0 <= k < src.core.n_cigar:
  */
-  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_v_cigar = ((PyObject *)__pyx_t_3);
   __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":2433
+  /* "pysam/csamtools.pyx":2436
  * 
  *             cigar = []
  *             cigar_p = bam1_cigar(src);             # <<<<<<<<<<<<<<
@@ -23591,7 +24335,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar___get__(struct
  */
   __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":2434
+  /* "pysam/csamtools.pyx":2437
  *             cigar = []
  *             cigar_p = bam1_cigar(src);
  *             for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
@@ -23601,40 +24345,40 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar___get__(struct
   __pyx_t_4 = __pyx_v_src->core.n_cigar;
   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {
 
-    /* "pysam/csamtools.pyx":2435
+    /* "pysam/csamtools.pyx":2438
  *             cigar_p = bam1_cigar(src);
  *             for k from 0 <= k < src.core.n_cigar:
  *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
  *                 cigar.append((op, l))
  */
-    __pyx_t_3 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) & 15)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) & 15)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_XDECREF(__pyx_v_op);
     __pyx_v_op = __pyx_t_3;
     __pyx_t_3 = 0;
 
-    /* "pysam/csamtools.pyx":2436
+    /* "pysam/csamtools.pyx":2439
  *             for k from 0 <= k < src.core.n_cigar:
  *                 op = cigar_p[k] & BAM_CIGAR_MASK
  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
  *                 cigar.append((op, l))
  *             return cigar
  */
-    __pyx_t_3 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_XDECREF(__pyx_v_l);
     __pyx_v_l = __pyx_t_3;
     __pyx_t_3 = 0;
 
-    /* "pysam/csamtools.pyx":2437
+    /* "pysam/csamtools.pyx":2440
  *                 op = cigar_p[k] & BAM_CIGAR_MASK
  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
  *                 cigar.append((op, l))             # <<<<<<<<<<<<<<
  *             return cigar
  * 
  */
-    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_INCREF(__pyx_v_op);
     PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_op);
@@ -23642,13 +24386,13 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar___get__(struct
     __Pyx_INCREF(__pyx_v_l);
     PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_l);
     __Pyx_GIVEREF(__pyx_v_l);
-    __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_cigar, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_cigar, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
   }
 
-  /* "pysam/csamtools.pyx":2438
+  /* "pysam/csamtools.pyx":2441
  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
  *                 cigar.append((op, l))
  *             return cigar             # <<<<<<<<<<<<<<
@@ -23688,7 +24432,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_5cigar_3__set__(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2440
+/* "pysam/csamtools.pyx":2443
  *             return cigar
  * 
  *         def __set__(self, values ):             # <<<<<<<<<<<<<<
@@ -23722,20 +24466,20 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2440);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2443);
 
-  /* "pysam/csamtools.pyx":2441
+  /* "pysam/csamtools.pyx":2444
  * 
  *         def __set__(self, values ):
  *             if values == None or len(values) == 0: return             # <<<<<<<<<<<<<<
  *             cdef uint32_t * p
  *             cdef bam1_t * src
  */
-  __pyx_t_1 = PyObject_RichCompare(__pyx_v_values, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_values, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (!__pyx_t_2) {
-    __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_4 = (__pyx_t_3 == 0);
     __pyx_t_5 = __pyx_t_4;
   } else {
@@ -23748,7 +24492,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2447
+  /* "pysam/csamtools.pyx":2450
  *             cdef int k
  * 
  *             k = 0             # <<<<<<<<<<<<<<
@@ -23757,7 +24501,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
  */
   __pyx_v_k = 0;
 
-  /* "pysam/csamtools.pyx":2449
+  /* "pysam/csamtools.pyx":2452
  *             k = 0
  * 
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -23767,7 +24511,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
   __pyx_t_6 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_6;
 
-  /* "pysam/csamtools.pyx":2452
+  /* "pysam/csamtools.pyx":2455
  * 
  *             # get location of cigar string
  *             p = bam1_cigar(src)             # <<<<<<<<<<<<<<
@@ -23776,16 +24520,16 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
  */
   __pyx_v_p = bam1_cigar(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":2457
+  /* "pysam/csamtools.pyx":2460
  *             pysam_bam_update( src,
  *                               src.core.n_cigar * 4,
  *                               len(values) * 4,             # <<<<<<<<<<<<<<
  *                               <uint8_t*>p )
  * 
  */
-  __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":2458
+  /* "pysam/csamtools.pyx":2461
  *                               src.core.n_cigar * 4,
  *                               len(values) * 4,
  *                               <uint8_t*>p )             # <<<<<<<<<<<<<<
@@ -23794,17 +24538,17 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
  */
   pysam_bam_update(__pyx_v_src, (__pyx_v_src->core.n_cigar * 4), (__pyx_t_3 * 4), ((uint8_t *)__pyx_v_p));
 
-  /* "pysam/csamtools.pyx":2461
+  /* "pysam/csamtools.pyx":2464
  * 
  *             # length is number of cigar operations, not bytes
  *             src.core.n_cigar = len(values)             # <<<<<<<<<<<<<<
  * 
  *             # re-acquire pointer to location in memory
  */
-  __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_src->core.n_cigar = __pyx_t_3;
 
-  /* "pysam/csamtools.pyx":2465
+  /* "pysam/csamtools.pyx":2468
  *             # re-acquire pointer to location in memory
  *             # as it might have moved
  *             p = bam1_cigar(src)             # <<<<<<<<<<<<<<
@@ -23813,7 +24557,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
  */
   __pyx_v_p = bam1_cigar(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":2468
+  /* "pysam/csamtools.pyx":2471
  * 
  *             # insert cigar operations
  *             for op, l in values:             # <<<<<<<<<<<<<<
@@ -23824,7 +24568,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
     __pyx_t_1 = __pyx_v_values; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
     __pyx_t_7 = NULL;
   } else {
-    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
   }
@@ -23832,23 +24576,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
     if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
       if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
       #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_8 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_8); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_8); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #else
-      __pyx_t_8 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
     } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
       if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
       #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_8); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_8); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #else
-      __pyx_t_8 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
     } else {
       __pyx_t_8 = __pyx_t_7(__pyx_t_1);
       if (unlikely(!__pyx_t_8)) {
         if (PyErr_Occurred()) {
           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         break;
       }
@@ -23864,7 +24608,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
       if (unlikely(size != 2)) {
         if (size > 2) __Pyx_RaiseTooManyValuesError(2);
         else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
       #if CYTHON_COMPILING_IN_CPYTHON
       if (likely(PyTuple_CheckExact(sequence))) {
@@ -23877,16 +24621,16 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
       __Pyx_INCREF(__pyx_t_9);
       __Pyx_INCREF(__pyx_t_10);
       #else
-      __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
-      __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_10);
       #endif
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     } else
     {
       Py_ssize_t index = -1;
-      __pyx_t_11 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_11 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_11);
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
       __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
@@ -23894,7 +24638,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
       __Pyx_GOTREF(__pyx_t_9);
       index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L6_unpacking_failed;
       __Pyx_GOTREF(__pyx_t_10);
-      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_t_12 = NULL;
       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
       goto __pyx_L7_unpacking_done;
@@ -23902,7 +24646,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
       __pyx_t_12 = NULL;
       if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_L7_unpacking_done:;
     }
     __Pyx_XDECREF(__pyx_v_op);
@@ -23912,23 +24656,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
     __pyx_v_l = __pyx_t_10;
     __pyx_t_10 = 0;
 
-    /* "pysam/csamtools.pyx":2469
+    /* "pysam/csamtools.pyx":2472
  *             # insert cigar operations
  *             for op, l in values:
  *                 p[k] = l << BAM_CIGAR_SHIFT | op             # <<<<<<<<<<<<<<
  *                 k += 1
  * 
  */
-    __pyx_t_8 = PyNumber_Lshift(__pyx_v_l, __pyx_int_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyNumber_Lshift(__pyx_v_l, __pyx_int_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
-    __pyx_t_10 = PyNumber_Or(__pyx_t_8, __pyx_v_op); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = PyNumber_Or(__pyx_t_8, __pyx_v_op); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_10);
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-    __pyx_t_13 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_10); if (unlikely((__pyx_t_13 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_13 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_10); if (unlikely((__pyx_t_13 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
     (__pyx_v_p[__pyx_v_k]) = __pyx_t_13;
 
-    /* "pysam/csamtools.pyx":2470
+    /* "pysam/csamtools.pyx":2473
  *             for op, l in values:
  *                 p[k] = l << BAM_CIGAR_SHIFT | op
  *                 k += 1             # <<<<<<<<<<<<<<
@@ -23939,7 +24683,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx
   }
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":2473
+  /* "pysam/csamtools.pyx":2476
  * 
  *             ## setting the cigar string also updates the "bin" attribute
  *             src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, p))             # <<<<<<<<<<<<<<
@@ -23977,7 +24721,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_11cigarstring_1__get__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2489
+/* "pysam/csamtools.pyx":2492
  *         Returns the empty string if not present.
  *         '''
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -24008,40 +24752,40 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring___get__(
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2489);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2492);
 
-  /* "pysam/csamtools.pyx":2490
+  /* "pysam/csamtools.pyx":2493
  *         '''
  *         def __get__(self):
  *             c = self.cigar             # <<<<<<<<<<<<<<
  *             if c == None: return ""
  *             # reverse order
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__cigar); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__cigar); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_c = __pyx_t_1;
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":2491
+  /* "pysam/csamtools.pyx":2494
  *         def __get__(self):
  *             c = self.cigar
  *             if c == None: return ""             # <<<<<<<<<<<<<<
  *             # reverse order
  *             else: return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])
  */
-  __pyx_t_1 = PyObject_RichCompare(__pyx_v_c, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_c, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (__pyx_t_2) {
     __Pyx_XDECREF(__pyx_r);
-    __Pyx_INCREF(((PyObject *)__pyx_kp_s_16));
-    __pyx_r = ((PyObject *)__pyx_kp_s_16);
+    __Pyx_INCREF(((PyObject *)__pyx_kp_s_20));
+    __pyx_r = ((PyObject *)__pyx_kp_s_20);
     goto __pyx_L0;
     goto __pyx_L3;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":2493
+    /* "pysam/csamtools.pyx":2496
  *             if c == None: return ""
  *             # reverse order
  *             else: return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])             # <<<<<<<<<<<<<<
@@ -24049,15 +24793,15 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring___get__(
  *         def __set__(self, cigar):
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_16), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_20), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     if (PyList_CheckExact(__pyx_v_c) || PyTuple_CheckExact(__pyx_v_c)) {
       __pyx_t_4 = __pyx_v_c; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
       __pyx_t_6 = NULL;
     } else {
-      __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_c); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_c); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_4);
       __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext;
     }
@@ -24065,23 +24809,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring___get__(
       if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_4)) {
         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_4)) {
         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else {
         __pyx_t_7 = __pyx_t_6(__pyx_t_4);
         if (unlikely(!__pyx_t_7)) {
           if (PyErr_Occurred()) {
             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           }
           break;
         }
@@ -24097,7 +24841,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring___get__(
         if (unlikely(size != 2)) {
           if (size > 2) __Pyx_RaiseTooManyValuesError(2);
           else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         #if CYTHON_COMPILING_IN_CPYTHON
         if (likely(PyTuple_CheckExact(sequence))) {
@@ -24110,16 +24854,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring___get__(
         __Pyx_INCREF(__pyx_t_8);
         __Pyx_INCREF(__pyx_t_9);
         #else
-        __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __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 = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_9);
         #endif
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       } else
       {
         Py_ssize_t index = -1;
-        __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_10);
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
@@ -24127,7 +24871,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring___get__(
         __Pyx_GOTREF(__pyx_t_8);
         index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed;
         __Pyx_GOTREF(__pyx_t_9);
-        if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __pyx_t_11 = NULL;
         __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
         goto __pyx_L7_unpacking_done;
@@ -24135,7 +24879,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring___get__(
         __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
         __pyx_t_11 = NULL;
         if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __pyx_L7_unpacking_done:;
       }
       __Pyx_XDECREF(__pyx_v_x);
@@ -24144,10 +24888,10 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring___get__(
       __Pyx_XDECREF(__pyx_v_y);
       __pyx_v_y = __pyx_t_9;
       __pyx_t_9 = 0;
-      __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_7 = PyInt_FromLong((__pyx_v_5pysam_9csamtools_CODE2CIGAR[__pyx_t_12])); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyInt_FromLong((__pyx_v_5pysam_9csamtools_CODE2CIGAR[__pyx_t_12])); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
-      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
       __Pyx_INCREF(__pyx_v_y);
       PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_y);
@@ -24155,20 +24899,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring___get__(
       PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_7);
       __Pyx_GIVEREF(__pyx_t_7);
       __pyx_t_7 = 0;
-      __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_147), ((PyObject *)__pyx_t_9)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_146), ((PyObject *)__pyx_t_9)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_7));
       __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
-      if (unlikely(__Pyx_PyList_Append(__pyx_t_3, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (unlikely(__Pyx_PyList_Append(__pyx_t_3, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
     }
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_INCREF(((PyObject *)__pyx_t_3));
     PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
-    __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __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_4)); __pyx_t_4 = 0;
@@ -24211,7 +24955,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_11cigarstring_3__set__(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2495
+/* "pysam/csamtools.pyx":2498
  *             else: return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])
  * 
  *         def __set__(self, cigar):             # <<<<<<<<<<<<<<
@@ -24242,72 +24986,72 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring_2__set__(struc
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2495);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2498);
 
-  /* "pysam/csamtools.pyx":2496
+  /* "pysam/csamtools.pyx":2499
  * 
  *         def __set__(self, cigar):
  *             if cigar == None or len(cigar) == 0: self.cigar = []             # <<<<<<<<<<<<<<
  *             parts = CIGAR_REGEX.findall( cigar )
  *             # reverse order
  */
-  __pyx_t_1 = PyObject_RichCompare(__pyx_v_cigar, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_cigar, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (!__pyx_t_2) {
-    __pyx_t_3 = PyObject_Length(__pyx_v_cigar); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Length(__pyx_v_cigar); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_4 = (__pyx_t_3 == 0);
     __pyx_t_5 = __pyx_t_4;
   } else {
     __pyx_t_5 = __pyx_t_2;
   }
   if (__pyx_t_5) {
-    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__cigar, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__cigar, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2497
+  /* "pysam/csamtools.pyx":2500
  *         def __set__(self, cigar):
  *             if cigar == None or len(cigar) == 0: self.cigar = []
  *             parts = CIGAR_REGEX.findall( cigar )             # <<<<<<<<<<<<<<
  *             # reverse order
  *             self.cigar = [ (CIGAR2CODE[ord(y)], int(x)) for x,y in parts ]
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__CIGAR_REGEX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__CIGAR_REGEX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_6 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__findall); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_6 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__findall); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_6);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2497; __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 = 2500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__pyx_v_cigar);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_cigar);
   __Pyx_GIVEREF(__pyx_v_cigar);
-  __pyx_t_7 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_7);
   __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
   __pyx_v_parts = __pyx_t_7;
   __pyx_t_7 = 0;
 
-  /* "pysam/csamtools.pyx":2499
+  /* "pysam/csamtools.pyx":2502
  *             parts = CIGAR_REGEX.findall( cigar )
  *             # reverse order
  *             self.cigar = [ (CIGAR2CODE[ord(y)], int(x)) for x,y in parts ]             # <<<<<<<<<<<<<<
  * 
  *     property seq:
  */
-  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_7);
   if (PyList_CheckExact(__pyx_v_parts) || PyTuple_CheckExact(__pyx_v_parts)) {
     __pyx_t_1 = __pyx_v_parts; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
     __pyx_t_8 = NULL;
   } else {
-    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_parts); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_parts); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext;
   }
@@ -24315,23 +25059,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring_2__set__(struc
     if (!__pyx_t_8 && PyList_CheckExact(__pyx_t_1)) {
       if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
       #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #else
-      __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
     } else if (!__pyx_t_8 && PyTuple_CheckExact(__pyx_t_1)) {
       if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
       #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #else
-      __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
     } else {
       __pyx_t_6 = __pyx_t_8(__pyx_t_1);
       if (unlikely(!__pyx_t_6)) {
         if (PyErr_Occurred()) {
           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         break;
       }
@@ -24347,7 +25091,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring_2__set__(struc
       if (unlikely(size != 2)) {
         if (size > 2) __Pyx_RaiseTooManyValuesError(2);
         else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
       #if CYTHON_COMPILING_IN_CPYTHON
       if (likely(PyTuple_CheckExact(sequence))) {
@@ -24360,16 +25104,16 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring_2__set__(struc
       __Pyx_INCREF(__pyx_t_9);
       __Pyx_INCREF(__pyx_t_10);
       #else
-      __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
-      __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_10);
       #endif
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     } else
     {
       Py_ssize_t index = -1;
-      __pyx_t_11 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_11 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_11);
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
       __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
@@ -24377,7 +25121,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring_2__set__(struc
       __Pyx_GOTREF(__pyx_t_9);
       index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L6_unpacking_failed;
       __Pyx_GOTREF(__pyx_t_10);
-      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_t_12 = NULL;
       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
       goto __pyx_L7_unpacking_done;
@@ -24385,7 +25129,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring_2__set__(struc
       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
       __pyx_t_12 = NULL;
       if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_L7_unpacking_done:;
     }
     __Pyx_XDECREF(__pyx_v_x);
@@ -24394,29 +25138,29 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring_2__set__(struc
     __Pyx_XDECREF(__pyx_v_y);
     __pyx_v_y = __pyx_t_10;
     __pyx_t_10 = 0;
-    __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__CIGAR2CODE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__CIGAR2CODE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
-    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_10);
     __Pyx_INCREF(__pyx_v_y);
     PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_y);
     __Pyx_GIVEREF(__pyx_v_y);
-    __pyx_t_9 = PyObject_Call(__pyx_builtin_ord, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyObject_Call(__pyx_builtin_ord, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
-    __pyx_t_10 = PyObject_GetItem(__pyx_t_6, __pyx_t_9); if (!__pyx_t_10) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = PyObject_GetItem(__pyx_t_6, __pyx_t_9); if (!__pyx_t_10) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_10);
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __Pyx_INCREF(__pyx_v_x);
     PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_x);
     __Pyx_GIVEREF(__pyx_v_x);
-    __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
-    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10);
     __Pyx_GIVEREF(__pyx_t_10);
@@ -24424,14 +25168,14 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_11cigarstring_2__set__(struc
     __Pyx_GIVEREF(__pyx_t_6);
     __pyx_t_10 = 0;
     __pyx_t_6 = 0;
-    if (unlikely(__Pyx_PyList_Append(__pyx_t_7, (PyObject*)__pyx_t_9))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (unlikely(__Pyx_PyList_Append(__pyx_t_7, (PyObject*)__pyx_t_9))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
   }
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __pyx_t_1 = ((PyObject *)__pyx_t_7);
   __Pyx_INCREF(__pyx_t_1);
   __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-  if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__cigar, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__cigar, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
   __pyx_r = 0;
@@ -24465,7 +25209,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_3seq_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2518
+/* "pysam/csamtools.pyx":2521
  * 
  *         """
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -24485,9 +25229,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_3seq___get__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2518);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2521);
 
-  /* "pysam/csamtools.pyx":2521
+  /* "pysam/csamtools.pyx":2524
  *             cdef bam1_t * src
  *             cdef char * s
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -24497,7 +25241,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_3seq___get__(struct __
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2523
+  /* "pysam/csamtools.pyx":2526
  *             src = self._delegate
  * 
  *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
@@ -24514,7 +25258,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_3seq___get__(struct __
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2525
+  /* "pysam/csamtools.pyx":2528
  *             if src.core.l_qseq == 0: return None
  * 
  *             return get_seq_range(src, 0, src.core.l_qseq)             # <<<<<<<<<<<<<<
@@ -24522,7 +25266,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_3seq___get__(struct __
  *         def __set__(self,seq):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_3 = __pyx_f_5pysam_9csamtools_get_seq_range(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __pyx_f_5pysam_9csamtools_get_seq_range(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_r = __pyx_t_3;
   __pyx_t_3 = 0;
@@ -24552,7 +25296,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_3seq_3__set__(PyObject *__py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2527
+/* "pysam/csamtools.pyx":2530
  *             return get_seq_range(src, 0, src.core.l_qseq)
  * 
  *         def __set__(self,seq):             # <<<<<<<<<<<<<<
@@ -24582,22 +25326,22 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2527);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2530);
   __Pyx_INCREF(__pyx_v_seq);
 
-  /* "pysam/csamtools.pyx":2535
+  /* "pysam/csamtools.pyx":2538
  *             cdef int l, k, nbytes_new, nbytes_old
  * 
  *             if seq == None:             # <<<<<<<<<<<<<<
  *                 l = 0
  *             else:
  */
-  __pyx_t_1 = PyObject_RichCompare(__pyx_v_seq, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_seq, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":2536
+    /* "pysam/csamtools.pyx":2539
  * 
  *             if seq == None:
  *                 l = 0             # <<<<<<<<<<<<<<
@@ -24609,24 +25353,24 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":2538
+    /* "pysam/csamtools.pyx":2541
  *                 l = 0
  *             else:
  *                 l = len(seq)             # <<<<<<<<<<<<<<
  *                 seq = _force_bytes(seq)
  * 
  */
-    __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_v_l = __pyx_t_3;
 
-    /* "pysam/csamtools.pyx":2539
+    /* "pysam/csamtools.pyx":2542
  *             else:
  *                 l = len(seq)
  *                 seq = _force_bytes(seq)             # <<<<<<<<<<<<<<
  * 
  *             src = self._delegate
  */
-    __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_seq)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_seq)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_v_seq);
     __pyx_v_seq = __pyx_t_1;
@@ -24634,7 +25378,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2541
+  /* "pysam/csamtools.pyx":2544
  *                 seq = _force_bytes(seq)
  * 
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -24644,7 +25388,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
   __pyx_t_4 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_4;
 
-  /* "pysam/csamtools.pyx":2545
+  /* "pysam/csamtools.pyx":2548
  *             # as the sequence is stored in half-bytes, the total length (sequence
  *             # plus quality scores) is (l+1)/2 + l
  *             nbytes_new = (l+1)/2 + l             # <<<<<<<<<<<<<<
@@ -24653,7 +25397,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
  */
   __pyx_v_nbytes_new = (__Pyx_div_long((__pyx_v_l + 1), 2) + __pyx_v_l);
 
-  /* "pysam/csamtools.pyx":2546
+  /* "pysam/csamtools.pyx":2549
  *             # plus quality scores) is (l+1)/2 + l
  *             nbytes_new = (l+1)/2 + l
  *             nbytes_old = (src.core.l_qseq+1)/2 + src.core.l_qseq             # <<<<<<<<<<<<<<
@@ -24662,7 +25406,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
  */
   __pyx_v_nbytes_old = (__Pyx_div_long((__pyx_v_src->core.l_qseq + 1), 2) + __pyx_v_src->core.l_qseq);
 
-  /* "pysam/csamtools.pyx":2549
+  /* "pysam/csamtools.pyx":2552
  * 
  *             # acquire pointer to location in memory
  *             p = bam1_seq( src )             # <<<<<<<<<<<<<<
@@ -24671,7 +25415,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
  */
   __pyx_v_p = bam1_seq(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":2550
+  /* "pysam/csamtools.pyx":2553
  *             # acquire pointer to location in memory
  *             p = bam1_seq( src )
  *             src.core.l_qseq = l             # <<<<<<<<<<<<<<
@@ -24680,7 +25424,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
  */
   __pyx_v_src->core.l_qseq = __pyx_v_l;
 
-  /* "pysam/csamtools.pyx":2556
+  /* "pysam/csamtools.pyx":2559
  *                               nbytes_old,
  *                               nbytes_new,
  *                               p)             # <<<<<<<<<<<<<<
@@ -24689,7 +25433,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
  */
   pysam_bam_update(__pyx_v_src, __pyx_v_nbytes_old, __pyx_v_nbytes_new, __pyx_v_p);
 
-  /* "pysam/csamtools.pyx":2558
+  /* "pysam/csamtools.pyx":2561
  *                               p)
  * 
  *             if l > 0:             # <<<<<<<<<<<<<<
@@ -24699,7 +25443,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
   __pyx_t_2 = (__pyx_v_l > 0);
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":2561
+    /* "pysam/csamtools.pyx":2564
  *                 # re-acquire pointer to location in memory
  *                 # as it might have moved
  *                 p = bam1_seq( src )             # <<<<<<<<<<<<<<
@@ -24708,7 +25452,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
  */
     __pyx_v_p = bam1_seq(__pyx_v_src);
 
-    /* "pysam/csamtools.pyx":2562
+    /* "pysam/csamtools.pyx":2565
  *                 # as it might have moved
  *                 p = bam1_seq( src )
  *                 for k from 0 <= k < nbytes_new: p[k] = 0             # <<<<<<<<<<<<<<
@@ -24720,17 +25464,17 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
       (__pyx_v_p[__pyx_v_k]) = 0;
     }
 
-    /* "pysam/csamtools.pyx":2564
+    /* "pysam/csamtools.pyx":2567
  *                 for k from 0 <= k < nbytes_new: p[k] = 0
  *                 # convert to C string
  *                 s = seq             # <<<<<<<<<<<<<<
  *                 for k from 0 <= k < l:
  *                     p[k/2] |= pysam_translate_sequence(s[k]) << 4 * (1 - k % 2)
  */
-    __pyx_t_6 = PyBytes_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyBytes_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_v_s = __pyx_t_6;
 
-    /* "pysam/csamtools.pyx":2565
+    /* "pysam/csamtools.pyx":2568
  *                 # convert to C string
  *                 s = seq
  *                 for k from 0 <= k < l:             # <<<<<<<<<<<<<<
@@ -24740,7 +25484,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
     __pyx_t_5 = __pyx_v_l;
     for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {
 
-      /* "pysam/csamtools.pyx":2566
+      /* "pysam/csamtools.pyx":2569
  *                 s = seq
  *                 for k from 0 <= k < l:
  *                     p[k/2] |= pysam_translate_sequence(s[k]) << 4 * (1 - k % 2)             # <<<<<<<<<<<<<<
@@ -24751,7 +25495,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
       (__pyx_v_p[__pyx_t_7]) = ((__pyx_v_p[__pyx_t_7]) | (pysam_translate_sequence((__pyx_v_s[__pyx_v_k])) << (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2)))));
     }
 
-    /* "pysam/csamtools.pyx":2569
+    /* "pysam/csamtools.pyx":2572
  * 
  *                 # erase qualities
  *                 p = bam1_qual( src )             # <<<<<<<<<<<<<<
@@ -24760,7 +25504,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_o
  */
     __pyx_v_p = bam1_qual(__pyx_v_src);
 
-    /* "pysam/csamtools.pyx":2570
+    /* "pysam/csamtools.pyx":2573
  *                 # erase qualities
  *                 p = bam1_qual( src )
  *                 p[0] = 0xff             # <<<<<<<<<<<<<<
@@ -24796,7 +25540,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_4qual_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2587
+/* "pysam/csamtools.pyx":2590
  *         quality scores and the sequence are not the same.
  *         """
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -24816,9 +25560,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4qual___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2587);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2590);
 
-  /* "pysam/csamtools.pyx":2592
+  /* "pysam/csamtools.pyx":2595
  *             cdef char * q
  * 
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -24828,7 +25572,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4qual___get__(struct _
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2594
+  /* "pysam/csamtools.pyx":2597
  *             src = self._delegate
  * 
  *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
@@ -24845,7 +25589,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4qual___get__(struct _
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2596
+  /* "pysam/csamtools.pyx":2599
  *             if src.core.l_qseq == 0: return None
  * 
  *             return get_qual_range(src, 0, src.core.l_qseq)             # <<<<<<<<<<<<<<
@@ -24853,7 +25597,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4qual___get__(struct _
  *         def __set__(self,qual):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_3 = __pyx_f_5pysam_9csamtools_get_qual_range(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __pyx_f_5pysam_9csamtools_get_qual_range(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_r = __pyx_t_3;
   __pyx_t_3 = 0;
@@ -24883,7 +25627,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_4qual_3__set__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2598
+/* "pysam/csamtools.pyx":2601
  *             return get_qual_range(src, 0, src.core.l_qseq)
  * 
  *         def __set__(self,qual):             # <<<<<<<<<<<<<<
@@ -24914,10 +25658,10 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4qual_2__set__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2598);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2601);
   __Pyx_INCREF(__pyx_v_qual);
 
-  /* "pysam/csamtools.pyx":2605
+  /* "pysam/csamtools.pyx":2608
  *             cdef int k
  * 
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -24927,7 +25671,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4qual_2__set__(struct __pyx_
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2606
+  /* "pysam/csamtools.pyx":2609
  * 
  *             src = self._delegate
  *             p = bam1_qual( src )             # <<<<<<<<<<<<<<
@@ -24936,18 +25680,18 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4qual_2__set__(struct __pyx_
  */
   __pyx_v_p = bam1_qual(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":2607
+  /* "pysam/csamtools.pyx":2610
  *             src = self._delegate
  *             p = bam1_qual( src )
  *             if qual == None or len(qual) == 0:             # <<<<<<<<<<<<<<
  *                 # if absent - set to 0xff
  *                 p[0] = 0xff
  */
-  __pyx_t_2 = PyObject_RichCompare(__pyx_v_qual, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_RichCompare(__pyx_v_qual, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   if (!__pyx_t_3) {
-    __pyx_t_4 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_5 = (__pyx_t_4 == 0);
     __pyx_t_6 = __pyx_t_5;
   } else {
@@ -24955,7 +25699,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4qual_2__set__(struct __pyx_
   }
   if (__pyx_t_6) {
 
-    /* "pysam/csamtools.pyx":2609
+    /* "pysam/csamtools.pyx":2612
  *             if qual == None or len(qual) == 0:
  *                 # if absent - set to 0xff
  *                 p[0] = 0xff             # <<<<<<<<<<<<<<
@@ -24964,7 +25708,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4qual_2__set__(struct __pyx_
  */
     (__pyx_v_p[0]) = 0xff;
 
-    /* "pysam/csamtools.pyx":2610
+    /* "pysam/csamtools.pyx":2613
  *                 # if absent - set to 0xff
  *                 p[0] = 0xff
  *                 return             # <<<<<<<<<<<<<<
@@ -24977,40 +25721,40 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4qual_2__set__(struct __pyx_
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2611
+  /* "pysam/csamtools.pyx":2614
  *                 p[0] = 0xff
  *                 return
  *             qual = _force_bytes(qual)             # <<<<<<<<<<<<<<
  *             cdef int l
  *             # convert to C string
  */
-  __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_qual)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_qual)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_v_qual);
   __pyx_v_qual = __pyx_t_2;
   __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":2614
+  /* "pysam/csamtools.pyx":2617
  *             cdef int l
  *             # convert to C string
  *             q = qual             # <<<<<<<<<<<<<<
  *             l = len(qual)
  *             if src.core.l_qseq != l:
  */
-  __pyx_t_7 = PyBytes_AsString(__pyx_v_qual); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = PyBytes_AsString(__pyx_v_qual); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_q = __pyx_t_7;
 
-  /* "pysam/csamtools.pyx":2615
+  /* "pysam/csamtools.pyx":2618
  *             # convert to C string
  *             q = qual
  *             l = len(qual)             # <<<<<<<<<<<<<<
  *             if src.core.l_qseq != l:
  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
  */
-  __pyx_t_4 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2618; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_l = __pyx_t_4;
 
-  /* "pysam/csamtools.pyx":2616
+  /* "pysam/csamtools.pyx":2619
  *             q = qual
  *             l = len(qual)
  *             if src.core.l_qseq != l:             # <<<<<<<<<<<<<<
@@ -25020,18 +25764,18 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4qual_2__set__(struct __pyx_
   __pyx_t_6 = (__pyx_v_src->core.l_qseq != __pyx_v_l);
   if (__pyx_t_6) {
 
-    /* "pysam/csamtools.pyx":2617
+    /* "pysam/csamtools.pyx":2620
  *             l = len(qual)
  *             if src.core.l_qseq != l:
  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))             # <<<<<<<<<<<<<<
  *             assert src.core.l_qseq == l
  *             for k from 0 <= k < l:
  */
-    __pyx_t_2 = PyInt_FromLong(__pyx_v_l); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyInt_FromLong(__pyx_v_l); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_8 = __Pyx_PyInt_to_py_int32_t(__pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = __Pyx_PyInt_to_py_int32_t(__pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
-    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
     __Pyx_GIVEREF(__pyx_t_2);
@@ -25039,25 +25783,25 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4qual_2__set__(struct __pyx_
     __Pyx_GIVEREF(__pyx_t_8);
     __pyx_t_2 = 0;
     __pyx_t_8 = 0;
-    __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_148), ((PyObject *)__pyx_t_9)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_147), ((PyObject *)__pyx_t_9)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_8));
     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
-    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_8));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
     __pyx_t_8 = 0;
-    __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
     __Pyx_Raise(__pyx_t_8, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":2618
+  /* "pysam/csamtools.pyx":2621
  *             if src.core.l_qseq != l:
  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
  *             assert src.core.l_qseq == l             # <<<<<<<<<<<<<<
@@ -25067,11 +25811,11 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4qual_2__set__(struct __pyx_
   #ifndef CYTHON_WITHOUT_ASSERTIONS
   if (unlikely(!(__pyx_v_src->core.l_qseq == __pyx_v_l))) {
     PyErr_SetNone(PyExc_AssertionError);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2618; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #endif
 
-  /* "pysam/csamtools.pyx":2619
+  /* "pysam/csamtools.pyx":2622
  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
  *             assert src.core.l_qseq == l
  *             for k from 0 <= k < l:             # <<<<<<<<<<<<<<
@@ -25081,7 +25825,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4qual_2__set__(struct __pyx_
   __pyx_t_10 = __pyx_v_l;
   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_10; __pyx_v_k++) {
 
-    /* "pysam/csamtools.pyx":2620
+    /* "pysam/csamtools.pyx":2623
  *             assert src.core.l_qseq == l
  *             for k from 0 <= k < l:
  *                 p[k] = <uint8_t>q[k] - 33             # <<<<<<<<<<<<<<
@@ -25117,7 +25861,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_5query_1__get__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2634
+/* "pysam/csamtools.pyx":2640
  *         were not considered for alignment may have been retained."""
  * 
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -25140,9 +25884,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5query___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2634);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2640);
 
-  /* "pysam/csamtools.pyx":2639
+  /* "pysam/csamtools.pyx":2645
  *             cdef char * s
  * 
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -25152,7 +25896,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5query___get__(struct
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2641
+  /* "pysam/csamtools.pyx":2647
  *             src = self._delegate
  * 
  *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
@@ -25169,27 +25913,27 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5query___get__(struct
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2643
+  /* "pysam/csamtools.pyx":2649
  *             if src.core.l_qseq == 0: return None
  * 
  *             start = query_start(src)             # <<<<<<<<<<<<<<
  *             end   = query_end(src)
  * 
  */
-  __pyx_t_3 = __pyx_f_5pysam_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __pyx_f_5pysam_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_start = __pyx_t_3;
 
-  /* "pysam/csamtools.pyx":2644
+  /* "pysam/csamtools.pyx":2650
  * 
  *             start = query_start(src)
  *             end   = query_end(src)             # <<<<<<<<<<<<<<
  * 
  *             return get_seq_range(src, start, end)
  */
-  __pyx_t_3 = __pyx_f_5pysam_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __pyx_f_5pysam_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_end = __pyx_t_3;
 
-  /* "pysam/csamtools.pyx":2646
+  /* "pysam/csamtools.pyx":2652
  *             end   = query_end(src)
  * 
  *             return get_seq_range(src, start, end)             # <<<<<<<<<<<<<<
@@ -25197,7 +25941,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5query___get__(struct
  *     property qqual:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_4 = __pyx_f_5pysam_9csamtools_get_seq_range(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __pyx_f_5pysam_9csamtools_get_seq_range(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __pyx_r = __pyx_t_4;
   __pyx_t_4 = 0;
@@ -25227,7 +25971,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_5qqual_1__get__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2652
+/* "pysam/csamtools.pyx":2659
  * 
  *         In Python 3, this property is of type bytes."""
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -25250,9 +25994,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5qqual___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2652);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2659);
 
-  /* "pysam/csamtools.pyx":2656
+  /* "pysam/csamtools.pyx":2663
  *             cdef uint32_t start, end
  * 
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -25262,7 +26006,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5qqual___get__(struct
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2658
+  /* "pysam/csamtools.pyx":2665
  *             src = self._delegate
  * 
  *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
@@ -25279,27 +26023,27 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5qqual___get__(struct
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2660
+  /* "pysam/csamtools.pyx":2667
  *             if src.core.l_qseq == 0: return None
  * 
  *             start = query_start(src)             # <<<<<<<<<<<<<<
  *             end   = query_end(src)
  * 
  */
-  __pyx_t_3 = __pyx_f_5pysam_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __pyx_f_5pysam_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_start = __pyx_t_3;
 
-  /* "pysam/csamtools.pyx":2661
+  /* "pysam/csamtools.pyx":2668
  * 
  *             start = query_start(src)
  *             end   = query_end(src)             # <<<<<<<<<<<<<<
  * 
  *             return get_qual_range(src, start, end)
  */
-  __pyx_t_3 = __pyx_f_5pysam_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __pyx_f_5pysam_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_end = __pyx_t_3;
 
-  /* "pysam/csamtools.pyx":2663
+  /* "pysam/csamtools.pyx":2670
  *             end   = query_end(src)
  * 
  *             return get_qual_range(src, start, end)             # <<<<<<<<<<<<<<
@@ -25307,7 +26051,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5qqual___get__(struct
  *     property qstart:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_4 = __pyx_f_5pysam_9csamtools_get_qual_range(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __pyx_f_5pysam_9csamtools_get_qual_range(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2670; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __pyx_r = __pyx_t_4;
   __pyx_t_4 = 0;
@@ -25337,7 +26081,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_6qstart_1__get__(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2667
+/* "pysam/csamtools.pyx":2674
  *     property qstart:
  *         """start index of the aligned query portion of the sequence (0-based, inclusive)"""
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -25355,9 +26099,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6qstart___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2667);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2674);
 
-  /* "pysam/csamtools.pyx":2668
+  /* "pysam/csamtools.pyx":2675
  *         """start index of the aligned query portion of the sequence (0-based, inclusive)"""
  *         def __get__(self):
  *             return query_start(self._delegate)             # <<<<<<<<<<<<<<
@@ -25365,8 +26109,8 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_6qstart___get__(struct
  *     property qend:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __pyx_f_5pysam_9csamtools_query_start(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __pyx_f_5pysam_9csamtools_query_start(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
@@ -25396,7 +26140,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_4qend_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2672
+/* "pysam/csamtools.pyx":2679
  *     property qend:
  *         """end index of the aligned query portion of the sequence (0-based, exclusive)"""
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -25414,9 +26158,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4qend___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2672);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2679);
 
-  /* "pysam/csamtools.pyx":2673
+  /* "pysam/csamtools.pyx":2680
  *         """end index of the aligned query portion of the sequence (0-based, exclusive)"""
  *         def __get__(self):
  *             return query_end(self._delegate)             # <<<<<<<<<<<<<<
@@ -25424,8 +26168,8 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4qend___get__(struct _
  *     property qlen:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __pyx_f_5pysam_9csamtools_query_end(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __pyx_f_5pysam_9csamtools_query_end(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
@@ -25455,7 +26199,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_4qlen_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2677
+/* "pysam/csamtools.pyx":2684
  *     property qlen:
  *         """Length of the aligned query sequence"""
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -25476,9 +26220,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4qlen___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2677);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2684);
 
-  /* "pysam/csamtools.pyx":2679
+  /* "pysam/csamtools.pyx":2686
  *         def __get__(self):
  *             cdef bam1_t * src
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -25488,7 +26232,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4qlen___get__(struct _
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2680
+  /* "pysam/csamtools.pyx":2687
  *             cdef bam1_t * src
  *             src = self._delegate
  *             return query_end(src)-query_start(src)             # <<<<<<<<<<<<<<
@@ -25496,9 +26240,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4qlen___get__(struct _
  *     property tags:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = __pyx_f_5pysam_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_3 = __pyx_f_5pysam_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_4 = PyInt_FromLong((__pyx_t_2 - __pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __pyx_f_5pysam_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __pyx_f_5pysam_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyInt_FromLong((__pyx_t_2 - __pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __pyx_r = __pyx_t_4;
   __pyx_t_4 = 0;
@@ -25528,7 +26272,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_4tags_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2697
+/* "pysam/csamtools.pyx":2704
  *         multiple times.
  *         """
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -25567,9 +26311,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2697);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2704);
 
-  /* "pysam/csamtools.pyx":2706
+  /* "pysam/csamtools.pyx":2713
  *             cdef int32_t nvalues
  * 
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -25579,7 +26323,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2707
+  /* "pysam/csamtools.pyx":2714
  * 
  *             src = self._delegate
  *             if src.l_aux == 0: return []             # <<<<<<<<<<<<<<
@@ -25589,7 +26333,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
   __pyx_t_2 = (__pyx_v_src->l_aux == 0);
   if (__pyx_t_2) {
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __pyx_r = ((PyObject *)__pyx_t_3);
     __pyx_t_3 = 0;
@@ -25598,7 +26342,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2708
+  /* "pysam/csamtools.pyx":2715
  *             src = self._delegate
  *             if src.l_aux == 0: return []
  *             s = bam1_aux( src )             # <<<<<<<<<<<<<<
@@ -25607,19 +26351,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
  */
   __pyx_v_s = bam1_aux(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":2709
+  /* "pysam/csamtools.pyx":2716
  *             if src.l_aux == 0: return []
  *             s = bam1_aux( src )
  *             result = []             # <<<<<<<<<<<<<<
  *             auxtag[2] = 0
  *             while s < (src.data + src.data_len):
  */
-  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_v_result = ((PyObject*)__pyx_t_3);
   __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":2710
+  /* "pysam/csamtools.pyx":2717
  *             s = bam1_aux( src )
  *             result = []
  *             auxtag[2] = 0             # <<<<<<<<<<<<<<
@@ -25628,7 +26372,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
  */
   (__pyx_v_auxtag[2]) = 0;
 
-  /* "pysam/csamtools.pyx":2711
+  /* "pysam/csamtools.pyx":2718
  *             result = []
  *             auxtag[2] = 0
  *             while s < (src.data + src.data_len):             # <<<<<<<<<<<<<<
@@ -25639,7 +26383,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
     __pyx_t_2 = (__pyx_v_s < (__pyx_v_src->data + __pyx_v_src->data_len));
     if (!__pyx_t_2) break;
 
-    /* "pysam/csamtools.pyx":2713
+    /* "pysam/csamtools.pyx":2720
  *             while s < (src.data + src.data_len):
  *                 # get tag
  *                 auxtag[0] = s[0]             # <<<<<<<<<<<<<<
@@ -25648,7 +26392,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
  */
     (__pyx_v_auxtag[0]) = (__pyx_v_s[0]);
 
-    /* "pysam/csamtools.pyx":2714
+    /* "pysam/csamtools.pyx":2721
  *                 # get tag
  *                 auxtag[0] = s[0]
  *                 auxtag[1] = s[1]             # <<<<<<<<<<<<<<
@@ -25657,7 +26401,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
  */
     (__pyx_v_auxtag[1]) = (__pyx_v_s[1]);
 
-    /* "pysam/csamtools.pyx":2715
+    /* "pysam/csamtools.pyx":2722
  *                 auxtag[0] = s[0]
  *                 auxtag[1] = s[1]
  *                 s += 2             # <<<<<<<<<<<<<<
@@ -25666,7 +26410,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
  */
     __pyx_v_s = (__pyx_v_s + 2);
 
-    /* "pysam/csamtools.pyx":2716
+    /* "pysam/csamtools.pyx":2723
  *                 auxtag[1] = s[1]
  *                 s += 2
  *                 auxtype = s[0]             # <<<<<<<<<<<<<<
@@ -25675,7 +26419,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
  */
     __pyx_v_auxtype = (__pyx_v_s[0]);
 
-    /* "pysam/csamtools.pyx":2717
+    /* "pysam/csamtools.pyx":2724
  *                 s += 2
  *                 auxtype = s[0]
  *                 if auxtype in ('c', 'C'):             # <<<<<<<<<<<<<<
@@ -25693,20 +26437,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
     __pyx_t_2 = __pyx_t_6;
     if (__pyx_t_2) {
 
-      /* "pysam/csamtools.pyx":2718
+      /* "pysam/csamtools.pyx":2725
  *                 auxtype = s[0]
  *                 if auxtype in ('c', 'C'):
  *                     value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
  *                     s += 1
  *                 elif auxtype in ('s', 'S'):
  */
-      __pyx_t_3 = PyInt_FromLong(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyInt_FromLong(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_XDECREF(__pyx_v_value);
       __pyx_v_value = __pyx_t_3;
       __pyx_t_3 = 0;
 
-      /* "pysam/csamtools.pyx":2719
+      /* "pysam/csamtools.pyx":2726
  *                 if auxtype in ('c', 'C'):
  *                     value = <int>bam_aux2i(s)
  *                     s += 1             # <<<<<<<<<<<<<<
@@ -25717,7 +26461,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
       goto __pyx_L6;
     }
 
-    /* "pysam/csamtools.pyx":2720
+    /* "pysam/csamtools.pyx":2727
  *                     value = <int>bam_aux2i(s)
  *                     s += 1
  *                 elif auxtype in ('s', 'S'):             # <<<<<<<<<<<<<<
@@ -25735,20 +26479,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
     __pyx_t_2 = __pyx_t_5;
     if (__pyx_t_2) {
 
-      /* "pysam/csamtools.pyx":2721
+      /* "pysam/csamtools.pyx":2728
  *                     s += 1
  *                 elif auxtype in ('s', 'S'):
  *                     value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
  *                     s += 2
  *                 elif auxtype in ('i', 'I'):
  */
-      __pyx_t_3 = PyInt_FromLong(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyInt_FromLong(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_XDECREF(__pyx_v_value);
       __pyx_v_value = __pyx_t_3;
       __pyx_t_3 = 0;
 
-      /* "pysam/csamtools.pyx":2722
+      /* "pysam/csamtools.pyx":2729
  *                 elif auxtype in ('s', 'S'):
  *                     value = <int>bam_aux2i(s)
  *                     s += 2             # <<<<<<<<<<<<<<
@@ -25759,7 +26503,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
       goto __pyx_L6;
     }
 
-    /* "pysam/csamtools.pyx":2723
+    /* "pysam/csamtools.pyx":2730
  *                     value = <int>bam_aux2i(s)
  *                     s += 2
  *                 elif auxtype in ('i', 'I'):             # <<<<<<<<<<<<<<
@@ -25777,20 +26521,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
     __pyx_t_2 = __pyx_t_6;
     if (__pyx_t_2) {
 
-      /* "pysam/csamtools.pyx":2724
+      /* "pysam/csamtools.pyx":2731
  *                     s += 2
  *                 elif auxtype in ('i', 'I'):
  *                     value = <int32_t>bam_aux2i(s)             # <<<<<<<<<<<<<<
  *                     s += 4
  *                 elif auxtype == 'f':
  */
-      __pyx_t_3 = __Pyx_PyInt_to_py_int32_t(((int32_t)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyInt_to_py_int32_t(((int32_t)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_XDECREF(__pyx_v_value);
       __pyx_v_value = __pyx_t_3;
       __pyx_t_3 = 0;
 
-      /* "pysam/csamtools.pyx":2725
+      /* "pysam/csamtools.pyx":2732
  *                 elif auxtype in ('i', 'I'):
  *                     value = <int32_t>bam_aux2i(s)
  *                     s += 4             # <<<<<<<<<<<<<<
@@ -25801,7 +26545,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
       goto __pyx_L6;
     }
 
-    /* "pysam/csamtools.pyx":2726
+    /* "pysam/csamtools.pyx":2733
  *                     value = <int32_t>bam_aux2i(s)
  *                     s += 4
  *                 elif auxtype == 'f':             # <<<<<<<<<<<<<<
@@ -25811,20 +26555,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
     __pyx_t_2 = (__pyx_v_auxtype == 'f');
     if (__pyx_t_2) {
 
-      /* "pysam/csamtools.pyx":2727
+      /* "pysam/csamtools.pyx":2734
  *                     s += 4
  *                 elif auxtype == 'f':
  *                     value = <float>bam_aux2f(s)             # <<<<<<<<<<<<<<
  *                     s += 4
  *                 elif auxtype == 'd':
  */
-      __pyx_t_3 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_XDECREF(__pyx_v_value);
       __pyx_v_value = __pyx_t_3;
       __pyx_t_3 = 0;
 
-      /* "pysam/csamtools.pyx":2728
+      /* "pysam/csamtools.pyx":2735
  *                 elif auxtype == 'f':
  *                     value = <float>bam_aux2f(s)
  *                     s += 4             # <<<<<<<<<<<<<<
@@ -25835,7 +26579,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
       goto __pyx_L6;
     }
 
-    /* "pysam/csamtools.pyx":2729
+    /* "pysam/csamtools.pyx":2736
  *                     value = <float>bam_aux2f(s)
  *                     s += 4
  *                 elif auxtype == 'd':             # <<<<<<<<<<<<<<
@@ -25845,20 +26589,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
     __pyx_t_2 = (__pyx_v_auxtype == 'd');
     if (__pyx_t_2) {
 
-      /* "pysam/csamtools.pyx":2730
+      /* "pysam/csamtools.pyx":2737
  *                     s += 4
  *                 elif auxtype == 'd':
  *                     value = <double>bam_aux2d(s)             # <<<<<<<<<<<<<<
  *                     s += 8
  *                 elif auxtype == 'A':
  */
-      __pyx_t_3 = PyFloat_FromDouble(((double)bam_aux2d(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyFloat_FromDouble(((double)bam_aux2d(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_XDECREF(__pyx_v_value);
       __pyx_v_value = __pyx_t_3;
       __pyx_t_3 = 0;
 
-      /* "pysam/csamtools.pyx":2731
+      /* "pysam/csamtools.pyx":2738
  *                 elif auxtype == 'd':
  *                     value = <double>bam_aux2d(s)
  *                     s += 8             # <<<<<<<<<<<<<<
@@ -25869,7 +26613,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
       goto __pyx_L6;
     }
 
-    /* "pysam/csamtools.pyx":2732
+    /* "pysam/csamtools.pyx":2739
  *                     value = <double>bam_aux2d(s)
  *                     s += 8
  *                 elif auxtype == 'A':             # <<<<<<<<<<<<<<
@@ -25879,23 +26623,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
     __pyx_t_2 = (__pyx_v_auxtype == 'A');
     if (__pyx_t_2) {
 
-      /* "pysam/csamtools.pyx":2733
+      /* "pysam/csamtools.pyx":2740
  *                     s += 8
  *                 elif auxtype == 'A':
  *                     value = "%c" % <char>bam_aux2A(s)             # <<<<<<<<<<<<<<
  *                     s += 1
  *                 elif auxtype in ('Z', 'H'):
  */
-      __pyx_t_3 = PyInt_FromLong(((char)bam_aux2A(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyInt_FromLong(((char)bam_aux2A(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
-      __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_149), __pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_148), __pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_7));
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
       __Pyx_XDECREF(__pyx_v_value);
       __pyx_v_value = ((PyObject *)__pyx_t_7);
       __pyx_t_7 = 0;
 
-      /* "pysam/csamtools.pyx":2734
+      /* "pysam/csamtools.pyx":2741
  *                 elif auxtype == 'A':
  *                     value = "%c" % <char>bam_aux2A(s)
  *                     s += 1             # <<<<<<<<<<<<<<
@@ -25906,7 +26650,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
       goto __pyx_L6;
     }
 
-    /* "pysam/csamtools.pyx":2735
+    /* "pysam/csamtools.pyx":2742
  *                     value = "%c" % <char>bam_aux2A(s)
  *                     s += 1
  *                 elif auxtype in ('Z', 'H'):             # <<<<<<<<<<<<<<
@@ -25924,32 +26668,32 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
     __pyx_t_2 = __pyx_t_5;
     if (__pyx_t_2) {
 
-      /* "pysam/csamtools.pyx":2736
+      /* "pysam/csamtools.pyx":2743
  *                     s += 1
  *                 elif auxtype in ('Z', 'H'):
  *                     value = _charptr_to_str(<char*>bam_aux2Z(s))             # <<<<<<<<<<<<<<
  *                     # +1 for NULL terminated string
  *                     s += len(value) + 1
  */
-      __pyx_t_7 = __pyx_f_5pysam_9csamtools__charptr_to_str(((char *)bam_aux2Z(__pyx_v_s))); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __pyx_f_5pysam_9csamtools__charptr_to_str(((char *)bam_aux2Z(__pyx_v_s))); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_XDECREF(__pyx_v_value);
       __pyx_v_value = __pyx_t_7;
       __pyx_t_7 = 0;
 
-      /* "pysam/csamtools.pyx":2738
+      /* "pysam/csamtools.pyx":2745
  *                     value = _charptr_to_str(<char*>bam_aux2Z(s))
  *                     # +1 for NULL terminated string
  *                     s += len(value) + 1             # <<<<<<<<<<<<<<
  *                 elif auxtype == 'B':
  *                     s += 1
  */
-      __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_v_s = (__pyx_v_s + (__pyx_t_8 + 1));
       goto __pyx_L6;
     }
 
-    /* "pysam/csamtools.pyx":2739
+    /* "pysam/csamtools.pyx":2746
  *                     # +1 for NULL terminated string
  *                     s += len(value) + 1
  *                 elif auxtype == 'B':             # <<<<<<<<<<<<<<
@@ -25959,7 +26703,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
     __pyx_t_2 = (__pyx_v_auxtype == 'B');
     if (__pyx_t_2) {
 
-      /* "pysam/csamtools.pyx":2740
+      /* "pysam/csamtools.pyx":2747
  *                     s += len(value) + 1
  *                 elif auxtype == 'B':
  *                     s += 1             # <<<<<<<<<<<<<<
@@ -25968,14 +26712,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
  */
       __pyx_v_s = (__pyx_v_s + 1);
 
-      /* "pysam/csamtools.pyx":2741
+      /* "pysam/csamtools.pyx":2748
  *                 elif auxtype == 'B':
  *                     s += 1
  *                     byte_size, nvalues, value = convertBinaryTagToList( s )             # <<<<<<<<<<<<<<
  *                     # 5 for 1 char and 1 int
  *                     s += 5 + ( nvalues * byte_size) - 1
  */
-      __pyx_t_7 = __pyx_f_5pysam_9csamtools_convertBinaryTagToList(__pyx_v_s); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __pyx_f_5pysam_9csamtools_convertBinaryTagToList(__pyx_v_s); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
         PyObject* sequence = __pyx_t_7;
@@ -25987,7 +26731,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
         if (unlikely(size != 3)) {
           if (size > 3) __Pyx_RaiseTooManyValuesError(3);
           else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         #if CYTHON_COMPILING_IN_CPYTHON
         if (likely(PyTuple_CheckExact(sequence))) {
@@ -26003,18 +26747,18 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
         __Pyx_INCREF(__pyx_t_9);
         __Pyx_INCREF(__pyx_t_10);
         #else
-        __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2741; __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 = 2748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_3);
-        __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2741; __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 = 2748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_9);
-        __pyx_t_10 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2741; __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 = 2748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_10);
         #endif
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       } else
       {
         Py_ssize_t index = -1;
-        __pyx_t_11 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_11 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_11);
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
@@ -26024,7 +26768,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
         __Pyx_GOTREF(__pyx_t_9);
         index = 2; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L7_unpacking_failed;
         __Pyx_GOTREF(__pyx_t_10);
-        if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __pyx_t_12 = NULL;
         __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
         goto __pyx_L8_unpacking_done;
@@ -26032,12 +26776,12 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
         __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
         __pyx_t_12 = NULL;
         if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __pyx_L8_unpacking_done:;
       }
-      __pyx_t_13 = __Pyx_PyInt_from_py_uint8_t(__pyx_t_3); if (unlikely((__pyx_t_13 == (uint8_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_13 = __Pyx_PyInt_from_py_uint8_t(__pyx_t_3); if (unlikely((__pyx_t_13 == (uint8_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-      __pyx_t_14 = __Pyx_PyInt_from_py_int32_t(__pyx_t_9); if (unlikely((__pyx_t_14 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_14 = __Pyx_PyInt_from_py_int32_t(__pyx_t_9); if (unlikely((__pyx_t_14 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
       __pyx_v_byte_size = __pyx_t_13;
       __pyx_v_nvalues = __pyx_t_14;
@@ -26045,7 +26789,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
       __pyx_v_value = __pyx_t_10;
       __pyx_t_10 = 0;
 
-      /* "pysam/csamtools.pyx":2743
+      /* "pysam/csamtools.pyx":2750
  *                     byte_size, nvalues, value = convertBinaryTagToList( s )
  *                     # 5 for 1 char and 1 int
  *                     s += 5 + ( nvalues * byte_size) - 1             # <<<<<<<<<<<<<<
@@ -26057,7 +26801,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
     }
     __pyx_L6:;
 
-    /* "pysam/csamtools.pyx":2745
+    /* "pysam/csamtools.pyx":2752
  *                     s += 5 + ( nvalues * byte_size) - 1
  * 
  *                 s += 1             # <<<<<<<<<<<<<<
@@ -26066,17 +26810,17 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
  */
     __pyx_v_s = (__pyx_v_s + 1);
 
-    /* "pysam/csamtools.pyx":2747
+    /* "pysam/csamtools.pyx":2754
  *                 s += 1
  * 
  *                 result.append( (_charptr_to_str(auxtag), value) )             # <<<<<<<<<<<<<<
  * 
  *             return result
  */
-    __pyx_t_7 = __pyx_f_5pysam_9csamtools__charptr_to_str(__pyx_v_auxtag); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = __pyx_f_5pysam_9csamtools__charptr_to_str(__pyx_v_auxtag); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
-    if (unlikely(!__pyx_v_value)) { __Pyx_RaiseUnboundLocalError("value"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
-    __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (unlikely(!__pyx_v_value)) { __Pyx_RaiseUnboundLocalError("value"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2754; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+    __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_10);
     PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7);
     __Pyx_GIVEREF(__pyx_t_7);
@@ -26084,11 +26828,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tags___get__(struct _
     PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_value);
     __Pyx_GIVEREF(__pyx_v_value);
     __pyx_t_7 = 0;
-    __pyx_t_15 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_10)); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_15 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_10)); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
   }
 
-  /* "pysam/csamtools.pyx":2749
+  /* "pysam/csamtools.pyx":2756
  *                 result.append( (_charptr_to_str(auxtag), value) )
  * 
  *             return result             # <<<<<<<<<<<<<<
@@ -26130,7 +26874,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_4tags_3__set__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2751
+/* "pysam/csamtools.pyx":2758
  *             return result
  * 
  *         def __set__(self, tags):             # <<<<<<<<<<<<<<
@@ -26183,9 +26927,9 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2751);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2758);
 
-  /* "pysam/csamtools.pyx":2757
+  /* "pysam/csamtools.pyx":2764
  *             cdef char * temp
  * 
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -26195,38 +26939,38 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2759
+  /* "pysam/csamtools.pyx":2766
  *             src = self._delegate
  * 
  *             fmts, args = ["<"], []             # <<<<<<<<<<<<<<
  * 
  *             if tags != None:
  */
-  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __Pyx_INCREF(((PyObject *)__pyx_kp_s_150));
-  PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_150));
-  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_150));
-  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_INCREF(((PyObject *)__pyx_kp_s_149));
+  PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_149));
+  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_149));
+  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_v_fmts = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
   __pyx_v_args = ((PyObject*)__pyx_t_3);
   __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":2761
+  /* "pysam/csamtools.pyx":2768
  *             fmts, args = ["<"], []
  * 
  *             if tags != None:             # <<<<<<<<<<<<<<
  * 
  *                 # map samtools code to python.struct code and byte size
  */
-  __pyx_t_3 = PyObject_RichCompare(__pyx_v_tags, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_RichCompare(__pyx_v_tags, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":2764
+    /* "pysam/csamtools.pyx":2771
  * 
  *                 # map samtools code to python.struct code and byte size
  *                 for pytag, value in tags:             # <<<<<<<<<<<<<<
@@ -26237,7 +26981,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       __pyx_t_3 = __pyx_v_tags; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
       __pyx_t_6 = NULL;
     } else {
-      __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_tags); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_tags); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext;
     }
@@ -26245,23 +26989,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_3)) {
         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_3)) {
         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #endif
       } else {
         __pyx_t_2 = __pyx_t_6(__pyx_t_3);
         if (unlikely(!__pyx_t_2)) {
           if (PyErr_Occurred()) {
             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           }
           break;
         }
@@ -26277,7 +27021,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         if (unlikely(size != 2)) {
           if (size > 2) __Pyx_RaiseTooManyValuesError(2);
           else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         #if CYTHON_COMPILING_IN_CPYTHON
         if (likely(PyTuple_CheckExact(sequence))) {
@@ -26290,16 +27034,16 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         __Pyx_INCREF(__pyx_t_7);
         __Pyx_INCREF(__pyx_t_8);
         #else
-        __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
-        __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
         #endif
         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
       } else
       {
         Py_ssize_t index = -1;
-        __pyx_t_9 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_9);
         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
         __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext;
@@ -26307,7 +27051,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         __Pyx_GOTREF(__pyx_t_7);
         index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed;
         __Pyx_GOTREF(__pyx_t_8);
-        if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __pyx_t_10 = NULL;
         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
         goto __pyx_L7_unpacking_done;
@@ -26315,7 +27059,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
         __pyx_t_10 = NULL;
         if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __pyx_L7_unpacking_done:;
       }
       __Pyx_XDECREF(__pyx_v_pytag);
@@ -26325,7 +27069,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       __pyx_v_value = __pyx_t_8;
       __pyx_t_8 = 0;
 
-      /* "pysam/csamtools.pyx":2765
+      /* "pysam/csamtools.pyx":2772
  *                 # map samtools code to python.struct code and byte size
  *                 for pytag, value in tags:
  *                     if not type(pytag) is bytes:             # <<<<<<<<<<<<<<
@@ -26336,16 +27080,16 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       __pyx_t_11 = (!__pyx_t_4);
       if (__pyx_t_11) {
 
-        /* "pysam/csamtools.pyx":2766
+        /* "pysam/csamtools.pyx":2773
  *                 for pytag, value in tags:
  *                     if not type(pytag) is bytes:
  *                         pytag = pytag.encode('ascii')             # <<<<<<<<<<<<<<
  *                     t = type(value)
  * 
  */
-        __pyx_t_2 = PyObject_GetAttr(__pyx_v_pytag, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyObject_GetAttr(__pyx_v_pytag, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
-        __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_151), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_150), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
         __Pyx_DECREF(__pyx_v_pytag);
@@ -26355,7 +27099,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       }
       __pyx_L8:;
 
-      /* "pysam/csamtools.pyx":2767
+      /* "pysam/csamtools.pyx":2774
  *                     if not type(pytag) is bytes:
  *                         pytag = pytag.encode('ascii')
  *                     t = type(value)             # <<<<<<<<<<<<<<
@@ -26366,7 +27110,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       __Pyx_XDECREF(((PyObject *)__pyx_v_t));
       __pyx_v_t = ((PyObject*)((PyObject *)Py_TYPE(__pyx_v_value)));
 
-      /* "pysam/csamtools.pyx":2769
+      /* "pysam/csamtools.pyx":2776
  *                     t = type(value)
  * 
  *                     if t is tuple or t is list:             # <<<<<<<<<<<<<<
@@ -26382,7 +27126,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       }
       if (__pyx_t_12) {
 
-        /* "pysam/csamtools.pyx":2771
+        /* "pysam/csamtools.pyx":2778
  *                     if t is tuple or t is list:
  *                         # binary tags - treat separately
  *                         pytype = 'B'             # <<<<<<<<<<<<<<
@@ -26393,20 +27137,20 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         __Pyx_XDECREF(__pyx_v_pytype);
         __pyx_v_pytype = ((PyObject *)__pyx_n_s__B);
 
-        /* "pysam/csamtools.pyx":2773
+        /* "pysam/csamtools.pyx":2780
  *                         pytype = 'B'
  *                         # get data type - first value determines type
  *                         if type(value[0]) is float:             # <<<<<<<<<<<<<<
  *                             datafmt, datatype = "f", "f"
  *                         else:
  */
-        __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_value, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_value, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
         __pyx_t_12 = (((PyObject *)Py_TYPE(__pyx_t_8)) == ((PyObject *)((PyObject*)(&PyFloat_Type))));
         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         if (__pyx_t_12) {
 
-          /* "pysam/csamtools.pyx":2774
+          /* "pysam/csamtools.pyx":2781
  *                         # get data type - first value determines type
  *                         if type(value[0]) is float:
  *                             datafmt, datatype = "f", "f"             # <<<<<<<<<<<<<<
@@ -26427,27 +27171,27 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         }
         /*else*/ {
 
-          /* "pysam/csamtools.pyx":2776
+          /* "pysam/csamtools.pyx":2783
  *                             datafmt, datatype = "f", "f"
  *                         else:
  *                             mi, ma = min(value), max(value)             # <<<<<<<<<<<<<<
  *                             absmax = max( abs(mi), abs(ma) )
  *                             # signed ints
  */
-          __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_2);
           __Pyx_INCREF(__pyx_v_value);
           PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_value);
           __Pyx_GIVEREF(__pyx_v_value);
-          __pyx_t_8 = PyObject_Call(__pyx_builtin_min, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_8 = PyObject_Call(__pyx_builtin_min, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_8);
           __Pyx_DECREF(((PyObject *)__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 = 2776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_2);
           __Pyx_INCREF(__pyx_v_value);
           PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_value);
           __Pyx_GIVEREF(__pyx_v_value);
-          __pyx_t_7 = PyObject_Call(__pyx_builtin_max, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyObject_Call(__pyx_builtin_max, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_7);
           __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
           __Pyx_XDECREF(__pyx_v_mi);
@@ -26457,19 +27201,19 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
           __pyx_v_ma = __pyx_t_7;
           __pyx_t_7 = 0;
 
-          /* "pysam/csamtools.pyx":2777
+          /* "pysam/csamtools.pyx":2784
  *                         else:
  *                             mi, ma = min(value), max(value)
  *                             absmax = max( abs(mi), abs(ma) )             # <<<<<<<<<<<<<<
  *                             # signed ints
  *                             if mi < 0:
  */
-          __pyx_t_7 = PyNumber_Absolute(__pyx_v_ma); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyNumber_Absolute(__pyx_v_ma); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_7);
-          __pyx_t_8 = PyNumber_Absolute(__pyx_v_mi); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_8 = PyNumber_Absolute(__pyx_v_mi); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_8);
-          __pyx_t_9 = PyObject_RichCompare(__pyx_t_7, __pyx_t_8, Py_GT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_9 = PyObject_RichCompare(__pyx_t_7, __pyx_t_8, Py_GT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
           if (__pyx_t_12) {
             __Pyx_INCREF(__pyx_t_7);
@@ -26487,27 +27231,27 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
           __pyx_v_absmax = __pyx_t_7;
           __pyx_t_7 = 0;
 
-          /* "pysam/csamtools.pyx":2779
+          /* "pysam/csamtools.pyx":2786
  *                             absmax = max( abs(mi), abs(ma) )
  *                             # signed ints
  *                             if mi < 0:             # <<<<<<<<<<<<<<
  *                                 if mi >= -127: datafmt, datatype = "b", 'c'
  *                                 elif mi >= -32767: datafmt, datatype = "h", 's'
  */
-          __pyx_t_7 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_7 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
           if (__pyx_t_12) {
 
-            /* "pysam/csamtools.pyx":2780
+            /* "pysam/csamtools.pyx":2787
  *                             # signed ints
  *                             if mi < 0:
  *                                 if mi >= -127: datafmt, datatype = "b", 'c'             # <<<<<<<<<<<<<<
  *                                 elif mi >= -32767: datafmt, datatype = "h", 's'
  *                                 elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
  */
-            __pyx_t_7 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_neg_127, Py_GE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_7 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_neg_127, Py_GE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
             if (__pyx_t_12) {
               __pyx_t_7 = ((PyObject *)__pyx_n_s__b);
@@ -26523,15 +27267,15 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
               goto __pyx_L12;
             }
 
-            /* "pysam/csamtools.pyx":2781
+            /* "pysam/csamtools.pyx":2788
  *                             if mi < 0:
  *                                 if mi >= -127: datafmt, datatype = "b", 'c'
  *                                 elif mi >= -32767: datafmt, datatype = "h", 's'             # <<<<<<<<<<<<<<
  *                                 elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
  *                                 else: datafmt, datatype = "i", 'i'
  */
-            __pyx_t_2 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_neg_32767, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_2 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_neg_32767, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
             if (__pyx_t_12) {
               __pyx_t_2 = ((PyObject *)__pyx_n_s__h);
@@ -26547,35 +27291,35 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
               goto __pyx_L12;
             }
 
-            /* "pysam/csamtools.pyx":2782
+            /* "pysam/csamtools.pyx":2789
  *                                 if mi >= -127: datafmt, datatype = "b", 'c'
  *                                 elif mi >= -32767: datafmt, datatype = "h", 's'
  *                                 elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
  *                                 else: datafmt, datatype = "i", 'i'
  * 
  */
-            __pyx_t_7 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_neg_2147483648, Py_LT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_7 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_neg_2147483648, Py_LT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
             if (__pyx_t_12) {
-              __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_152), __pyx_v_value); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_151), __pyx_v_value); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
               __Pyx_GOTREF(((PyObject *)__pyx_t_7));
-              __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
               __Pyx_GOTREF(__pyx_t_2);
               PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_7));
               __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
               __pyx_t_7 = 0;
-              __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
               __Pyx_GOTREF(__pyx_t_7);
               __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
               __Pyx_Raise(__pyx_t_7, 0, 0, 0);
               __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-              {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
               goto __pyx_L12;
             }
             /*else*/ {
 
-              /* "pysam/csamtools.pyx":2783
+              /* "pysam/csamtools.pyx":2790
  *                                 elif mi >= -32767: datafmt, datatype = "h", 's'
  *                                 elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
  *                                 else: datafmt, datatype = "i", 'i'             # <<<<<<<<<<<<<<
@@ -26598,15 +27342,15 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
           }
           /*else*/ {
 
-            /* "pysam/csamtools.pyx":2787
+            /* "pysam/csamtools.pyx":2794
  *                             # unsigned ints
  *                             else:
  *                                 if absmax <= 255: datafmt, datatype = "B", 'C'             # <<<<<<<<<<<<<<
  *                                 elif absmax <= 65535: datafmt, datatype = "H", 'S'
  *                                 elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
  */
-            __pyx_t_2 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_255, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_2 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_255, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
             if (__pyx_t_12) {
               __pyx_t_2 = ((PyObject *)__pyx_n_s__B);
@@ -26622,15 +27366,15 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
               goto __pyx_L13;
             }
 
-            /* "pysam/csamtools.pyx":2788
+            /* "pysam/csamtools.pyx":2795
  *                             else:
  *                                 if absmax <= 255: datafmt, datatype = "B", 'C'
  *                                 elif absmax <= 65535: datafmt, datatype = "H", 'S'             # <<<<<<<<<<<<<<
  *                                 elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
  *                                 else: datafmt, datatype = "I", 'I'
  */
-            __pyx_t_7 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_65535, Py_LE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_7 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_65535, Py_LE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
             if (__pyx_t_12) {
               __pyx_t_7 = ((PyObject *)__pyx_n_s__H);
@@ -26646,35 +27390,35 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
               goto __pyx_L13;
             }
 
-            /* "pysam/csamtools.pyx":2789
+            /* "pysam/csamtools.pyx":2796
  *                                 if absmax <= 255: datafmt, datatype = "B", 'C'
  *                                 elif absmax <= 65535: datafmt, datatype = "H", 'S'
  *                                 elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
  *                                 else: datafmt, datatype = "I", 'I'
  * 
  */
-            __pyx_t_2 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_4294967295, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_2 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_4294967295, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
             if (__pyx_t_12) {
-              __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_152), __pyx_v_value); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_151), __pyx_v_value); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
               __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-              __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
               __Pyx_GOTREF(__pyx_t_7);
               PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_2));
               __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
               __pyx_t_2 = 0;
-              __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
               __Pyx_GOTREF(__pyx_t_2);
               __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
               __Pyx_Raise(__pyx_t_2, 0, 0, 0);
               __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-              {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
               goto __pyx_L13;
             }
             /*else*/ {
 
-              /* "pysam/csamtools.pyx":2790
+              /* "pysam/csamtools.pyx":2797
  *                                 elif absmax <= 65535: datafmt, datatype = "H", 'S'
  *                                 elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
  *                                 else: datafmt, datatype = "I", 'I'             # <<<<<<<<<<<<<<
@@ -26698,17 +27442,17 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         }
         __pyx_L10:;
 
-        /* "pysam/csamtools.pyx":2792
+        /* "pysam/csamtools.pyx":2799
  *                                 else: datafmt, datatype = "I", 'I'
  * 
  *                         datafmt = "2sccI%i%s" % (len(value), datafmt)             # <<<<<<<<<<<<<<
  *                         args.extend( [pytag[:2],
  *                                       pytype.encode('ascii'),
  */
-        __pyx_t_13 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_13 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
-        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2792; __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 = 2799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
         PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7);
         __Pyx_GIVEREF(__pyx_t_7);
@@ -26716,70 +27460,70 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_datafmt);
         __Pyx_GIVEREF(__pyx_v_datafmt);
         __pyx_t_7 = 0;
-        __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_153), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_152), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_7));
         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
         __Pyx_DECREF(__pyx_v_datafmt);
         __pyx_v_datafmt = ((PyObject *)__pyx_t_7);
         __pyx_t_7 = 0;
 
-        /* "pysam/csamtools.pyx":2793
+        /* "pysam/csamtools.pyx":2800
  * 
  *                         datafmt = "2sccI%i%s" % (len(value), datafmt)
  *                         args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
  *                                       pytype.encode('ascii'),
  *                                       datatype.encode('ascii'),
  */
-        __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_args), __pyx_n_s__extend); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_args), __pyx_n_s__extend); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
 
-        /* "pysam/csamtools.pyx":2796
+        /* "pysam/csamtools.pyx":2803
  *                                       pytype.encode('ascii'),
  *                                       datatype.encode('ascii'),
  *                                       len(value)] + list(value) )             # <<<<<<<<<<<<<<
  *                         fmts.append( datafmt )
  *                         continue
  */
-        __pyx_t_2 = __Pyx_PySequence_GetSlice(__pyx_v_pytag, 0, 2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = __Pyx_PySequence_GetSlice(__pyx_v_pytag, 0, 2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
 
-        /* "pysam/csamtools.pyx":2794
+        /* "pysam/csamtools.pyx":2801
  *                         datafmt = "2sccI%i%s" % (len(value), datafmt)
  *                         args.extend( [pytag[:2],
  *                                       pytype.encode('ascii'),             # <<<<<<<<<<<<<<
  *                                       datatype.encode('ascii'),
  *                                       len(value)] + list(value) )
  */
-        __pyx_t_8 = PyObject_GetAttr(__pyx_v_pytype, __pyx_n_s__encode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyObject_GetAttr(__pyx_v_pytype, __pyx_n_s__encode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __pyx_t_9 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_154), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_153), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_9);
         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
 
-        /* "pysam/csamtools.pyx":2795
+        /* "pysam/csamtools.pyx":2802
  *                         args.extend( [pytag[:2],
  *                                       pytype.encode('ascii'),
  *                                       datatype.encode('ascii'),             # <<<<<<<<<<<<<<
  *                                       len(value)] + list(value) )
  *                         fmts.append( datafmt )
  */
-        __pyx_t_8 = PyObject_GetAttr(__pyx_v_datatype, __pyx_n_s__encode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyObject_GetAttr(__pyx_v_datatype, __pyx_n_s__encode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __pyx_t_14 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_155), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_14 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_154), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_14);
         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
 
-        /* "pysam/csamtools.pyx":2796
+        /* "pysam/csamtools.pyx":2803
  *                                       pytype.encode('ascii'),
  *                                       datatype.encode('ascii'),
  *                                       len(value)] + list(value) )             # <<<<<<<<<<<<<<
  *                         fmts.append( datafmt )
  *                         continue
  */
-        __pyx_t_13 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_13 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __pyx_t_15 = PyList_New(4); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_15 = PyList_New(4); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_15);
         PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_2);
         __Pyx_GIVEREF(__pyx_t_2);
@@ -26793,39 +27537,39 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         __pyx_t_9 = 0;
         __pyx_t_14 = 0;
         __pyx_t_8 = 0;
-        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
         __Pyx_INCREF(__pyx_v_value);
         PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_value);
         __Pyx_GIVEREF(__pyx_v_value);
-        __pyx_t_14 = PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_14 = PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_14);
         __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
-        __pyx_t_8 = PyNumber_Add(((PyObject *)__pyx_t_15), __pyx_t_14); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyNumber_Add(((PyObject *)__pyx_t_15), __pyx_t_14); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_8));
         __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0;
         __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
-        __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_14);
         PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_t_8));
         __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
         __pyx_t_8 = 0;
-        __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0;
         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
 
-        /* "pysam/csamtools.pyx":2797
+        /* "pysam/csamtools.pyx":2804
  *                                       datatype.encode('ascii'),
  *                                       len(value)] + list(value) )
  *                         fmts.append( datafmt )             # <<<<<<<<<<<<<<
  *                         continue
  * 
  */
-        __pyx_t_16 = PyList_Append(__pyx_v_fmts, __pyx_v_datafmt); if (unlikely(__pyx_t_16 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_16 = PyList_Append(__pyx_v_fmts, __pyx_v_datafmt); if (unlikely(__pyx_t_16 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-        /* "pysam/csamtools.pyx":2798
+        /* "pysam/csamtools.pyx":2805
  *                                       len(value)] + list(value) )
  *                         fmts.append( datafmt )
  *                         continue             # <<<<<<<<<<<<<<
@@ -26837,7 +27581,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       }
       __pyx_L9:;
 
-      /* "pysam/csamtools.pyx":2800
+      /* "pysam/csamtools.pyx":2807
  *                         continue
  * 
  *                     if t is float:             # <<<<<<<<<<<<<<
@@ -26847,7 +27591,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       __pyx_t_12 = (__pyx_v_t == ((PyObject*)(&PyFloat_Type)));
       if (__pyx_t_12) {
 
-        /* "pysam/csamtools.pyx":2801
+        /* "pysam/csamtools.pyx":2808
  * 
  *                     if t is float:
  *                         fmt, pytype = "2scf", 'f'             # <<<<<<<<<<<<<<
@@ -26867,7 +27611,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         goto __pyx_L14;
       }
 
-      /* "pysam/csamtools.pyx":2802
+      /* "pysam/csamtools.pyx":2809
  *                     if t is float:
  *                         fmt, pytype = "2scf", 'f'
  *                     elif t is int:             # <<<<<<<<<<<<<<
@@ -26877,27 +27621,27 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       __pyx_t_12 = (__pyx_v_t == ((PyObject*)(&PyInt_Type)));
       if (__pyx_t_12) {
 
-        /* "pysam/csamtools.pyx":2804
+        /* "pysam/csamtools.pyx":2811
  *                     elif t is int:
  *                         # negative values
  *                         if value < 0:             # <<<<<<<<<<<<<<
  *                             if value >= -127: fmt, pytype = "2scb", 'c'
  *                             elif value >= -32767: fmt, pytype = "2sch", 's'
  */
-        __pyx_t_14 = PyObject_RichCompare(__pyx_v_value, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_14 = PyObject_RichCompare(__pyx_v_value, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
         if (__pyx_t_12) {
 
-          /* "pysam/csamtools.pyx":2805
+          /* "pysam/csamtools.pyx":2812
  *                         # negative values
  *                         if value < 0:
  *                             if value >= -127: fmt, pytype = "2scb", 'c'             # <<<<<<<<<<<<<<
  *                             elif value >= -32767: fmt, pytype = "2sch", 's'
  *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
  */
-          __pyx_t_14 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_127, Py_GE); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_14 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_127, Py_GE); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
           if (__pyx_t_12) {
             __pyx_t_14 = ((PyObject *)__pyx_kp_s__2scb);
@@ -26913,15 +27657,15 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
             goto __pyx_L16;
           }
 
-          /* "pysam/csamtools.pyx":2806
+          /* "pysam/csamtools.pyx":2813
  *                         if value < 0:
  *                             if value >= -127: fmt, pytype = "2scb", 'c'
  *                             elif value >= -32767: fmt, pytype = "2sch", 's'             # <<<<<<<<<<<<<<
  *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
  *                             else: fmt, pytype = "2sci", 'i'
  */
-          __pyx_t_8 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_32767, Py_GE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_8 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_32767, Py_GE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
           if (__pyx_t_12) {
             __pyx_t_8 = ((PyObject *)__pyx_kp_s__2sch);
@@ -26937,35 +27681,35 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
             goto __pyx_L16;
           }
 
-          /* "pysam/csamtools.pyx":2807
+          /* "pysam/csamtools.pyx":2814
  *                             if value >= -127: fmt, pytype = "2scb", 'c'
  *                             elif value >= -32767: fmt, pytype = "2sch", 's'
  *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
  *                             else: fmt, pytype = "2sci", 'i'
  *                         # positive values
  */
-          __pyx_t_14 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_2147483648, Py_LT); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_14 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_2147483648, Py_LT); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
           if (__pyx_t_12) {
-            __pyx_t_14 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_152), __pyx_v_value); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_14 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_151), __pyx_v_value); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_GOTREF(((PyObject *)__pyx_t_14));
-            __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_GOTREF(__pyx_t_8);
             PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_14));
             __Pyx_GIVEREF(((PyObject *)__pyx_t_14));
             __pyx_t_14 = 0;
-            __pyx_t_14 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_14 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_GOTREF(__pyx_t_14);
             __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
             __Pyx_Raise(__pyx_t_14, 0, 0, 0);
             __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
-            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             goto __pyx_L16;
           }
           /*else*/ {
 
-            /* "pysam/csamtools.pyx":2808
+            /* "pysam/csamtools.pyx":2815
  *                             elif value >= -32767: fmt, pytype = "2sch", 's'
  *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
  *                             else: fmt, pytype = "2sci", 'i'             # <<<<<<<<<<<<<<
@@ -26988,15 +27732,15 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         }
         /*else*/ {
 
-          /* "pysam/csamtools.pyx":2811
+          /* "pysam/csamtools.pyx":2818
  *                         # positive values
  *                         else:
  *                             if value <= 255: fmt, pytype = "2scB", 'C'             # <<<<<<<<<<<<<<
  *                             elif value <= 65535: fmt, pytype = "2scH", 'S'
  *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
  */
-          __pyx_t_8 = PyObject_RichCompare(__pyx_v_value, __pyx_int_255, Py_LE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_8 = PyObject_RichCompare(__pyx_v_value, __pyx_int_255, Py_LE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
           if (__pyx_t_12) {
             __pyx_t_8 = ((PyObject *)__pyx_kp_s__2scB);
@@ -27012,15 +27756,15 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
             goto __pyx_L17;
           }
 
-          /* "pysam/csamtools.pyx":2812
+          /* "pysam/csamtools.pyx":2819
  *                         else:
  *                             if value <= 255: fmt, pytype = "2scB", 'C'
  *                             elif value <= 65535: fmt, pytype = "2scH", 'S'             # <<<<<<<<<<<<<<
  *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
  *                             else: fmt, pytype = "2scI", 'I'
  */
-          __pyx_t_14 = PyObject_RichCompare(__pyx_v_value, __pyx_int_65535, Py_LE); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_14 = PyObject_RichCompare(__pyx_v_value, __pyx_int_65535, Py_LE); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
           if (__pyx_t_12) {
             __pyx_t_14 = ((PyObject *)__pyx_kp_s__2scH);
@@ -27036,35 +27780,35 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
             goto __pyx_L17;
           }
 
-          /* "pysam/csamtools.pyx":2813
+          /* "pysam/csamtools.pyx":2820
  *                             if value <= 255: fmt, pytype = "2scB", 'C'
  *                             elif value <= 65535: fmt, pytype = "2scH", 'S'
  *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
  *                             else: fmt, pytype = "2scI", 'I'
  *                     else:
  */
-          __pyx_t_8 = PyObject_RichCompare(__pyx_v_value, __pyx_int_4294967295, Py_GT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_8 = PyObject_RichCompare(__pyx_v_value, __pyx_int_4294967295, Py_GT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
           if (__pyx_t_12) {
-            __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_152), __pyx_v_value); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_151), __pyx_v_value); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_GOTREF(((PyObject *)__pyx_t_8));
-            __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_GOTREF(__pyx_t_14);
             PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_t_8));
             __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
             __pyx_t_8 = 0;
-            __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_GOTREF(__pyx_t_8);
             __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0;
             __Pyx_Raise(__pyx_t_8, 0, 0, 0);
             __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             goto __pyx_L17;
           }
           /*else*/ {
 
-            /* "pysam/csamtools.pyx":2814
+            /* "pysam/csamtools.pyx":2821
  *                             elif value <= 65535: fmt, pytype = "2scH", 'S'
  *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
  *                             else: fmt, pytype = "2scI", 'I'             # <<<<<<<<<<<<<<
@@ -27089,7 +27833,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       }
       /*else*/ {
 
-        /* "pysam/csamtools.pyx":2817
+        /* "pysam/csamtools.pyx":2824
  *                     else:
  *                         # Note: hex strings (H) are not supported yet
  *                         if t is not bytes:             # <<<<<<<<<<<<<<
@@ -27099,16 +27843,16 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         __pyx_t_12 = (__pyx_v_t != ((PyObject*)(&PyBytes_Type)));
         if (__pyx_t_12) {
 
-          /* "pysam/csamtools.pyx":2818
+          /* "pysam/csamtools.pyx":2825
  *                         # Note: hex strings (H) are not supported yet
  *                         if t is not bytes:
  *                             value = value.encode('ascii')             # <<<<<<<<<<<<<<
  *                         if len(value) == 1:
  *                             fmt, pytype = "2scc", 'A'
  */
-          __pyx_t_14 = PyObject_GetAttr(__pyx_v_value, __pyx_n_s__encode); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_14 = PyObject_GetAttr(__pyx_v_value, __pyx_n_s__encode); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_14);
-          __pyx_t_8 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_k_tuple_156), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_8 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_k_tuple_155), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_8);
           __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
           __Pyx_DECREF(__pyx_v_value);
@@ -27118,18 +27862,18 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         }
         __pyx_L18:;
 
-        /* "pysam/csamtools.pyx":2819
+        /* "pysam/csamtools.pyx":2826
  *                         if t is not bytes:
  *                             value = value.encode('ascii')
  *                         if len(value) == 1:             # <<<<<<<<<<<<<<
  *                             fmt, pytype = "2scc", 'A'
  *                         else:
  */
-        __pyx_t_13 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_13 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __pyx_t_12 = (__pyx_t_13 == 1);
         if (__pyx_t_12) {
 
-          /* "pysam/csamtools.pyx":2820
+          /* "pysam/csamtools.pyx":2827
  *                             value = value.encode('ascii')
  *                         if len(value) == 1:
  *                             fmt, pytype = "2scc", 'A'             # <<<<<<<<<<<<<<
@@ -27150,17 +27894,17 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
         }
         /*else*/ {
 
-          /* "pysam/csamtools.pyx":2822
+          /* "pysam/csamtools.pyx":2829
  *                             fmt, pytype = "2scc", 'A'
  *                         else:
  *                             fmt, pytype = "2sc%is" % (len(value)+1), 'Z'             # <<<<<<<<<<<<<<
  * 
  *                     args.extend( [pytag[:2],
  */
-          __pyx_t_13 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __pyx_t_14 = PyInt_FromSsize_t((__pyx_t_13 + 1)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_13 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_14 = PyInt_FromSsize_t((__pyx_t_13 + 1)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_14);
-          __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_157), __pyx_t_14); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_156), __pyx_t_14); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(((PyObject *)__pyx_t_8));
           __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
           __pyx_t_14 = ((PyObject *)__pyx_n_s__Z);
@@ -27176,39 +27920,39 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       }
       __pyx_L14:;
 
-      /* "pysam/csamtools.pyx":2824
+      /* "pysam/csamtools.pyx":2831
  *                             fmt, pytype = "2sc%is" % (len(value)+1), 'Z'
  * 
  *                     args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
  *                                   pytype.encode('ascii'),
  *                                   value ] )
  */
-      __pyx_t_14 = PyObject_GetAttr(((PyObject *)__pyx_v_args), __pyx_n_s__extend); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_14 = PyObject_GetAttr(((PyObject *)__pyx_v_args), __pyx_n_s__extend); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_14);
-      __pyx_t_8 = __Pyx_PySequence_GetSlice(__pyx_v_pytag, 0, 2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = __Pyx_PySequence_GetSlice(__pyx_v_pytag, 0, 2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
 
-      /* "pysam/csamtools.pyx":2825
+      /* "pysam/csamtools.pyx":2832
  * 
  *                     args.extend( [pytag[:2],
  *                                   pytype.encode('ascii'),             # <<<<<<<<<<<<<<
  *                                   value ] )
  * 
  */
-      __pyx_t_7 = PyObject_GetAttr(__pyx_v_pytype, __pyx_n_s__encode); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_GetAttr(__pyx_v_pytype, __pyx_n_s__encode); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
-      __pyx_t_15 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_k_tuple_158), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_15 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_k_tuple_157), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_15);
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 
-      /* "pysam/csamtools.pyx":2826
+      /* "pysam/csamtools.pyx":2833
  *                     args.extend( [pytag[:2],
  *                                   pytype.encode('ascii'),
  *                                   value ] )             # <<<<<<<<<<<<<<
  * 
  *                     fmts.append( fmt )
  */
-      __pyx_t_7 = PyList_New(3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyList_New(3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
       __Pyx_GIVEREF(__pyx_t_8);
@@ -27219,44 +27963,44 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
       __Pyx_GIVEREF(__pyx_v_value);
       __pyx_t_8 = 0;
       __pyx_t_15 = 0;
-      __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_15);
       PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_t_7));
       __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
       __pyx_t_7 = 0;
-      __pyx_t_7 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
       __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0;
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 
-      /* "pysam/csamtools.pyx":2828
+      /* "pysam/csamtools.pyx":2835
  *                                   value ] )
  * 
  *                     fmts.append( fmt )             # <<<<<<<<<<<<<<
  * 
  *                 fmt = "".join(fmts)
  */
-      __pyx_t_16 = PyList_Append(__pyx_v_fmts, __pyx_v_fmt); if (unlikely(__pyx_t_16 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_16 = PyList_Append(__pyx_v_fmts, __pyx_v_fmt); if (unlikely(__pyx_t_16 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_L4_continue:;
     }
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
-    /* "pysam/csamtools.pyx":2830
+    /* "pysam/csamtools.pyx":2837
  *                     fmts.append( fmt )
  * 
  *                 fmt = "".join(fmts)             # <<<<<<<<<<<<<<
  *                 total_size = struct.calcsize(fmt)
  *                 buffer = ctypes.create_string_buffer(total_size)
  */
-    __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_16), __pyx_n_s__join); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_20), __pyx_n_s__join); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
     __Pyx_INCREF(((PyObject *)__pyx_v_fmts));
     PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_fmts));
     __Pyx_GIVEREF(((PyObject *)__pyx_v_fmts));
-    __pyx_t_15 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_15 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_15);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
@@ -27264,75 +28008,75 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
     __pyx_v_fmt = __pyx_t_15;
     __pyx_t_15 = 0;
 
-    /* "pysam/csamtools.pyx":2831
+    /* "pysam/csamtools.pyx":2838
  * 
  *                 fmt = "".join(fmts)
  *                 total_size = struct.calcsize(fmt)             # <<<<<<<<<<<<<<
  *                 buffer = ctypes.create_string_buffer(total_size)
  *                 struct.pack_into( fmt,
  */
-    __pyx_t_15 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_15 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_15);
-    __pyx_t_7 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__calcsize); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__calcsize); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
     __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-    __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_15);
     __Pyx_INCREF(__pyx_v_fmt);
     PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_fmt);
     __Pyx_GIVEREF(__pyx_v_fmt);
-    __pyx_t_3 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0;
     __pyx_v_total_size = __pyx_t_3;
     __pyx_t_3 = 0;
 
-    /* "pysam/csamtools.pyx":2832
+    /* "pysam/csamtools.pyx":2839
  *                 fmt = "".join(fmts)
  *                 total_size = struct.calcsize(fmt)
  *                 buffer = ctypes.create_string_buffer(total_size)             # <<<<<<<<<<<<<<
  *                 struct.pack_into( fmt,
  *                                   buffer,
  */
-    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ctypes); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ctypes); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_15 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s_159); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_15 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s_158); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_15);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_INCREF(__pyx_v_total_size);
     PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_total_size);
     __Pyx_GIVEREF(__pyx_v_total_size);
-    __pyx_t_7 = PyObject_Call(__pyx_t_15, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyObject_Call(__pyx_t_15, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
     __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
     __pyx_v_buffer = __pyx_t_7;
     __pyx_t_7 = 0;
 
-    /* "pysam/csamtools.pyx":2833
+    /* "pysam/csamtools.pyx":2840
  *                 total_size = struct.calcsize(fmt)
  *                 buffer = ctypes.create_string_buffer(total_size)
  *                 struct.pack_into( fmt,             # <<<<<<<<<<<<<<
  *                                   buffer,
  *                                   0,
  */
-    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
-    __pyx_t_3 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__pack_into); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__pack_into); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 
-    /* "pysam/csamtools.pyx":2834
+    /* "pysam/csamtools.pyx":2841
  *                 buffer = ctypes.create_string_buffer(total_size)
  *                 struct.pack_into( fmt,
  *                                   buffer,             # <<<<<<<<<<<<<<
  *                                   0,
  *                                   *args )
  */
-    __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
     __Pyx_INCREF(__pyx_v_fmt);
     PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_fmt);
@@ -27344,20 +28088,20 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
     PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_int_0);
     __Pyx_GIVEREF(__pyx_int_0);
 
-    /* "pysam/csamtools.pyx":2836
+    /* "pysam/csamtools.pyx":2843
  *                                   buffer,
  *                                   0,
  *                                   *args )             # <<<<<<<<<<<<<<
  * 
  *             # delete the old data and allocate new space.
  */
-    __pyx_t_15 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_15 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_15));
-    __pyx_t_14 = PyNumber_Add(((PyObject *)__pyx_t_7), ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_14 = PyNumber_Add(((PyObject *)__pyx_t_7), ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_14));
     __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0;
-    __pyx_t_15 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_15 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_15);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0;
@@ -27366,17 +28110,17 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2843
+  /* "pysam/csamtools.pyx":2850
  *             pysam_bam_update( src,
  *                               src.l_aux,
  *                               total_size,             # <<<<<<<<<<<<<<
  *                               bam1_aux( src ) )
  * 
  */
-  if (unlikely(!__pyx_v_total_size)) { __Pyx_RaiseUnboundLocalError("total_size"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2843; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
-  __pyx_t_17 = __Pyx_PyInt_AsSize_t(__pyx_v_total_size); if (unlikely((__pyx_t_17 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__pyx_v_total_size)) { __Pyx_RaiseUnboundLocalError("total_size"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2850; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+  __pyx_t_17 = __Pyx_PyInt_AsSize_t(__pyx_v_total_size); if (unlikely((__pyx_t_17 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":2844
+  /* "pysam/csamtools.pyx":2851
  *                               src.l_aux,
  *                               total_size,
  *                               bam1_aux( src ) )             # <<<<<<<<<<<<<<
@@ -27385,29 +28129,29 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
  */
   pysam_bam_update(__pyx_v_src, __pyx_v_src->l_aux, __pyx_t_17, bam1_aux(__pyx_v_src));
 
-  /* "pysam/csamtools.pyx":2846
+  /* "pysam/csamtools.pyx":2853
  *                               bam1_aux( src ) )
  * 
  *             src.l_aux = total_size             # <<<<<<<<<<<<<<
  * 
  *             # copy data only if there is any
  */
-  __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_v_total_size); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_v_total_size); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_src->l_aux = __pyx_t_18;
 
-  /* "pysam/csamtools.pyx":2849
+  /* "pysam/csamtools.pyx":2856
  * 
  *             # copy data only if there is any
  *             if total_size != 0:             # <<<<<<<<<<<<<<
  * 
  *                 # get location of new data
  */
-  __pyx_t_15 = PyObject_RichCompare(__pyx_v_total_size, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_15 = PyObject_RichCompare(__pyx_v_total_size, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
   if (__pyx_t_12) {
 
-    /* "pysam/csamtools.pyx":2852
+    /* "pysam/csamtools.pyx":2859
  * 
  *                 # get location of new data
  *                 s = bam1_aux( src )             # <<<<<<<<<<<<<<
@@ -27416,37 +28160,37 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_
  */
     __pyx_v_s = bam1_aux(__pyx_v_src);
 
-    /* "pysam/csamtools.pyx":2855
+    /* "pysam/csamtools.pyx":2862
  * 
  *                 # check if there is direct path from buffer.raw to tmp
  *                 p = buffer.raw             # <<<<<<<<<<<<<<
  *                 # create handle to make sure buffer stays alive long
  *                 # enough for memcpy, see issue 129
  */
-    if (unlikely(!__pyx_v_buffer)) { __Pyx_RaiseUnboundLocalError("buffer"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2855; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
-    __pyx_t_15 = PyObject_GetAttr(__pyx_v_buffer, __pyx_n_s__raw); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (unlikely(!__pyx_v_buffer)) { __Pyx_RaiseUnboundLocalError("buffer"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2862; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+    __pyx_t_15 = PyObject_GetAttr(__pyx_v_buffer, __pyx_n_s__raw); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_15);
     __pyx_v_p = __pyx_t_15;
     __pyx_t_15 = 0;
 
-    /* "pysam/csamtools.pyx":2858
+    /* "pysam/csamtools.pyx":2865
  *                 # create handle to make sure buffer stays alive long
  *                 # enough for memcpy, see issue 129
  *                 temp = p             # <<<<<<<<<<<<<<
  *                 memcpy( s, temp, total_size )
  * 
  */
-    __pyx_t_19 = PyBytes_AsString(__pyx_v_p); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_19 = PyBytes_AsString(__pyx_v_p); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_v_temp = __pyx_t_19;
 
-    /* "pysam/csamtools.pyx":2859
+    /* "pysam/csamtools.pyx":2866
  *                 # enough for memcpy, see issue 129
  *                 temp = p
  *                 memcpy( s, temp, total_size )             # <<<<<<<<<<<<<<
  * 
  *     property flag:
  */
-    __pyx_t_17 = __Pyx_PyInt_AsSize_t(__pyx_v_total_size); if (unlikely((__pyx_t_17 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_17 = __Pyx_PyInt_AsSize_t(__pyx_v_total_size); if (unlikely((__pyx_t_17 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     memcpy(__pyx_v_s, __pyx_v_temp, __pyx_t_17);
     goto __pyx_L20;
   }
@@ -27496,7 +28240,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_4flag_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2863
+/* "pysam/csamtools.pyx":2870
  *     property flag:
  *         """properties flag"""
  *         def __get__(self): return self._delegate.core.flag             # <<<<<<<<<<<<<<
@@ -27513,9 +28257,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4flag___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2863);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2870);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_self->_delegate->core.flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_self->_delegate->core.flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -27545,7 +28289,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_4flag_3__set__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2864
+/* "pysam/csamtools.pyx":2871
  *         """properties flag"""
  *         def __get__(self): return self._delegate.core.flag
  *         def __set__(self, flag): self._delegate.core.flag = flag             # <<<<<<<<<<<<<<
@@ -27562,8 +28306,8 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4flag_2__set__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2864);
-  __pyx_t_1 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_flag); if (unlikely((__pyx_t_1 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2871);
+  __pyx_t_1 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_flag); if (unlikely((__pyx_t_1 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_delegate->core.flag = __pyx_t_1;
 
   __pyx_r = 0;
@@ -27588,7 +28332,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_5rname_1__get__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2882
+/* "pysam/csamtools.pyx":2889
  * 
  *         """
  *         def __get__(self): return self._delegate.core.tid             # <<<<<<<<<<<<<<
@@ -27605,9 +28349,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5rname___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2882);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2889);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -27637,7 +28381,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_5rname_3__set__(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2883
+/* "pysam/csamtools.pyx":2890
  *         """
  *         def __get__(self): return self._delegate.core.tid
  *         def __set__(self, tid): self._delegate.core.tid = tid             # <<<<<<<<<<<<<<
@@ -27654,8 +28398,8 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5rname_2__set__(struct __pyx
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2883);
-  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_tid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2890);
+  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_tid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_delegate->core.tid = __pyx_t_1;
 
   __pyx_r = 0;
@@ -27680,7 +28424,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_3tid_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2896
+/* "pysam/csamtools.pyx":2903
  * 
  *         """
  *         def __get__(self): return self._delegate.core.tid             # <<<<<<<<<<<<<<
@@ -27697,9 +28441,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_3tid___get__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2896);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2903);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -27729,7 +28473,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_3tid_3__set__(PyObject *__py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2897
+/* "pysam/csamtools.pyx":2904
  *         """
  *         def __get__(self): return self._delegate.core.tid
  *         def __set__(self, tid): self._delegate.core.tid = tid             # <<<<<<<<<<<<<<
@@ -27746,8 +28490,8 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3tid_2__set__(struct __pyx_o
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2897);
-  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_tid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2904);
+  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_tid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_delegate->core.tid = __pyx_t_1;
 
   __pyx_r = 0;
@@ -27772,7 +28516,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_3pos_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2901
+/* "pysam/csamtools.pyx":2908
  *     property pos:
  *         """0-based leftmost coordinate"""
  *         def __get__(self): return self._delegate.core.pos             # <<<<<<<<<<<<<<
@@ -27789,9 +28533,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_3pos___get__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2901);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2908);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2908; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -27821,7 +28565,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_3pos_3__set__(PyObject *__py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2902
+/* "pysam/csamtools.pyx":2909
  *         """0-based leftmost coordinate"""
  *         def __get__(self): return self._delegate.core.pos
  *         def __set__(self, pos):             # <<<<<<<<<<<<<<
@@ -27840,9 +28584,9 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3pos_2__set__(struct __pyx_o
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2902);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2909);
 
-  /* "pysam/csamtools.pyx":2905
+  /* "pysam/csamtools.pyx":2912
  *             ## setting the cigar string also updates the "bin" attribute
  *             cdef bam1_t * src
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -27852,7 +28596,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3pos_2__set__(struct __pyx_o
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2906
+  /* "pysam/csamtools.pyx":2913
  *             cdef bam1_t * src
  *             src = self._delegate
  *             if src.core.n_cigar:             # <<<<<<<<<<<<<<
@@ -27861,7 +28605,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3pos_2__set__(struct __pyx_o
  */
   if (__pyx_v_src->core.n_cigar) {
 
-    /* "pysam/csamtools.pyx":2907
+    /* "pysam/csamtools.pyx":2914
  *             src = self._delegate
  *             if src.core.n_cigar:
  *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )             # <<<<<<<<<<<<<<
@@ -27873,7 +28617,7 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3pos_2__set__(struct __pyx_o
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":2909
+    /* "pysam/csamtools.pyx":2916
  *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )
  *             else:
  *                 src.core.bin = bam_reg2bin( src.core.pos, src.core.pos + 1)             # <<<<<<<<<<<<<<
@@ -27884,14 +28628,14 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3pos_2__set__(struct __pyx_o
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2910
+  /* "pysam/csamtools.pyx":2917
  *             else:
  *                 src.core.bin = bam_reg2bin( src.core.pos, src.core.pos + 1)
  *             self._delegate.core.pos = pos             # <<<<<<<<<<<<<<
  *     property bin:
  *         """properties bin"""
  */
-  __pyx_t_2 = __Pyx_PyInt_from_py_int32_t(__pyx_v_pos); if (unlikely((__pyx_t_2 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_from_py_int32_t(__pyx_v_pos); if (unlikely((__pyx_t_2 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2917; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_delegate->core.pos = __pyx_t_2;
 
   __pyx_r = 0;
@@ -27916,7 +28660,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_3bin_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2913
+/* "pysam/csamtools.pyx":2920
  *     property bin:
  *         """properties bin"""
  *         def __get__(self): return self._delegate.core.bin             # <<<<<<<<<<<<<<
@@ -27933,9 +28677,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_3bin___get__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2913);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2920);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_self->_delegate->core.bin); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2913; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_self->_delegate->core.bin); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2920; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -27965,7 +28709,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_3bin_3__set__(PyObject *__py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2914
+/* "pysam/csamtools.pyx":2921
  *         """properties bin"""
  *         def __get__(self): return self._delegate.core.bin
  *         def __set__(self, bin): self._delegate.core.bin = bin             # <<<<<<<<<<<<<<
@@ -27982,8 +28726,8 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_3bin_2__set__(struct __pyx_o
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2914);
-  __pyx_t_1 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_bin); if (unlikely((__pyx_t_1 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2914; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2921);
+  __pyx_t_1 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_bin); if (unlikely((__pyx_t_1 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_delegate->core.bin = __pyx_t_1;
 
   __pyx_r = 0;
@@ -28008,7 +28752,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_4rlen_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2917
+/* "pysam/csamtools.pyx":2924
  *     property rlen:
  *         '''length of the read (read only). Returns 0 if not given.'''
  *         def __get__(self): return self._delegate.core.l_qseq             # <<<<<<<<<<<<<<
@@ -28025,9 +28769,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4rlen___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2917);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2924);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.l_qseq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2917; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.l_qseq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -28057,7 +28801,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_4aend_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2923
+/* "pysam/csamtools.pyx":2930
  *         aend points to one past the last aligned residue.
  *         Returns None if not available.'''
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -28080,9 +28824,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4aend___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2923);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2930);
 
-  /* "pysam/csamtools.pyx":2925
+  /* "pysam/csamtools.pyx":2932
  *         def __get__(self):
  *             cdef bam1_t * src
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -28092,19 +28836,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4aend___get__(struct _
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2926
+  /* "pysam/csamtools.pyx":2933
  *             cdef bam1_t * src
  *             src = self._delegate
  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:             # <<<<<<<<<<<<<<
  *                 return None
  *             return bam_calend(&src.core, bam1_cigar(src))
  */
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2933; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = PyNumber_And(__pyx_t_2, __pyx_int_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyNumber_And(__pyx_t_2, __pyx_int_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2933; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2933; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   if (!__pyx_t_4) {
     __pyx_t_5 = (__pyx_v_src->core.n_cigar == 0);
@@ -28114,7 +28858,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4aend___get__(struct _
   }
   if (__pyx_t_6) {
 
-    /* "pysam/csamtools.pyx":2927
+    /* "pysam/csamtools.pyx":2934
  *             src = self._delegate
  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
  *                 return None             # <<<<<<<<<<<<<<
@@ -28129,7 +28873,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4aend___get__(struct _
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2928
+  /* "pysam/csamtools.pyx":2935
  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
  *                 return None
  *             return bam_calend(&src.core, bam1_cigar(src))             # <<<<<<<<<<<<<<
@@ -28137,7 +28881,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4aend___get__(struct _
  *     property alen:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(bam_calend((&__pyx_v_src->core), bam1_cigar(__pyx_v_src))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2928; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(bam_calend((&__pyx_v_src->core), bam1_cigar(__pyx_v_src))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_r = __pyx_t_3;
   __pyx_t_3 = 0;
@@ -28168,7 +28912,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_4alen_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2933
+/* "pysam/csamtools.pyx":2940
  *         '''aligned length of the read on the reference genome.  Returns None if
  *         not available.'''
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -28191,9 +28935,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4alen___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2933);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2940);
 
-  /* "pysam/csamtools.pyx":2935
+  /* "pysam/csamtools.pyx":2942
  *         def __get__(self):
  *             cdef bam1_t * src
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -28203,19 +28947,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4alen___get__(struct _
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":2936
+  /* "pysam/csamtools.pyx":2943
  *             cdef bam1_t * src
  *             src = self._delegate
  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:             # <<<<<<<<<<<<<<
  *                 return None
  *             return bam_calend(&src.core,
  */
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = PyNumber_And(__pyx_t_2, __pyx_int_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyNumber_And(__pyx_t_2, __pyx_int_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   if (!__pyx_t_4) {
     __pyx_t_5 = (__pyx_v_src->core.n_cigar == 0);
@@ -28225,7 +28969,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4alen___get__(struct _
   }
   if (__pyx_t_6) {
 
-    /* "pysam/csamtools.pyx":2937
+    /* "pysam/csamtools.pyx":2944
  *             src = self._delegate
  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
  *                 return None             # <<<<<<<<<<<<<<
@@ -28240,7 +28984,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4alen___get__(struct _
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":2938
+  /* "pysam/csamtools.pyx":2945
  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
  *                 return None
  *             return bam_calend(&src.core,             # <<<<<<<<<<<<<<
@@ -28249,14 +28993,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4alen___get__(struct _
  */
   __Pyx_XDECREF(__pyx_r);
 
-  /* "pysam/csamtools.pyx":2940
+  /* "pysam/csamtools.pyx":2947
  *             return bam_calend(&src.core,
  *                                bam1_cigar(src)) - \
  *                                self._delegate.core.pos             # <<<<<<<<<<<<<<
  * 
  *     property mapq:
  */
-  __pyx_t_3 = PyInt_FromLong((bam_calend((&__pyx_v_src->core), bam1_cigar(__pyx_v_src)) - __pyx_v_self->_delegate->core.pos)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyInt_FromLong((bam_calend((&__pyx_v_src->core), bam1_cigar(__pyx_v_src)) - __pyx_v_self->_delegate->core.pos)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_r = __pyx_t_3;
   __pyx_t_3 = 0;
@@ -28287,7 +29031,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_4mapq_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2944
+/* "pysam/csamtools.pyx":2951
  *     property mapq:
  *         """mapping quality"""
  *         def __get__(self): return self._delegate.core.qual             # <<<<<<<<<<<<<<
@@ -28304,9 +29048,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4mapq___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2944);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2951);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_self->_delegate->core.qual); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_self->_delegate->core.qual); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -28336,7 +29080,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_4mapq_3__set__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2945
+/* "pysam/csamtools.pyx":2952
  *         """mapping quality"""
  *         def __get__(self): return self._delegate.core.qual
  *         def __set__(self, qual): self._delegate.core.qual = qual             # <<<<<<<<<<<<<<
@@ -28353,8 +29097,8 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4mapq_2__set__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2945);
-  __pyx_t_1 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_qual); if (unlikely((__pyx_t_1 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2952);
+  __pyx_t_1 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_qual); if (unlikely((__pyx_t_1 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_delegate->core.qual = __pyx_t_1;
 
   __pyx_r = 0;
@@ -28379,7 +29123,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_4mrnm_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2951
+/* "pysam/csamtools.pyx":2958
  *         deprecated, use RNEXT instead.
  *         """
  *         def __get__(self): return self._delegate.core.mtid             # <<<<<<<<<<<<<<
@@ -28396,9 +29140,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4mrnm___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2951);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2958);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -28428,7 +29172,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_4mrnm_3__set__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2952
+/* "pysam/csamtools.pyx":2959
  *         """
  *         def __get__(self): return self._delegate.core.mtid
  *         def __set__(self, mtid): self._delegate.core.mtid = mtid             # <<<<<<<<<<<<<<
@@ -28445,8 +29189,8 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4mrnm_2__set__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2952);
-  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_mtid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2959);
+  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_mtid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_delegate->core.mtid = __pyx_t_1;
 
   __pyx_r = 0;
@@ -28471,7 +29215,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_5rnext_1__get__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2955
+/* "pysam/csamtools.pyx":2962
  *     property rnext:
  *         """the :term:`reference` id of the mate """
  *         def __get__(self): return self._delegate.core.mtid             # <<<<<<<<<<<<<<
@@ -28488,9 +29232,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5rnext___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2955);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2962);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -28520,7 +29264,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_5rnext_3__set__(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2956
+/* "pysam/csamtools.pyx":2963
  *         """the :term:`reference` id of the mate """
  *         def __get__(self): return self._delegate.core.mtid
  *         def __set__(self, mtid): self._delegate.core.mtid = mtid             # <<<<<<<<<<<<<<
@@ -28537,8 +29281,8 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5rnext_2__set__(struct __pyx
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2956);
-  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_mtid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2963);
+  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_mtid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_delegate->core.mtid = __pyx_t_1;
 
   __pyx_r = 0;
@@ -28563,7 +29307,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_4mpos_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2960
+/* "pysam/csamtools.pyx":2967
  *         """the position of the mate
  *         deprecated, use PNEXT instead."""
  *         def __get__(self): return self._delegate.core.mpos             # <<<<<<<<<<<<<<
@@ -28580,9 +29324,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4mpos___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2960);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2967);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -28612,7 +29356,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_4mpos_3__set__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2961
+/* "pysam/csamtools.pyx":2968
  *         deprecated, use PNEXT instead."""
  *         def __get__(self): return self._delegate.core.mpos
  *         def __set__(self, mpos): self._delegate.core.mpos = mpos             # <<<<<<<<<<<<<<
@@ -28629,8 +29373,8 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4mpos_2__set__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2961);
-  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_mpos); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2968);
+  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_mpos); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_delegate->core.mpos = __pyx_t_1;
 
   __pyx_r = 0;
@@ -28655,7 +29399,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_5pnext_1__get__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2964
+/* "pysam/csamtools.pyx":2971
  *     property pnext:
  *         """the position of the mate"""
  *         def __get__(self): return self._delegate.core.mpos             # <<<<<<<<<<<<<<
@@ -28672,9 +29416,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5pnext___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2964);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2971);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2964; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -28704,7 +29448,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_5pnext_3__set__(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2965
+/* "pysam/csamtools.pyx":2972
  *         """the position of the mate"""
  *         def __get__(self): return self._delegate.core.mpos
  *         def __set__(self, mpos): self._delegate.core.mpos = mpos             # <<<<<<<<<<<<<<
@@ -28721,8 +29465,8 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5pnext_2__set__(struct __pyx
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2965);
-  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_mpos); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2965; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2972);
+  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_mpos); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_delegate->core.mpos = __pyx_t_1;
 
   __pyx_r = 0;
@@ -28747,7 +29491,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_5isize_1__get__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2973
+/* "pysam/csamtools.pyx":2980
  *         """the insert size
  *         deprecated: use tlen instead"""
  *         def __get__(self): return self._delegate.core.isize             # <<<<<<<<<<<<<<
@@ -28764,9 +29508,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_5isize___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2973);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2980);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.isize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.isize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -28796,7 +29540,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_5isize_3__set__(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2974
+/* "pysam/csamtools.pyx":2981
  *         deprecated: use tlen instead"""
  *         def __get__(self): return self._delegate.core.isize
  *         def __set__(self, isize): self._delegate.core.isize = isize             # <<<<<<<<<<<<<<
@@ -28813,8 +29557,8 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_5isize_2__set__(struct __pyx
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2974);
-  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_isize); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2974; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2981);
+  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_isize); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_delegate->core.isize = __pyx_t_1;
 
   __pyx_r = 0;
@@ -28839,7 +29583,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_4tlen_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2977
+/* "pysam/csamtools.pyx":2984
  *     property tlen:
  *         """the insert size"""
  *         def __get__(self): return self._delegate.core.isize             # <<<<<<<<<<<<<<
@@ -28856,9 +29600,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_4tlen___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2977);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2984);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.isize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_delegate->core.isize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -28888,7 +29632,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_4tlen_3__set__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2978
+/* "pysam/csamtools.pyx":2985
  *         """the insert size"""
  *         def __get__(self): return self._delegate.core.isize
  *         def __set__(self, isize): self._delegate.core.isize = isize             # <<<<<<<<<<<<<<
@@ -28905,8 +29649,8 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_4tlen_2__set__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2978);
-  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_isize); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2985);
+  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_isize); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_delegate->core.isize = __pyx_t_1;
 
   __pyx_r = 0;
@@ -28931,7 +29675,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_9is_paired_1__get__(Py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2981
+/* "pysam/csamtools.pyx":2988
  *     property is_paired:
  *         """true if read is paired in sequencing"""
  *         def __get__(self): return (self._delegate.core.flag & BAM_FPAIRED) != 0             # <<<<<<<<<<<<<<
@@ -28948,9 +29692,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_9is_paired___get__(str
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2981);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2988);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_self->_delegate->core.flag & 1) != 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_self->_delegate->core.flag & 1) != 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -28980,7 +29724,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_9is_paired_3__set__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2982
+/* "pysam/csamtools.pyx":2989
  *         """true if read is paired in sequencing"""
  *         def __get__(self): return (self._delegate.core.flag & BAM_FPAIRED) != 0
  *         def __set__(self,val):             # <<<<<<<<<<<<<<
@@ -28997,23 +29741,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_9is_paired_2__set__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2982);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2989);
 
-  /* "pysam/csamtools.pyx":2983
+  /* "pysam/csamtools.pyx":2990
  *         def __get__(self): return (self._delegate.core.flag & BAM_FPAIRED) != 0
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FPAIRED             # <<<<<<<<<<<<<<
  *             else: self._delegate.core.flag &= ~BAM_FPAIRED
  *     property is_proper_pair:
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 1);
     goto __pyx_L3;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":2984
+    /* "pysam/csamtools.pyx":2991
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FPAIRED
  *             else: self._delegate.core.flag &= ~BAM_FPAIRED             # <<<<<<<<<<<<<<
@@ -29046,7 +29790,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_14is_proper_pair_1__ge
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2987
+/* "pysam/csamtools.pyx":2994
  *     property is_proper_pair:
  *         """true if read is mapped in a proper pair"""
  *         def __get__(self): return (self.flag & BAM_FPROPER_PAIR) != 0             # <<<<<<<<<<<<<<
@@ -29064,14 +29808,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_14is_proper_pair___get
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2987);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 2994);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2994; __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_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -29102,7 +29846,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_14is_proper_pair_3__set__(Py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2988
+/* "pysam/csamtools.pyx":2995
  *         """true if read is mapped in a proper pair"""
  *         def __get__(self): return (self.flag & BAM_FPROPER_PAIR) != 0
  *         def __set__(self,val):             # <<<<<<<<<<<<<<
@@ -29119,23 +29863,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_14is_proper_pair_2__set__(st
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2988);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 2995);
 
-  /* "pysam/csamtools.pyx":2989
+  /* "pysam/csamtools.pyx":2996
  *         def __get__(self): return (self.flag & BAM_FPROPER_PAIR) != 0
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR             # <<<<<<<<<<<<<<
  *             else: self._delegate.core.flag &= ~BAM_FPROPER_PAIR
  *     property is_unmapped:
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2996; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 2);
     goto __pyx_L3;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":2990
+    /* "pysam/csamtools.pyx":2997
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR
  *             else: self._delegate.core.flag &= ~BAM_FPROPER_PAIR             # <<<<<<<<<<<<<<
@@ -29168,7 +29912,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_11is_unmapped_1__get__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2993
+/* "pysam/csamtools.pyx":3000
  *     property is_unmapped:
  *         """true if read itself is unmapped"""
  *         def __get__(self): return (self.flag & BAM_FUNMAP) != 0             # <<<<<<<<<<<<<<
@@ -29186,14 +29930,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_11is_unmapped___get__(
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2993);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3000);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3000; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3000; __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_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3000; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -29224,7 +29968,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_11is_unmapped_3__set__(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2994
+/* "pysam/csamtools.pyx":3001
  *         """true if read itself is unmapped"""
  *         def __get__(self): return (self.flag & BAM_FUNMAP) != 0
  *         def __set__(self,val):             # <<<<<<<<<<<<<<
@@ -29241,23 +29985,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_11is_unmapped_2__set__(struc
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 2994);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 3001);
 
-  /* "pysam/csamtools.pyx":2995
+  /* "pysam/csamtools.pyx":3002
  *         def __get__(self): return (self.flag & BAM_FUNMAP) != 0
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FUNMAP             # <<<<<<<<<<<<<<
  *             else: self._delegate.core.flag &= ~BAM_FUNMAP
  *     property mate_is_unmapped:
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 4);
     goto __pyx_L3;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":2996
+    /* "pysam/csamtools.pyx":3003
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FUNMAP
  *             else: self._delegate.core.flag &= ~BAM_FUNMAP             # <<<<<<<<<<<<<<
@@ -29290,7 +30034,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_16mate_is_unmapped_1__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":2999
+/* "pysam/csamtools.pyx":3006
  *     property mate_is_unmapped:
  *         """true if the mate is unmapped"""
  *         def __get__(self): return (self.flag & BAM_FMUNMAP) != 0             # <<<<<<<<<<<<<<
@@ -29308,14 +30052,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_16mate_is_unmapped___g
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 2999);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3006);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3006; __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_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -29346,7 +30090,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_16mate_is_unmapped_3__set__(
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3000
+/* "pysam/csamtools.pyx":3007
  *         """true if the mate is unmapped"""
  *         def __get__(self): return (self.flag & BAM_FMUNMAP) != 0
  *         def __set__(self,val):             # <<<<<<<<<<<<<<
@@ -29363,23 +30107,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_16mate_is_unmapped_2__set__(
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 3000);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 3007);
 
-  /* "pysam/csamtools.pyx":3001
+  /* "pysam/csamtools.pyx":3008
  *         def __get__(self): return (self.flag & BAM_FMUNMAP) != 0
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FMUNMAP             # <<<<<<<<<<<<<<
  *             else: self._delegate.core.flag &= ~BAM_FMUNMAP
  *     property is_reverse:
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 8);
     goto __pyx_L3;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":3002
+    /* "pysam/csamtools.pyx":3009
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FMUNMAP
  *             else: self._delegate.core.flag &= ~BAM_FMUNMAP             # <<<<<<<<<<<<<<
@@ -29412,7 +30156,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_10is_reverse_1__get__(
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3005
+/* "pysam/csamtools.pyx":3012
  *     property is_reverse:
  *         """true if read is mapped to reverse strand"""
  *         def __get__(self): return (self.flag & BAM_FREVERSE) != 0             # <<<<<<<<<<<<<<
@@ -29430,14 +30174,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10is_reverse___get__(s
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3005);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3012);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_16); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_16); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3012; __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_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -29468,7 +30212,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_10is_reverse_3__set__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3006
+/* "pysam/csamtools.pyx":3013
  *         """true if read is mapped to reverse strand"""
  *         def __get__(self): return (self.flag & BAM_FREVERSE) != 0
  *         def __set__(self,val):             # <<<<<<<<<<<<<<
@@ -29485,23 +30229,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_10is_reverse_2__set__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 3006);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 3013);
 
-  /* "pysam/csamtools.pyx":3007
+  /* "pysam/csamtools.pyx":3014
  *         def __get__(self): return (self.flag & BAM_FREVERSE) != 0
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FREVERSE             # <<<<<<<<<<<<<<
  *             else: self._delegate.core.flag &= ~BAM_FREVERSE
  *     property mate_is_reverse:
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 16);
     goto __pyx_L3;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":3008
+    /* "pysam/csamtools.pyx":3015
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FREVERSE
  *             else: self._delegate.core.flag &= ~BAM_FREVERSE             # <<<<<<<<<<<<<<
@@ -29534,7 +30278,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_15mate_is_reverse_1__g
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3011
+/* "pysam/csamtools.pyx":3018
  *     property mate_is_reverse:
  *         """true is read is mapped to reverse strand"""
  *         def __get__(self): return (self.flag & BAM_FMREVERSE) != 0             # <<<<<<<<<<<<<<
@@ -29552,14 +30296,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_15mate_is_reverse___ge
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3011);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3018);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_32); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_32); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -29590,7 +30334,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_15mate_is_reverse_3__set__(P
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3012
+/* "pysam/csamtools.pyx":3019
  *         """true is read is mapped to reverse strand"""
  *         def __get__(self): return (self.flag & BAM_FMREVERSE) != 0
  *         def __set__(self,val):             # <<<<<<<<<<<<<<
@@ -29607,23 +30351,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_15mate_is_reverse_2__set__(s
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 3012);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 3019);
 
-  /* "pysam/csamtools.pyx":3013
+  /* "pysam/csamtools.pyx":3020
  *         def __get__(self): return (self.flag & BAM_FMREVERSE) != 0
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FMREVERSE             # <<<<<<<<<<<<<<
  *             else: self._delegate.core.flag &= ~BAM_FMREVERSE
  *     property is_read1:
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3013; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 32);
     goto __pyx_L3;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":3014
+    /* "pysam/csamtools.pyx":3021
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FMREVERSE
  *             else: self._delegate.core.flag &= ~BAM_FMREVERSE             # <<<<<<<<<<<<<<
@@ -29656,7 +30400,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_8is_read1_1__get__(PyO
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3017
+/* "pysam/csamtools.pyx":3024
  *     property is_read1:
  *         """true if this is read1"""
  *         def __get__(self): return (self.flag & BAM_FREAD1) != 0             # <<<<<<<<<<<<<<
@@ -29674,14 +30418,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_8is_read1___get__(stru
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3017);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3024);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -29712,7 +30456,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_8is_read1_3__set__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3018
+/* "pysam/csamtools.pyx":3025
  *         """true if this is read1"""
  *         def __get__(self): return (self.flag & BAM_FREAD1) != 0
  *         def __set__(self,val):             # <<<<<<<<<<<<<<
@@ -29729,23 +30473,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_8is_read1_2__set__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 3018);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 3025);
 
-  /* "pysam/csamtools.pyx":3019
+  /* "pysam/csamtools.pyx":3026
  *         def __get__(self): return (self.flag & BAM_FREAD1) != 0
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FREAD1             # <<<<<<<<<<<<<<
  *             else: self._delegate.core.flag &= ~BAM_FREAD1
  *     property is_read2:
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3026; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 64);
     goto __pyx_L3;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":3020
+    /* "pysam/csamtools.pyx":3027
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FREAD1
  *             else: self._delegate.core.flag &= ~BAM_FREAD1             # <<<<<<<<<<<<<<
@@ -29778,7 +30522,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_8is_read2_1__get__(PyO
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3023
+/* "pysam/csamtools.pyx":3030
  *     property is_read2:
  *         """true if this is read2"""
  *         def __get__(self): return (self.flag & BAM_FREAD2) != 0             # <<<<<<<<<<<<<<
@@ -29796,14 +30540,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_8is_read2___get__(stru
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3023);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3030);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_128); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_128); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -29834,7 +30578,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_8is_read2_3__set__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3024
+/* "pysam/csamtools.pyx":3031
  *         """true if this is read2"""
  *         def __get__(self): return (self.flag & BAM_FREAD2) != 0
  *         def __set__(self,val):             # <<<<<<<<<<<<<<
@@ -29851,23 +30595,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_8is_read2_2__set__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 3024);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 3031);
 
-  /* "pysam/csamtools.pyx":3025
+  /* "pysam/csamtools.pyx":3032
  *         def __get__(self): return (self.flag & BAM_FREAD2) != 0
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FREAD2             # <<<<<<<<<<<<<<
  *             else: self._delegate.core.flag &= ~BAM_FREAD2
  *     property is_secondary:
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 128);
     goto __pyx_L3;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":3026
+    /* "pysam/csamtools.pyx":3033
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FREAD2
  *             else: self._delegate.core.flag &= ~BAM_FREAD2             # <<<<<<<<<<<<<<
@@ -29900,7 +30644,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_12is_secondary_1__get_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3029
+/* "pysam/csamtools.pyx":3036
  *     property is_secondary:
  *         """true if not primary alignment"""
  *         def __get__(self): return (self.flag & BAM_FSECONDARY) != 0             # <<<<<<<<<<<<<<
@@ -29918,14 +30662,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12is_secondary___get__
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3029);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3036);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_256); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_256); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3036; __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_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -29956,7 +30700,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_12is_secondary_3__set__(PyOb
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3030
+/* "pysam/csamtools.pyx":3037
  *         """true if not primary alignment"""
  *         def __get__(self): return (self.flag & BAM_FSECONDARY) != 0
  *         def __set__(self,val):             # <<<<<<<<<<<<<<
@@ -29973,23 +30717,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_12is_secondary_2__set__(stru
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 3030);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 3037);
 
-  /* "pysam/csamtools.pyx":3031
+  /* "pysam/csamtools.pyx":3038
  *         def __get__(self): return (self.flag & BAM_FSECONDARY) != 0
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FSECONDARY             # <<<<<<<<<<<<<<
  *             else: self._delegate.core.flag &= ~BAM_FSECONDARY
  *     property is_qcfail:
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 256);
     goto __pyx_L3;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":3032
+    /* "pysam/csamtools.pyx":3039
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FSECONDARY
  *             else: self._delegate.core.flag &= ~BAM_FSECONDARY             # <<<<<<<<<<<<<<
@@ -30022,7 +30766,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_9is_qcfail_1__get__(Py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3035
+/* "pysam/csamtools.pyx":3042
  *     property is_qcfail:
  *         """true if QC failure"""
  *         def __get__(self): return (self.flag & BAM_FQCFAIL) != 0             # <<<<<<<<<<<<<<
@@ -30040,14 +30784,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_9is_qcfail___get__(str
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3035);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3042);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_512); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_512); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3042; __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_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -30078,7 +30822,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_9is_qcfail_3__set__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3036
+/* "pysam/csamtools.pyx":3043
  *         """true if QC failure"""
  *         def __get__(self): return (self.flag & BAM_FQCFAIL) != 0
  *         def __set__(self,val):             # <<<<<<<<<<<<<<
@@ -30095,23 +30839,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_9is_qcfail_2__set__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 3036);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 3043);
 
-  /* "pysam/csamtools.pyx":3037
+  /* "pysam/csamtools.pyx":3044
  *         def __get__(self): return (self.flag & BAM_FQCFAIL) != 0
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FQCFAIL             # <<<<<<<<<<<<<<
  *             else: self._delegate.core.flag &= ~BAM_FQCFAIL
  *     property is_duplicate:
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 512);
     goto __pyx_L3;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":3038
+    /* "pysam/csamtools.pyx":3045
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FQCFAIL
  *             else: self._delegate.core.flag &= ~BAM_FQCFAIL             # <<<<<<<<<<<<<<
@@ -30144,7 +30888,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_12is_duplicate_1__get_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3041
+/* "pysam/csamtools.pyx":3048
  *     property is_duplicate:
  *         """true if optical or PCR duplicate"""
  *         def __get__(self): return (self.flag & BAM_FDUP) != 0             # <<<<<<<<<<<<<<
@@ -30162,14 +30906,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12is_duplicate___get__
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3041);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3048);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_1024); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_1024); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3048; __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_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -30200,7 +30944,7 @@ static int __pyx_pw_5pysam_9csamtools_11AlignedRead_12is_duplicate_3__set__(PyOb
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3042
+/* "pysam/csamtools.pyx":3049
  *         """true if optical or PCR duplicate"""
  *         def __get__(self): return (self.flag & BAM_FDUP) != 0
  *         def __set__(self,val):             # <<<<<<<<<<<<<<
@@ -30217,23 +30961,23 @@ static int __pyx_pf_5pysam_9csamtools_11AlignedRead_12is_duplicate_2__set__(stru
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 3042);
+  __Pyx_TraceCall("__set__", __pyx_f[0], 3049);
 
-  /* "pysam/csamtools.pyx":3043
+  /* "pysam/csamtools.pyx":3050
  *         def __get__(self): return (self.flag & BAM_FDUP) != 0
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FDUP             # <<<<<<<<<<<<<<
  *             else: self._delegate.core.flag &= ~BAM_FDUP
  * 
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 1024);
     goto __pyx_L3;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":3044
+    /* "pysam/csamtools.pyx":3051
  *         def __set__(self,val):
  *             if val: self._delegate.core.flag |= BAM_FDUP
  *             else: self._delegate.core.flag &= ~BAM_FDUP             # <<<<<<<<<<<<<<
@@ -30266,7 +31010,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_9positions_1__get__(Py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3052
+/* "pysam/csamtools.pyx":3059
  *     property positions:
  *         """a list of reference positions that this read aligns to."""
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -30298,9 +31042,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_9positions___get__(str
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3052);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3059);
 
-  /* "pysam/csamtools.pyx":3058
+  /* "pysam/csamtools.pyx":3065
  *             cdef bam1_t * src
  * 
  *             src = self._delegate             # <<<<<<<<<<<<<<
@@ -30310,7 +31054,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_9positions___get__(str
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":3059
+  /* "pysam/csamtools.pyx":3066
  * 
  *             src = self._delegate
  *             if src.core.n_cigar == 0: return []             # <<<<<<<<<<<<<<
@@ -30320,7 +31064,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_9positions___get__(str
   __pyx_t_2 = (__pyx_v_src->core.n_cigar == 0);
   if (__pyx_t_2) {
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __pyx_r = ((PyObject *)__pyx_t_3);
     __pyx_t_3 = 0;
@@ -30329,19 +31073,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_9positions___get__(str
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":3061
+  /* "pysam/csamtools.pyx":3068
  *             if src.core.n_cigar == 0: return []
  * 
  *             result = []             # <<<<<<<<<<<<<<
  *             pos = src.core.pos
  *             cigar_p = bam1_cigar(src)
  */
-  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_v_result = ((PyObject*)__pyx_t_3);
   __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":3062
+  /* "pysam/csamtools.pyx":3069
  * 
  *             result = []
  *             pos = src.core.pos             # <<<<<<<<<<<<<<
@@ -30351,7 +31095,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_9positions___get__(str
   __pyx_t_4 = __pyx_v_src->core.pos;
   __pyx_v_pos = __pyx_t_4;
 
-  /* "pysam/csamtools.pyx":3063
+  /* "pysam/csamtools.pyx":3070
  *             result = []
  *             pos = src.core.pos
  *             cigar_p = bam1_cigar(src)             # <<<<<<<<<<<<<<
@@ -30360,7 +31104,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_9positions___get__(str
  */
   __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":3065
+  /* "pysam/csamtools.pyx":3072
  *             cigar_p = bam1_cigar(src)
  * 
  *             for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
@@ -30370,7 +31114,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_9positions___get__(str
   __pyx_t_5 = __pyx_v_src->core.n_cigar;
   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {
 
-    /* "pysam/csamtools.pyx":3066
+    /* "pysam/csamtools.pyx":3073
  * 
  *             for k from 0 <= k < src.core.n_cigar:
  *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
@@ -30379,20 +31123,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_9positions___get__(str
  */
     __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
 
-    /* "pysam/csamtools.pyx":3067
+    /* "pysam/csamtools.pyx":3074
  *             for k from 0 <= k < src.core.n_cigar:
  *                 op = cigar_p[k] & BAM_CIGAR_MASK
  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
  *                 if op == BAM_CMATCH:
  *                     for i from pos <= i < pos + l:
  */
-    __pyx_t_3 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3067; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_XDECREF(__pyx_v_l);
     __pyx_v_l = __pyx_t_3;
     __pyx_t_3 = 0;
 
-    /* "pysam/csamtools.pyx":3068
+    /* "pysam/csamtools.pyx":3075
  *                 op = cigar_p[k] & BAM_CIGAR_MASK
  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
  *                 if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
@@ -30402,39 +31146,39 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_9positions___get__(str
     __pyx_t_2 = (__pyx_v_op == 0);
     if (__pyx_t_2) {
 
-      /* "pysam/csamtools.pyx":3069
+      /* "pysam/csamtools.pyx":3076
  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
  *                 if op == BAM_CMATCH:
  *                     for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
  *                         result.append( i )
  * 
  */
-      __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
-      __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_6); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_6); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
       for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {
 
-        /* "pysam/csamtools.pyx":3070
+        /* "pysam/csamtools.pyx":3077
  *                 if op == BAM_CMATCH:
  *                     for i from pos <= i < pos + l:
  *                         result.append( i )             # <<<<<<<<<<<<<<
  * 
  *                 if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
  */
-        __pyx_t_6 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_6 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3077; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
-        __pyx_t_8 = PyList_Append(__pyx_v_result, __pyx_t_6); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyList_Append(__pyx_v_result, __pyx_t_6); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3077; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
       }
       goto __pyx_L6;
     }
     __pyx_L6:;
 
-    /* "pysam/csamtools.pyx":3072
+    /* "pysam/csamtools.pyx":3079
  *                         result.append( i )
  * 
  *                 if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
@@ -30446,26 +31190,26 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_9positions___get__(str
       case 2:
       case 3:
 
-      /* "pysam/csamtools.pyx":3073
+      /* "pysam/csamtools.pyx":3080
  * 
  *                 if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
  *                     pos += l             # <<<<<<<<<<<<<<
  * 
  *             return result
  */
-      __pyx_t_6 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
-      __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_6, __pyx_v_l); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_6, __pyx_v_l); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
       __pyx_v_pos = __pyx_t_7;
       break;
     }
   }
 
-  /* "pysam/csamtools.pyx":3075
+  /* "pysam/csamtools.pyx":3082
  *                     pos += l
  * 
  *             return result             # <<<<<<<<<<<<<<
@@ -30504,7 +31248,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_15inferred_length_1__g
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3082
+/* "pysam/csamtools.pyx":3089
  *         Returns 0 if CIGAR string is not present.
  *         """
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -30529,9 +31273,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_15inferred_length___ge
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3082);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3089);
 
-  /* "pysam/csamtools.pyx":3088
+  /* "pysam/csamtools.pyx":3095
  *            cdef bam1_t * src
  * 
  *            src = self._delegate             # <<<<<<<<<<<<<<
@@ -30541,7 +31285,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_15inferred_length___ge
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":3089
+  /* "pysam/csamtools.pyx":3096
  * 
  *            src = self._delegate
  *            if src.core.n_cigar == 0: return 0             # <<<<<<<<<<<<<<
@@ -30558,7 +31302,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_15inferred_length___ge
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":3091
+  /* "pysam/csamtools.pyx":3098
  *            if src.core.n_cigar == 0: return 0
  * 
  *            qpos = 0             # <<<<<<<<<<<<<<
@@ -30567,7 +31311,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_15inferred_length___ge
  */
   __pyx_v_qpos = 0;
 
-  /* "pysam/csamtools.pyx":3092
+  /* "pysam/csamtools.pyx":3099
  * 
  *            qpos = 0
  *            cigar_p = bam1_cigar(src)             # <<<<<<<<<<<<<<
@@ -30576,7 +31320,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_15inferred_length___ge
  */
   __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":3094
+  /* "pysam/csamtools.pyx":3101
  *            cigar_p = bam1_cigar(src)
  * 
  *            for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
@@ -30586,7 +31330,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_15inferred_length___ge
   __pyx_t_3 = __pyx_v_src->core.n_cigar;
   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {
 
-    /* "pysam/csamtools.pyx":3095
+    /* "pysam/csamtools.pyx":3102
  * 
  *            for k from 0 <= k < src.core.n_cigar:
  *                op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
@@ -30595,7 +31339,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_15inferred_length___ge
  */
     __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
 
-    /* "pysam/csamtools.pyx":3097
+    /* "pysam/csamtools.pyx":3104
  *                op = cigar_p[k] & BAM_CIGAR_MASK
  * 
  *                if op == BAM_CMATCH or op == BAM_CINS or op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
@@ -30607,7 +31351,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_15inferred_length___ge
       case 1:
       case 4:
 
-      /* "pysam/csamtools.pyx":3098
+      /* "pysam/csamtools.pyx":3105
  * 
  *                if op == BAM_CMATCH or op == BAM_CINS or op == BAM_CSOFT_CLIP:
  *                    qpos += cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
@@ -30619,7 +31363,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_15inferred_length___ge
     }
   }
 
-  /* "pysam/csamtools.pyx":3100
+  /* "pysam/csamtools.pyx":3107
  *                    qpos += cigar_p[k] >> BAM_CIGAR_SHIFT
  * 
  *            return qpos             # <<<<<<<<<<<<<<
@@ -30627,7 +31371,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_15inferred_length___ge
  * 
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_4 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __pyx_r = __pyx_t_4;
   __pyx_t_4 = 0;
@@ -30657,7 +31401,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_13aligned_pairs_1__get
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3108
+/* "pysam/csamtools.pyx":3115
  *        Unaligned position are marked by None.
  *        """
  *        def __get__(self):             # <<<<<<<<<<<<<<
@@ -30691,9 +31435,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3108);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3115);
 
-  /* "pysam/csamtools.pyx":3114
+  /* "pysam/csamtools.pyx":3121
  *            cdef bam1_t * src
  * 
  *            src = self._delegate             # <<<<<<<<<<<<<<
@@ -30703,7 +31447,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":3115
+  /* "pysam/csamtools.pyx":3122
  * 
  *            src = self._delegate
  *            if src.core.n_cigar == 0: return []             # <<<<<<<<<<<<<<
@@ -30713,7 +31457,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
   __pyx_t_2 = (__pyx_v_src->core.n_cigar == 0);
   if (__pyx_t_2) {
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __pyx_r = ((PyObject *)__pyx_t_3);
     __pyx_t_3 = 0;
@@ -30722,19 +31466,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":3117
+  /* "pysam/csamtools.pyx":3124
  *            if src.core.n_cigar == 0: return []
  * 
  *            result = []             # <<<<<<<<<<<<<<
  *            pos = src.core.pos
  *            qpos = 0
  */
-  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __pyx_v_result = ((PyObject*)__pyx_t_3);
   __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":3118
+  /* "pysam/csamtools.pyx":3125
  * 
  *            result = []
  *            pos = src.core.pos             # <<<<<<<<<<<<<<
@@ -30744,7 +31488,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
   __pyx_t_4 = __pyx_v_src->core.pos;
   __pyx_v_pos = __pyx_t_4;
 
-  /* "pysam/csamtools.pyx":3119
+  /* "pysam/csamtools.pyx":3126
  *            result = []
  *            pos = src.core.pos
  *            qpos = 0             # <<<<<<<<<<<<<<
@@ -30753,7 +31497,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
  */
   __pyx_v_qpos = 0;
 
-  /* "pysam/csamtools.pyx":3120
+  /* "pysam/csamtools.pyx":3127
  *            pos = src.core.pos
  *            qpos = 0
  *            cigar_p = bam1_cigar(src)             # <<<<<<<<<<<<<<
@@ -30762,7 +31506,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
  */
   __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":3122
+  /* "pysam/csamtools.pyx":3129
  *            cigar_p = bam1_cigar(src)
  * 
  *            for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
@@ -30772,7 +31516,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
   __pyx_t_5 = __pyx_v_src->core.n_cigar;
   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {
 
-    /* "pysam/csamtools.pyx":3123
+    /* "pysam/csamtools.pyx":3130
  * 
  *            for k from 0 <= k < src.core.n_cigar:
  *                op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
@@ -30781,20 +31525,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
  */
     __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
 
-    /* "pysam/csamtools.pyx":3124
+    /* "pysam/csamtools.pyx":3131
  *            for k from 0 <= k < src.core.n_cigar:
  *                op = cigar_p[k] & BAM_CIGAR_MASK
  *                l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
  * 
  *                if op == BAM_CMATCH:
  */
-    __pyx_t_3 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_XDECREF(__pyx_v_l);
     __pyx_v_l = __pyx_t_3;
     __pyx_t_3 = 0;
 
-    /* "pysam/csamtools.pyx":3137
+    /* "pysam/csamtools.pyx":3144
  *                        qpos += 1
  * 
  *                elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
@@ -30803,7 +31547,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
  */
     switch (__pyx_v_op) {
 
-      /* "pysam/csamtools.pyx":3126
+      /* "pysam/csamtools.pyx":3133
  *                l = cigar_p[k] >> BAM_CIGAR_SHIFT
  * 
  *                if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
@@ -30812,34 +31556,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
  */
       case 0:
 
-      /* "pysam/csamtools.pyx":3127
+      /* "pysam/csamtools.pyx":3134
  * 
  *                if op == BAM_CMATCH:
  *                    for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
  *                        result.append( (qpos, i) )
  *                        qpos += 1
  */
-      __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
-      __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_6); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_6); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
       for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {
 
-        /* "pysam/csamtools.pyx":3128
+        /* "pysam/csamtools.pyx":3135
  *                if op == BAM_CMATCH:
  *                    for i from pos <= i < pos + l:
  *                        result.append( (qpos, i) )             # <<<<<<<<<<<<<<
  *                        qpos += 1
  *                    pos += l
  */
-        __pyx_t_6 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_6 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
-        __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_3);
-        __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
         PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6);
         __Pyx_GIVEREF(__pyx_t_6);
@@ -30847,10 +31591,10 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
         __Pyx_GIVEREF(__pyx_t_3);
         __pyx_t_6 = 0;
         __pyx_t_3 = 0;
-        __pyx_t_9 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_8)); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_8)); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
 
-        /* "pysam/csamtools.pyx":3129
+        /* "pysam/csamtools.pyx":3136
  *                    for i from pos <= i < pos + l:
  *                        result.append( (qpos, i) )
  *                        qpos += 1             # <<<<<<<<<<<<<<
@@ -30860,24 +31604,24 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
         __pyx_v_qpos = (__pyx_v_qpos + 1);
       }
 
-      /* "pysam/csamtools.pyx":3130
+      /* "pysam/csamtools.pyx":3137
  *                        result.append( (qpos, i) )
  *                        qpos += 1
  *                    pos += l             # <<<<<<<<<<<<<<
  * 
  *                elif op == BAM_CINS:
  */
-      __pyx_t_8 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
-      __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_8, __pyx_v_l); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_8, __pyx_v_l); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
       __pyx_v_pos = __pyx_t_7;
       break;
 
-      /* "pysam/csamtools.pyx":3132
+      /* "pysam/csamtools.pyx":3139
  *                    pos += l
  * 
  *                elif op == BAM_CINS:             # <<<<<<<<<<<<<<
@@ -30886,32 +31630,32 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
  */
       case 1:
 
-      /* "pysam/csamtools.pyx":3133
+      /* "pysam/csamtools.pyx":3140
  * 
  *                elif op == BAM_CINS:
  *                    for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
  *                        result.append( (qpos, None) )
  *                        qpos += 1
  */
-      __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
-      __pyx_t_8 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
       for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {
 
-        /* "pysam/csamtools.pyx":3134
+        /* "pysam/csamtools.pyx":3141
  *                elif op == BAM_CINS:
  *                    for i from pos <= i < pos + l:
  *                        result.append( (qpos, None) )             # <<<<<<<<<<<<<<
  *                        qpos += 1
  * 
  */
-        __pyx_t_8 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_3);
         PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
         __Pyx_GIVEREF(__pyx_t_8);
@@ -30919,10 +31663,10 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
         PyTuple_SET_ITEM(__pyx_t_3, 1, Py_None);
         __Pyx_GIVEREF(Py_None);
         __pyx_t_8 = 0;
-        __pyx_t_9 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_3)); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_3)); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 
-        /* "pysam/csamtools.pyx":3135
+        /* "pysam/csamtools.pyx":3142
  *                    for i from pos <= i < pos + l:
  *                        result.append( (qpos, None) )
  *                        qpos += 1             # <<<<<<<<<<<<<<
@@ -30933,7 +31677,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
       }
       break;
 
-      /* "pysam/csamtools.pyx":3137
+      /* "pysam/csamtools.pyx":3144
  *                        qpos += 1
  * 
  *                elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
@@ -30943,32 +31687,32 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
       case 2:
       case 3:
 
-      /* "pysam/csamtools.pyx":3138
+      /* "pysam/csamtools.pyx":3145
  * 
  *                elif op == BAM_CDEL or op == BAM_CREF_SKIP:
  *                    for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
  *                        result.append( (None, i) )
  *                    pos += l
  */
-      __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
-      __pyx_t_8 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
       for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {
 
-        /* "pysam/csamtools.pyx":3139
+        /* "pysam/csamtools.pyx":3146
  *                elif op == BAM_CDEL or op == BAM_CREF_SKIP:
  *                    for i from pos <= i < pos + l:
  *                        result.append( (None, i) )             # <<<<<<<<<<<<<<
  *                    pos += l
  * 
  */
-        __pyx_t_8 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_8);
-        __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_3);
         __Pyx_INCREF(Py_None);
         PyTuple_SET_ITEM(__pyx_t_3, 0, Py_None);
@@ -30976,30 +31720,30 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_13aligned_pairs___get_
         PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8);
         __Pyx_GIVEREF(__pyx_t_8);
         __pyx_t_8 = 0;
-        __pyx_t_9 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_3)); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_3)); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
       }
 
-      /* "pysam/csamtools.pyx":3140
+      /* "pysam/csamtools.pyx":3147
  *                    for i from pos <= i < pos + l:
  *                        result.append( (None, i) )
  *                    pos += l             # <<<<<<<<<<<<<<
  * 
  *            return result
  */
-      __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
-      __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
       __pyx_v_pos = __pyx_t_7;
       break;
     }
   }
 
-  /* "pysam/csamtools.pyx":3142
+  /* "pysam/csamtools.pyx":3149
  *                    pos += l
  * 
  *            return result             # <<<<<<<<<<<<<<
@@ -31057,11 +31801,11 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_11overlap(PyObject *__
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("overlap", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3148; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("overlap", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3155; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "overlap") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3148; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "overlap") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3155; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
       goto __pyx_L5_argtuple_error;
@@ -31069,12 +31813,12 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_11overlap(PyObject *__
       values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
       values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
     }
-    __pyx_v_start = __Pyx_PyInt_from_py_uint32_t(values[0]); if (unlikely((__pyx_v_start == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3148; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    __pyx_v_end = __Pyx_PyInt_from_py_uint32_t(values[1]); if (unlikely((__pyx_v_end == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3148; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_start = __Pyx_PyInt_from_py_uint32_t(values[0]); if (unlikely((__pyx_v_start == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3155; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_end = __Pyx_PyInt_from_py_uint32_t(values[1]); if (unlikely((__pyx_v_end == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3155; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("overlap", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3148; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("overlap", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3155; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.AlignedRead.overlap", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -31085,7 +31829,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_11overlap(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3148
+/* "pysam/csamtools.pyx":3155
  *     ##
  *     #######################################################################
  *     def overlap( self, uint32_t start, uint32_t end ):             # <<<<<<<<<<<<<<
@@ -31121,9 +31865,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("overlap", 0);
-  __Pyx_TraceCall("overlap", __pyx_f[0], 3148);
+  __Pyx_TraceCall("overlap", __pyx_f[0], 3155);
 
-  /* "pysam/csamtools.pyx":3157
+  /* "pysam/csamtools.pyx":3164
  *         cdef bam1_t * src
  * 
  *         overlap = 0             # <<<<<<<<<<<<<<
@@ -31132,7 +31876,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
  */
   __pyx_v_overlap = 0;
 
-  /* "pysam/csamtools.pyx":3159
+  /* "pysam/csamtools.pyx":3166
  *         overlap = 0
  * 
  *         src = self._delegate             # <<<<<<<<<<<<<<
@@ -31142,7 +31886,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
   __pyx_t_1 = __pyx_v_self->_delegate;
   __pyx_v_src = __pyx_t_1;
 
-  /* "pysam/csamtools.pyx":3160
+  /* "pysam/csamtools.pyx":3167
  * 
  *         src = self._delegate
  *         if src.core.n_cigar == 0: return 0             # <<<<<<<<<<<<<<
@@ -31159,7 +31903,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":3161
+  /* "pysam/csamtools.pyx":3168
  *         src = self._delegate
  *         if src.core.n_cigar == 0: return 0
  *         pos = src.core.pos             # <<<<<<<<<<<<<<
@@ -31169,7 +31913,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
   __pyx_t_3 = __pyx_v_src->core.pos;
   __pyx_v_pos = __pyx_t_3;
 
-  /* "pysam/csamtools.pyx":3162
+  /* "pysam/csamtools.pyx":3169
  *         if src.core.n_cigar == 0: return 0
  *         pos = src.core.pos
  *         o = 0             # <<<<<<<<<<<<<<
@@ -31178,7 +31922,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
  */
   __pyx_v_o = 0;
 
-  /* "pysam/csamtools.pyx":3164
+  /* "pysam/csamtools.pyx":3171
  *         o = 0
  * 
  *         cigar_p = bam1_cigar(src)             # <<<<<<<<<<<<<<
@@ -31187,7 +31931,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
  */
   __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
 
-  /* "pysam/csamtools.pyx":3165
+  /* "pysam/csamtools.pyx":3172
  * 
  *         cigar_p = bam1_cigar(src)
  *         for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
@@ -31197,7 +31941,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
   __pyx_t_4 = __pyx_v_src->core.n_cigar;
   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {
 
-    /* "pysam/csamtools.pyx":3166
+    /* "pysam/csamtools.pyx":3173
  *         cigar_p = bam1_cigar(src)
  *         for k from 0 <= k < src.core.n_cigar:
  *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
@@ -31206,20 +31950,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
  */
     __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
 
-    /* "pysam/csamtools.pyx":3167
+    /* "pysam/csamtools.pyx":3174
  *         for k from 0 <= k < src.core.n_cigar:
  *             op = cigar_p[k] & BAM_CIGAR_MASK
  *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
  * 
  *             if op == BAM_CMATCH:
  */
-    __pyx_t_5 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     __Pyx_XDECREF(__pyx_v_l);
     __pyx_v_l = __pyx_t_5;
     __pyx_t_5 = 0;
 
-    /* "pysam/csamtools.pyx":3169
+    /* "pysam/csamtools.pyx":3176
  *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
  * 
  *             if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
@@ -31229,7 +31973,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
     __pyx_t_2 = (__pyx_v_op == 0);
     if (__pyx_t_2) {
 
-      /* "pysam/csamtools.pyx":3170
+      /* "pysam/csamtools.pyx":3177
  * 
  *             if op == BAM_CMATCH:
  *                 o = min( pos + l, end) - max( pos, start )             # <<<<<<<<<<<<<<
@@ -31237,19 +31981,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
  * 
  */
       __pyx_t_6 = __pyx_v_end;
-      __pyx_t_5 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __pyx_t_7 = PyNumber_Add(__pyx_t_5, __pyx_v_l); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyNumber_Add(__pyx_t_5, __pyx_v_l); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-      __pyx_t_8 = __Pyx_PyInt_to_py_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = __Pyx_PyInt_to_py_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
-      __pyx_t_9 = PyObject_RichCompare(__pyx_t_8, __pyx_t_7, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyObject_RichCompare(__pyx_t_8, __pyx_t_7, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
       if (__pyx_t_2) {
-        __pyx_t_9 = __Pyx_PyInt_to_py_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_9 = __Pyx_PyInt_to_py_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_9);
         __pyx_t_5 = __pyx_t_9;
         __pyx_t_9 = 0;
@@ -31265,17 +32009,17 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
       } else {
         __pyx_t_11 = __pyx_t_10;
       }
-      __pyx_t_7 = __Pyx_PyInt_to_py_uint32_t(__pyx_t_11); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __Pyx_PyInt_to_py_uint32_t(__pyx_t_11); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
-      __pyx_t_9 = PyNumber_Subtract(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyNumber_Subtract(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-      __pyx_t_12 = __Pyx_PyInt_AsInt(__pyx_t_9); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_12 = __Pyx_PyInt_AsInt(__pyx_t_9); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
       __pyx_v_o = __pyx_t_12;
 
-      /* "pysam/csamtools.pyx":3171
+      /* "pysam/csamtools.pyx":3178
  *             if op == BAM_CMATCH:
  *                 o = min( pos + l, end) - max( pos, start )
  *                 if o > 0: overlap += o             # <<<<<<<<<<<<<<
@@ -31292,7 +32036,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
     }
     __pyx_L6:;
 
-    /* "pysam/csamtools.pyx":3173
+    /* "pysam/csamtools.pyx":3180
  *                 if o > 0: overlap += o
  * 
  *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
@@ -31304,26 +32048,26 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
       case 2:
       case 3:
 
-      /* "pysam/csamtools.pyx":3174
+      /* "pysam/csamtools.pyx":3181
  * 
  *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
  *                 pos += l             # <<<<<<<<<<<<<<
  * 
  *         return overlap
  */
-      __pyx_t_9 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
-      __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-      __pyx_t_11 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_11 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_11 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_11 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       __pyx_v_pos = __pyx_t_11;
       break;
     }
   }
 
-  /* "pysam/csamtools.pyx":3176
+  /* "pysam/csamtools.pyx":3183
  *                 pos += l
  * 
  *         return overlap             # <<<<<<<<<<<<<<
@@ -31331,7 +32075,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_10overlap(struct __pyx
  *     def opt(self, tag):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_7 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_overlap); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_overlap); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_7);
   __pyx_r = __pyx_t_7;
   __pyx_t_7 = 0;
@@ -31366,7 +32110,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_13opt(PyObject *__pyx_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3178
+/* "pysam/csamtools.pyx":3185
  *         return overlap
  * 
  *     def opt(self, tag):             # <<<<<<<<<<<<<<
@@ -31401,31 +32145,31 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("opt", 0);
-  __Pyx_TraceCall("opt", __pyx_f[0], 3178);
+  __Pyx_TraceCall("opt", __pyx_f[0], 3185);
 
-  /* "pysam/csamtools.pyx":3183
+  /* "pysam/csamtools.pyx":3190
  *         cdef uint8_t * v
  *         cdef int nvalues
  *         btag = _force_bytes(tag)             # <<<<<<<<<<<<<<
  *         v = bam_aux_get(self._delegate, btag)
  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
  */
-  __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_tag)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_bytes(__pyx_v_tag)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_btag = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3184
+  /* "pysam/csamtools.pyx":3191
  *         cdef int nvalues
  *         btag = _force_bytes(tag)
  *         v = bam_aux_get(self._delegate, btag)             # <<<<<<<<<<<<<<
  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
  *         auxtype = chr(v[0])
  */
-  __pyx_t_2 = PyBytes_AsString(((PyObject *)__pyx_v_btag)); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyBytes_AsString(((PyObject *)__pyx_v_btag)); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_v = bam_aux_get(__pyx_v_self->_delegate, __pyx_t_2);
 
-  /* "pysam/csamtools.pyx":3185
+  /* "pysam/csamtools.pyx":3192
  *         btag = _force_bytes(tag)
  *         v = bam_aux_get(self._delegate, btag)
  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )             # <<<<<<<<<<<<<<
@@ -31434,64 +32178,64 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
  */
   __pyx_t_3 = (__pyx_v_v == NULL);
   if (__pyx_t_3) {
-    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_160), __pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_159), __pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_1));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
     __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":3186
+  /* "pysam/csamtools.pyx":3193
  *         v = bam_aux_get(self._delegate, btag)
  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
  *         auxtype = chr(v[0])             # <<<<<<<<<<<<<<
  *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
  *             return <int>bam_aux2i(v)
  */
-  __pyx_t_1 = __Pyx_PyInt_to_py_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_Call(__pyx_builtin_chr, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_builtin_chr, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
   __pyx_v_auxtype = __pyx_t_1;
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3187
+  /* "pysam/csamtools.pyx":3194
  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
  *         auxtype = chr(v[0])
  *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':             # <<<<<<<<<<<<<<
  *             return <int>bam_aux2i(v)
  *         elif auxtype == 'i' or auxtype == 'I':
  */
-  __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__c), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__c), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (!__pyx_t_3) {
-    __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__C), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__C), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     if (!__pyx_t_5) {
-      __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__s), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__s), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       if (!__pyx_t_6) {
-        __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__S), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__S), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
         __pyx_t_8 = __pyx_t_7;
       } else {
@@ -31507,7 +32251,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
   }
   if (__pyx_t_5) {
 
-    /* "pysam/csamtools.pyx":3188
+    /* "pysam/csamtools.pyx":3195
  *         auxtype = chr(v[0])
  *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
  *             return <int>bam_aux2i(v)             # <<<<<<<<<<<<<<
@@ -31515,7 +32259,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
  *             return <int32_t>bam_aux2i(v)
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_1 = PyInt_FromLong(((int)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyInt_FromLong(((int)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __pyx_r = __pyx_t_1;
     __pyx_t_1 = 0;
@@ -31523,19 +32267,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
     goto __pyx_L4;
   }
 
-  /* "pysam/csamtools.pyx":3189
+  /* "pysam/csamtools.pyx":3196
  *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
  *             return <int>bam_aux2i(v)
  *         elif auxtype == 'i' or auxtype == 'I':             # <<<<<<<<<<<<<<
  *             return <int32_t>bam_aux2i(v)
  *         elif auxtype == 'f' or auxtype == 'F':
  */
-  __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__i), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__i), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (!__pyx_t_5) {
-    __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__I), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__I), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __pyx_t_6 = __pyx_t_3;
   } else {
@@ -31543,7 +32287,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
   }
   if (__pyx_t_6) {
 
-    /* "pysam/csamtools.pyx":3190
+    /* "pysam/csamtools.pyx":3197
  *             return <int>bam_aux2i(v)
  *         elif auxtype == 'i' or auxtype == 'I':
  *             return <int32_t>bam_aux2i(v)             # <<<<<<<<<<<<<<
@@ -31551,7 +32295,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
  *             return <float>bam_aux2f(v)
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((int32_t)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((int32_t)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __pyx_r = __pyx_t_1;
     __pyx_t_1 = 0;
@@ -31559,19 +32303,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
     goto __pyx_L4;
   }
 
-  /* "pysam/csamtools.pyx":3191
+  /* "pysam/csamtools.pyx":3198
  *         elif auxtype == 'i' or auxtype == 'I':
  *             return <int32_t>bam_aux2i(v)
  *         elif auxtype == 'f' or auxtype == 'F':             # <<<<<<<<<<<<<<
  *             return <float>bam_aux2f(v)
  *         elif auxtype == 'd' or auxtype == 'D':
  */
-  __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__f), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__f), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (!__pyx_t_6) {
-    __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__F), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__F), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __pyx_t_3 = __pyx_t_5;
   } else {
@@ -31579,7 +32323,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
   }
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":3192
+    /* "pysam/csamtools.pyx":3199
  *             return <int32_t>bam_aux2i(v)
  *         elif auxtype == 'f' or auxtype == 'F':
  *             return <float>bam_aux2f(v)             # <<<<<<<<<<<<<<
@@ -31587,7 +32331,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
  *             return <double>bam_aux2d(v)
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_1 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __pyx_r = __pyx_t_1;
     __pyx_t_1 = 0;
@@ -31595,19 +32339,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
     goto __pyx_L4;
   }
 
-  /* "pysam/csamtools.pyx":3193
+  /* "pysam/csamtools.pyx":3200
  *         elif auxtype == 'f' or auxtype == 'F':
  *             return <float>bam_aux2f(v)
  *         elif auxtype == 'd' or auxtype == 'D':             # <<<<<<<<<<<<<<
  *             return <double>bam_aux2d(v)
  *         elif auxtype == 'A':
  */
-  __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__d), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__d), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (!__pyx_t_3) {
-    __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__D), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__D), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __pyx_t_5 = __pyx_t_6;
   } else {
@@ -31615,7 +32359,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
   }
   if (__pyx_t_5) {
 
-    /* "pysam/csamtools.pyx":3194
+    /* "pysam/csamtools.pyx":3201
  *             return <float>bam_aux2f(v)
  *         elif auxtype == 'd' or auxtype == 'D':
  *             return <double>bam_aux2d(v)             # <<<<<<<<<<<<<<
@@ -31623,7 +32367,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
  *             # there might a more efficient way
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_1 = PyFloat_FromDouble(((double)bam_aux2d(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyFloat_FromDouble(((double)bam_aux2d(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __pyx_r = __pyx_t_1;
     __pyx_t_1 = 0;
@@ -31631,19 +32375,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
     goto __pyx_L4;
   }
 
-  /* "pysam/csamtools.pyx":3195
+  /* "pysam/csamtools.pyx":3202
  *         elif auxtype == 'd' or auxtype == 'D':
  *             return <double>bam_aux2d(v)
  *         elif auxtype == 'A':             # <<<<<<<<<<<<<<
  *             # there might a more efficient way
  *             # to convert a char into a string
  */
-  __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__A), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__A), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (__pyx_t_5) {
 
-    /* "pysam/csamtools.pyx":3198
+    /* "pysam/csamtools.pyx":3205
  *             # there might a more efficient way
  *             # to convert a char into a string
  *             return '%c' % <char>bam_aux2A(v)             # <<<<<<<<<<<<<<
@@ -31651,9 +32395,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
  *             return _charptr_to_str(<char*>bam_aux2Z(v))
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_1 = PyInt_FromLong(((char)bam_aux2A(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyInt_FromLong(((char)bam_aux2A(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_149), __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_148), __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __pyx_r = ((PyObject *)__pyx_t_4);
@@ -31662,19 +32406,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
     goto __pyx_L4;
   }
 
-  /* "pysam/csamtools.pyx":3199
+  /* "pysam/csamtools.pyx":3206
  *             # to convert a char into a string
  *             return '%c' % <char>bam_aux2A(v)
  *         elif auxtype == 'Z':             # <<<<<<<<<<<<<<
  *             return _charptr_to_str(<char*>bam_aux2Z(v))
  *         elif auxtype == 'B':
  */
-  __pyx_t_4 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__Z), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__Z), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   if (__pyx_t_5) {
 
-    /* "pysam/csamtools.pyx":3200
+    /* "pysam/csamtools.pyx":3207
  *             return '%c' % <char>bam_aux2A(v)
  *         elif auxtype == 'Z':
  *             return _charptr_to_str(<char*>bam_aux2Z(v))             # <<<<<<<<<<<<<<
@@ -31682,7 +32426,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
  *             bytesize, nvalues, values = convertBinaryTagToList( v + 1 )
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_4 = __pyx_f_5pysam_9csamtools__charptr_to_str(((char *)bam_aux2Z(__pyx_v_v))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __pyx_f_5pysam_9csamtools__charptr_to_str(((char *)bam_aux2Z(__pyx_v_v))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __pyx_r = __pyx_t_4;
     __pyx_t_4 = 0;
@@ -31690,26 +32434,26 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
     goto __pyx_L4;
   }
 
-  /* "pysam/csamtools.pyx":3201
+  /* "pysam/csamtools.pyx":3208
  *         elif auxtype == 'Z':
  *             return _charptr_to_str(<char*>bam_aux2Z(v))
  *         elif auxtype == 'B':             # <<<<<<<<<<<<<<
  *             bytesize, nvalues, values = convertBinaryTagToList( v + 1 )
  *             return values
  */
-  __pyx_t_4 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__B), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_RichCompare(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__B), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   if (__pyx_t_5) {
 
-    /* "pysam/csamtools.pyx":3202
+    /* "pysam/csamtools.pyx":3209
  *             return _charptr_to_str(<char*>bam_aux2Z(v))
  *         elif auxtype == 'B':
  *             bytesize, nvalues, values = convertBinaryTagToList( v + 1 )             # <<<<<<<<<<<<<<
  *             return values
  *         else:
  */
-    __pyx_t_4 = __pyx_f_5pysam_9csamtools_convertBinaryTagToList((__pyx_v_v + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __pyx_f_5pysam_9csamtools_convertBinaryTagToList((__pyx_v_v + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
       PyObject* sequence = __pyx_t_4;
@@ -31721,7 +32465,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
       if (unlikely(size != 3)) {
         if (size > 3) __Pyx_RaiseTooManyValuesError(3);
         else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
       #if CYTHON_COMPILING_IN_CPYTHON
       if (likely(PyTuple_CheckExact(sequence))) {
@@ -31737,18 +32481,18 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
       __Pyx_INCREF(__pyx_t_9);
       __Pyx_INCREF(__pyx_t_10);
       #else
-      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __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 = 3209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
-      __pyx_t_10 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __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 = 3209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_10);
       #endif
       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
     } else
     {
       Py_ssize_t index = -1;
-      __pyx_t_11 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_11 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_11);
       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
       __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
@@ -31758,7 +32502,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
       __Pyx_GOTREF(__pyx_t_9);
       index = 2; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L5_unpacking_failed;
       __Pyx_GOTREF(__pyx_t_10);
-      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_t_12 = NULL;
       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
       goto __pyx_L6_unpacking_done;
@@ -31766,10 +32510,10 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
       __pyx_t_12 = NULL;
       if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_L6_unpacking_done:;
     }
-    __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_9); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_9); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
     __pyx_v_bytesize = __pyx_t_1;
     __pyx_t_1 = 0;
@@ -31777,7 +32521,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
     __pyx_v_values = __pyx_t_10;
     __pyx_t_10 = 0;
 
-    /* "pysam/csamtools.pyx":3203
+    /* "pysam/csamtools.pyx":3210
  *         elif auxtype == 'B':
  *             bytesize, nvalues, values = convertBinaryTagToList( v + 1 )
  *             return values             # <<<<<<<<<<<<<<
@@ -31792,26 +32536,26 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_12opt(struct __pyx_obj
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":3205
+    /* "pysam/csamtools.pyx":3212
  *             return values
  *         else:
  *             raise ValueError("unknown auxilliary type '%s'" % auxtype)             # <<<<<<<<<<<<<<
  * 
  * 
  */
-    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_161), __pyx_v_auxtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_160), __pyx_v_auxtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
-    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_10);
     PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_4));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
     __pyx_t_4 = 0;
-    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
     __Pyx_Raise(__pyx_t_4, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L4:;
 
@@ -31848,7 +32592,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11AlignedRead_15fancy_str(PyObject *
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3208
+/* "pysam/csamtools.pyx":3215
  * 
  * 
  *     def fancy_str (self):             # <<<<<<<<<<<<<<
@@ -31879,58 +32623,58 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_14fancy_str(struct __p
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("fancy_str", 0);
-  __Pyx_TraceCall("fancy_str", __pyx_f[0], 3208);
+  __Pyx_TraceCall("fancy_str", __pyx_f[0], 3215);
 
-  /* "pysam/csamtools.pyx":3211
+  /* "pysam/csamtools.pyx":3218
  *         """returns list of fieldnames/values in pretty format for debugging
  *         """
  *         ret_string = []             # <<<<<<<<<<<<<<
  *         field_names = {
  *            "tid":           "Contig index",
  */
-  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_ret_string = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3212
+  /* "pysam/csamtools.pyx":3219
  *         """
  *         ret_string = []
  *         field_names = {             # <<<<<<<<<<<<<<
  *            "tid":           "Contig index",
  *            "pos":           "Mapped position on contig",
  */
-  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__tid), ((PyObject *)__pyx_kp_s_162)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__pos), ((PyObject *)__pyx_kp_s_163)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mtid), ((PyObject *)__pyx_kp_s_164)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mpos), ((PyObject *)__pyx_kp_s_165)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__isize), ((PyObject *)__pyx_kp_s_166)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__flag), ((PyObject *)__pyx_kp_s_167)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__n_cigar), ((PyObject *)__pyx_kp_s_168)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__cigar), ((PyObject *)__pyx_kp_s_169)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qual), ((PyObject *)__pyx_kp_s_170)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__bin), ((PyObject *)__pyx_kp_s_171)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_qname), ((PyObject *)__pyx_kp_s_172)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qname), ((PyObject *)__pyx_kp_s_173)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_qseq), ((PyObject *)__pyx_kp_s_174)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qseq), ((PyObject *)__pyx_kp_s_175)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__bqual), ((PyObject *)__pyx_kp_s_176)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_aux), ((PyObject *)__pyx_kp_s_177)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__m_data), ((PyObject *)__pyx_kp_s_178)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__data_len), ((PyObject *)__pyx_kp_s_179)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__tid), ((PyObject *)__pyx_kp_s_161)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__pos), ((PyObject *)__pyx_kp_s_162)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mtid), ((PyObject *)__pyx_kp_s_163)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mpos), ((PyObject *)__pyx_kp_s_164)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__isize), ((PyObject *)__pyx_kp_s_165)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__flag), ((PyObject *)__pyx_kp_s_166)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__n_cigar), ((PyObject *)__pyx_kp_s_167)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__cigar), ((PyObject *)__pyx_kp_s_168)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qual), ((PyObject *)__pyx_kp_s_169)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__bin), ((PyObject *)__pyx_kp_s_170)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_qname), ((PyObject *)__pyx_kp_s_171)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qname), ((PyObject *)__pyx_kp_s_172)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_qseq), ((PyObject *)__pyx_kp_s_173)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qseq), ((PyObject *)__pyx_kp_s_174)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__bqual), ((PyObject *)__pyx_kp_s_175)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_aux), ((PyObject *)__pyx_kp_s_176)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__m_data), ((PyObject *)__pyx_kp_s_177)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__data_len), ((PyObject *)__pyx_kp_s_178)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_field_names = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3232
+  /* "pysam/csamtools.pyx":3239
  *            "data_len":      "Current data length",
  *            }
  *         fields_names_in_order = ["tid", "pos", "mtid", "mpos", "isize", "flag",             # <<<<<<<<<<<<<<
  *                                  "n_cigar", "cigar", "qual", "bin", "l_qname", "qname",
  *                                  "l_qseq", "qseq", "bqual", "l_aux", "m_data", "data_len"]
  */
-  __pyx_t_1 = PyList_New(18); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyList_New(18); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(((PyObject *)__pyx_n_s__tid));
   PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__tid));
@@ -31989,7 +32733,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_14fancy_str(struct __p
   __pyx_v_fields_names_in_order = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3236
+  /* "pysam/csamtools.pyx":3243
  *                                  "l_qseq", "qseq", "bqual", "l_aux", "m_data", "data_len"]
  * 
  *         for f in fields_names_in_order:             # <<<<<<<<<<<<<<
@@ -32000,29 +32744,29 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_14fancy_str(struct __p
   for (;;) {
     if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
     #if CYTHON_COMPILING_IN_CPYTHON
-    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     #else
-    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     #endif
     __Pyx_XDECREF(__pyx_v_f);
     __pyx_v_f = __pyx_t_3;
     __pyx_t_3 = 0;
 
-    /* "pysam/csamtools.pyx":3237
+    /* "pysam/csamtools.pyx":3244
  * 
  *         for f in fields_names_in_order:
  *             if not f in self.__dict__:             # <<<<<<<<<<<<<<
  *                 continue
  *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))
  */
-    __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s____dict__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s____dict__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_4 = (__Pyx_PySequence_Contains(__pyx_v_f, __pyx_t_3, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = (__Pyx_PySequence_Contains(__pyx_v_f, __pyx_t_3, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
     __pyx_t_5 = (!__pyx_t_4);
     if (__pyx_t_5) {
 
-      /* "pysam/csamtools.pyx":3238
+      /* "pysam/csamtools.pyx":3245
  *         for f in fields_names_in_order:
  *             if not f in self.__dict__:
  *                 continue             # <<<<<<<<<<<<<<
@@ -32034,32 +32778,32 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_14fancy_str(struct __p
     }
     __pyx_L5:;
 
-    /* "pysam/csamtools.pyx":3239
+    /* "pysam/csamtools.pyx":3246
  *             if not f in self.__dict__:
  *                 continue
  *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))             # <<<<<<<<<<<<<<
  * 
  *         for f in self.__dict__:
  */
-    __pyx_t_3 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_field_names), __pyx_v_f); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_field_names), __pyx_v_f); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_6 = PyNumber_Add(((PyObject *)__pyx_kp_s_181), __pyx_v_f); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyNumber_Add(((PyObject *)__pyx_kp_s_180), __pyx_v_f); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
-    __pyx_t_7 = PyNumber_Add(__pyx_t_6, ((PyObject *)__pyx_kp_s_182)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyNumber_Add(__pyx_t_6, ((PyObject *)__pyx_kp_s_181)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-    __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s____getattribute__); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s____getattribute__); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
-    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
     __Pyx_INCREF(__pyx_v_f);
     PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_f);
     __Pyx_GIVEREF(__pyx_v_f);
-    __pyx_t_9 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
-    __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
     PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
     __Pyx_GIVEREF(__pyx_t_3);
@@ -32070,29 +32814,29 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_14fancy_str(struct __p
     __pyx_t_3 = 0;
     __pyx_t_7 = 0;
     __pyx_t_9 = 0;
-    __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_180), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_179), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_9));
     __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
-    __pyx_t_10 = PyList_Append(__pyx_v_ret_string, ((PyObject *)__pyx_t_9)); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = PyList_Append(__pyx_v_ret_string, ((PyObject *)__pyx_t_9)); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
     __pyx_L3_continue:;
   }
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3241
+  /* "pysam/csamtools.pyx":3248
  *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))
  * 
  *         for f in self.__dict__:             # <<<<<<<<<<<<<<
  *             if not f in field_names:
  *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s____dict__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s____dict__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
     __pyx_t_9 = __pyx_t_1; __Pyx_INCREF(__pyx_t_9); __pyx_t_2 = 0;
     __pyx_t_11 = NULL;
   } else {
-    __pyx_t_2 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __pyx_t_11 = Py_TYPE(__pyx_t_9)->tp_iternext;
   }
@@ -32101,23 +32845,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_14fancy_str(struct __p
     if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_9)) {
       if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_9)) break;
       #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #else
-      __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
     } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_9)) {
       if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
       #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #else
-      __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
     } else {
       __pyx_t_1 = __pyx_t_11(__pyx_t_9);
       if (unlikely(!__pyx_t_1)) {
         if (PyErr_Occurred()) {
           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         break;
       }
@@ -32127,50 +32871,50 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_14fancy_str(struct __p
     __pyx_v_f = __pyx_t_1;
     __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":3242
+    /* "pysam/csamtools.pyx":3249
  * 
  *         for f in self.__dict__:
  *             if not f in field_names:             # <<<<<<<<<<<<<<
  *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))
  *         return ret_string
  */
-    __pyx_t_5 = (__Pyx_PyDict_Contains(__pyx_v_f, ((PyObject *)__pyx_v_field_names), Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = (__Pyx_PyDict_Contains(__pyx_v_f, ((PyObject *)__pyx_v_field_names), Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_4 = (!__pyx_t_5);
     if (__pyx_t_4) {
 
-      /* "pysam/csamtools.pyx":3243
+      /* "pysam/csamtools.pyx":3250
  *         for f in self.__dict__:
  *             if not f in field_names:
  *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))             # <<<<<<<<<<<<<<
  *         return ret_string
  * 
  */
-      __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s____getattribute__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s____getattribute__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
       __Pyx_INCREF(__pyx_v_f);
       PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_f);
       __Pyx_GIVEREF(__pyx_v_f);
-      __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
-      __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
       __Pyx_INCREF(__pyx_v_f);
       PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_f);
       __Pyx_GIVEREF(__pyx_v_f);
-      __Pyx_INCREF(((PyObject *)__pyx_kp_s_16));
-      PyTuple_SET_ITEM(__pyx_t_8, 1, ((PyObject *)__pyx_kp_s_16));
-      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_16));
+      __Pyx_INCREF(((PyObject *)__pyx_kp_s_20));
+      PyTuple_SET_ITEM(__pyx_t_8, 1, ((PyObject *)__pyx_kp_s_20));
+      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_20));
       PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
       __Pyx_GIVEREF(__pyx_t_7);
       __pyx_t_7 = 0;
-      __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_180), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_179), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_7));
       __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
-      __pyx_t_10 = PyList_Append(__pyx_v_ret_string, ((PyObject *)__pyx_t_7)); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_10 = PyList_Append(__pyx_v_ret_string, ((PyObject *)__pyx_t_7)); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
       goto __pyx_L8;
     }
@@ -32178,7 +32922,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11AlignedRead_14fancy_str(struct __p
   }
   __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
 
-  /* "pysam/csamtools.pyx":3244
+  /* "pysam/csamtools.pyx":3251
  *             if not f in field_names:
  *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))
  *         return ret_string             # <<<<<<<<<<<<<<
@@ -32226,7 +32970,7 @@ static int __pyx_pw_5pysam_9csamtools_11PileupProxy_1__init__(PyObject *__pyx_v_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3263
+/* "pysam/csamtools.pyx":3270
  *     will change.
  *     '''
  *     def __init__(self):             # <<<<<<<<<<<<<<
@@ -32243,20 +32987,20 @@ static int __pyx_pf_5pysam_9csamtools_11PileupProxy___init__(CYTHON_UNUSED struc
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__init__", 0);
-  __Pyx_TraceCall("__init__", __pyx_f[0], 3263);
+  __Pyx_TraceCall("__init__", __pyx_f[0], 3270);
 
-  /* "pysam/csamtools.pyx":3264
+  /* "pysam/csamtools.pyx":3271
  *     '''
  *     def __init__(self):
  *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
  * 
  *     def __str__(self):
  */
-  __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_184), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_183), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_Raise(__pyx_t_1, 0, 0, 0);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
   __pyx_r = 0;
   goto __pyx_L0;
@@ -32281,7 +33025,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11PileupProxy_3__str__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3266
+/* "pysam/csamtools.pyx":3273
  *         raise TypeError("This class cannot be instantiated from Python")
  * 
  *     def __str__(self):             # <<<<<<<<<<<<<<
@@ -32302,9 +33046,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11PileupProxy_2__str__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__str__", 0);
-  __Pyx_TraceCall("__str__", __pyx_f[0], 3266);
+  __Pyx_TraceCall("__str__", __pyx_f[0], 3273);
 
-  /* "pysam/csamtools.pyx":3267
+  /* "pysam/csamtools.pyx":3274
  * 
  *     def __str__(self):
  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
@@ -32313,30 +33057,30 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11PileupProxy_2__str__(struct __pyx_
  */
   __Pyx_XDECREF(__pyx_r);
 
-  /* "pysam/csamtools.pyx":3268
+  /* "pysam/csamtools.pyx":3275
  *     def __str__(self):
  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
  *             "\n" +\             # <<<<<<<<<<<<<<
  *             "\n".join( map(str, self.pileups) )
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
 
-  /* "pysam/csamtools.pyx":3267
+  /* "pysam/csamtools.pyx":3274
  * 
  *     def __str__(self):
  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
  *             "\n" +\
  *             "\n".join( map(str, self.pileups) )
  */
-  __pyx_t_2 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = PyInt_FromLong(__pyx_v_self->pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyInt_FromLong(__pyx_v_self->pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__n); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__n); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
   __Pyx_GIVEREF(__pyx_t_2);
@@ -32347,7 +33091,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11PileupProxy_2__str__(struct __pyx_
   __pyx_t_2 = 0;
   __pyx_t_3 = 0;
   __pyx_t_4 = 0;
-  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3267; __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 = 3274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
   PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
@@ -32355,34 +33099,34 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11PileupProxy_2__str__(struct __pyx_
   PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_5));
   __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
   __pyx_t_5 = 0;
-  __pyx_t_5 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
-  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
   __Pyx_GIVEREF(__pyx_t_5);
   __pyx_t_5 = 0;
-  __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
-  __pyx_t_4 = PyNumber_Add(__pyx_t_5, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyNumber_Add(__pyx_t_5, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 
-  /* "pysam/csamtools.pyx":3269
+  /* "pysam/csamtools.pyx":3276
  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
  *             "\n" +\
  *             "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
  * 
  *     property tid:
  */
-  __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_6), __pyx_n_s__join); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_6), __pyx_n_s__join); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pileups); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pileups); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
   PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
@@ -32390,19 +33134,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11PileupProxy_2__str__(struct __pyx_
   PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
-  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
-  __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -32438,7 +33182,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11PileupProxy_3tid_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3273
+/* "pysam/csamtools.pyx":3280
  *     property tid:
  *         '''the chromosome ID as is defined in the header'''
  *         def __get__(self): return self.tid             # <<<<<<<<<<<<<<
@@ -32455,9 +33199,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11PileupProxy_3tid___get__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3273);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3280);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -32487,7 +33231,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11PileupProxy_1n_1__get__(PyObject *
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3277
+/* "pysam/csamtools.pyx":3284
  *     property n:
  *         '''number of reads mapping to this column.'''
  *         def __get__(self): return self.n_pu             # <<<<<<<<<<<<<<
@@ -32504,9 +33248,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11PileupProxy_1n___get__(struct __py
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3277);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3284);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->n_pu); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->n_pu); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -32536,7 +33280,7 @@ static int __pyx_pw_5pysam_9csamtools_11PileupProxy_1n_3__set__(PyObject *__pyx_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3278
+/* "pysam/csamtools.pyx":3285
  *         '''number of reads mapping to this column.'''
  *         def __get__(self): return self.n_pu
  *         def __set__(self, n): self.n_pu = n             # <<<<<<<<<<<<<<
@@ -32553,8 +33297,8 @@ static int __pyx_pf_5pysam_9csamtools_11PileupProxy_1n_2__set__(struct __pyx_obj
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_TraceCall("__set__", __pyx_f[0], 3278);
-  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_n); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_TraceCall("__set__", __pyx_f[0], 3285);
+  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_n); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->n_pu = __pyx_t_1;
 
   __pyx_r = 0;
@@ -32579,7 +33323,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11PileupProxy_3pos_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3281
+/* "pysam/csamtools.pyx":3288
  * 
  *     property pos:
  *         def __get__(self): return self.pos             # <<<<<<<<<<<<<<
@@ -32596,9 +33340,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11PileupProxy_3pos___get__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3281);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3288);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -32628,7 +33372,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_11PileupProxy_7pileups_1__get__(PyOb
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3285
+/* "pysam/csamtools.pyx":3292
  *     property pileups:
  *         '''list of reads (:class:`pysam.PileupRead`) aligned to this column'''
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -32652,21 +33396,21 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11PileupProxy_7pileups___get__(struc
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3285);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3292);
 
-  /* "pysam/csamtools.pyx":3287
+  /* "pysam/csamtools.pyx":3294
  *         def __get__(self):
  *             cdef int x
  *             pileups = []             # <<<<<<<<<<<<<<
  * 
  *             if self.plp == NULL or self.plp[0] == NULL:
  */
-  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_pileups = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3289
+  /* "pysam/csamtools.pyx":3296
  *             pileups = []
  * 
  *             if self.plp == NULL or self.plp[0] == NULL:             # <<<<<<<<<<<<<<
@@ -32682,23 +33426,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11PileupProxy_7pileups___get__(struc
   }
   if (__pyx_t_4) {
 
-    /* "pysam/csamtools.pyx":3290
+    /* "pysam/csamtools.pyx":3297
  * 
  *             if self.plp == NULL or self.plp[0] == NULL:
  *                 raise ValueError("PileupProxy accessed after iterator finished")             # <<<<<<<<<<<<<<
  * 
  *             # warning: there could be problems if self.n and self.buf are
  */
-    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_186), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_185), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":3294
+  /* "pysam/csamtools.pyx":3301
  *             # warning: there could be problems if self.n and self.buf are
  *             # out of sync.
  *             for x from 0 <= x < self.n_pu:             # <<<<<<<<<<<<<<
@@ -32708,20 +33452,20 @@ static PyObject *__pyx_pf_5pysam_9csamtools_11PileupProxy_7pileups___get__(struc
   __pyx_t_5 = __pyx_v_self->n_pu;
   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {
 
-    /* "pysam/csamtools.pyx":3295
+    /* "pysam/csamtools.pyx":3302
  *             # out of sync.
  *             for x from 0 <= x < self.n_pu:
  *                 pileups.append( makePileupRead( &(self.plp[0][x])) )             # <<<<<<<<<<<<<<
  *             return pileups
  * 
  */
-    __pyx_t_1 = __pyx_f_5pysam_9csamtools_makePileupRead((&((__pyx_v_self->plp[0])[__pyx_v_x]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __pyx_f_5pysam_9csamtools_makePileupRead((&((__pyx_v_self->plp[0])[__pyx_v_x]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_6 = PyList_Append(__pyx_v_pileups, __pyx_t_1); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyList_Append(__pyx_v_pileups, __pyx_t_1); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   }
 
-  /* "pysam/csamtools.pyx":3296
+  /* "pysam/csamtools.pyx":3303
  *             for x from 0 <= x < self.n_pu:
  *                 pileups.append( makePileupRead( &(self.plp[0][x])) )
  *             return pileups             # <<<<<<<<<<<<<<
@@ -32761,7 +33505,7 @@ static int __pyx_pw_5pysam_9csamtools_10PileupRead_1__init__(PyObject *__pyx_v_s
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3302
+/* "pysam/csamtools.pyx":3309
  *     '''
  * 
  *     def __init__(self):             # <<<<<<<<<<<<<<
@@ -32778,20 +33522,20 @@ static int __pyx_pf_5pysam_9csamtools_10PileupRead___init__(CYTHON_UNUSED struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__init__", 0);
-  __Pyx_TraceCall("__init__", __pyx_f[0], 3302);
+  __Pyx_TraceCall("__init__", __pyx_f[0], 3309);
 
-  /* "pysam/csamtools.pyx":3303
+  /* "pysam/csamtools.pyx":3310
  * 
  *     def __init__(self):
  *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
  * 
  *     def __str__(self):
  */
-  __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_187), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_186), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_Raise(__pyx_t_1, 0, 0, 0);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
   __pyx_r = 0;
   goto __pyx_L0;
@@ -32816,7 +33560,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_10PileupRead_3__str__(PyObject *__py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3305
+/* "pysam/csamtools.pyx":3312
  *         raise TypeError("This class cannot be instantiated from Python")
  * 
  *     def __str__(self):             # <<<<<<<<<<<<<<
@@ -32841,9 +33585,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_2__str__(struct __pyx_o
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__str__", 0);
-  __Pyx_TraceCall("__str__", __pyx_f[0], 3305);
+  __Pyx_TraceCall("__str__", __pyx_f[0], 3312);
 
-  /* "pysam/csamtools.pyx":3306
+  /* "pysam/csamtools.pyx":3313
  * 
  *     def __str__(self):
  *         return "\t".join( map(str, (self.alignment, self.qpos, self.indel, self.level, self.is_del, self.is_head, self.is_tail ) ) )             # <<<<<<<<<<<<<<
@@ -32851,23 +33595,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_2__str__(struct __pyx_o
  *     property alignment:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__alignment); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__alignment); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__qpos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__qpos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__indel); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__indel); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__level); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__level); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
-  __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__is_del); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__is_del); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_6);
-  __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__is_head); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__is_head); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_7);
-  __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__is_tail); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__is_tail); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
-  __pyx_t_9 = PyTuple_New(7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = PyTuple_New(7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_9);
   PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
   __Pyx_GIVEREF(__pyx_t_2);
@@ -32890,7 +33634,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_2__str__(struct __pyx_o
   __pyx_t_6 = 0;
   __pyx_t_7 = 0;
   __pyx_t_8 = 0;
-  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
   PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
@@ -32898,15 +33642,15 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_2__str__(struct __pyx_o
   PyTuple_SET_ITEM(__pyx_t_8, 1, ((PyObject *)__pyx_t_9));
   __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
   __pyx_t_9 = 0;
-  __pyx_t_9 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_9);
   __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
-  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
   PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9);
   __Pyx_GIVEREF(__pyx_t_9);
   __pyx_t_9 = 0;
-  __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_9);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
@@ -32946,7 +33690,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_10PileupRead_9alignment_1__get__(PyO
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3310
+/* "pysam/csamtools.pyx":3317
  *     property alignment:
  *         """a :class:`pysam.AlignedRead` object of the aligned read"""
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -32959,9 +33703,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_9alignment___get__(stru
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3310);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3317);
 
-  /* "pysam/csamtools.pyx":3311
+  /* "pysam/csamtools.pyx":3318
  *         """a :class:`pysam.AlignedRead` object of the aligned read"""
  *         def __get__(self):
  *             return self._alignment             # <<<<<<<<<<<<<<
@@ -32992,7 +33736,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_10PileupRead_4qpos_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3314
+/* "pysam/csamtools.pyx":3321
  *     property qpos:
  *         """position of the read base at the pileup site, 0-based"""
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -33009,9 +33753,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_4qpos___get__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3314);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3321);
 
-  /* "pysam/csamtools.pyx":3315
+  /* "pysam/csamtools.pyx":3322
  *         """position of the read base at the pileup site, 0-based"""
  *         def __get__(self):
  *             return self._qpos             # <<<<<<<<<<<<<<
@@ -33019,7 +33763,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_4qpos___get__(struct __
  *         """indel length; 0 for no indel, positive for ins and negative for del"""
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_qpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_self->_qpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -33049,7 +33793,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_10PileupRead_5indel_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3318
+/* "pysam/csamtools.pyx":3325
  *     property indel:
  *         """indel length; 0 for no indel, positive for ins and negative for del"""
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -33066,9 +33810,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_5indel___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3318);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3325);
 
-  /* "pysam/csamtools.pyx":3319
+  /* "pysam/csamtools.pyx":3326
  *         """indel length; 0 for no indel, positive for ins and negative for del"""
  *         def __get__(self):
  *             return self._indel             # <<<<<<<<<<<<<<
@@ -33076,7 +33820,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_5indel___get__(struct _
  *         """1 iff the base on the padded read is a deletion"""
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_indel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_indel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -33106,7 +33850,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_10PileupRead_6is_del_1__get__(PyObje
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3322
+/* "pysam/csamtools.pyx":3329
  *     property is_del:
  *         """1 iff the base on the padded read is a deletion"""
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -33123,9 +33867,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_6is_del___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3322);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3329);
 
-  /* "pysam/csamtools.pyx":3323
+  /* "pysam/csamtools.pyx":3330
  *         """1 iff the base on the padded read is a deletion"""
  *         def __get__(self):
  *             return self._is_del             # <<<<<<<<<<<<<<
@@ -33133,7 +33877,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_6is_del___get__(struct
  *         def __get__(self):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_self->_is_del); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_self->_is_del); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -33163,7 +33907,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_10PileupRead_7is_head_1__get__(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3325
+/* "pysam/csamtools.pyx":3332
  *             return self._is_del
  *     property is_head:
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -33180,9 +33924,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_7is_head___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3325);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3332);
 
-  /* "pysam/csamtools.pyx":3326
+  /* "pysam/csamtools.pyx":3333
  *     property is_head:
  *         def __get__(self):
  *             return self._is_head             # <<<<<<<<<<<<<<
@@ -33190,7 +33934,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_7is_head___get__(struct
  *         def __get__(self):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_self->_is_head); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_self->_is_head); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -33220,7 +33964,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_10PileupRead_7is_tail_1__get__(PyObj
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3328
+/* "pysam/csamtools.pyx":3335
  *             return self._is_head
  *     property is_tail:
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -33237,9 +33981,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_7is_tail___get__(struct
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3328);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3335);
 
-  /* "pysam/csamtools.pyx":3329
+  /* "pysam/csamtools.pyx":3336
  *     property is_tail:
  *         def __get__(self):
  *             return self._is_tail             # <<<<<<<<<<<<<<
@@ -33247,7 +33991,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_7is_tail___get__(struct
  *         def __get__(self):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_self->_is_tail); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_self->_is_tail); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -33277,7 +34021,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_10PileupRead_5level_1__get__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3331
+/* "pysam/csamtools.pyx":3338
  *             return self._is_tail
  *     property level:
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -33294,9 +34038,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_5level___get__(struct _
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3331);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3338);
 
-  /* "pysam/csamtools.pyx":3332
+  /* "pysam/csamtools.pyx":3339
  *     property level:
  *         def __get__(self):
  *             return self._level             # <<<<<<<<<<<<<<
@@ -33304,7 +34048,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_10PileupRead_5level___get__(struct _
  * class Outs:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_level); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_level); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -33358,7 +34102,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_1__init__(PyObject *__pyx_self
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3336; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -33373,7 +34117,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_1__init__(PyObject *__pyx_self
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3336; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.Outs.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -33384,7 +34128,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_1__init__(PyObject *__pyx_self
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3336
+/* "pysam/csamtools.pyx":3343
  * class Outs:
  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
  *     def __init__(self, id = 1):             # <<<<<<<<<<<<<<
@@ -33401,28 +34145,28 @@ static PyObject *__pyx_pf_5pysam_9csamtools_4Outs___init__(CYTHON_UNUSED PyObjec
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__init__", 0);
-  __Pyx_TraceCall("__init__", __pyx_f[0], 3336);
+  __Pyx_TraceCall("__init__", __pyx_f[0], 3343);
 
-  /* "pysam/csamtools.pyx":3337
+  /* "pysam/csamtools.pyx":3344
  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
  *     def __init__(self, id = 1):
  *         self.streams = []             # <<<<<<<<<<<<<<
  *         self.id = id
  * 
  */
-  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__streams, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__streams, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3338
+  /* "pysam/csamtools.pyx":3345
  *     def __init__(self, id = 1):
  *         self.streams = []
  *         self.id = id             # <<<<<<<<<<<<<<
  * 
  *     def setdevice(self, filename):
  */
-  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__id, __pyx_v_id) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__id, __pyx_v_id) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
   goto __pyx_L0;
@@ -33467,11 +34211,11 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_3setdevice(PyObject *__pyx_sel
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("setdevice", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3340; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("setdevice", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setdevice") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3340; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setdevice") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
       goto __pyx_L5_argtuple_error;
@@ -33484,7 +34228,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_3setdevice(PyObject *__pyx_sel
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("setdevice", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3340; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("setdevice", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.Outs.setdevice", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -33495,7 +34239,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_3setdevice(PyObject *__pyx_sel
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3340
+/* "pysam/csamtools.pyx":3347
  *         self.id = id
  * 
  *     def setdevice(self, filename):             # <<<<<<<<<<<<<<
@@ -33515,26 +34259,26 @@ static PyObject *__pyx_pf_5pysam_9csamtools_4Outs_2setdevice(CYTHON_UNUSED PyObj
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("setdevice", 0);
-  __Pyx_TraceCall("setdevice", __pyx_f[0], 3340);
+  __Pyx_TraceCall("setdevice", __pyx_f[0], 3347);
 
-  /* "pysam/csamtools.pyx":3342
+  /* "pysam/csamtools.pyx":3349
  *     def setdevice(self, filename):
  *         '''open an existing file, like "/dev/null"'''
  *         fd = os.open(filename, os.O_WRONLY)             # <<<<<<<<<<<<<<
  *         self.setfd(fd)
  * 
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__O_WRONLY); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__O_WRONLY); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __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 = 3342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__pyx_v_filename);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_filename);
@@ -33542,28 +34286,28 @@ static PyObject *__pyx_pf_5pysam_9csamtools_4Outs_2setdevice(CYTHON_UNUSED PyObj
   PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
   __Pyx_GIVEREF(__pyx_t_3);
   __pyx_t_3 = 0;
-  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
   __pyx_v_fd = __pyx_t_3;
   __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":3343
+  /* "pysam/csamtools.pyx":3350
  *         '''open an existing file, like "/dev/null"'''
  *         fd = os.open(filename, os.O_WRONLY)
  *         self.setfd(fd)             # <<<<<<<<<<<<<<
  * 
  *     def setfile(self, filename):
  */
-  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__setfd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__setfd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __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 = 3350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__pyx_v_fd);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fd);
   __Pyx_GIVEREF(__pyx_v_fd);
-  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
@@ -33615,11 +34359,11 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_5setfile(PyObject *__pyx_self,
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("setfile", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3345; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("setfile", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3352; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setfile") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3345; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setfile") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3352; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
       goto __pyx_L5_argtuple_error;
@@ -33632,7 +34376,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_5setfile(PyObject *__pyx_self,
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("setfile", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3345; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("setfile", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3352; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.Outs.setfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -33643,7 +34387,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_5setfile(PyObject *__pyx_self,
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3345
+/* "pysam/csamtools.pyx":3352
  *         self.setfd(fd)
  * 
  *     def setfile(self, filename):             # <<<<<<<<<<<<<<
@@ -33664,35 +34408,35 @@ static PyObject *__pyx_pf_5pysam_9csamtools_4Outs_4setfile(CYTHON_UNUSED PyObjec
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("setfile", 0);
-  __Pyx_TraceCall("setfile", __pyx_f[0], 3345);
+  __Pyx_TraceCall("setfile", __pyx_f[0], 3352);
 
-  /* "pysam/csamtools.pyx":3347
+  /* "pysam/csamtools.pyx":3354
  *     def setfile(self, filename):
  *         '''open a new file.'''
  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);             # <<<<<<<<<<<<<<
  *         self.setfd(fd)
  * 
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__O_WRONLY); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__O_WRONLY); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__O_CREAT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__O_CREAT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = PyNumber_Or(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyNumber_Or(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_INCREF(__pyx_v_filename);
   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_filename);
@@ -33703,28 +34447,28 @@ static PyObject *__pyx_pf_5pysam_9csamtools_4Outs_4setfile(CYTHON_UNUSED PyObjec
   PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_0660);
   __Pyx_GIVEREF(__pyx_int_0660);
   __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
   __pyx_v_fd = __pyx_t_1;
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3348
+  /* "pysam/csamtools.pyx":3355
  *         '''open a new file.'''
  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
  *         self.setfd(fd)             # <<<<<<<<<<<<<<
  * 
  *     def setfd(self, fd):
  */
-  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__setfd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__setfd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_INCREF(__pyx_v_fd);
   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_fd);
   __Pyx_GIVEREF(__pyx_v_fd);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
@@ -33777,11 +34521,11 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_7setfd(PyObject *__pyx_self, P
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fd)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("setfd", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("setfd", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3357; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setfd") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setfd") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3357; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
       goto __pyx_L5_argtuple_error;
@@ -33794,7 +34538,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_7setfd(PyObject *__pyx_self, P
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("setfd", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("setfd", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3357; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.Outs.setfd", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -33805,7 +34549,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_7setfd(PyObject *__pyx_self, P
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3350
+/* "pysam/csamtools.pyx":3357
  *         self.setfd(fd)
  * 
  *     def setfd(self, fd):             # <<<<<<<<<<<<<<
@@ -33825,103 +34569,103 @@ static PyObject *__pyx_pf_5pysam_9csamtools_4Outs_6setfd(CYTHON_UNUSED PyObject
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("setfd", 0);
-  __Pyx_TraceCall("setfd", __pyx_f[0], 3350);
+  __Pyx_TraceCall("setfd", __pyx_f[0], 3357);
 
-  /* "pysam/csamtools.pyx":3351
+  /* "pysam/csamtools.pyx":3358
  * 
  *     def setfd(self, fd):
  *         ofd = os.dup(self.id)      #  Save old stream on new unit.             # <<<<<<<<<<<<<<
  *         self.streams.append(ofd)
  *         sys.stdout.flush()          #  Buffered data goes to old stream.
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dup); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dup); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3358; __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_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
   __pyx_v_ofd = __pyx_t_1;
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3352
+  /* "pysam/csamtools.pyx":3359
  *     def setfd(self, fd):
  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
  *         self.streams.append(ofd)             # <<<<<<<<<<<<<<
  *         sys.stdout.flush()          #  Buffered data goes to old stream.
  *         sys.stderr.flush()          #  Buffered data goes to old stream.
  */
-  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_3 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_v_ofd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_v_ofd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":3353
+  /* "pysam/csamtools.pyx":3360
  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
  *         self.streams.append(ofd)
  *         sys.stdout.flush()          #  Buffered data goes to old stream.             # <<<<<<<<<<<<<<
  *         sys.stderr.flush()          #  Buffered data goes to old stream.
  *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.
  */
-  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stdout); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stdout); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3354
+  /* "pysam/csamtools.pyx":3361
  *         self.streams.append(ofd)
  *         sys.stdout.flush()          #  Buffered data goes to old stream.
  *         sys.stderr.flush()          #  Buffered data goes to old stream.             # <<<<<<<<<<<<<<
  *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.
  *         os.close(fd)                #  Close other unit (look out, caller.)
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__stderr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__stderr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":3355
+  /* "pysam/csamtools.pyx":3362
  *         sys.stdout.flush()          #  Buffered data goes to old stream.
  *         sys.stderr.flush()          #  Buffered data goes to old stream.
  *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.             # <<<<<<<<<<<<<<
  *         os.close(fd)                #  Close other unit (look out, caller.)
  * 
  */
-  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__dup2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__dup2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3362; __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 = 3355; __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 = 3362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_INCREF(__pyx_v_fd);
   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fd);
@@ -33929,30 +34673,30 @@ static PyObject *__pyx_pf_5pysam_9csamtools_4Outs_6setfd(CYTHON_UNUSED PyObject
   PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
   __Pyx_GIVEREF(__pyx_t_3);
   __pyx_t_3 = 0;
-  __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 = 3355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __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 = 3362; __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_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":3356
+  /* "pysam/csamtools.pyx":3363
  *         sys.stderr.flush()          #  Buffered data goes to old stream.
  *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.
  *         os.close(fd)                #  Close other unit (look out, caller.)             # <<<<<<<<<<<<<<
  * 
  *     def restore(self):
  */
-  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_INCREF(__pyx_v_fd);
   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_fd);
   __Pyx_GIVEREF(__pyx_v_fd);
-  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
@@ -33987,7 +34731,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_4Outs_9restore(PyObject *__pyx_self,
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3358
+/* "pysam/csamtools.pyx":3365
  *         os.close(fd)                #  Close other unit (look out, caller.)
  * 
  *     def restore(self):             # <<<<<<<<<<<<<<
@@ -34008,81 +34752,81 @@ static PyObject *__pyx_pf_5pysam_9csamtools_4Outs_8restore(CYTHON_UNUSED PyObjec
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("restore", 0);
-  __Pyx_TraceCall("restore", __pyx_f[0], 3358);
+  __Pyx_TraceCall("restore", __pyx_f[0], 3365);
 
-  /* "pysam/csamtools.pyx":3360
+  /* "pysam/csamtools.pyx":3367
  *     def restore(self):
  *         '''restore previous output stream'''
  *         if self.streams:             # <<<<<<<<<<<<<<
  *             # the following was not sufficient, hence flush both stderr and stdout
  *             # os.fsync( self.id )
  */
-  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":3363
+    /* "pysam/csamtools.pyx":3370
  *             # the following was not sufficient, hence flush both stderr and stdout
  *             # os.fsync( self.id )
  *             sys.stdout.flush()             # <<<<<<<<<<<<<<
  *             sys.stderr.flush()
  *             os.dup2(self.streams[-1], self.id)
  */
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__stdout); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__stdout); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
-    /* "pysam/csamtools.pyx":3364
+    /* "pysam/csamtools.pyx":3371
  *             # os.fsync( self.id )
  *             sys.stdout.flush()
  *             sys.stderr.flush()             # <<<<<<<<<<<<<<
  *             os.dup2(self.streams[-1], self.id)
  *             os.close(self.streams[-1])
  */
-    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stderr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stderr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":3365
+    /* "pysam/csamtools.pyx":3372
  *             sys.stdout.flush()
  *             sys.stderr.flush()
  *             os.dup2(self.streams[-1], self.id)             # <<<<<<<<<<<<<<
  *             os.close(self.streams[-1])
  *             del self.streams[-1]
  */
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dup2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dup2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
     __Pyx_GIVEREF(__pyx_t_4);
@@ -34090,50 +34834,50 @@ static PyObject *__pyx_pf_5pysam_9csamtools_4Outs_8restore(CYTHON_UNUSED PyObjec
     __Pyx_GIVEREF(__pyx_t_1);
     __pyx_t_4 = 0;
     __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":3366
+    /* "pysam/csamtools.pyx":3373
  *             sys.stderr.flush()
  *             os.dup2(self.streams[-1], self.id)
  *             os.close(self.streams[-1])             # <<<<<<<<<<<<<<
  *             del self.streams[-1]
  * 
  */
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__close); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__close); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3366; __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 = 3373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
     __Pyx_GIVEREF(__pyx_t_3);
     __pyx_t_3 = 0;
-    __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
-    /* "pysam/csamtools.pyx":3367
+    /* "pysam/csamtools.pyx":3374
  *             os.dup2(self.streams[-1], self.id)
  *             os.close(self.streams[-1])
  *             del self.streams[-1]             # <<<<<<<<<<<<<<
  * 
  * def _samtools_dispatch( method,
  */
-    __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    if (__Pyx_DelItemInt(__pyx_t_3, -1, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (__Pyx_DelItemInt(__pyx_t_3, -1, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
     goto __pyx_L3;
   }
@@ -34170,7 +34914,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_1_samtools_dispatch(PyObject *__pyx_
     static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__method,&__pyx_n_s__args,&__pyx_n_s__catch_stdout,0};
     PyObject* values[3] = {0,0,0};
 
-    /* "pysam/csamtools.pyx":3370
+    /* "pysam/csamtools.pyx":3377
  * 
  * def _samtools_dispatch( method,
  *                         args = (),             # <<<<<<<<<<<<<<
@@ -34178,7 +34922,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_1_samtools_dispatch(PyObject *__pyx_
  *     '''call ``method`` in samtools providing arguments in args.
  */
     values[1] = ((PyObject *)__pyx_empty_tuple);
-    values[2] = __pyx_k_188;
+    values[2] = __pyx_k_187;
     if (unlikely(__pyx_kwds)) {
       Py_ssize_t kw_args;
       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
@@ -34206,7 +34950,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_1_samtools_dispatch(PyObject *__pyx_
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_samtools_dispatch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3369; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_samtools_dispatch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3376; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -34223,7 +34967,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_1_samtools_dispatch(PyObject *__pyx_
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("_samtools_dispatch", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3369; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("_samtools_dispatch", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3376; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -34234,7 +34978,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_1_samtools_dispatch(PyObject *__pyx_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3369
+/* "pysam/csamtools.pyx":3376
  *             del self.streams[-1]
  * 
  * def _samtools_dispatch( method,             # <<<<<<<<<<<<<<
@@ -34285,77 +35029,77 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("_samtools_dispatch", 0);
-  __Pyx_TraceCall("_samtools_dispatch", __pyx_f[0], 3369);
+  __Pyx_TraceCall("_samtools_dispatch", __pyx_f[0], 3376);
   __Pyx_INCREF(__pyx_v_method);
   __Pyx_INCREF(__pyx_v_args);
   __Pyx_INCREF(__pyx_v_catch_stdout);
 
-  /* "pysam/csamtools.pyx":3395
+  /* "pysam/csamtools.pyx":3402
  * 
  *     # some special cases
  *     if method == "index":             # <<<<<<<<<<<<<<
  *         if not os.path.exists( args[0] ):
  *             raise IOError( "No such file or directory: '%s'" % args[0] )
  */
-  __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__index), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__index), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (__pyx_t_2) {
 
-    /* "pysam/csamtools.pyx":3396
+    /* "pysam/csamtools.pyx":3403
  *     # some special cases
  *     if method == "index":
  *         if not os.path.exists( args[0] ):             # <<<<<<<<<<<<<<
  *             raise IOError( "No such file or directory: '%s'" % args[0] )
  * 
  */
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_args, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_args, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
     __Pyx_GIVEREF(__pyx_t_3);
     __pyx_t_3 = 0;
-    __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3403; __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_4)); __pyx_t_4 = 0;
-    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
     __pyx_t_5 = (!__pyx_t_2);
     if (__pyx_t_5) {
 
-      /* "pysam/csamtools.pyx":3397
+      /* "pysam/csamtools.pyx":3404
  *     if method == "index":
  *         if not os.path.exists( args[0] ):
  *             raise IOError( "No such file or directory: '%s'" % args[0] )             # <<<<<<<<<<<<<<
  * 
  *     # redirect stderr and stdout to file
  */
-      __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_args, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_args, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
-      __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_189), __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_188), __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_4));
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_4));
       __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
       __pyx_t_4 = 0;
-      __pyx_t_4 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_4);
       __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
       __Pyx_Raise(__pyx_t_4, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L4;
     }
     __pyx_L4:;
@@ -34363,19 +35107,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":3400
+  /* "pysam/csamtools.pyx":3407
  * 
  *     # redirect stderr and stdout to file
  *     stderr_h, stderr_f = tempfile.mkstemp()             # <<<<<<<<<<<<<<
  *     pysam_set_stderr( stderr_h )
  * 
  */
-  __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__tempfile); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__tempfile); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__mkstemp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__mkstemp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __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 = 3400; __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 = 3407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
@@ -34388,7 +35132,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
     if (unlikely(size != 2)) {
       if (size > 2) __Pyx_RaiseTooManyValuesError(2);
       else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     #if CYTHON_COMPILING_IN_CPYTHON
     if (likely(PyTuple_CheckExact(sequence))) {
@@ -34401,16 +35145,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
     __Pyx_INCREF(__pyx_t_3);
     __Pyx_INCREF(__pyx_t_1);
     #else
-    __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3400; __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 = 3407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     #endif
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   } else
   {
     Py_ssize_t index = -1;
-    __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
     __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext;
@@ -34418,7 +35162,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
     __Pyx_GOTREF(__pyx_t_3);
     index = 1; __pyx_t_1 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_1)) goto __pyx_L5_unpacking_failed;
     __Pyx_GOTREF(__pyx_t_1);
-    if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_7 = NULL;
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     goto __pyx_L6_unpacking_done;
@@ -34426,7 +35170,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     __pyx_t_7 = NULL;
     if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_L6_unpacking_done:;
   }
   __pyx_v_stderr_h = __pyx_t_3;
@@ -34434,39 +35178,39 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
   __pyx_v_stderr_f = __pyx_t_1;
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3401
+  /* "pysam/csamtools.pyx":3408
  *     # redirect stderr and stdout to file
  *     stderr_h, stderr_f = tempfile.mkstemp()
  *     pysam_set_stderr( stderr_h )             # <<<<<<<<<<<<<<
  * 
  *     if catch_stdout:
  */
-  __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_v_stderr_h); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_v_stderr_h); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   pysam_set_stderr(__pyx_t_8);
 
-  /* "pysam/csamtools.pyx":3403
+  /* "pysam/csamtools.pyx":3410
  *     pysam_set_stderr( stderr_h )
  * 
  *     if catch_stdout:             # <<<<<<<<<<<<<<
  *         stdout_h, stdout_f = tempfile.mkstemp()
  *         try:
  */
-  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_5) {
 
-    /* "pysam/csamtools.pyx":3404
+    /* "pysam/csamtools.pyx":3411
  * 
  *     if catch_stdout:
  *         stdout_h, stdout_f = tempfile.mkstemp()             # <<<<<<<<<<<<<<
  *         try:
  *             stdout_save = Outs( sys.stdout.fileno() )
  */
-    __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__tempfile); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__tempfile); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
-    __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__mkstemp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__mkstemp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
@@ -34479,7 +35223,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       if (unlikely(size != 2)) {
         if (size > 2) __Pyx_RaiseTooManyValuesError(2);
         else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
       #if CYTHON_COMPILING_IN_CPYTHON
       if (likely(PyTuple_CheckExact(sequence))) {
@@ -34492,16 +35236,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __Pyx_INCREF(__pyx_t_1);
       __Pyx_INCREF(__pyx_t_3);
       #else
-      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       #endif
       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
     } else
     {
       Py_ssize_t index = -1;
-      __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
       __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext;
@@ -34509,7 +35253,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __Pyx_GOTREF(__pyx_t_1);
       index = 1; __pyx_t_3 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L8_unpacking_failed;
       __Pyx_GOTREF(__pyx_t_3);
-      if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_t_7 = NULL;
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
       goto __pyx_L9_unpacking_done;
@@ -34517,7 +35261,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
       __pyx_t_7 = NULL;
       if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_L9_unpacking_done:;
     }
     __pyx_v_stdout_h = __pyx_t_1;
@@ -34525,7 +35269,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
     __pyx_v_stdout_f = __pyx_t_3;
     __pyx_t_3 = 0;
 
-    /* "pysam/csamtools.pyx":3405
+    /* "pysam/csamtools.pyx":3412
  *     if catch_stdout:
  *         stdout_h, stdout_f = tempfile.mkstemp()
  *         try:             # <<<<<<<<<<<<<<
@@ -34539,53 +35283,53 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __Pyx_XGOTREF(__pyx_t_11);
       /*try:*/ {
 
-        /* "pysam/csamtools.pyx":3406
+        /* "pysam/csamtools.pyx":3413
  *         stdout_h, stdout_f = tempfile.mkstemp()
  *         try:
  *             stdout_save = Outs( sys.stdout.fileno() )             # <<<<<<<<<<<<<<
  *             stdout_save.setfd( stdout_h )
  *         except AttributeError:
  */
-        __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__Outs); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+        __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__Outs); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3413; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
         __Pyx_GOTREF(__pyx_t_4);
-        __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+        __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3413; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
         __Pyx_GOTREF(__pyx_t_3);
-        __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stdout); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+        __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stdout); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3413; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
         __Pyx_GOTREF(__pyx_t_1);
         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-        __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__fileno); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+        __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__fileno); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3413; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
         __Pyx_GOTREF(__pyx_t_3);
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-        __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+        __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3413; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
         __Pyx_GOTREF(__pyx_t_1);
         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3413; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
         __Pyx_GOTREF(__pyx_t_3);
         PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
         __Pyx_GIVEREF(__pyx_t_1);
         __pyx_t_1 = 0;
-        __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+        __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3413; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
         __Pyx_GOTREF(__pyx_t_1);
         __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
         __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
         __pyx_v_stdout_save = __pyx_t_1;
         __pyx_t_1 = 0;
 
-        /* "pysam/csamtools.pyx":3407
+        /* "pysam/csamtools.pyx":3414
  *         try:
  *             stdout_save = Outs( sys.stdout.fileno() )
  *             stdout_save.setfd( stdout_h )             # <<<<<<<<<<<<<<
  *         except AttributeError:
  *             # stdout has already been redirected
  */
-        __pyx_t_1 = PyObject_GetAttr(__pyx_v_stdout_save, __pyx_n_s__setfd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+        __pyx_t_1 = PyObject_GetAttr(__pyx_v_stdout_save, __pyx_n_s__setfd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3414; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
         __Pyx_GOTREF(__pyx_t_1);
-        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3414; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
         __Pyx_GOTREF(__pyx_t_3);
         __Pyx_INCREF(__pyx_v_stdout_h);
         PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_stdout_h);
         __Pyx_GIVEREF(__pyx_v_stdout_h);
-        __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
+        __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3414; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
         __Pyx_GOTREF(__pyx_t_4);
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
         __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
@@ -34601,7 +35345,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
       __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-      /* "pysam/csamtools.pyx":3408
+      /* "pysam/csamtools.pyx":3415
  *             stdout_save = Outs( sys.stdout.fileno() )
  *             stdout_save.setfd( stdout_h )
  *         except AttributeError:             # <<<<<<<<<<<<<<
@@ -34611,19 +35355,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __pyx_t_8 = PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
       if (__pyx_t_8) {
         __Pyx_AddTraceback("pysam.csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
-        if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_3, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3408; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
+        if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_3, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3415; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
         __Pyx_GOTREF(__pyx_t_4);
         __Pyx_GOTREF(__pyx_t_3);
         __Pyx_GOTREF(__pyx_t_1);
 
-        /* "pysam/csamtools.pyx":3410
+        /* "pysam/csamtools.pyx":3417
  *         except AttributeError:
  *             # stdout has already been redirected
  *             catch_stdout = False             # <<<<<<<<<<<<<<
  * 
  *         # patch for `samtools view`
  */
-        __pyx_t_6 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3410; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
+        __pyx_t_6 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
         __Pyx_GOTREF(__pyx_t_6);
         __Pyx_DECREF(__pyx_v_catch_stdout);
         __pyx_v_catch_stdout = __pyx_t_6;
@@ -34647,52 +35391,52 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __pyx_L17_try_end:;
     }
 
-    /* "pysam/csamtools.pyx":3415
+    /* "pysam/csamtools.pyx":3422
  *         # samtools `view` closes stdout, from which I can not
  *         # recover. Thus redirect output to file with -o option.
  *         if method == "view":             # <<<<<<<<<<<<<<
  *             if "-o" in args: raise ValueError("option -o is forbidden in samtools view")
  *             args = ( "-o", stdout_f ) + args
  */
-    __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__view), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__view), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     if (__pyx_t_5) {
 
-      /* "pysam/csamtools.pyx":3416
+      /* "pysam/csamtools.pyx":3423
  *         # recover. Thus redirect output to file with -o option.
  *         if method == "view":
  *             if "-o" in args: raise ValueError("option -o is forbidden in samtools view")             # <<<<<<<<<<<<<<
  *             args = ( "-o", stdout_f ) + args
  * 
  */
-      __pyx_t_5 = (__Pyx_PySequence_Contains(((PyObject *)__pyx_kp_s_190), __pyx_v_args, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = (__Pyx_PySequence_Contains(((PyObject *)__pyx_kp_s_189), __pyx_v_args, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       if (__pyx_t_5) {
-        __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_192), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_191), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
         __Pyx_Raise(__pyx_t_1, 0, 0, 0);
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         goto __pyx_L21;
       }
       __pyx_L21:;
 
-      /* "pysam/csamtools.pyx":3417
+      /* "pysam/csamtools.pyx":3424
  *         if method == "view":
  *             if "-o" in args: raise ValueError("option -o is forbidden in samtools view")
  *             args = ( "-o", stdout_f ) + args             # <<<<<<<<<<<<<<
  * 
  *     # do the function call to samtools
  */
-      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __Pyx_INCREF(((PyObject *)__pyx_kp_s_190));
-      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_190));
-      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_190));
+      __Pyx_INCREF(((PyObject *)__pyx_kp_s_189));
+      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_189));
+      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_189));
       __Pyx_INCREF(__pyx_v_stdout_f);
       PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_stdout_f);
       __Pyx_GIVEREF(__pyx_v_stdout_f);
-      __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_t_1), __pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_t_1), __pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
       __Pyx_DECREF(__pyx_v_args);
@@ -34705,43 +35449,43 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
   }
   __pyx_L7:;
 
-  /* "pysam/csamtools.pyx":3423
+  /* "pysam/csamtools.pyx":3430
  *     cdef int i, n, retval
  * 
  *     n = len(args)             # <<<<<<<<<<<<<<
  *     method = _force_cmdline_bytes(method)
  *     args = [ _force_cmdline_bytes(a) for a in args ]
  */
-  __pyx_t_12 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_12 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_n = __pyx_t_12;
 
-  /* "pysam/csamtools.pyx":3424
+  /* "pysam/csamtools.pyx":3431
  * 
  *     n = len(args)
  *     method = _force_cmdline_bytes(method)             # <<<<<<<<<<<<<<
  *     args = [ _force_cmdline_bytes(a) for a in args ]
  * 
  */
-  __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_cmdline_bytes(__pyx_v_method)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_cmdline_bytes(__pyx_v_method)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_v_method);
   __pyx_v_method = __pyx_t_3;
   __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":3425
+  /* "pysam/csamtools.pyx":3432
  *     n = len(args)
  *     method = _force_cmdline_bytes(method)
  *     args = [ _force_cmdline_bytes(a) for a in args ]             # <<<<<<<<<<<<<<
  * 
  *     # allocate two more for first (dummy) argument (contains command)
  */
-  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   if (PyList_CheckExact(__pyx_v_args) || PyTuple_CheckExact(__pyx_v_args)) {
     __pyx_t_1 = __pyx_v_args; __Pyx_INCREF(__pyx_t_1); __pyx_t_12 = 0;
     __pyx_t_13 = NULL;
   } else {
-    __pyx_t_12 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_args); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_12 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_args); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __pyx_t_13 = Py_TYPE(__pyx_t_1)->tp_iternext;
   }
@@ -34749,23 +35493,23 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
     if (!__pyx_t_13 && PyList_CheckExact(__pyx_t_1)) {
       if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_1)) break;
       #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_4); __pyx_t_12++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_4); __pyx_t_12++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #else
-      __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
     } else if (!__pyx_t_13 && PyTuple_CheckExact(__pyx_t_1)) {
       if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
       #if CYTHON_COMPILING_IN_CPYTHON
-      __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_4); __pyx_t_12++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_4); __pyx_t_12++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #else
-      __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       #endif
     } else {
       __pyx_t_4 = __pyx_t_13(__pyx_t_1);
       if (unlikely(!__pyx_t_4)) {
         if (PyErr_Occurred()) {
           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
-          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         break;
       }
@@ -34774,9 +35518,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
     __Pyx_XDECREF(__pyx_v_a);
     __pyx_v_a = __pyx_t_4;
     __pyx_t_4 = 0;
-    __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_cmdline_bytes(__pyx_v_a)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_9csamtools__force_cmdline_bytes(__pyx_v_a)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
-    if (unlikely(__Pyx_PyList_Append(__pyx_t_3, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (unlikely(__Pyx_PyList_Append(__pyx_t_3, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   }
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -34787,7 +35531,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
   __pyx_v_args = __pyx_t_1;
   __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3428
+  /* "pysam/csamtools.pyx":3435
  * 
  *     # allocate two more for first (dummy) argument (contains command)
  *     cargs = <char**>calloc( n+2, sizeof( char *) )             # <<<<<<<<<<<<<<
@@ -34796,7 +35540,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  */
   __pyx_v_cargs = ((char **)calloc((__pyx_v_n + 2), (sizeof(char *))));
 
-  /* "pysam/csamtools.pyx":3429
+  /* "pysam/csamtools.pyx":3436
  *     # allocate two more for first (dummy) argument (contains command)
  *     cargs = <char**>calloc( n+2, sizeof( char *) )
  *     cargs[0] = "samtools"             # <<<<<<<<<<<<<<
@@ -34805,17 +35549,17 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  */
   (__pyx_v_cargs[0]) = __pyx_k__samtools;
 
-  /* "pysam/csamtools.pyx":3430
+  /* "pysam/csamtools.pyx":3437
  *     cargs = <char**>calloc( n+2, sizeof( char *) )
  *     cargs[0] = "samtools"
  *     cargs[1] = method             # <<<<<<<<<<<<<<
  *     for i from 0 <= i < n: cargs[i+2] = args[i]
  * 
  */
-  __pyx_t_14 = PyBytes_AsString(__pyx_v_method); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_14 = PyBytes_AsString(__pyx_v_method); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   (__pyx_v_cargs[1]) = __pyx_t_14;
 
-  /* "pysam/csamtools.pyx":3431
+  /* "pysam/csamtools.pyx":3438
  *     cargs[0] = "samtools"
  *     cargs[1] = method
  *     for i from 0 <= i < n: cargs[i+2] = args[i]             # <<<<<<<<<<<<<<
@@ -34824,14 +35568,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  */
   __pyx_t_8 = __pyx_v_n;
   for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) {
-    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_args, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_args, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_14 = PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_14 = PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     (__pyx_v_cargs[(__pyx_v_i + 2)]) = __pyx_t_14;
   }
 
-  /* "pysam/csamtools.pyx":3433
+  /* "pysam/csamtools.pyx":3440
  *     for i from 0 <= i < n: cargs[i+2] = args[i]
  * 
  *     retval = pysam_dispatch(n+2, cargs)             # <<<<<<<<<<<<<<
@@ -34840,7 +35584,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  */
   __pyx_v_retval = pysam_dispatch((__pyx_v_n + 2), __pyx_v_cargs);
 
-  /* "pysam/csamtools.pyx":3434
+  /* "pysam/csamtools.pyx":3441
  * 
  *     retval = pysam_dispatch(n+2, cargs)
  *     free( cargs )             # <<<<<<<<<<<<<<
@@ -34849,32 +35593,32 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  */
   free(__pyx_v_cargs);
 
-  /* "pysam/csamtools.pyx":3438
+  /* "pysam/csamtools.pyx":3445
  *     # restore stdout/stderr. This will also flush, so
  *     # needs to be before reading back the file contents
  *     if catch_stdout:             # <<<<<<<<<<<<<<
  *         stdout_save.restore()
  *         try:
  */
-  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_5) {
 
-    /* "pysam/csamtools.pyx":3439
+    /* "pysam/csamtools.pyx":3446
  *     # needs to be before reading back the file contents
  *     if catch_stdout:
  *         stdout_save.restore()             # <<<<<<<<<<<<<<
  *         try:
  *             with open( stdout_f, "r") as inf:
  */
-    if (unlikely(!__pyx_v_stdout_save)) { __Pyx_RaiseUnboundLocalError("stdout_save"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
-    __pyx_t_1 = PyObject_GetAttr(__pyx_v_stdout_save, __pyx_n_s__restore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (unlikely(!__pyx_v_stdout_save)) { __Pyx_RaiseUnboundLocalError("stdout_save"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3446; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+    __pyx_t_1 = PyObject_GetAttr(__pyx_v_stdout_save, __pyx_n_s__restore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
-    /* "pysam/csamtools.pyx":3440
+    /* "pysam/csamtools.pyx":3447
  *     if catch_stdout:
  *         stdout_save.restore()
  *         try:             # <<<<<<<<<<<<<<
@@ -34888,7 +35632,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __Pyx_XGOTREF(__pyx_t_9);
       /*try:*/ {
 
-        /* "pysam/csamtools.pyx":3441
+        /* "pysam/csamtools.pyx":3448
  *         stdout_save.restore()
  *         try:
  *             with open( stdout_f, "r") as inf:             # <<<<<<<<<<<<<<
@@ -34896,8 +35640,8 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  *         except UnicodeDecodeError:
  */
         /*with:*/ {
-          if (unlikely(!__pyx_v_stdout_f)) { __Pyx_RaiseUnboundLocalError("stdout_f"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L27_error;} }
-          __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
+          if (unlikely(!__pyx_v_stdout_f)) { __Pyx_RaiseUnboundLocalError("stdout_f"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L27_error;} }
+          __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
           __Pyx_GOTREF(__pyx_t_3);
           __Pyx_INCREF(__pyx_v_stdout_f);
           PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_stdout_f);
@@ -34905,14 +35649,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
           __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
           PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__r));
           __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
-          __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
+          __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
           __Pyx_GOTREF(__pyx_t_1);
           __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
-          __pyx_t_15 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
+          __pyx_t_15 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
           __Pyx_GOTREF(__pyx_t_15);
-          __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L35_error;}
+          __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L35_error;}
           __Pyx_GOTREF(__pyx_t_3);
-          __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 = 3441; __pyx_clineno = __LINE__; goto __pyx_L35_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 = 3448; __pyx_clineno = __LINE__; goto __pyx_L35_error;}
           __Pyx_GOTREF(__pyx_t_4);
           __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -34927,16 +35671,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
                 __pyx_v_inf = __pyx_t_4;
                 __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-                /* "pysam/csamtools.pyx":3442
+                /* "pysam/csamtools.pyx":3449
  *         try:
  *             with open( stdout_f, "r") as inf:
  *                 out_stdout = inf.readlines()             # <<<<<<<<<<<<<<
  *         except UnicodeDecodeError:
  *             with open( stdout_f, "rb") as inf:
  */
-                __pyx_t_4 = PyObject_GetAttr(__pyx_v_inf, __pyx_n_s__readlines); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L41_error;}
+                __pyx_t_4 = PyObject_GetAttr(__pyx_v_inf, __pyx_n_s__readlines); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3449; __pyx_clineno = __LINE__; goto __pyx_L41_error;}
                 __Pyx_GOTREF(__pyx_t_4);
-                __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3442; __pyx_clineno = __LINE__; goto __pyx_L41_error;}
+                __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3449; __pyx_clineno = __LINE__; goto __pyx_L41_error;}
                 __Pyx_GOTREF(__pyx_t_1);
                 __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                 __pyx_v_out_stdout = __pyx_t_1;
@@ -34952,7 +35696,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
               __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
               __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-              /* "pysam/csamtools.pyx":3441
+              /* "pysam/csamtools.pyx":3448
  *         stdout_save.restore()
  *         try:
  *             with open( stdout_f, "r") as inf:             # <<<<<<<<<<<<<<
@@ -34961,11 +35705,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  */
               /*except:*/ {
                 __Pyx_AddTraceback("pysam.csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
-                if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_4, &__pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
+                if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_4, &__pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
                 __Pyx_GOTREF(__pyx_t_1);
                 __Pyx_GOTREF(__pyx_t_4);
                 __Pyx_GOTREF(__pyx_t_3);
-                __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
+                __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
                 __Pyx_GOTREF(__pyx_t_6);
                 __Pyx_INCREF(__pyx_t_1);
                 PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
@@ -34978,11 +35722,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
                 __Pyx_GIVEREF(__pyx_t_3);
                 __pyx_t_19 = PyObject_Call(__pyx_t_15, __pyx_t_6, NULL);
                 __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-                if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
+                if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
                 __Pyx_GOTREF(__pyx_t_19);
                 __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_19);
                 __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
-                if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
+                if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
                 __pyx_t_2 = (!__pyx_t_5);
                 if (__pyx_t_2) {
                   __Pyx_GIVEREF(__pyx_t_1);
@@ -34990,7 +35734,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
                   __Pyx_GIVEREF(__pyx_t_3);
                   __Pyx_ErrRestore(__pyx_t_1, __pyx_t_4, __pyx_t_3);
                   __pyx_t_1 = 0; __pyx_t_4 = 0; __pyx_t_3 = 0; 
-                  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
+                  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
                   goto __pyx_L52;
                 }
                 __pyx_L52:;
@@ -35016,13 +35760,13 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
           }
           /*finally:*/ {
             if (__pyx_t_15) {
-              __pyx_t_18 = PyObject_Call(__pyx_t_15, __pyx_k_tuple_193, NULL);
+              __pyx_t_18 = PyObject_Call(__pyx_t_15, __pyx_k_tuple_192, NULL);
               __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-              if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
+              if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
               __Pyx_GOTREF(__pyx_t_18);
               __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_18);
               __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
-              if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
+              if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
             }
           }
           goto __pyx_L53;
@@ -35042,7 +35786,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
       __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
 
-      /* "pysam/csamtools.pyx":3443
+      /* "pysam/csamtools.pyx":3450
  *             with open( stdout_f, "r") as inf:
  *                 out_stdout = inf.readlines()
  *         except UnicodeDecodeError:             # <<<<<<<<<<<<<<
@@ -35052,12 +35796,12 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __pyx_t_8 = PyErr_ExceptionMatches(__pyx_builtin_UnicodeDecodeError);
       if (__pyx_t_8) {
         __Pyx_AddTraceback("pysam.csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
-        if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3443; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
+        if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3450; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
         __Pyx_GOTREF(__pyx_t_3);
         __Pyx_GOTREF(__pyx_t_4);
         __Pyx_GOTREF(__pyx_t_1);
 
-        /* "pysam/csamtools.pyx":3444
+        /* "pysam/csamtools.pyx":3451
  *                 out_stdout = inf.readlines()
  *         except UnicodeDecodeError:
  *             with open( stdout_f, "rb") as inf:             # <<<<<<<<<<<<<<
@@ -35065,7 +35809,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  *                 out_stdout = inf.read()
  */
         /*with:*/ {
-          __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
+          __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
           __Pyx_GOTREF(__pyx_t_6);
           __Pyx_INCREF(__pyx_v_stdout_f);
           PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_stdout_f);
@@ -35073,14 +35817,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
           __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
           PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_n_s__rb));
           __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rb));
-          __pyx_t_20 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
+          __pyx_t_20 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
           __Pyx_GOTREF(__pyx_t_20);
           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
-          __pyx_t_15 = PyObject_GetAttr(__pyx_t_20, __pyx_n_s____exit__); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
+          __pyx_t_15 = PyObject_GetAttr(__pyx_t_20, __pyx_n_s____exit__); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
           __Pyx_GOTREF(__pyx_t_15);
-          __pyx_t_6 = PyObject_GetAttr(__pyx_t_20, __pyx_n_s____enter__); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L56_error;}
+          __pyx_t_6 = PyObject_GetAttr(__pyx_t_20, __pyx_n_s____enter__); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L56_error;}
           __Pyx_GOTREF(__pyx_t_6);
-          __pyx_t_21 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L56_error;}
+          __pyx_t_21 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L56_error;}
           __Pyx_GOTREF(__pyx_t_21);
           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
           __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
@@ -35096,16 +35840,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
                 __pyx_v_inf = __pyx_t_21;
                 __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
 
-                /* "pysam/csamtools.pyx":3446
+                /* "pysam/csamtools.pyx":3453
  *             with open( stdout_f, "rb") as inf:
  *                 # read binary output
  *                 out_stdout = inf.read()             # <<<<<<<<<<<<<<
  *         os.remove( stdout_f )
  *     else:
  */
-                __pyx_t_21 = PyObject_GetAttr(__pyx_v_inf, __pyx_n_s__read); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3446; __pyx_clineno = __LINE__; goto __pyx_L62_error;}
+                __pyx_t_21 = PyObject_GetAttr(__pyx_v_inf, __pyx_n_s__read); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3453; __pyx_clineno = __LINE__; goto __pyx_L62_error;}
                 __Pyx_GOTREF(__pyx_t_21);
-                __pyx_t_20 = PyObject_Call(__pyx_t_21, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3446; __pyx_clineno = __LINE__; goto __pyx_L62_error;}
+                __pyx_t_20 = PyObject_Call(__pyx_t_21, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3453; __pyx_clineno = __LINE__; goto __pyx_L62_error;}
                 __Pyx_GOTREF(__pyx_t_20);
                 __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
                 __Pyx_XDECREF(__pyx_v_out_stdout);
@@ -35121,7 +35865,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
               __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
               __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
 
-              /* "pysam/csamtools.pyx":3444
+              /* "pysam/csamtools.pyx":3451
  *                 out_stdout = inf.readlines()
  *         except UnicodeDecodeError:
  *             with open( stdout_f, "rb") as inf:             # <<<<<<<<<<<<<<
@@ -35130,11 +35874,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  */
               /*except:*/ {
                 __Pyx_AddTraceback("pysam.csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
-                if (__Pyx_GetException(&__pyx_t_20, &__pyx_t_21, &__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
+                if (__Pyx_GetException(&__pyx_t_20, &__pyx_t_21, &__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
                 __Pyx_GOTREF(__pyx_t_20);
                 __Pyx_GOTREF(__pyx_t_21);
                 __Pyx_GOTREF(__pyx_t_6);
-                __pyx_t_22 = PyTuple_New(3); if (unlikely(!__pyx_t_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
+                __pyx_t_22 = PyTuple_New(3); if (unlikely(!__pyx_t_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
                 __Pyx_GOTREF(__pyx_t_22);
                 __Pyx_INCREF(__pyx_t_20);
                 PyTuple_SET_ITEM(__pyx_t_22, 0, __pyx_t_20);
@@ -35147,11 +35891,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
                 __Pyx_GIVEREF(__pyx_t_6);
                 __pyx_t_19 = PyObject_Call(__pyx_t_15, __pyx_t_22, NULL);
                 __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-                if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
+                if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
                 __Pyx_GOTREF(__pyx_t_19);
                 __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_19);
                 __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
-                if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
+                if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
                 __pyx_t_5 = (!__pyx_t_2);
                 if (__pyx_t_5) {
                   __Pyx_GIVEREF(__pyx_t_20);
@@ -35159,7 +35903,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
                   __Pyx_GIVEREF(__pyx_t_6);
                   __Pyx_ErrRestore(__pyx_t_20, __pyx_t_21, __pyx_t_6);
                   __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_6 = 0; 
-                  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
+                  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
                   goto __pyx_L73;
                 }
                 __pyx_L73:;
@@ -35185,13 +35929,13 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
           }
           /*finally:*/ {
             if (__pyx_t_15) {
-              __pyx_t_16 = PyObject_Call(__pyx_t_15, __pyx_k_tuple_194, NULL);
+              __pyx_t_16 = PyObject_Call(__pyx_t_15, __pyx_k_tuple_193, NULL);
               __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-              if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
+              if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
               __Pyx_GOTREF(__pyx_t_16);
               __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_16);
               __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
-              if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
+              if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
             }
           }
           goto __pyx_L74;
@@ -35219,24 +35963,24 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __pyx_L34_try_end:;
     }
 
-    /* "pysam/csamtools.pyx":3447
+    /* "pysam/csamtools.pyx":3454
  *                 # read binary output
  *                 out_stdout = inf.read()
  *         os.remove( stdout_f )             # <<<<<<<<<<<<<<
  *     else:
  *         out_stdout = []
  */
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__remove); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__remove); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3447; __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 = 3454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_INCREF(__pyx_v_stdout_f);
     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_stdout_f);
     __Pyx_GIVEREF(__pyx_v_stdout_f);
-    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
@@ -35245,21 +35989,21 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":3449
+    /* "pysam/csamtools.pyx":3456
  *         os.remove( stdout_f )
  *     else:
  *         out_stdout = []             # <<<<<<<<<<<<<<
  * 
  *     # get error messages
  */
-    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __pyx_v_out_stdout = ((PyObject *)__pyx_t_3);
     __pyx_t_3 = 0;
   }
   __pyx_L26:;
 
-  /* "pysam/csamtools.pyx":3452
+  /* "pysam/csamtools.pyx":3459
  * 
  *     # get error messages
  *     pysam_unset_stderr()             # <<<<<<<<<<<<<<
@@ -35268,7 +36012,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  */
   pysam_unset_stderr();
 
-  /* "pysam/csamtools.pyx":3453
+  /* "pysam/csamtools.pyx":3460
  *     # get error messages
  *     pysam_unset_stderr()
  *     try:             # <<<<<<<<<<<<<<
@@ -35283,7 +36027,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __Pyx_XGOTREF(__pyx_t_11);
       /*try:*/ {
 
-        /* "pysam/csamtools.pyx":3454
+        /* "pysam/csamtools.pyx":3461
  *     pysam_unset_stderr()
  *     try:
  *         with open( stderr_f, "r") as inf:             # <<<<<<<<<<<<<<
@@ -35291,7 +36035,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  *     except UnicodeDecodeError:
  */
         /*with:*/ {
-          __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L78_error;}
+          __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L78_error;}
           __Pyx_GOTREF(__pyx_t_3);
           __Pyx_INCREF(__pyx_v_stderr_f);
           PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_stderr_f);
@@ -35299,14 +36043,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
           __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
           PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__r));
           __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
-          __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L78_error;}
+          __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L78_error;}
           __Pyx_GOTREF(__pyx_t_1);
           __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
-          __pyx_t_15 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L78_error;}
+          __pyx_t_15 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L78_error;}
           __Pyx_GOTREF(__pyx_t_15);
-          __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L86_error;}
+          __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L86_error;}
           __Pyx_GOTREF(__pyx_t_3);
-          __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 = 3454; __pyx_clineno = __LINE__; goto __pyx_L86_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 = 3461; __pyx_clineno = __LINE__; goto __pyx_L86_error;}
           __Pyx_GOTREF(__pyx_t_4);
           __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -35322,16 +36066,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
                 __pyx_v_inf = __pyx_t_4;
                 __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-                /* "pysam/csamtools.pyx":3455
+                /* "pysam/csamtools.pyx":3462
  *     try:
  *         with open( stderr_f, "r") as inf:
  *             out_stderr = inf.readlines()             # <<<<<<<<<<<<<<
  *     except UnicodeDecodeError:
  *         with open( stderr_f, "rb") as inf:
  */
-                __pyx_t_4 = PyObject_GetAttr(__pyx_v_inf, __pyx_n_s__readlines); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3455; __pyx_clineno = __LINE__; goto __pyx_L92_error;}
+                __pyx_t_4 = PyObject_GetAttr(__pyx_v_inf, __pyx_n_s__readlines); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3462; __pyx_clineno = __LINE__; goto __pyx_L92_error;}
                 __Pyx_GOTREF(__pyx_t_4);
-                __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3455; __pyx_clineno = __LINE__; goto __pyx_L92_error;}
+                __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3462; __pyx_clineno = __LINE__; goto __pyx_L92_error;}
                 __Pyx_GOTREF(__pyx_t_1);
                 __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                 __pyx_v_out_stderr = __pyx_t_1;
@@ -35350,7 +36094,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
               __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
               __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-              /* "pysam/csamtools.pyx":3454
+              /* "pysam/csamtools.pyx":3461
  *     pysam_unset_stderr()
  *     try:
  *         with open( stderr_f, "r") as inf:             # <<<<<<<<<<<<<<
@@ -35359,11 +36103,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  */
               /*except:*/ {
                 __Pyx_AddTraceback("pysam.csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
-                if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_4, &__pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L94_except_error;}
+                if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_4, &__pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L94_except_error;}
                 __Pyx_GOTREF(__pyx_t_1);
                 __Pyx_GOTREF(__pyx_t_4);
                 __Pyx_GOTREF(__pyx_t_3);
-                __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L94_except_error;}
+                __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L94_except_error;}
                 __Pyx_GOTREF(__pyx_t_6);
                 __Pyx_INCREF(__pyx_t_1);
                 PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
@@ -35376,11 +36120,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
                 __Pyx_GIVEREF(__pyx_t_3);
                 __pyx_t_19 = PyObject_Call(__pyx_t_15, __pyx_t_6, NULL);
                 __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-                if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L94_except_error;}
+                if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L94_except_error;}
                 __Pyx_GOTREF(__pyx_t_19);
                 __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_19);
                 __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
-                if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L94_except_error;}
+                if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L94_except_error;}
                 __pyx_t_2 = (!__pyx_t_5);
                 if (__pyx_t_2) {
                   __Pyx_GIVEREF(__pyx_t_1);
@@ -35388,7 +36132,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
                   __Pyx_GIVEREF(__pyx_t_3);
                   __Pyx_ErrRestore(__pyx_t_1, __pyx_t_4, __pyx_t_3);
                   __pyx_t_1 = 0; __pyx_t_4 = 0; __pyx_t_3 = 0; 
-                  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L94_except_error;}
+                  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L94_except_error;}
                   goto __pyx_L103;
                 }
                 __pyx_L103:;
@@ -35414,13 +36158,13 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
           }
           /*finally:*/ {
             if (__pyx_t_15) {
-              __pyx_t_18 = PyObject_Call(__pyx_t_15, __pyx_k_tuple_195, NULL);
+              __pyx_t_18 = PyObject_Call(__pyx_t_15, __pyx_k_tuple_194, NULL);
               __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-              if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L78_error;}
+              if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L78_error;}
               __Pyx_GOTREF(__pyx_t_18);
               __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_18);
               __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
-              if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L78_error;}
+              if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L78_error;}
             }
           }
           goto __pyx_L104;
@@ -35432,14 +36176,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       }
       /*else:*/ {
 
-        /* "pysam/csamtools.pyx":3461
+        /* "pysam/csamtools.pyx":3468
  *             out_stderr = inf.read()
  *     else:
  *         out_stderr = []             # <<<<<<<<<<<<<<
  *     finally:
  *         os.remove( stderr_f )
  */
-        __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
+        __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3468; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
         __Pyx_GOTREF(__pyx_t_3);
         __Pyx_XDECREF(__pyx_v_out_stderr);
         __pyx_v_out_stderr = ((PyObject *)__pyx_t_3);
@@ -35458,7 +36202,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
       __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
 
-      /* "pysam/csamtools.pyx":3456
+      /* "pysam/csamtools.pyx":3463
  *         with open( stderr_f, "r") as inf:
  *             out_stderr = inf.readlines()
  *     except UnicodeDecodeError:             # <<<<<<<<<<<<<<
@@ -35468,12 +36212,12 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       __pyx_t_8 = PyErr_ExceptionMatches(__pyx_builtin_UnicodeDecodeError);
       if (__pyx_t_8) {
         __Pyx_AddTraceback("pysam.csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
-        if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3456; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
+        if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3463; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
         __Pyx_GOTREF(__pyx_t_3);
         __Pyx_GOTREF(__pyx_t_4);
         __Pyx_GOTREF(__pyx_t_1);
 
-        /* "pysam/csamtools.pyx":3457
+        /* "pysam/csamtools.pyx":3464
  *             out_stderr = inf.readlines()
  *     except UnicodeDecodeError:
  *         with open( stderr_f, "rb") as inf:             # <<<<<<<<<<<<<<
@@ -35481,7 +36225,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  *             out_stderr = inf.read()
  */
         /*with:*/ {
-          __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
+          __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
           __Pyx_GOTREF(__pyx_t_6);
           __Pyx_INCREF(__pyx_v_stderr_f);
           PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_stderr_f);
@@ -35489,14 +36233,14 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
           __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
           PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_n_s__rb));
           __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rb));
-          __pyx_t_21 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
+          __pyx_t_21 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
           __Pyx_GOTREF(__pyx_t_21);
           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
-          __pyx_t_15 = PyObject_GetAttr(__pyx_t_21, __pyx_n_s____exit__); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
+          __pyx_t_15 = PyObject_GetAttr(__pyx_t_21, __pyx_n_s____exit__); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
           __Pyx_GOTREF(__pyx_t_15);
-          __pyx_t_6 = PyObject_GetAttr(__pyx_t_21, __pyx_n_s____enter__); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L107_error;}
+          __pyx_t_6 = PyObject_GetAttr(__pyx_t_21, __pyx_n_s____enter__); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L107_error;}
           __Pyx_GOTREF(__pyx_t_6);
-          __pyx_t_20 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L107_error;}
+          __pyx_t_20 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L107_error;}
           __Pyx_GOTREF(__pyx_t_20);
           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
           __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
@@ -35512,16 +36256,16 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
                 __pyx_v_inf = __pyx_t_20;
                 __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
 
-                /* "pysam/csamtools.pyx":3459
+                /* "pysam/csamtools.pyx":3466
  *         with open( stderr_f, "rb") as inf:
  *             # read binary output
  *             out_stderr = inf.read()             # <<<<<<<<<<<<<<
  *     else:
  *         out_stderr = []
  */
-                __pyx_t_20 = PyObject_GetAttr(__pyx_v_inf, __pyx_n_s__read); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3459; __pyx_clineno = __LINE__; goto __pyx_L113_error;}
+                __pyx_t_20 = PyObject_GetAttr(__pyx_v_inf, __pyx_n_s__read); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3466; __pyx_clineno = __LINE__; goto __pyx_L113_error;}
                 __Pyx_GOTREF(__pyx_t_20);
-                __pyx_t_21 = PyObject_Call(__pyx_t_20, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3459; __pyx_clineno = __LINE__; goto __pyx_L113_error;}
+                __pyx_t_21 = PyObject_Call(__pyx_t_20, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3466; __pyx_clineno = __LINE__; goto __pyx_L113_error;}
                 __Pyx_GOTREF(__pyx_t_21);
                 __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
                 __Pyx_XDECREF(__pyx_v_out_stderr);
@@ -35538,7 +36282,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
               __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
               __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
 
-              /* "pysam/csamtools.pyx":3457
+              /* "pysam/csamtools.pyx":3464
  *             out_stderr = inf.readlines()
  *     except UnicodeDecodeError:
  *         with open( stderr_f, "rb") as inf:             # <<<<<<<<<<<<<<
@@ -35547,11 +36291,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  */
               /*except:*/ {
                 __Pyx_AddTraceback("pysam.csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
-                if (__Pyx_GetException(&__pyx_t_21, &__pyx_t_20, &__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L115_except_error;}
+                if (__Pyx_GetException(&__pyx_t_21, &__pyx_t_20, &__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L115_except_error;}
                 __Pyx_GOTREF(__pyx_t_21);
                 __Pyx_GOTREF(__pyx_t_20);
                 __Pyx_GOTREF(__pyx_t_6);
-                __pyx_t_22 = PyTuple_New(3); if (unlikely(!__pyx_t_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L115_except_error;}
+                __pyx_t_22 = PyTuple_New(3); if (unlikely(!__pyx_t_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L115_except_error;}
                 __Pyx_GOTREF(__pyx_t_22);
                 __Pyx_INCREF(__pyx_t_21);
                 PyTuple_SET_ITEM(__pyx_t_22, 0, __pyx_t_21);
@@ -35564,11 +36308,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
                 __Pyx_GIVEREF(__pyx_t_6);
                 __pyx_t_19 = PyObject_Call(__pyx_t_15, __pyx_t_22, NULL);
                 __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-                if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L115_except_error;}
+                if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L115_except_error;}
                 __Pyx_GOTREF(__pyx_t_19);
                 __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_19);
                 __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
-                if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L115_except_error;}
+                if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L115_except_error;}
                 __pyx_t_5 = (!__pyx_t_2);
                 if (__pyx_t_5) {
                   __Pyx_GIVEREF(__pyx_t_21);
@@ -35576,7 +36320,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
                   __Pyx_GIVEREF(__pyx_t_6);
                   __Pyx_ErrRestore(__pyx_t_21, __pyx_t_20, __pyx_t_6);
                   __pyx_t_21 = 0; __pyx_t_20 = 0; __pyx_t_6 = 0; 
-                  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L115_except_error;}
+                  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L115_except_error;}
                   goto __pyx_L124;
                 }
                 __pyx_L124:;
@@ -35602,13 +36346,13 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
           }
           /*finally:*/ {
             if (__pyx_t_15) {
-              __pyx_t_16 = PyObject_Call(__pyx_t_15, __pyx_k_tuple_196, NULL);
+              __pyx_t_16 = PyObject_Call(__pyx_t_15, __pyx_k_tuple_195, NULL);
               __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-              if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
+              if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
               __Pyx_GOTREF(__pyx_t_16);
               __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_16);
               __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
-              if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
+              if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L80_except_error;}
             }
           }
           goto __pyx_L125;
@@ -35637,7 +36381,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
     }
   }
 
-  /* "pysam/csamtools.pyx":3463
+  /* "pysam/csamtools.pyx":3470
  *         out_stderr = []
  *     finally:
  *         os.remove( stderr_f )             # <<<<<<<<<<<<<<
@@ -35664,17 +36408,17 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
       goto __pyx_L77;
     }
     __pyx_L77:;
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3463; __pyx_clineno = __LINE__; goto __pyx_L126_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3470; __pyx_clineno = __LINE__; goto __pyx_L126_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__remove); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3463; __pyx_clineno = __LINE__; goto __pyx_L126_error;}
+    __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__remove); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3470; __pyx_clineno = __LINE__; goto __pyx_L126_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __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 = 3463; __pyx_clineno = __LINE__; goto __pyx_L126_error;}
+    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3470; __pyx_clineno = __LINE__; goto __pyx_L126_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_INCREF(__pyx_v_stderr_f);
     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_stderr_f);
     __Pyx_GIVEREF(__pyx_v_stderr_f);
-    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3463; __pyx_clineno = __LINE__; goto __pyx_L126_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3470; __pyx_clineno = __LINE__; goto __pyx_L126_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
@@ -35700,7 +36444,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
     }
   }
 
-  /* "pysam/csamtools.pyx":3465
+  /* "pysam/csamtools.pyx":3472
  *         os.remove( stderr_f )
  * 
  *     return retval, out_stderr, out_stdout             # <<<<<<<<<<<<<<
@@ -35708,11 +36452,11 @@ static PyObject *__pyx_pf_5pysam_9csamtools__samtools_dispatch(CYTHON_UNUSED PyO
  * cdef class SNPCall:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_3 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  if (unlikely(!__pyx_v_out_stderr)) { __Pyx_RaiseUnboundLocalError("out_stderr"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3465; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
-  if (unlikely(!__pyx_v_out_stdout)) { __Pyx_RaiseUnboundLocalError("out_stdout"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3465; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
-  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__pyx_v_out_stderr)) { __Pyx_RaiseUnboundLocalError("out_stderr"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3472; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+  if (unlikely(!__pyx_v_out_stdout)) { __Pyx_RaiseUnboundLocalError("out_stdout"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3472; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
   __Pyx_GIVEREF(__pyx_t_3);
@@ -35769,7 +36513,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7SNPCall_3tid_1__get__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3480
+/* "pysam/csamtools.pyx":3487
  *     property tid:
  *         '''the chromosome ID as is defined in the header'''
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -35786,9 +36530,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall_3tid___get__(struct __pyx_o
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3480);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3487);
 
-  /* "pysam/csamtools.pyx":3481
+  /* "pysam/csamtools.pyx":3488
  *         '''the chromosome ID as is defined in the header'''
  *         def __get__(self):
  *             return self._tid             # <<<<<<<<<<<<<<
@@ -35796,7 +36540,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall_3tid___get__(struct __pyx_o
  *     property pos:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -35826,7 +36570,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7SNPCall_3pos_1__get__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3485
+/* "pysam/csamtools.pyx":3492
  *     property pos:
  *        '''nucleotide position of SNP.'''
  *        def __get__(self): return self._pos             # <<<<<<<<<<<<<<
@@ -35843,9 +36587,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall_3pos___get__(struct __pyx_o
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3485);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3492);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -35875,7 +36619,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7SNPCall_14reference_base_1__get__(P
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3489
+/* "pysam/csamtools.pyx":3496
  *     property reference_base:
  *        '''reference base at pos. ``N`` if no reference sequence supplied.'''
  *        def __get__(self): return from_string_and_size( &self._reference_base, 1 )             # <<<<<<<<<<<<<<
@@ -35892,9 +36636,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall_14reference_base___get__(st
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3489);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3496);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __pyx_f_5pysam_9csamtools_from_string_and_size((&__pyx_v_self->_reference_base), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __pyx_f_5pysam_9csamtools_from_string_and_size((&__pyx_v_self->_reference_base), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -35924,7 +36668,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7SNPCall_8genotype_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3493
+/* "pysam/csamtools.pyx":3500
  *     property genotype:
  *        '''the genotype called.'''
  *        def __get__(self): return from_string_and_size( &self._genotype, 1 )             # <<<<<<<<<<<<<<
@@ -35941,9 +36685,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall_8genotype___get__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3493);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3500);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __pyx_f_5pysam_9csamtools_from_string_and_size((&__pyx_v_self->_genotype), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __pyx_f_5pysam_9csamtools_from_string_and_size((&__pyx_v_self->_genotype), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -35973,7 +36717,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7SNPCall_17consensus_quality_1__get_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3497
+/* "pysam/csamtools.pyx":3504
  *     property consensus_quality:
  *        '''the genotype quality (Phred-scaled).'''
  *        def __get__(self): return self._consensus_quality             # <<<<<<<<<<<<<<
@@ -35990,9 +36734,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall_17consensus_quality___get__
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3497);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3504);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_consensus_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_consensus_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -36022,7 +36766,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7SNPCall_11snp_quality_1__get__(PyOb
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3501
+/* "pysam/csamtools.pyx":3508
  *     property snp_quality:
  *        '''the snp quality (Phred scaled) - probability of consensus being identical to reference sequence.'''
  *        def __get__(self): return self._snp_quality             # <<<<<<<<<<<<<<
@@ -36039,9 +36783,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall_11snp_quality___get__(struc
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3501);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3508);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_snp_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_snp_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -36071,7 +36815,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7SNPCall_15mapping_quality_1__get__(
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3505
+/* "pysam/csamtools.pyx":3512
  *     property mapping_quality:
  *        '''the root mean square (rms) of the mapping quality of all reads involved in the call.'''
  *        def __get__(self): return self._rms_mapping_quality             # <<<<<<<<<<<<<<
@@ -36088,9 +36832,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall_15mapping_quality___get__(s
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3505);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3512);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_rms_mapping_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_rms_mapping_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -36120,7 +36864,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7SNPCall_8coverage_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3509
+/* "pysam/csamtools.pyx":3516
  *     property coverage:
  *        '''coverage or read depth - the number of reads involved in the call.'''
  *        def __get__(self): return self._coverage             # <<<<<<<<<<<<<<
@@ -36137,9 +36881,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall_8coverage___get__(struct __
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
-  __Pyx_TraceCall("__get__", __pyx_f[0], 3509);
+  __Pyx_TraceCall("__get__", __pyx_f[0], 3516);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_coverage); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_coverage); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -36169,7 +36913,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_7SNPCall_1__str__(PyObject *__pyx_v_
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":3511
+/* "pysam/csamtools.pyx":3518
  *        def __get__(self): return self._coverage
  * 
  *     def __str__(self):             # <<<<<<<<<<<<<<
@@ -36195,9 +36939,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall___str__(struct __pyx_obj_5p
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__str__", 0);
-  __Pyx_TraceCall("__str__", __pyx_f[0], 3511);
+  __Pyx_TraceCall("__str__", __pyx_f[0], 3518);
 
-  /* "pysam/csamtools.pyx":3513
+  /* "pysam/csamtools.pyx":3520
  *     def __str__(self):
  * 
  *         return "\t".join( map(str, (             # <<<<<<<<<<<<<<
@@ -36205,89 +36949,89 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall___str__(struct __pyx_obj_5p
  *                     self.pos,
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_5), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
 
-  /* "pysam/csamtools.pyx":3514
+  /* "pysam/csamtools.pyx":3521
  * 
  *         return "\t".join( map(str, (
  *                     self.tid,             # <<<<<<<<<<<<<<
  *                     self.pos,
  *                     self.reference_base,
  */
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
 
-  /* "pysam/csamtools.pyx":3515
+  /* "pysam/csamtools.pyx":3522
  *         return "\t".join( map(str, (
  *                     self.tid,
  *                     self.pos,             # <<<<<<<<<<<<<<
  *                     self.reference_base,
  *                     self.genotype,
  */
-  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3522; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
 
-  /* "pysam/csamtools.pyx":3516
+  /* "pysam/csamtools.pyx":3523
  *                     self.tid,
  *                     self.pos,
  *                     self.reference_base,             # <<<<<<<<<<<<<<
  *                     self.genotype,
  *                     self.consensus_quality,
  */
-  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reference_base); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reference_base); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
 
-  /* "pysam/csamtools.pyx":3517
+  /* "pysam/csamtools.pyx":3524
  *                     self.pos,
  *                     self.reference_base,
  *                     self.genotype,             # <<<<<<<<<<<<<<
  *                     self.consensus_quality,
  *                     self.snp_quality,
  */
-  __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__genotype); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__genotype); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
 
-  /* "pysam/csamtools.pyx":3518
+  /* "pysam/csamtools.pyx":3525
  *                     self.reference_base,
  *                     self.genotype,
  *                     self.consensus_quality,             # <<<<<<<<<<<<<<
  *                     self.snp_quality,
  *                     self.mapping_quality,
  */
-  __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__consensus_quality); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__consensus_quality); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_6);
 
-  /* "pysam/csamtools.pyx":3519
+  /* "pysam/csamtools.pyx":3526
  *                     self.genotype,
  *                     self.consensus_quality,
  *                     self.snp_quality,             # <<<<<<<<<<<<<<
  *                     self.mapping_quality,
  *                     self.coverage ) ) )
  */
-  __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__snp_quality); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3519; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__snp_quality); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_7);
 
-  /* "pysam/csamtools.pyx":3520
+  /* "pysam/csamtools.pyx":3527
  *                     self.consensus_quality,
  *                     self.snp_quality,
  *                     self.mapping_quality,             # <<<<<<<<<<<<<<
  *                     self.coverage ) ) )
  * 
  */
-  __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__mapping_quality); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__mapping_quality); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
 
-  /* "pysam/csamtools.pyx":3521
+  /* "pysam/csamtools.pyx":3528
  *                     self.snp_quality,
  *                     self.mapping_quality,
  *                     self.coverage ) ) )             # <<<<<<<<<<<<<<
  * 
  * 
  */
-  __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__coverage); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__coverage); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_9);
-  __pyx_t_10 = PyTuple_New(8); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_10 = PyTuple_New(8); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_10);
   PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2);
   __Pyx_GIVEREF(__pyx_t_2);
@@ -36313,7 +37057,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall___str__(struct __pyx_obj_5p
   __pyx_t_7 = 0;
   __pyx_t_8 = 0;
   __pyx_t_9 = 0;
-  __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_9);
   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
   PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
@@ -36321,15 +37065,15 @@ static PyObject *__pyx_pf_5pysam_9csamtools_7SNPCall___str__(struct __pyx_obj_5p
   PyTuple_SET_ITEM(__pyx_t_9, 1, ((PyObject *)__pyx_t_10));
   __Pyx_GIVEREF(((PyObject *)__pyx_t_10));
   __pyx_t_10 = 0;
-  __pyx_t_10 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_10 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_10);
   __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
-  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_9);
   PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10);
   __Pyx_GIVEREF(__pyx_t_10);
   __pyx_t_10 = 0;
-  __pyx_t_10 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_10 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_10);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
@@ -36391,7 +37135,7 @@ static int __pyx_pw_5pysam_9csamtools_12IndexedReads_1__init__(PyObject *__pyx_v
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4031; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4038; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -36403,10 +37147,10 @@ static int __pyx_pw_5pysam_9csamtools_12IndexedReads_1__init__(PyObject *__pyx_v
     }
     __pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)values[0]);
     if (values[1]) {
-      __pyx_v_reopen = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4031; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_reopen = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4038; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
 
-      /* "pysam/csamtools.pyx":4031
+      /* "pysam/csamtools.pyx":4038
  *     """
  * 
  *     def __init__(self, Samfile samfile, int reopen = True ):             # <<<<<<<<<<<<<<
@@ -36418,13 +37162,13 @@ static int __pyx_pw_5pysam_9csamtools_12IndexedReads_1__init__(PyObject *__pyx_v
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4031; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4038; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.csamtools.IndexedReads.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_9csamtools_12IndexedReads___init__(((struct __pyx_obj_5pysam_9csamtools_IndexedReads *)__pyx_v_self), __pyx_v_samfile, __pyx_v_reopen);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -36441,16 +37185,17 @@ static int __pyx_pf_5pysam_9csamtools_12IndexedReads___init__(struct __pyx_obj_5
   __Pyx_RefNannyDeclarations
   PyObject *__pyx_t_1 = NULL;
   PyObject *__pyx_t_2 = NULL;
-  char *__pyx_t_3;
-  samfile_t *__pyx_t_4;
+  const char* __pyx_t_3;
+  char *__pyx_t_4;
+  samfile_t *__pyx_t_5;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__init__", 0);
-  __Pyx_TraceCall("__init__", __pyx_f[0], 4031);
+  __Pyx_TraceCall("__init__", __pyx_f[0], 4038);
 
-  /* "pysam/csamtools.pyx":4032
+  /* "pysam/csamtools.pyx":4039
  * 
  *     def __init__(self, Samfile samfile, int reopen = True ):
  *         self.samfile = samfile             # <<<<<<<<<<<<<<
@@ -36463,7 +37208,7 @@ static int __pyx_pf_5pysam_9csamtools_12IndexedReads___init__(struct __pyx_obj_5
   __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
   __pyx_v_self->samfile = __pyx_v_samfile;
 
-  /* "pysam/csamtools.pyx":4034
+  /* "pysam/csamtools.pyx":4041
  *         self.samfile = samfile
  * 
  *         if samfile.isbam: mode = b"rb"             # <<<<<<<<<<<<<<
@@ -36477,7 +37222,7 @@ static int __pyx_pf_5pysam_9csamtools_12IndexedReads___init__(struct __pyx_obj_5
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":4035
+    /* "pysam/csamtools.pyx":4042
  * 
  *         if samfile.isbam: mode = b"rb"
  *         else: mode = b"r"             # <<<<<<<<<<<<<<
@@ -36489,7 +37234,7 @@ static int __pyx_pf_5pysam_9csamtools_12IndexedReads___init__(struct __pyx_obj_5
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":4039
+  /* "pysam/csamtools.pyx":4046
  *         # reopen the file - note that this makes the iterator
  *         # slow and causes pileup to slow down significantly.
  *         if reopen:             # <<<<<<<<<<<<<<
@@ -36498,46 +37243,47 @@ static int __pyx_pf_5pysam_9csamtools_12IndexedReads___init__(struct __pyx_obj_5
  */
   if (__pyx_v_reopen) {
 
-    /* "pysam/csamtools.pyx":4040
+    /* "pysam/csamtools.pyx":4047
  *         # slow and causes pileup to slow down significantly.
  *         if reopen:
  *             store = StderrStore()             # <<<<<<<<<<<<<<
  *             self.fp = samopen( samfile._filename, mode, NULL )
  *             store.release()
  */
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __pyx_v_store = __pyx_t_2;
     __pyx_t_2 = 0;
 
-    /* "pysam/csamtools.pyx":4041
+    /* "pysam/csamtools.pyx":4048
  *         if reopen:
  *             store = StderrStore()
  *             self.fp = samopen( samfile._filename, mode, NULL )             # <<<<<<<<<<<<<<
  *             store.release()
  *             assert self.fp != NULL
  */
-    __pyx_t_3 = PyBytes_AsString(((PyObject *)__pyx_v_mode)); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_v_self->fp = samopen(__pyx_v_samfile->_filename, __pyx_t_3, NULL);
+    __pyx_t_3 = PyBytes_AsString(__pyx_v_samfile->_filename); if (unlikely((__pyx_t_3 == (const char*)NULL) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyBytes_AsString(((PyObject *)__pyx_v_mode)); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_v_self->fp = samopen(__pyx_t_3, __pyx_t_4, NULL);
 
-    /* "pysam/csamtools.pyx":4042
+    /* "pysam/csamtools.pyx":4049
  *             store = StderrStore()
  *             self.fp = samopen( samfile._filename, mode, NULL )
  *             store.release()             # <<<<<<<<<<<<<<
  *             assert self.fp != NULL
  *             self.owns_samfile = True
  */
-    __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-    /* "pysam/csamtools.pyx":4043
+    /* "pysam/csamtools.pyx":4050
  *             self.fp = samopen( samfile._filename, mode, NULL )
  *             store.release()
  *             assert self.fp != NULL             # <<<<<<<<<<<<<<
@@ -36547,11 +37293,11 @@ static int __pyx_pf_5pysam_9csamtools_12IndexedReads___init__(struct __pyx_obj_5
     #ifndef CYTHON_WITHOUT_ASSERTIONS
     if (unlikely(!(__pyx_v_self->fp != NULL))) {
       PyErr_SetNone(PyExc_AssertionError);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     #endif
 
-    /* "pysam/csamtools.pyx":4044
+    /* "pysam/csamtools.pyx":4051
  *             store.release()
  *             assert self.fp != NULL
  *             self.owns_samfile = True             # <<<<<<<<<<<<<<
@@ -36563,17 +37309,17 @@ static int __pyx_pf_5pysam_9csamtools_12IndexedReads___init__(struct __pyx_obj_5
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":4046
+    /* "pysam/csamtools.pyx":4053
  *             self.owns_samfile = True
  *         else:
  *             self.fp = samfile.samfile             # <<<<<<<<<<<<<<
  *             self.owns_samfile = False
  * 
  */
-    __pyx_t_4 = __pyx_v_samfile->samfile;
-    __pyx_v_self->fp = __pyx_t_4;
+    __pyx_t_5 = __pyx_v_samfile->samfile;
+    __pyx_v_self->fp = __pyx_t_5;
 
-    /* "pysam/csamtools.pyx":4047
+    /* "pysam/csamtools.pyx":4054
  *         else:
  *             self.fp = samfile.samfile
  *             self.owns_samfile = False             # <<<<<<<<<<<<<<
@@ -36584,7 +37330,7 @@ static int __pyx_pf_5pysam_9csamtools_12IndexedReads___init__(struct __pyx_obj_5
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":4049
+  /* "pysam/csamtools.pyx":4056
  *             self.owns_samfile = False
  * 
  *         assert samfile.isbam, "can only IndexReads on bam files"             # <<<<<<<<<<<<<<
@@ -36593,8 +37339,8 @@ static int __pyx_pf_5pysam_9csamtools_12IndexedReads___init__(struct __pyx_obj_5
  */
   #ifndef CYTHON_WITHOUT_ASSERTIONS
   if (unlikely(!__pyx_v_samfile->isbam)) {
-    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_197));
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_196));
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #endif
 
@@ -36625,7 +37371,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_12IndexedReads_3build(PyObject *__py
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":4051
+/* "pysam/csamtools.pyx":4058
  *         assert samfile.isbam, "can only IndexReads on bam files"
  * 
  *     def build( self ):             # <<<<<<<<<<<<<<
@@ -36649,26 +37395,26 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_2build(struct __pyx_o
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("build", 0);
-  __Pyx_TraceCall("build", __pyx_f[0], 4051);
+  __Pyx_TraceCall("build", __pyx_f[0], 4058);
 
-  /* "pysam/csamtools.pyx":4054
+  /* "pysam/csamtools.pyx":4061
  *         '''build index.'''
  * 
  *         self.index = collections.defaultdict( list )             # <<<<<<<<<<<<<<
  * 
  *         # this method will start indexing from the current file position
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__collections); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__collections); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__defaultdict); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__defaultdict); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4061; __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 = 4054; __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 = 4061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyList_Type))));
   PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)((PyObject*)(&PyList_Type))));
   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyList_Type))));
-  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
@@ -36678,7 +37424,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_2build(struct __pyx_o
   __pyx_v_self->index = __pyx_t_3;
   __pyx_t_3 = 0;
 
-  /* "pysam/csamtools.pyx":4058
+  /* "pysam/csamtools.pyx":4065
  *         # this method will start indexing from the current file position
  *         # if you decide
  *         cdef int ret = 1             # <<<<<<<<<<<<<<
@@ -36687,7 +37433,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_2build(struct __pyx_o
  */
   __pyx_v_ret = 1;
 
-  /* "pysam/csamtools.pyx":4059
+  /* "pysam/csamtools.pyx":4066
  *         # if you decide
  *         cdef int ret = 1
  *         cdef bam1_t * b = <bam1_t*> calloc(1, sizeof( bam1_t) )             # <<<<<<<<<<<<<<
@@ -36696,7 +37442,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_2build(struct __pyx_o
  */
   __pyx_v_b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
 
-  /* "pysam/csamtools.pyx":4063
+  /* "pysam/csamtools.pyx":4070
  *         cdef uint64_t pos
  * 
  *         while ret > 0:             # <<<<<<<<<<<<<<
@@ -36707,7 +37453,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_2build(struct __pyx_o
     __pyx_t_4 = (__pyx_v_ret > 0);
     if (!__pyx_t_4) break;
 
-    /* "pysam/csamtools.pyx":4064
+    /* "pysam/csamtools.pyx":4071
  * 
  *         while ret > 0:
  *             pos = bam_tell( self.fp.x.bam )             # <<<<<<<<<<<<<<
@@ -36716,7 +37462,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_2build(struct __pyx_o
  */
     __pyx_v_pos = bam_tell(__pyx_v_self->fp->x.bam);
 
-    /* "pysam/csamtools.pyx":4065
+    /* "pysam/csamtools.pyx":4072
  *         while ret > 0:
  *             pos = bam_tell( self.fp.x.bam )
  *             ret = samread( self.fp, b)             # <<<<<<<<<<<<<<
@@ -36725,7 +37471,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_2build(struct __pyx_o
  */
     __pyx_v_ret = samread(__pyx_v_self->fp, __pyx_v_b);
 
-    /* "pysam/csamtools.pyx":4066
+    /* "pysam/csamtools.pyx":4073
  *             pos = bam_tell( self.fp.x.bam )
  *             ret = samread( self.fp, b)
  *             if ret > 0:             # <<<<<<<<<<<<<<
@@ -36735,31 +37481,31 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_2build(struct __pyx_o
     __pyx_t_4 = (__pyx_v_ret > 0);
     if (__pyx_t_4) {
 
-      /* "pysam/csamtools.pyx":4067
+      /* "pysam/csamtools.pyx":4074
  *             ret = samread( self.fp, b)
  *             if ret > 0:
  *                 qname = _charptr_to_str(bam1_qname( b ))             # <<<<<<<<<<<<<<
  *                 self.index[qname].append( pos )
  * 
  */
-      __pyx_t_3 = __pyx_f_5pysam_9csamtools__charptr_to_str(bam1_qname(__pyx_v_b)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4067; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __pyx_f_5pysam_9csamtools__charptr_to_str(bam1_qname(__pyx_v_b)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_XDECREF(__pyx_v_qname);
       __pyx_v_qname = __pyx_t_3;
       __pyx_t_3 = 0;
 
-      /* "pysam/csamtools.pyx":4068
+      /* "pysam/csamtools.pyx":4075
  *             if ret > 0:
  *                 qname = _charptr_to_str(bam1_qname( b ))
  *                 self.index[qname].append( pos )             # <<<<<<<<<<<<<<
  * 
  *         bam_destroy1( b )
  */
-      __pyx_t_3 = PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
-      __pyx_t_1 = __Pyx_PyInt_to_py_uint64_t(__pyx_v_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_PyInt_to_py_uint64_t(__pyx_v_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_2 = __Pyx_PyObject_Append(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_Append(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -36769,7 +37515,7 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_2build(struct __pyx_o
     __pyx_L5:;
   }
 
-  /* "pysam/csamtools.pyx":4070
+  /* "pysam/csamtools.pyx":4077
  *                 self.index[qname].append( pos )
  * 
  *         bam_destroy1( b )             # <<<<<<<<<<<<<<
@@ -36806,7 +37552,7 @@ static PyObject *__pyx_pw_5pysam_9csamtools_12IndexedReads_5find(PyObject *__pyx
   return __pyx_r;
 }
 
-/* "pysam/csamtools.pyx":4072
+/* "pysam/csamtools.pyx":4079
  *         bam_destroy1( b )
  * 
  *     def find( self, qname ):             # <<<<<<<<<<<<<<
@@ -36826,19 +37572,19 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_4find(struct __pyx_ob
   int __pyx_clineno = 0;
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("find", 0);
-  __Pyx_TraceCall("find", __pyx_f[0], 4072);
+  __Pyx_TraceCall("find", __pyx_f[0], 4079);
 
-  /* "pysam/csamtools.pyx":4073
+  /* "pysam/csamtools.pyx":4080
  * 
  *     def find( self, qname ):
  *         if qname in self.index:             # <<<<<<<<<<<<<<
  *             return IteratorRowSelection( self.samfile, self.index[qname], reopen = False )
  *         else:
  */
-  __pyx_t_1 = (__Pyx_PySequence_Contains(__pyx_v_qname, __pyx_v_self->index, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = (__Pyx_PySequence_Contains(__pyx_v_qname, __pyx_v_self->index, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
 
-    /* "pysam/csamtools.pyx":4074
+    /* "pysam/csamtools.pyx":4081
  *     def find( self, qname ):
  *         if qname in self.index:
  *             return IteratorRowSelection( self.samfile, self.index[qname], reopen = False )             # <<<<<<<<<<<<<<
@@ -36846,9 +37592,9 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_4find(struct __pyx_ob
  *             raise KeyError( "read %s not found" % qname )
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4081; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4081; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
     PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->samfile));
@@ -36856,13 +37602,13 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_4find(struct __pyx_ob
     PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
     __Pyx_GIVEREF(__pyx_t_2);
     __pyx_t_2 = 0;
-    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4081; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-    __pyx_t_4 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4081; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
-    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reopen), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reopen), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4081; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowSelection)), ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_9csamtools_IteratorRowSelection)), ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4081; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
@@ -36873,26 +37619,26 @@ static PyObject *__pyx_pf_5pysam_9csamtools_12IndexedReads_4find(struct __pyx_ob
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":4076
+    /* "pysam/csamtools.pyx":4083
  *             return IteratorRowSelection( self.samfile, self.index[qname], reopen = False )
  *         else:
  *             raise KeyError( "read %s not found" % qname )             # <<<<<<<<<<<<<<
  * 
  *     def __dealloc__(self):
  */
-    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_198), __pyx_v_qname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_197), __pyx_v_qname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
-    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_4));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
     __pyx_t_4 = 0;
-    __pyx_t_4 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
     __Pyx_Raise(__pyx_t_4, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L3:;
 
@@ -36920,7 +37666,7 @@ static void __pyx_pw_5pysam_9csamtools_12IndexedReads_7__dealloc__(PyObject *__p
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/csamtools.pyx":4078
+/* "pysam/csamtools.pyx":4085
  *             raise KeyError( "read %s not found" % qname )
  * 
  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
@@ -36932,9 +37678,9 @@ static void __pyx_pf_5pysam_9csamtools_12IndexedReads_6__dealloc__(struct __pyx_
   __Pyx_RefNannyDeclarations
   __Pyx_TraceDeclarations
   __Pyx_RefNannySetupContext("__dealloc__", 0);
-  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 4078);
+  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 4085);
 
-  /* "pysam/csamtools.pyx":4079
+  /* "pysam/csamtools.pyx":4086
  * 
  *     def __dealloc__(self):
  *         if self.owns_samfile: samclose( self.fp )             # <<<<<<<<<<<<<<
@@ -36958,6 +37704,10 @@ static PyObject *__pyx_tp_new_5pysam_9csamtools_Fastafile(PyTypeObject *t, PyObj
   if (!o) return 0;
   p = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)o);
   p->__pyx_vtab = __pyx_vtabptr_5pysam_9csamtools_Fastafile;
+  p->_filename = Py_None; Py_INCREF(Py_None);
+  p->_references = Py_None; Py_INCREF(Py_None);
+  p->_lengths = Py_None; Py_INCREF(Py_None);
+  p->reference2length = Py_None; Py_INCREF(Py_None);
   if (__pyx_pw_5pysam_9csamtools_9Fastafile_1__cinit__(o, a, k) < 0) {
     Py_DECREF(o); o = 0;
   }
@@ -36965,6 +37715,8 @@ static PyObject *__pyx_tp_new_5pysam_9csamtools_Fastafile(PyTypeObject *t, PyObj
 }
 
 static void __pyx_tp_dealloc_5pysam_9csamtools_Fastafile(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools_Fastafile *p = (struct __pyx_obj_5pysam_9csamtools_Fastafile *)o;
+  PyObject_GC_UnTrack(o);
   {
     PyObject *etype, *eval, *etb;
     PyErr_Fetch(&etype, &eval, &etb);
@@ -36974,23 +37726,87 @@ static void __pyx_tp_dealloc_5pysam_9csamtools_Fastafile(PyObject *o) {
     --Py_REFCNT(o);
     PyErr_Restore(etype, eval, etb);
   }
+  Py_CLEAR(p->_filename);
+  Py_CLEAR(p->_references);
+  Py_CLEAR(p->_lengths);
+  Py_CLEAR(p->reference2length);
+  PyObject_GC_Track(o);
   (*Py_TYPE(o)->tp_free)(o);
 }
 
+static int __pyx_tp_traverse_5pysam_9csamtools_Fastafile(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_5pysam_9csamtools_Fastafile *p = (struct __pyx_obj_5pysam_9csamtools_Fastafile *)o;
+  if (p->_filename) {
+    e = (*v)(p->_filename, a); if (e) return e;
+  }
+  if (p->_references) {
+    e = (*v)(p->_references, a); if (e) return e;
+  }
+  if (p->_lengths) {
+    e = (*v)(p->_lengths, a); if (e) return e;
+  }
+  if (p->reference2length) {
+    e = (*v)(p->reference2length, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_5pysam_9csamtools_Fastafile(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools_Fastafile *p = (struct __pyx_obj_5pysam_9csamtools_Fastafile *)o;
+  PyObject* tmp;
+  tmp = ((PyObject*)p->_filename);
+  p->_filename = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->_references);
+  p->_references = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->_lengths);
+  p->_lengths = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->reference2length);
+  p->reference2length = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+static PyObject *__pyx_sq_item_5pysam_9csamtools_Fastafile(PyObject *o, Py_ssize_t i) {
+  PyObject *r;
+  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
+  r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);
+  Py_DECREF(x);
+  return r;
+}
+
 static PyObject *__pyx_getprop_5pysam_9csamtools_9Fastafile_filename(PyObject *o, CYTHON_UNUSED void *x) {
   return __pyx_pw_5pysam_9csamtools_9Fastafile_8filename_1__get__(o);
 }
 
+static PyObject *__pyx_getprop_5pysam_9csamtools_9Fastafile_references(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_5pysam_9csamtools_9Fastafile_10references_1__get__(o);
+}
+
+static PyObject *__pyx_getprop_5pysam_9csamtools_9Fastafile_nreferences(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_5pysam_9csamtools_9Fastafile_11nreferences_1__get__(o);
+}
+
+static PyObject *__pyx_getprop_5pysam_9csamtools_9Fastafile_lengths(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_5pysam_9csamtools_9Fastafile_7lengths_1__get__(o);
+}
+
 static PyMethodDef __pyx_methods_5pysam_9csamtools_Fastafile[] = {
   {__Pyx_NAMESTR("_isOpen"), (PyCFunction)__pyx_pw_5pysam_9csamtools_9Fastafile_3_isOpen, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_9csamtools_9Fastafile_2_isOpen)},
   {__Pyx_NAMESTR("_open"), (PyCFunction)__pyx_pw_5pysam_9csamtools_9Fastafile_7_open, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_9csamtools_9Fastafile_6_open)},
   {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pw_5pysam_9csamtools_9Fastafile_9close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_9csamtools_9Fastafile_8close)},
   {__Pyx_NAMESTR("fetch"), (PyCFunction)__pyx_pw_5pysam_9csamtools_9Fastafile_13fetch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_9csamtools_9Fastafile_12fetch)},
+  {__Pyx_NAMESTR("getReferenceLength"), (PyCFunction)__pyx_pw_5pysam_9csamtools_9Fastafile_15getReferenceLength, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_9csamtools_9Fastafile_14getReferenceLength)},
   {0, 0, 0, 0}
 };
 
 static struct PyGetSetDef __pyx_getsets_5pysam_9csamtools_Fastafile[] = {
-  {(char *)"filename", __pyx_getprop_5pysam_9csamtools_9Fastafile_filename, 0, __Pyx_DOCSTR(__pyx_k_199), 0},
+  {(char *)"filename", __pyx_getprop_5pysam_9csamtools_9Fastafile_filename, 0, __Pyx_DOCSTR(__pyx_k_198), 0},
+  {(char *)"references", __pyx_getprop_5pysam_9csamtools_9Fastafile_references, 0, __Pyx_DOCSTR(__pyx_k_199), 0},
+  {(char *)"nreferences", __pyx_getprop_5pysam_9csamtools_9Fastafile_nreferences, 0, __Pyx_DOCSTR(__pyx_k_200), 0},
+  {(char *)"lengths", __pyx_getprop_5pysam_9csamtools_9Fastafile_lengths, 0, __Pyx_DOCSTR(__pyx_k_201), 0},
   {0, 0, 0, 0, 0}
 };
 
@@ -37056,18 +37872,18 @@ static PySequenceMethods __pyx_tp_as_sequence_Fastafile = {
   __pyx_pw_5pysam_9csamtools_9Fastafile_5__len__, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
-  0, /*sq_item*/
+  __pyx_sq_item_5pysam_9csamtools_Fastafile, /*sq_item*/
   0, /*sq_slice*/
   0, /*sq_ass_item*/
   0, /*sq_ass_slice*/
-  0, /*sq_contains*/
+  __pyx_pw_5pysam_9csamtools_9Fastafile_19__contains__, /*sq_contains*/
   0, /*sq_inplace_concat*/
   0, /*sq_inplace_repeat*/
 };
 
 static PyMappingMethods __pyx_tp_as_mapping_Fastafile = {
   __pyx_pw_5pysam_9csamtools_9Fastafile_5__len__, /*mp_length*/
-  0, /*mp_subscript*/
+  __pyx_pw_5pysam_9csamtools_9Fastafile_17__getitem__, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
@@ -37116,10 +37932,10 @@ static PyTypeObject __pyx_type_5pysam_9csamtools_Fastafile = {
   0, /*tp_getattro*/
   0, /*tp_setattro*/
   &__pyx_tp_as_buffer_Fastafile, /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
   __Pyx_DOCSTR("*(filename)*\n\n    A *FASTA* file. The file is automatically opened.\n\n    The file expects an indexed fasta file.\n\n    TODO:\n        add automatic indexing.\n        add function to get sequence names.\n    "), /*tp_doc*/
-  0, /*tp_traverse*/
-  0, /*tp_clear*/
+  __pyx_tp_traverse_5pysam_9csamtools_Fastafile, /*tp_traverse*/
+  __pyx_tp_clear_5pysam_9csamtools_Fastafile, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
   0, /*tp_iter*/
@@ -37347,6 +38163,7 @@ static PyObject *__pyx_tp_new_5pysam_9csamtools_Fastqfile(PyTypeObject *t, PyObj
   if (!o) return 0;
   p = ((struct __pyx_obj_5pysam_9csamtools_Fastqfile *)o);
   p->__pyx_vtab = __pyx_vtabptr_5pysam_9csamtools_Fastqfile;
+  p->_filename = Py_None; Py_INCREF(Py_None);
   if (__pyx_pw_5pysam_9csamtools_9Fastqfile_1__cinit__(o, a, k) < 0) {
     Py_DECREF(o); o = 0;
   }
@@ -37354,6 +38171,8 @@ static PyObject *__pyx_tp_new_5pysam_9csamtools_Fastqfile(PyTypeObject *t, PyObj
 }
 
 static void __pyx_tp_dealloc_5pysam_9csamtools_Fastqfile(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools_Fastqfile *p = (struct __pyx_obj_5pysam_9csamtools_Fastqfile *)o;
+  PyObject_GC_UnTrack(o);
   {
     PyObject *etype, *eval, *etb;
     PyErr_Fetch(&etype, &eval, &etb);
@@ -37363,9 +38182,29 @@ static void __pyx_tp_dealloc_5pysam_9csamtools_Fastqfile(PyObject *o) {
     --Py_REFCNT(o);
     PyErr_Restore(etype, eval, etb);
   }
+  Py_CLEAR(p->_filename);
+  PyObject_GC_Track(o);
   (*Py_TYPE(o)->tp_free)(o);
 }
 
+static int __pyx_tp_traverse_5pysam_9csamtools_Fastqfile(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_5pysam_9csamtools_Fastqfile *p = (struct __pyx_obj_5pysam_9csamtools_Fastqfile *)o;
+  if (p->_filename) {
+    e = (*v)(p->_filename, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_5pysam_9csamtools_Fastqfile(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools_Fastqfile *p = (struct __pyx_obj_5pysam_9csamtools_Fastqfile *)o;
+  PyObject* tmp;
+  tmp = ((PyObject*)p->_filename);
+  p->_filename = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
 static PyObject *__pyx_getprop_5pysam_9csamtools_9Fastqfile_filename(PyObject *o, CYTHON_UNUSED void *x) {
   return __pyx_pw_5pysam_9csamtools_9Fastqfile_8filename_1__get__(o);
 }
@@ -37375,12 +38214,11 @@ static PyMethodDef __pyx_methods_5pysam_9csamtools_Fastqfile[] = {
   {__Pyx_NAMESTR("_open"), (PyCFunction)__pyx_pw_5pysam_9csamtools_9Fastqfile_5_open, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_9csamtools_9Fastqfile_4_open)},
   {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pw_5pysam_9csamtools_9Fastqfile_7close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_9csamtools_9Fastqfile_6close)},
   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_9csamtools_9Fastqfile_13__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_9csamtools_9Fastqfile_12__next__)},
-  {__Pyx_NAMESTR("test"), (PyCFunction)__pyx_pw_5pysam_9csamtools_9Fastqfile_15test, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_9csamtools_9Fastqfile_14test)},
   {0, 0, 0, 0}
 };
 
 static struct PyGetSetDef __pyx_getsets_5pysam_9csamtools_Fastqfile[] = {
-  {(char *)"filename", __pyx_getprop_5pysam_9csamtools_9Fastqfile_filename, 0, __Pyx_DOCSTR(__pyx_k_199), 0},
+  {(char *)"filename", __pyx_getprop_5pysam_9csamtools_9Fastqfile_filename, 0, __Pyx_DOCSTR(__pyx_k_198), 0},
   {0, 0, 0, 0, 0}
 };
 
@@ -37506,10 +38344,10 @@ static PyTypeObject __pyx_type_5pysam_9csamtools_Fastqfile = {
   0, /*tp_getattro*/
   0, /*tp_setattro*/
   &__pyx_tp_as_buffer_Fastqfile, /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
   __Pyx_DOCSTR("*(filename)*\n\n    A *FASTQ* file. The file is automatically opened.\n\n    "), /*tp_doc*/
-  0, /*tp_traverse*/
-  0, /*tp_clear*/
+  __pyx_tp_traverse_5pysam_9csamtools_Fastqfile, /*tp_traverse*/
+  __pyx_tp_clear_5pysam_9csamtools_Fastqfile, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
   __pyx_pw_5pysam_9csamtools_9Fastqfile_11__iter__, /*tp_iter*/
@@ -38016,46 +38854,46 @@ static PyMethodDef __pyx_methods_5pysam_9csamtools_AlignedRead[] = {
 };
 
 static struct PyGetSetDef __pyx_getsets_5pysam_9csamtools_AlignedRead[] = {
-  {(char *)"qname", __pyx_getprop_5pysam_9csamtools_11AlignedRead_qname, __pyx_setprop_5pysam_9csamtools_11AlignedRead_qname, __Pyx_DOCSTR(__pyx_k_200), 0},
-  {(char *)"cigar", __pyx_getprop_5pysam_9csamtools_11AlignedRead_cigar, __pyx_setprop_5pysam_9csamtools_11AlignedRead_cigar, __Pyx_DOCSTR(__pyx_k_201), 0},
-  {(char *)"cigarstring", __pyx_getprop_5pysam_9csamtools_11AlignedRead_cigarstring, __pyx_setprop_5pysam_9csamtools_11AlignedRead_cigarstring, __Pyx_DOCSTR(__pyx_k_202), 0},
-  {(char *)"seq", __pyx_getprop_5pysam_9csamtools_11AlignedRead_seq, __pyx_setprop_5pysam_9csamtools_11AlignedRead_seq, __Pyx_DOCSTR(__pyx_k_203), 0},
-  {(char *)"qual", __pyx_getprop_5pysam_9csamtools_11AlignedRead_qual, __pyx_setprop_5pysam_9csamtools_11AlignedRead_qual, __Pyx_DOCSTR(__pyx_k_204), 0},
-  {(char *)"query", __pyx_getprop_5pysam_9csamtools_11AlignedRead_query, 0, __Pyx_DOCSTR(__pyx_k_205), 0},
-  {(char *)"qqual", __pyx_getprop_5pysam_9csamtools_11AlignedRead_qqual, 0, __Pyx_DOCSTR(__pyx_k_206), 0},
-  {(char *)"qstart", __pyx_getprop_5pysam_9csamtools_11AlignedRead_qstart, 0, __Pyx_DOCSTR(__pyx_k_207), 0},
-  {(char *)"qend", __pyx_getprop_5pysam_9csamtools_11AlignedRead_qend, 0, __Pyx_DOCSTR(__pyx_k_208), 0},
-  {(char *)"qlen", __pyx_getprop_5pysam_9csamtools_11AlignedRead_qlen, 0, __Pyx_DOCSTR(__pyx_k_209), 0},
-  {(char *)"tags", __pyx_getprop_5pysam_9csamtools_11AlignedRead_tags, __pyx_setprop_5pysam_9csamtools_11AlignedRead_tags, __Pyx_DOCSTR(__pyx_k_210), 0},
-  {(char *)"flag", __pyx_getprop_5pysam_9csamtools_11AlignedRead_flag, __pyx_setprop_5pysam_9csamtools_11AlignedRead_flag, __Pyx_DOCSTR(__pyx_k_211), 0},
-  {(char *)"rname", __pyx_getprop_5pysam_9csamtools_11AlignedRead_rname, __pyx_setprop_5pysam_9csamtools_11AlignedRead_rname, __Pyx_DOCSTR(__pyx_k_212), 0},
-  {(char *)"tid", __pyx_getprop_5pysam_9csamtools_11AlignedRead_tid, __pyx_setprop_5pysam_9csamtools_11AlignedRead_tid, __Pyx_DOCSTR(__pyx_k_213), 0},
-  {(char *)"pos", __pyx_getprop_5pysam_9csamtools_11AlignedRead_pos, __pyx_setprop_5pysam_9csamtools_11AlignedRead_pos, __Pyx_DOCSTR(__pyx_k_214), 0},
-  {(char *)"bin", __pyx_getprop_5pysam_9csamtools_11AlignedRead_bin, __pyx_setprop_5pysam_9csamtools_11AlignedRead_bin, __Pyx_DOCSTR(__pyx_k_215), 0},
-  {(char *)"rlen", __pyx_getprop_5pysam_9csamtools_11AlignedRead_rlen, 0, __Pyx_DOCSTR(__pyx_k_216), 0},
-  {(char *)"aend", __pyx_getprop_5pysam_9csamtools_11AlignedRead_aend, 0, __Pyx_DOCSTR(__pyx_k_217), 0},
-  {(char *)"alen", __pyx_getprop_5pysam_9csamtools_11AlignedRead_alen, 0, __Pyx_DOCSTR(__pyx_k_218), 0},
-  {(char *)"mapq", __pyx_getprop_5pysam_9csamtools_11AlignedRead_mapq, __pyx_setprop_5pysam_9csamtools_11AlignedRead_mapq, __Pyx_DOCSTR(__pyx_k_219), 0},
-  {(char *)"mrnm", __pyx_getprop_5pysam_9csamtools_11AlignedRead_mrnm, __pyx_setprop_5pysam_9csamtools_11AlignedRead_mrnm, __Pyx_DOCSTR(__pyx_k_220), 0},
-  {(char *)"rnext", __pyx_getprop_5pysam_9csamtools_11AlignedRead_rnext, __pyx_setprop_5pysam_9csamtools_11AlignedRead_rnext, __Pyx_DOCSTR(__pyx_k_221), 0},
-  {(char *)"mpos", __pyx_getprop_5pysam_9csamtools_11AlignedRead_mpos, __pyx_setprop_5pysam_9csamtools_11AlignedRead_mpos, __Pyx_DOCSTR(__pyx_k_222), 0},
-  {(char *)"pnext", __pyx_getprop_5pysam_9csamtools_11AlignedRead_pnext, __pyx_setprop_5pysam_9csamtools_11AlignedRead_pnext, __Pyx_DOCSTR(__pyx_k_223), 0},
-  {(char *)"isize", __pyx_getprop_5pysam_9csamtools_11AlignedRead_isize, __pyx_setprop_5pysam_9csamtools_11AlignedRead_isize, __Pyx_DOCSTR(__pyx_k_224), 0},
-  {(char *)"tlen", __pyx_getprop_5pysam_9csamtools_11AlignedRead_tlen, __pyx_setprop_5pysam_9csamtools_11AlignedRead_tlen, __Pyx_DOCSTR(__pyx_k_225), 0},
-  {(char *)"is_paired", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_paired, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_paired, __Pyx_DOCSTR(__pyx_k_226), 0},
-  {(char *)"is_proper_pair", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_proper_pair, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_proper_pair, __Pyx_DOCSTR(__pyx_k_227), 0},
-  {(char *)"is_unmapped", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_unmapped, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_unmapped, __Pyx_DOCSTR(__pyx_k_228), 0},
-  {(char *)"mate_is_unmapped", __pyx_getprop_5pysam_9csamtools_11AlignedRead_mate_is_unmapped, __pyx_setprop_5pysam_9csamtools_11AlignedRead_mate_is_unmapped, __Pyx_DOCSTR(__pyx_k_229), 0},
-  {(char *)"is_reverse", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_reverse, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_reverse, __Pyx_DOCSTR(__pyx_k_230), 0},
-  {(char *)"mate_is_reverse", __pyx_getprop_5pysam_9csamtools_11AlignedRead_mate_is_reverse, __pyx_setprop_5pysam_9csamtools_11AlignedRead_mate_is_reverse, __Pyx_DOCSTR(__pyx_k_231), 0},
-  {(char *)"is_read1", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_read1, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_read1, __Pyx_DOCSTR(__pyx_k_232), 0},
-  {(char *)"is_read2", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_read2, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_read2, __Pyx_DOCSTR(__pyx_k_233), 0},
-  {(char *)"is_secondary", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_secondary, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_secondary, __Pyx_DOCSTR(__pyx_k_234), 0},
-  {(char *)"is_qcfail", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_qcfail, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_qcfail, __Pyx_DOCSTR(__pyx_k_235), 0},
-  {(char *)"is_duplicate", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_duplicate, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_duplicate, __Pyx_DOCSTR(__pyx_k_236), 0},
-  {(char *)"positions", __pyx_getprop_5pysam_9csamtools_11AlignedRead_positions, 0, __Pyx_DOCSTR(__pyx_k_237), 0},
-  {(char *)"inferred_length", __pyx_getprop_5pysam_9csamtools_11AlignedRead_inferred_length, 0, __Pyx_DOCSTR(__pyx_k_238), 0},
-  {(char *)"aligned_pairs", __pyx_getprop_5pysam_9csamtools_11AlignedRead_aligned_pairs, 0, __Pyx_DOCSTR(__pyx_k_239), 0},
+  {(char *)"qname", __pyx_getprop_5pysam_9csamtools_11AlignedRead_qname, __pyx_setprop_5pysam_9csamtools_11AlignedRead_qname, __Pyx_DOCSTR(__pyx_k_202), 0},
+  {(char *)"cigar", __pyx_getprop_5pysam_9csamtools_11AlignedRead_cigar, __pyx_setprop_5pysam_9csamtools_11AlignedRead_cigar, __Pyx_DOCSTR(__pyx_k_203), 0},
+  {(char *)"cigarstring", __pyx_getprop_5pysam_9csamtools_11AlignedRead_cigarstring, __pyx_setprop_5pysam_9csamtools_11AlignedRead_cigarstring, __Pyx_DOCSTR(__pyx_k_204), 0},
+  {(char *)"seq", __pyx_getprop_5pysam_9csamtools_11AlignedRead_seq, __pyx_setprop_5pysam_9csamtools_11AlignedRead_seq, __Pyx_DOCSTR(__pyx_k_205), 0},
+  {(char *)"qual", __pyx_getprop_5pysam_9csamtools_11AlignedRead_qual, __pyx_setprop_5pysam_9csamtools_11AlignedRead_qual, __Pyx_DOCSTR(__pyx_k_206), 0},
+  {(char *)"query", __pyx_getprop_5pysam_9csamtools_11AlignedRead_query, 0, __Pyx_DOCSTR(__pyx_k_207), 0},
+  {(char *)"qqual", __pyx_getprop_5pysam_9csamtools_11AlignedRead_qqual, 0, __Pyx_DOCSTR(__pyx_k_208), 0},
+  {(char *)"qstart", __pyx_getprop_5pysam_9csamtools_11AlignedRead_qstart, 0, __Pyx_DOCSTR(__pyx_k_209), 0},
+  {(char *)"qend", __pyx_getprop_5pysam_9csamtools_11AlignedRead_qend, 0, __Pyx_DOCSTR(__pyx_k_210), 0},
+  {(char *)"qlen", __pyx_getprop_5pysam_9csamtools_11AlignedRead_qlen, 0, __Pyx_DOCSTR(__pyx_k_211), 0},
+  {(char *)"tags", __pyx_getprop_5pysam_9csamtools_11AlignedRead_tags, __pyx_setprop_5pysam_9csamtools_11AlignedRead_tags, __Pyx_DOCSTR(__pyx_k_212), 0},
+  {(char *)"flag", __pyx_getprop_5pysam_9csamtools_11AlignedRead_flag, __pyx_setprop_5pysam_9csamtools_11AlignedRead_flag, __Pyx_DOCSTR(__pyx_k_213), 0},
+  {(char *)"rname", __pyx_getprop_5pysam_9csamtools_11AlignedRead_rname, __pyx_setprop_5pysam_9csamtools_11AlignedRead_rname, __Pyx_DOCSTR(__pyx_k_214), 0},
+  {(char *)"tid", __pyx_getprop_5pysam_9csamtools_11AlignedRead_tid, __pyx_setprop_5pysam_9csamtools_11AlignedRead_tid, __Pyx_DOCSTR(__pyx_k_215), 0},
+  {(char *)"pos", __pyx_getprop_5pysam_9csamtools_11AlignedRead_pos, __pyx_setprop_5pysam_9csamtools_11AlignedRead_pos, __Pyx_DOCSTR(__pyx_k_216), 0},
+  {(char *)"bin", __pyx_getprop_5pysam_9csamtools_11AlignedRead_bin, __pyx_setprop_5pysam_9csamtools_11AlignedRead_bin, __Pyx_DOCSTR(__pyx_k_217), 0},
+  {(char *)"rlen", __pyx_getprop_5pysam_9csamtools_11AlignedRead_rlen, 0, __Pyx_DOCSTR(__pyx_k_218), 0},
+  {(char *)"aend", __pyx_getprop_5pysam_9csamtools_11AlignedRead_aend, 0, __Pyx_DOCSTR(__pyx_k_219), 0},
+  {(char *)"alen", __pyx_getprop_5pysam_9csamtools_11AlignedRead_alen, 0, __Pyx_DOCSTR(__pyx_k_220), 0},
+  {(char *)"mapq", __pyx_getprop_5pysam_9csamtools_11AlignedRead_mapq, __pyx_setprop_5pysam_9csamtools_11AlignedRead_mapq, __Pyx_DOCSTR(__pyx_k_221), 0},
+  {(char *)"mrnm", __pyx_getprop_5pysam_9csamtools_11AlignedRead_mrnm, __pyx_setprop_5pysam_9csamtools_11AlignedRead_mrnm, __Pyx_DOCSTR(__pyx_k_222), 0},
+  {(char *)"rnext", __pyx_getprop_5pysam_9csamtools_11AlignedRead_rnext, __pyx_setprop_5pysam_9csamtools_11AlignedRead_rnext, __Pyx_DOCSTR(__pyx_k_223), 0},
+  {(char *)"mpos", __pyx_getprop_5pysam_9csamtools_11AlignedRead_mpos, __pyx_setprop_5pysam_9csamtools_11AlignedRead_mpos, __Pyx_DOCSTR(__pyx_k_224), 0},
+  {(char *)"pnext", __pyx_getprop_5pysam_9csamtools_11AlignedRead_pnext, __pyx_setprop_5pysam_9csamtools_11AlignedRead_pnext, __Pyx_DOCSTR(__pyx_k_225), 0},
+  {(char *)"isize", __pyx_getprop_5pysam_9csamtools_11AlignedRead_isize, __pyx_setprop_5pysam_9csamtools_11AlignedRead_isize, __Pyx_DOCSTR(__pyx_k_226), 0},
+  {(char *)"tlen", __pyx_getprop_5pysam_9csamtools_11AlignedRead_tlen, __pyx_setprop_5pysam_9csamtools_11AlignedRead_tlen, __Pyx_DOCSTR(__pyx_k_227), 0},
+  {(char *)"is_paired", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_paired, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_paired, __Pyx_DOCSTR(__pyx_k_228), 0},
+  {(char *)"is_proper_pair", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_proper_pair, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_proper_pair, __Pyx_DOCSTR(__pyx_k_229), 0},
+  {(char *)"is_unmapped", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_unmapped, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_unmapped, __Pyx_DOCSTR(__pyx_k_230), 0},
+  {(char *)"mate_is_unmapped", __pyx_getprop_5pysam_9csamtools_11AlignedRead_mate_is_unmapped, __pyx_setprop_5pysam_9csamtools_11AlignedRead_mate_is_unmapped, __Pyx_DOCSTR(__pyx_k_231), 0},
+  {(char *)"is_reverse", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_reverse, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_reverse, __Pyx_DOCSTR(__pyx_k_232), 0},
+  {(char *)"mate_is_reverse", __pyx_getprop_5pysam_9csamtools_11AlignedRead_mate_is_reverse, __pyx_setprop_5pysam_9csamtools_11AlignedRead_mate_is_reverse, __Pyx_DOCSTR(__pyx_k_233), 0},
+  {(char *)"is_read1", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_read1, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_read1, __Pyx_DOCSTR(__pyx_k_234), 0},
+  {(char *)"is_read2", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_read2, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_read2, __Pyx_DOCSTR(__pyx_k_235), 0},
+  {(char *)"is_secondary", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_secondary, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_secondary, __Pyx_DOCSTR(__pyx_k_236), 0},
+  {(char *)"is_qcfail", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_qcfail, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_qcfail, __Pyx_DOCSTR(__pyx_k_237), 0},
+  {(char *)"is_duplicate", __pyx_getprop_5pysam_9csamtools_11AlignedRead_is_duplicate, __pyx_setprop_5pysam_9csamtools_11AlignedRead_is_duplicate, __Pyx_DOCSTR(__pyx_k_238), 0},
+  {(char *)"positions", __pyx_getprop_5pysam_9csamtools_11AlignedRead_positions, 0, __Pyx_DOCSTR(__pyx_k_239), 0},
+  {(char *)"inferred_length", __pyx_getprop_5pysam_9csamtools_11AlignedRead_inferred_length, 0, __Pyx_DOCSTR(__pyx_k_240), 0},
+  {(char *)"aligned_pairs", __pyx_getprop_5pysam_9csamtools_11AlignedRead_aligned_pairs, 0, __Pyx_DOCSTR(__pyx_k_241), 0},
   {0, 0, 0, 0, 0}
 };
 
@@ -38220,6 +39058,7 @@ static PyObject *__pyx_tp_new_5pysam_9csamtools_Samfile(PyTypeObject *t, PyObjec
   if (!o) return 0;
   p = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)o);
   p->__pyx_vtab = __pyx_vtabptr_5pysam_9csamtools_Samfile;
+  p->_filename = Py_None; Py_INCREF(Py_None);
   if (__pyx_pw_5pysam_9csamtools_7Samfile_1__cinit__(o, a, k) < 0) {
     Py_DECREF(o); o = 0;
   }
@@ -38227,6 +39066,8 @@ static PyObject *__pyx_tp_new_5pysam_9csamtools_Samfile(PyTypeObject *t, PyObjec
 }
 
 static void __pyx_tp_dealloc_5pysam_9csamtools_Samfile(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools_Samfile *p = (struct __pyx_obj_5pysam_9csamtools_Samfile *)o;
+  PyObject_GC_UnTrack(o);
   {
     PyObject *etype, *eval, *etb;
     PyErr_Fetch(&etype, &eval, &etb);
@@ -38236,9 +39077,29 @@ static void __pyx_tp_dealloc_5pysam_9csamtools_Samfile(PyObject *o) {
     --Py_REFCNT(o);
     PyErr_Restore(etype, eval, etb);
   }
+  Py_CLEAR(p->_filename);
+  PyObject_GC_Track(o);
   (*Py_TYPE(o)->tp_free)(o);
 }
 
+static int __pyx_tp_traverse_5pysam_9csamtools_Samfile(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_5pysam_9csamtools_Samfile *p = (struct __pyx_obj_5pysam_9csamtools_Samfile *)o;
+  if (p->_filename) {
+    e = (*v)(p->_filename, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_5pysam_9csamtools_Samfile(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools_Samfile *p = (struct __pyx_obj_5pysam_9csamtools_Samfile *)o;
+  PyObject* tmp;
+  tmp = ((PyObject*)p->_filename);
+  p->_filename = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
 static PyObject *__pyx_getprop_5pysam_9csamtools_7Samfile_filename(PyObject *o, CYTHON_UNUSED void *x) {
   return __pyx_pw_5pysam_9csamtools_7Samfile_8filename_1__get__(o);
 }
@@ -38295,9 +39156,9 @@ static PyMethodDef __pyx_methods_5pysam_9csamtools_Samfile[] = {
 };
 
 static struct PyGetSetDef __pyx_getsets_5pysam_9csamtools_Samfile[] = {
-  {(char *)"filename", __pyx_getprop_5pysam_9csamtools_7Samfile_filename, 0, __Pyx_DOCSTR(__pyx_k_199), 0},
-  {(char *)"nreferences", __pyx_getprop_5pysam_9csamtools_7Samfile_nreferences, 0, __Pyx_DOCSTR(__pyx_k_240), 0},
-  {(char *)"references", __pyx_getprop_5pysam_9csamtools_7Samfile_references, 0, __Pyx_DOCSTR(__pyx_k_241), 0},
+  {(char *)"filename", __pyx_getprop_5pysam_9csamtools_7Samfile_filename, 0, __Pyx_DOCSTR(__pyx_k_198), 0},
+  {(char *)"nreferences", __pyx_getprop_5pysam_9csamtools_7Samfile_nreferences, 0, __Pyx_DOCSTR(__pyx_k_200), 0},
+  {(char *)"references", __pyx_getprop_5pysam_9csamtools_7Samfile_references, 0, __Pyx_DOCSTR(__pyx_k_199), 0},
   {(char *)"lengths", __pyx_getprop_5pysam_9csamtools_7Samfile_lengths, 0, __Pyx_DOCSTR(__pyx_k_242), 0},
   {(char *)"mapped", __pyx_getprop_5pysam_9csamtools_7Samfile_mapped, 0, __Pyx_DOCSTR(__pyx_k_243), 0},
   {(char *)"unmapped", __pyx_getprop_5pysam_9csamtools_7Samfile_unmapped, 0, __Pyx_DOCSTR(__pyx_k_244), 0},
@@ -38428,10 +39289,10 @@ static PyTypeObject __pyx_type_5pysam_9csamtools_Samfile = {
   0, /*tp_getattro*/
   0, /*tp_setattro*/
   &__pyx_tp_as_buffer_Samfile, /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
   __Pyx_DOCSTR("*(filename, mode=None, template = None, referencenames = None, referencelengths = None, text = NULL, header = None,\n         add_sq_text = False, check_header = True, check_sq = True )*\n\n    A :term:`SAM`/:term:`BAM` formatted file. The file is automatically opened.\n\n    *mode* should be ``r`` for reading or ``w`` for writing. The default is text mode (:term:`SAM`). For binary\n    (:term:`BAM`) I/O you should append ``b`` for compressed or ``u`` for uncompressed :te [...]
-  0, /*tp_traverse*/
-  0, /*tp_clear*/
+  __pyx_tp_traverse_5pysam_9csamtools_Samfile, /*tp_traverse*/
+  __pyx_tp_clear_5pysam_9csamtools_Samfile, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
   __pyx_pw_5pysam_9csamtools_7Samfile_41__iter__, /*tp_iter*/
@@ -41014,7 +41875,417 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct__genexpr = {
   #endif
 };
 
-static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct__genexpr = {
+static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct__genexpr = {
+  0, /*sq_length*/
+  0, /*sq_concat*/
+  0, /*sq_repeat*/
+  0, /*sq_item*/
+  0, /*sq_slice*/
+  0, /*sq_ass_item*/
+  0, /*sq_ass_slice*/
+  0, /*sq_contains*/
+  0, /*sq_inplace_concat*/
+  0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct__genexpr = {
+  0, /*mp_length*/
+  0, /*mp_subscript*/
+  0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct__genexpr = {
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getreadbuffer*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getwritebuffer*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getsegcount*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getcharbuffer*/
+  #endif
+  #if PY_VERSION_HEX >= 0x02060000
+  0, /*bf_getbuffer*/
+  #endif
+  #if PY_VERSION_HEX >= 0x02060000
+  0, /*bf_releasebuffer*/
+  #endif
+};
+
+static PyTypeObject __pyx_type_5pysam_9csamtools___pyx_scope_struct__genexpr = {
+  PyVarObject_HEAD_INIT(0, 0)
+  __Pyx_NAMESTR("pysam.csamtools.__pyx_scope_struct__genexpr"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct__genexpr), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_5pysam_9csamtools___pyx_scope_struct__genexpr, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #else
+  0, /*reserved*/
+  #endif
+  0, /*tp_repr*/
+  &__pyx_tp_as_number___pyx_scope_struct__genexpr, /*tp_as_number*/
+  &__pyx_tp_as_sequence___pyx_scope_struct__genexpr, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping___pyx_scope_struct__genexpr, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  &__pyx_tp_as_buffer___pyx_scope_struct__genexpr, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_5pysam_9csamtools___pyx_scope_struct__genexpr, /*tp_traverse*/
+  __pyx_tp_clear_5pysam_9csamtools___pyx_scope_struct__genexpr, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_5pysam_9csamtools___pyx_scope_struct__genexpr, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_5pysam_9csamtools___pyx_scope_struct__genexpr, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  #if PY_VERSION_HEX >= 0x02060000
+  0, /*tp_version_tag*/
+  #endif
+};
+
+static PyObject *__pyx_tp_new_5pysam_9csamtools___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *p;
+  PyObject *o = (*t->tp_alloc)(t, 0);
+  if (!o) return 0;
+  p = ((struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *)o);
+  p->__pyx_v_x = 0;
+  p->__pyx_v_y = 0;
+  p->__pyx_t_0 = 0;
+  p->__pyx_t_1 = 0;
+  return o;
+}
+
+static void __pyx_tp_dealloc_5pysam_9csamtools___pyx_scope_struct_1_genexpr(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_x);
+  Py_CLEAR(p->__pyx_v_y);
+  Py_CLEAR(p->__pyx_t_0);
+  Py_CLEAR(p->__pyx_t_1);
+  PyObject_GC_Track(o);
+  (*Py_TYPE(o)->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_5pysam_9csamtools___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *)o;
+  if (p->__pyx_v_x) {
+    e = (*v)(p->__pyx_v_x, a); if (e) return e;
+  }
+  if (p->__pyx_v_y) {
+    e = (*v)(p->__pyx_v_y, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  if (p->__pyx_t_1) {
+    e = (*v)(p->__pyx_t_1, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_5pysam_9csamtools___pyx_scope_struct_1_genexpr(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *)o;
+  PyObject* tmp;
+  tmp = ((PyObject*)p->__pyx_v_x);
+  p->__pyx_v_x = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->__pyx_v_y);
+  p->__pyx_v_y = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->__pyx_t_0);
+  p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->__pyx_t_1);
+  p->__pyx_t_1 = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyMethodDef __pyx_methods_5pysam_9csamtools___pyx_scope_struct_1_genexpr[] = {
+  {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1_genexpr = {
+  0, /*nb_add*/
+  0, /*nb_subtract*/
+  0, /*nb_multiply*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_divide*/
+  #endif
+  0, /*nb_remainder*/
+  0, /*nb_divmod*/
+  0, /*nb_power*/
+  0, /*nb_negative*/
+  0, /*nb_positive*/
+  0, /*nb_absolute*/
+  0, /*nb_nonzero*/
+  0, /*nb_invert*/
+  0, /*nb_lshift*/
+  0, /*nb_rshift*/
+  0, /*nb_and*/
+  0, /*nb_xor*/
+  0, /*nb_or*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_coerce*/
+  #endif
+  0, /*nb_int*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_long*/
+  #else
+  0, /*reserved*/
+  #endif
+  0, /*nb_float*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_oct*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_hex*/
+  #endif
+  0, /*nb_inplace_add*/
+  0, /*nb_inplace_subtract*/
+  0, /*nb_inplace_multiply*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_inplace_divide*/
+  #endif
+  0, /*nb_inplace_remainder*/
+  0, /*nb_inplace_power*/
+  0, /*nb_inplace_lshift*/
+  0, /*nb_inplace_rshift*/
+  0, /*nb_inplace_and*/
+  0, /*nb_inplace_xor*/
+  0, /*nb_inplace_or*/
+  0, /*nb_floor_divide*/
+  0, /*nb_true_divide*/
+  0, /*nb_inplace_floor_divide*/
+  0, /*nb_inplace_true_divide*/
+  #if PY_VERSION_HEX >= 0x02050000
+  0, /*nb_index*/
+  #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1_genexpr = {
+  0, /*sq_length*/
+  0, /*sq_concat*/
+  0, /*sq_repeat*/
+  0, /*sq_item*/
+  0, /*sq_slice*/
+  0, /*sq_ass_item*/
+  0, /*sq_ass_slice*/
+  0, /*sq_contains*/
+  0, /*sq_inplace_concat*/
+  0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1_genexpr = {
+  0, /*mp_length*/
+  0, /*mp_subscript*/
+  0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1_genexpr = {
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getreadbuffer*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getwritebuffer*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getsegcount*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getcharbuffer*/
+  #endif
+  #if PY_VERSION_HEX >= 0x02060000
+  0, /*bf_getbuffer*/
+  #endif
+  #if PY_VERSION_HEX >= 0x02060000
+  0, /*bf_releasebuffer*/
+  #endif
+};
+
+static PyTypeObject __pyx_type_5pysam_9csamtools___pyx_scope_struct_1_genexpr = {
+  PyVarObject_HEAD_INIT(0, 0)
+  __Pyx_NAMESTR("pysam.csamtools.__pyx_scope_struct_1_genexpr"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_5pysam_9csamtools___pyx_scope_struct_1_genexpr, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #else
+  0, /*reserved*/
+  #endif
+  0, /*tp_repr*/
+  &__pyx_tp_as_number___pyx_scope_struct_1_genexpr, /*tp_as_number*/
+  &__pyx_tp_as_sequence___pyx_scope_struct_1_genexpr, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping___pyx_scope_struct_1_genexpr, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  &__pyx_tp_as_buffer___pyx_scope_struct_1_genexpr, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_5pysam_9csamtools___pyx_scope_struct_1_genexpr, /*tp_traverse*/
+  __pyx_tp_clear_5pysam_9csamtools___pyx_scope_struct_1_genexpr, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_5pysam_9csamtools___pyx_scope_struct_1_genexpr, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_5pysam_9csamtools___pyx_scope_struct_1_genexpr, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  #if PY_VERSION_HEX >= 0x02060000
+  0, /*tp_version_tag*/
+  #endif
+};
+
+static PyObject *__pyx_tp_new_5pysam_9csamtools___pyx_scope_struct_2__open(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *p;
+  PyObject *o = (*t->tp_alloc)(t, 0);
+  if (!o) return 0;
+  p = ((struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *)o);
+  p->__pyx_v_data = 0;
+  return o;
+}
+
+static void __pyx_tp_dealloc_5pysam_9csamtools___pyx_scope_struct_2__open(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_data);
+  PyObject_GC_Track(o);
+  (*Py_TYPE(o)->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_5pysam_9csamtools___pyx_scope_struct_2__open(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *)o;
+  if (p->__pyx_v_data) {
+    e = (*v)(p->__pyx_v_data, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_5pysam_9csamtools___pyx_scope_struct_2__open(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *)o;
+  PyObject* tmp;
+  tmp = ((PyObject*)p->__pyx_v_data);
+  p->__pyx_v_data = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyMethodDef __pyx_methods_5pysam_9csamtools___pyx_scope_struct_2__open[] = {
+  {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2__open = {
+  0, /*nb_add*/
+  0, /*nb_subtract*/
+  0, /*nb_multiply*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_divide*/
+  #endif
+  0, /*nb_remainder*/
+  0, /*nb_divmod*/
+  0, /*nb_power*/
+  0, /*nb_negative*/
+  0, /*nb_positive*/
+  0, /*nb_absolute*/
+  0, /*nb_nonzero*/
+  0, /*nb_invert*/
+  0, /*nb_lshift*/
+  0, /*nb_rshift*/
+  0, /*nb_and*/
+  0, /*nb_xor*/
+  0, /*nb_or*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_coerce*/
+  #endif
+  0, /*nb_int*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_long*/
+  #else
+  0, /*reserved*/
+  #endif
+  0, /*nb_float*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_oct*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_hex*/
+  #endif
+  0, /*nb_inplace_add*/
+  0, /*nb_inplace_subtract*/
+  0, /*nb_inplace_multiply*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_inplace_divide*/
+  #endif
+  0, /*nb_inplace_remainder*/
+  0, /*nb_inplace_power*/
+  0, /*nb_inplace_lshift*/
+  0, /*nb_inplace_rshift*/
+  0, /*nb_inplace_and*/
+  0, /*nb_inplace_xor*/
+  0, /*nb_inplace_or*/
+  0, /*nb_floor_divide*/
+  0, /*nb_true_divide*/
+  0, /*nb_inplace_floor_divide*/
+  0, /*nb_inplace_true_divide*/
+  #if PY_VERSION_HEX >= 0x02050000
+  0, /*nb_index*/
+  #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2__open = {
   0, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
@@ -41027,13 +42298,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct__genexpr = {
   0, /*sq_inplace_repeat*/
 };
 
-static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct__genexpr = {
+static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2__open = {
   0, /*mp_length*/
   0, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
-static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct__genexpr = {
+static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2__open = {
   #if PY_MAJOR_VERSION < 3
   0, /*bf_getreadbuffer*/
   #endif
@@ -41054,12 +42325,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct__genexpr = {
   #endif
 };
 
-static PyTypeObject __pyx_type_5pysam_9csamtools___pyx_scope_struct__genexpr = {
+static PyTypeObject __pyx_type_5pysam_9csamtools___pyx_scope_struct_2__open = {
   PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.csamtools.__pyx_scope_struct__genexpr"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct__genexpr), /*tp_basicsize*/
+  __Pyx_NAMESTR("pysam.csamtools.__pyx_scope_struct_2__open"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open), /*tp_basicsize*/
   0, /*tp_itemsize*/
-  __pyx_tp_dealloc_5pysam_9csamtools___pyx_scope_struct__genexpr, /*tp_dealloc*/
+  __pyx_tp_dealloc_5pysam_9csamtools___pyx_scope_struct_2__open, /*tp_dealloc*/
   0, /*tp_print*/
   0, /*tp_getattr*/
   0, /*tp_setattr*/
@@ -41069,24 +42340,24 @@ static PyTypeObject __pyx_type_5pysam_9csamtools___pyx_scope_struct__genexpr = {
   0, /*reserved*/
   #endif
   0, /*tp_repr*/
-  &__pyx_tp_as_number___pyx_scope_struct__genexpr, /*tp_as_number*/
-  &__pyx_tp_as_sequence___pyx_scope_struct__genexpr, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping___pyx_scope_struct__genexpr, /*tp_as_mapping*/
+  &__pyx_tp_as_number___pyx_scope_struct_2__open, /*tp_as_number*/
+  &__pyx_tp_as_sequence___pyx_scope_struct_2__open, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping___pyx_scope_struct_2__open, /*tp_as_mapping*/
   0, /*tp_hash*/
   0, /*tp_call*/
   0, /*tp_str*/
   0, /*tp_getattro*/
   0, /*tp_setattro*/
-  &__pyx_tp_as_buffer___pyx_scope_struct__genexpr, /*tp_as_buffer*/
+  &__pyx_tp_as_buffer___pyx_scope_struct_2__open, /*tp_as_buffer*/
   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
   0, /*tp_doc*/
-  __pyx_tp_traverse_5pysam_9csamtools___pyx_scope_struct__genexpr, /*tp_traverse*/
-  __pyx_tp_clear_5pysam_9csamtools___pyx_scope_struct__genexpr, /*tp_clear*/
+  __pyx_tp_traverse_5pysam_9csamtools___pyx_scope_struct_2__open, /*tp_traverse*/
+  __pyx_tp_clear_5pysam_9csamtools___pyx_scope_struct_2__open, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
   0, /*tp_iter*/
   0, /*tp_iternext*/
-  __pyx_methods_5pysam_9csamtools___pyx_scope_struct__genexpr, /*tp_methods*/
+  __pyx_methods_5pysam_9csamtools___pyx_scope_struct_2__open, /*tp_methods*/
   0, /*tp_members*/
   0, /*tp_getset*/
   0, /*tp_base*/
@@ -41096,7 +42367,7 @@ static PyTypeObject __pyx_type_5pysam_9csamtools___pyx_scope_struct__genexpr = {
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_9csamtools___pyx_scope_struct__genexpr, /*tp_new*/
+  __pyx_tp_new_5pysam_9csamtools___pyx_scope_struct_2__open, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -41110,70 +42381,271 @@ static PyTypeObject __pyx_type_5pysam_9csamtools___pyx_scope_struct__genexpr = {
   #endif
 };
 
-static PyObject *__pyx_tp_new_5pysam_9csamtools___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
-  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *p;
+static PyObject *__pyx_tp_new_5pysam_9csamtools___pyx_scope_struct_3_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr *p;
   PyObject *o = (*t->tp_alloc)(t, 0);
   if (!o) return 0;
-  p = ((struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *)o);
+  p = ((struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr *)o);
+  p->__pyx_outer_scope = 0;
   p->__pyx_v_x = 0;
-  p->__pyx_v_y = 0;
   p->__pyx_t_0 = 0;
-  p->__pyx_t_1 = 0;
   return o;
 }
 
-static void __pyx_tp_dealloc_5pysam_9csamtools___pyx_scope_struct_1_genexpr(PyObject *o) {
-  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *)o;
+static void __pyx_tp_dealloc_5pysam_9csamtools___pyx_scope_struct_3_genexpr(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr *)o;
   PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_outer_scope);
   Py_CLEAR(p->__pyx_v_x);
-  Py_CLEAR(p->__pyx_v_y);
   Py_CLEAR(p->__pyx_t_0);
-  Py_CLEAR(p->__pyx_t_1);
   PyObject_GC_Track(o);
   (*Py_TYPE(o)->tp_free)(o);
 }
 
-static int __pyx_tp_traverse_5pysam_9csamtools___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) {
+static int __pyx_tp_traverse_5pysam_9csamtools___pyx_scope_struct_3_genexpr(PyObject *o, visitproc v, void *a) {
   int e;
-  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *)o;
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr *)o;
+  if (p->__pyx_outer_scope) {
+    e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e;
+  }
   if (p->__pyx_v_x) {
     e = (*v)(p->__pyx_v_x, a); if (e) return e;
   }
-  if (p->__pyx_v_y) {
-    e = (*v)(p->__pyx_v_y, a); if (e) return e;
-  }
   if (p->__pyx_t_0) {
     e = (*v)(p->__pyx_t_0, a); if (e) return e;
   }
-  if (p->__pyx_t_1) {
-    e = (*v)(p->__pyx_t_1, a); if (e) return e;
-  }
   return 0;
 }
 
-static int __pyx_tp_clear_5pysam_9csamtools___pyx_scope_struct_1_genexpr(PyObject *o) {
-  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr *)o;
+static int __pyx_tp_clear_5pysam_9csamtools___pyx_scope_struct_3_genexpr(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr *)o;
   PyObject* tmp;
+  tmp = ((PyObject*)p->__pyx_outer_scope);
+  p->__pyx_outer_scope = ((struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
   tmp = ((PyObject*)p->__pyx_v_x);
   p->__pyx_v_x = Py_None; Py_INCREF(Py_None);
   Py_XDECREF(tmp);
-  tmp = ((PyObject*)p->__pyx_v_y);
-  p->__pyx_v_y = Py_None; Py_INCREF(Py_None);
-  Py_XDECREF(tmp);
   tmp = ((PyObject*)p->__pyx_t_0);
   p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
   Py_XDECREF(tmp);
-  tmp = ((PyObject*)p->__pyx_t_1);
-  p->__pyx_t_1 = Py_None; Py_INCREF(Py_None);
+  return 0;
+}
+
+static PyMethodDef __pyx_methods_5pysam_9csamtools___pyx_scope_struct_3_genexpr[] = {
+  {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_genexpr = {
+  0, /*nb_add*/
+  0, /*nb_subtract*/
+  0, /*nb_multiply*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_divide*/
+  #endif
+  0, /*nb_remainder*/
+  0, /*nb_divmod*/
+  0, /*nb_power*/
+  0, /*nb_negative*/
+  0, /*nb_positive*/
+  0, /*nb_absolute*/
+  0, /*nb_nonzero*/
+  0, /*nb_invert*/
+  0, /*nb_lshift*/
+  0, /*nb_rshift*/
+  0, /*nb_and*/
+  0, /*nb_xor*/
+  0, /*nb_or*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_coerce*/
+  #endif
+  0, /*nb_int*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_long*/
+  #else
+  0, /*reserved*/
+  #endif
+  0, /*nb_float*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_oct*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_hex*/
+  #endif
+  0, /*nb_inplace_add*/
+  0, /*nb_inplace_subtract*/
+  0, /*nb_inplace_multiply*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*nb_inplace_divide*/
+  #endif
+  0, /*nb_inplace_remainder*/
+  0, /*nb_inplace_power*/
+  0, /*nb_inplace_lshift*/
+  0, /*nb_inplace_rshift*/
+  0, /*nb_inplace_and*/
+  0, /*nb_inplace_xor*/
+  0, /*nb_inplace_or*/
+  0, /*nb_floor_divide*/
+  0, /*nb_true_divide*/
+  0, /*nb_inplace_floor_divide*/
+  0, /*nb_inplace_true_divide*/
+  #if PY_VERSION_HEX >= 0x02050000
+  0, /*nb_index*/
+  #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_genexpr = {
+  0, /*sq_length*/
+  0, /*sq_concat*/
+  0, /*sq_repeat*/
+  0, /*sq_item*/
+  0, /*sq_slice*/
+  0, /*sq_ass_item*/
+  0, /*sq_ass_slice*/
+  0, /*sq_contains*/
+  0, /*sq_inplace_concat*/
+  0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_genexpr = {
+  0, /*mp_length*/
+  0, /*mp_subscript*/
+  0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_genexpr = {
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getreadbuffer*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getwritebuffer*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getsegcount*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getcharbuffer*/
+  #endif
+  #if PY_VERSION_HEX >= 0x02060000
+  0, /*bf_getbuffer*/
+  #endif
+  #if PY_VERSION_HEX >= 0x02060000
+  0, /*bf_releasebuffer*/
+  #endif
+};
+
+static PyTypeObject __pyx_type_5pysam_9csamtools___pyx_scope_struct_3_genexpr = {
+  PyVarObject_HEAD_INIT(0, 0)
+  __Pyx_NAMESTR("pysam.csamtools.__pyx_scope_struct_3_genexpr"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_3_genexpr), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_5pysam_9csamtools___pyx_scope_struct_3_genexpr, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #else
+  0, /*reserved*/
+  #endif
+  0, /*tp_repr*/
+  &__pyx_tp_as_number___pyx_scope_struct_3_genexpr, /*tp_as_number*/
+  &__pyx_tp_as_sequence___pyx_scope_struct_3_genexpr, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping___pyx_scope_struct_3_genexpr, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  &__pyx_tp_as_buffer___pyx_scope_struct_3_genexpr, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_5pysam_9csamtools___pyx_scope_struct_3_genexpr, /*tp_traverse*/
+  __pyx_tp_clear_5pysam_9csamtools___pyx_scope_struct_3_genexpr, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_5pysam_9csamtools___pyx_scope_struct_3_genexpr, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_5pysam_9csamtools___pyx_scope_struct_3_genexpr, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  #if PY_VERSION_HEX >= 0x02060000
+  0, /*tp_version_tag*/
+  #endif
+};
+
+static PyObject *__pyx_tp_new_5pysam_9csamtools___pyx_scope_struct_4_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr *p;
+  PyObject *o = (*t->tp_alloc)(t, 0);
+  if (!o) return 0;
+  p = ((struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr *)o);
+  p->__pyx_outer_scope = 0;
+  p->__pyx_v_x = 0;
+  p->__pyx_t_0 = 0;
+  return o;
+}
+
+static void __pyx_tp_dealloc_5pysam_9csamtools___pyx_scope_struct_4_genexpr(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_outer_scope);
+  Py_CLEAR(p->__pyx_v_x);
+  Py_CLEAR(p->__pyx_t_0);
+  PyObject_GC_Track(o);
+  (*Py_TYPE(o)->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_5pysam_9csamtools___pyx_scope_struct_4_genexpr(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr *)o;
+  if (p->__pyx_outer_scope) {
+    e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e;
+  }
+  if (p->__pyx_v_x) {
+    e = (*v)(p->__pyx_v_x, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_5pysam_9csamtools___pyx_scope_struct_4_genexpr(PyObject *o) {
+  struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr *p = (struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr *)o;
+  PyObject* tmp;
+  tmp = ((PyObject*)p->__pyx_outer_scope);
+  p->__pyx_outer_scope = ((struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_2__open *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->__pyx_v_x);
+  p->__pyx_v_x = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->__pyx_t_0);
+  p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
   Py_XDECREF(tmp);
   return 0;
 }
 
-static PyMethodDef __pyx_methods_5pysam_9csamtools___pyx_scope_struct_1_genexpr[] = {
+static PyMethodDef __pyx_methods_5pysam_9csamtools___pyx_scope_struct_4_genexpr[] = {
   {0, 0, 0, 0}
 };
 
-static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1_genexpr = {
+static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_genexpr = {
   0, /*nb_add*/
   0, /*nb_subtract*/
   0, /*nb_multiply*/
@@ -41231,7 +42703,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1_genexpr = {
   #endif
 };
 
-static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1_genexpr = {
+static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_genexpr = {
   0, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
@@ -41244,13 +42716,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1_genexpr = {
   0, /*sq_inplace_repeat*/
 };
 
-static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1_genexpr = {
+static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_genexpr = {
   0, /*mp_length*/
   0, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
-static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1_genexpr = {
+static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_genexpr = {
   #if PY_MAJOR_VERSION < 3
   0, /*bf_getreadbuffer*/
   #endif
@@ -41271,12 +42743,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1_genexpr = {
   #endif
 };
 
-static PyTypeObject __pyx_type_5pysam_9csamtools___pyx_scope_struct_1_genexpr = {
+static PyTypeObject __pyx_type_5pysam_9csamtools___pyx_scope_struct_4_genexpr = {
   PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.csamtools.__pyx_scope_struct_1_genexpr"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_1_genexpr), /*tp_basicsize*/
+  __Pyx_NAMESTR("pysam.csamtools.__pyx_scope_struct_4_genexpr"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_9csamtools___pyx_scope_struct_4_genexpr), /*tp_basicsize*/
   0, /*tp_itemsize*/
-  __pyx_tp_dealloc_5pysam_9csamtools___pyx_scope_struct_1_genexpr, /*tp_dealloc*/
+  __pyx_tp_dealloc_5pysam_9csamtools___pyx_scope_struct_4_genexpr, /*tp_dealloc*/
   0, /*tp_print*/
   0, /*tp_getattr*/
   0, /*tp_setattr*/
@@ -41286,24 +42758,24 @@ static PyTypeObject __pyx_type_5pysam_9csamtools___pyx_scope_struct_1_genexpr =
   0, /*reserved*/
   #endif
   0, /*tp_repr*/
-  &__pyx_tp_as_number___pyx_scope_struct_1_genexpr, /*tp_as_number*/
-  &__pyx_tp_as_sequence___pyx_scope_struct_1_genexpr, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping___pyx_scope_struct_1_genexpr, /*tp_as_mapping*/
+  &__pyx_tp_as_number___pyx_scope_struct_4_genexpr, /*tp_as_number*/
+  &__pyx_tp_as_sequence___pyx_scope_struct_4_genexpr, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping___pyx_scope_struct_4_genexpr, /*tp_as_mapping*/
   0, /*tp_hash*/
   0, /*tp_call*/
   0, /*tp_str*/
   0, /*tp_getattro*/
   0, /*tp_setattro*/
-  &__pyx_tp_as_buffer___pyx_scope_struct_1_genexpr, /*tp_as_buffer*/
+  &__pyx_tp_as_buffer___pyx_scope_struct_4_genexpr, /*tp_as_buffer*/
   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
   0, /*tp_doc*/
-  __pyx_tp_traverse_5pysam_9csamtools___pyx_scope_struct_1_genexpr, /*tp_traverse*/
-  __pyx_tp_clear_5pysam_9csamtools___pyx_scope_struct_1_genexpr, /*tp_clear*/
+  __pyx_tp_traverse_5pysam_9csamtools___pyx_scope_struct_4_genexpr, /*tp_traverse*/
+  __pyx_tp_clear_5pysam_9csamtools___pyx_scope_struct_4_genexpr, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
   0, /*tp_iter*/
   0, /*tp_iternext*/
-  __pyx_methods_5pysam_9csamtools___pyx_scope_struct_1_genexpr, /*tp_methods*/
+  __pyx_methods_5pysam_9csamtools___pyx_scope_struct_4_genexpr, /*tp_methods*/
   0, /*tp_members*/
   0, /*tp_getset*/
   0, /*tp_base*/
@@ -41313,7 +42785,7 @@ static PyTypeObject __pyx_type_5pysam_9csamtools___pyx_scope_struct_1_genexpr =
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_9csamtools___pyx_scope_struct_1_genexpr, /*tp_new*/
+  __pyx_tp_new_5pysam_9csamtools___pyx_scope_struct_4_genexpr, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -41351,39 +42823,37 @@ static struct PyModuleDef __pyx_moduledef = {
 
 static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_kp_u_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 1, 0, 0},
-  {&__pyx_kp_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0},
-  {&__pyx_kp_s_100, __pyx_k_100, sizeof(__pyx_k_100), 0, 0, 1, 0},
-  {&__pyx_kp_s_102, __pyx_k_102, sizeof(__pyx_k_102), 0, 0, 1, 0},
-  {&__pyx_kp_s_105, __pyx_k_105, sizeof(__pyx_k_105), 0, 0, 1, 0},
-  {&__pyx_kp_s_110, __pyx_k_110, sizeof(__pyx_k_110), 0, 0, 1, 0},
-  {&__pyx_kp_s_112, __pyx_k_112, sizeof(__pyx_k_112), 0, 0, 1, 0},
+  {&__pyx_kp_b_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 0, 0},
+  {&__pyx_kp_s_101, __pyx_k_101, sizeof(__pyx_k_101), 0, 0, 1, 0},
+  {&__pyx_kp_s_104, __pyx_k_104, sizeof(__pyx_k_104), 0, 0, 1, 0},
+  {&__pyx_kp_s_109, __pyx_k_109, sizeof(__pyx_k_109), 0, 0, 1, 0},
+  {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0},
+  {&__pyx_kp_s_111, __pyx_k_111, sizeof(__pyx_k_111), 0, 0, 1, 0},
+  {&__pyx_kp_s_113, __pyx_k_113, sizeof(__pyx_k_113), 0, 0, 1, 0},
   {&__pyx_kp_s_114, __pyx_k_114, sizeof(__pyx_k_114), 0, 0, 1, 0},
   {&__pyx_kp_s_115, __pyx_k_115, sizeof(__pyx_k_115), 0, 0, 1, 0},
-  {&__pyx_kp_s_116, __pyx_k_116, sizeof(__pyx_k_116), 0, 0, 1, 0},
+  {&__pyx_kp_s_118, __pyx_k_118, sizeof(__pyx_k_118), 0, 0, 1, 0},
   {&__pyx_kp_s_119, __pyx_k_119, sizeof(__pyx_k_119), 0, 0, 1, 0},
   {&__pyx_kp_s_120, __pyx_k_120, sizeof(__pyx_k_120), 0, 0, 1, 0},
   {&__pyx_kp_s_121, __pyx_k_121, sizeof(__pyx_k_121), 0, 0, 1, 0},
   {&__pyx_kp_s_122, __pyx_k_122, sizeof(__pyx_k_122), 0, 0, 1, 0},
-  {&__pyx_kp_s_123, __pyx_k_123, sizeof(__pyx_k_123), 0, 0, 1, 0},
-  {&__pyx_kp_s_125, __pyx_k_125, sizeof(__pyx_k_125), 0, 0, 1, 0},
-  {&__pyx_kp_s_128, __pyx_k_128, sizeof(__pyx_k_128), 0, 0, 1, 0},
-  {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
-  {&__pyx_kp_s_131, __pyx_k_131, sizeof(__pyx_k_131), 0, 0, 1, 0},
+  {&__pyx_kp_s_124, __pyx_k_124, sizeof(__pyx_k_124), 0, 0, 1, 0},
+  {&__pyx_kp_s_127, __pyx_k_127, sizeof(__pyx_k_127), 0, 0, 1, 0},
+  {&__pyx_kp_s_130, __pyx_k_130, sizeof(__pyx_k_130), 0, 0, 1, 0},
+  {&__pyx_kp_s_136, __pyx_k_136, sizeof(__pyx_k_136), 0, 0, 1, 0},
   {&__pyx_kp_s_137, __pyx_k_137, sizeof(__pyx_k_137), 0, 0, 1, 0},
   {&__pyx_kp_s_138, __pyx_k_138, sizeof(__pyx_k_138), 0, 0, 1, 0},
-  {&__pyx_kp_s_139, __pyx_k_139, sizeof(__pyx_k_139), 0, 0, 1, 0},
-  {&__pyx_kp_s_141, __pyx_k_141, sizeof(__pyx_k_141), 0, 0, 1, 0},
+  {&__pyx_kp_s_140, __pyx_k_140, sizeof(__pyx_k_140), 0, 0, 1, 0},
+  {&__pyx_kp_s_146, __pyx_k_146, sizeof(__pyx_k_146), 0, 0, 1, 0},
   {&__pyx_kp_s_147, __pyx_k_147, sizeof(__pyx_k_147), 0, 0, 1, 0},
   {&__pyx_kp_s_148, __pyx_k_148, sizeof(__pyx_k_148), 0, 0, 1, 0},
   {&__pyx_kp_s_149, __pyx_k_149, sizeof(__pyx_k_149), 0, 0, 1, 0},
   {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0},
-  {&__pyx_kp_s_150, __pyx_k_150, sizeof(__pyx_k_150), 0, 0, 1, 0},
+  {&__pyx_kp_s_151, __pyx_k_151, sizeof(__pyx_k_151), 0, 0, 1, 0},
   {&__pyx_kp_s_152, __pyx_k_152, sizeof(__pyx_k_152), 0, 0, 1, 0},
-  {&__pyx_kp_s_153, __pyx_k_153, sizeof(__pyx_k_153), 0, 0, 1, 0},
-  {&__pyx_kp_s_157, __pyx_k_157, sizeof(__pyx_k_157), 0, 0, 1, 0},
-  {&__pyx_n_s_159, __pyx_k_159, sizeof(__pyx_k_159), 0, 0, 1, 1},
-  {&__pyx_kp_b_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 0, 0},
-  {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0},
+  {&__pyx_kp_s_156, __pyx_k_156, sizeof(__pyx_k_156), 0, 0, 1, 0},
+  {&__pyx_n_s_158, __pyx_k_158, sizeof(__pyx_k_158), 0, 0, 1, 1},
+  {&__pyx_kp_s_159, __pyx_k_159, sizeof(__pyx_k_159), 0, 0, 1, 0},
   {&__pyx_kp_s_160, __pyx_k_160, sizeof(__pyx_k_160), 0, 0, 1, 0},
   {&__pyx_kp_s_161, __pyx_k_161, sizeof(__pyx_k_161), 0, 0, 1, 0},
   {&__pyx_kp_s_162, __pyx_k_162, sizeof(__pyx_k_162), 0, 0, 1, 0},
@@ -41405,19 +42875,22 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_kp_s_177, __pyx_k_177, sizeof(__pyx_k_177), 0, 0, 1, 0},
   {&__pyx_kp_s_178, __pyx_k_178, sizeof(__pyx_k_178), 0, 0, 1, 0},
   {&__pyx_kp_s_179, __pyx_k_179, sizeof(__pyx_k_179), 0, 0, 1, 0},
-  {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0},
   {&__pyx_kp_s_180, __pyx_k_180, sizeof(__pyx_k_180), 0, 0, 1, 0},
   {&__pyx_kp_s_181, __pyx_k_181, sizeof(__pyx_k_181), 0, 0, 1, 0},
   {&__pyx_kp_s_182, __pyx_k_182, sizeof(__pyx_k_182), 0, 0, 1, 0},
-  {&__pyx_kp_s_183, __pyx_k_183, sizeof(__pyx_k_183), 0, 0, 1, 0},
-  {&__pyx_kp_s_185, __pyx_k_185, sizeof(__pyx_k_185), 0, 0, 1, 0},
+  {&__pyx_kp_s_184, __pyx_k_184, sizeof(__pyx_k_184), 0, 0, 1, 0},
+  {&__pyx_kp_s_188, __pyx_k_188, sizeof(__pyx_k_188), 0, 0, 1, 0},
   {&__pyx_kp_s_189, __pyx_k_189, sizeof(__pyx_k_189), 0, 0, 1, 0},
   {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0},
   {&__pyx_kp_s_190, __pyx_k_190, sizeof(__pyx_k_190), 0, 0, 1, 0},
-  {&__pyx_kp_s_191, __pyx_k_191, sizeof(__pyx_k_191), 0, 0, 1, 0},
+  {&__pyx_kp_s_196, __pyx_k_196, sizeof(__pyx_k_196), 0, 0, 1, 0},
   {&__pyx_kp_s_197, __pyx_k_197, sizeof(__pyx_k_197), 0, 0, 1, 0},
-  {&__pyx_kp_s_198, __pyx_k_198, sizeof(__pyx_k_198), 0, 0, 1, 0},
+  {&__pyx_kp_b_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 0, 0},
+  {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0},
   {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0},
+  {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0},
+  {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 0},
+  {&__pyx_kp_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 0},
   {&__pyx_n_s_262, __pyx_k_262, sizeof(__pyx_k_262), 0, 0, 1, 1},
   {&__pyx_kp_s_264, __pyx_k_264, sizeof(__pyx_k_264), 0, 0, 1, 0},
   {&__pyx_kp_s_269, __pyx_k_269, sizeof(__pyx_k_269), 0, 0, 1, 0},
@@ -41434,13 +42907,16 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s_294, __pyx_k_294, sizeof(__pyx_k_294), 0, 0, 1, 1},
   {&__pyx_kp_s_295, __pyx_k_295, sizeof(__pyx_k_295), 0, 0, 1, 0},
   {&__pyx_kp_u_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 1, 0, 0},
+  {&__pyx_kp_s_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 0, 1, 0},
   {&__pyx_n_s_304, __pyx_k_304, sizeof(__pyx_k_304), 0, 0, 1, 1},
   {&__pyx_n_s_307, __pyx_k_307, sizeof(__pyx_k_307), 0, 0, 1, 1},
   {&__pyx_n_s_310, __pyx_k_310, sizeof(__pyx_k_310), 0, 0, 1, 1},
   {&__pyx_n_s_313, __pyx_k_313, sizeof(__pyx_k_313), 0, 0, 1, 1},
   {&__pyx_n_s_316, __pyx_k_316, sizeof(__pyx_k_316), 0, 0, 1, 1},
   {&__pyx_kp_s_317, __pyx_k_317, sizeof(__pyx_k_317), 0, 0, 1, 0},
-  {&__pyx_kp_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 0},
+  {&__pyx_kp_b_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 0, 0},
+  {&__pyx_kp_b_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 0, 0, 0},
+  {&__pyx_kp_b_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 0, 0},
   {&__pyx_kp_s_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 1, 0},
   {&__pyx_kp_s_38, __pyx_k_38, sizeof(__pyx_k_38), 0, 0, 1, 0},
   {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0},
@@ -41474,6 +42950,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
   {&__pyx_kp_s_90, __pyx_k_90, sizeof(__pyx_k_90), 0, 0, 1, 0},
   {&__pyx_kp_s_93, __pyx_k_93, sizeof(__pyx_k_93), 0, 0, 1, 0},
+  {&__pyx_kp_s_99, __pyx_k_99, sizeof(__pyx_k_99), 0, 0, 1, 0},
   {&__pyx_kp_s__2scB, __pyx_k__2scB, sizeof(__pyx_k__2scB), 0, 0, 1, 0},
   {&__pyx_kp_s__2scH, __pyx_k__2scH, sizeof(__pyx_k__2scH), 0, 0, 1, 0},
   {&__pyx_kp_s__2scI, __pyx_k__2scI, sizeof(__pyx_k__2scI), 0, 0, 1, 0},
@@ -41507,6 +42984,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s__ID, __pyx_k__ID, sizeof(__pyx_k__ID), 0, 0, 1, 1},
   {&__pyx_n_s__IOError, __pyx_k__IOError, sizeof(__pyx_k__IOError), 0, 0, 1, 1},
   {&__pyx_n_s__IS_PYTHON3, __pyx_k__IS_PYTHON3, sizeof(__pyx_k__IS_PYTHON3), 0, 0, 1, 1},
+  {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1},
   {&__pyx_n_s__IndexedReads, __pyx_k__IndexedReads, sizeof(__pyx_k__IndexedReads), 0, 0, 1, 1},
   {&__pyx_n_s__IteratorColumn, __pyx_k__IteratorColumn, sizeof(__pyx_k__IteratorColumn), 0, 0, 1, 1},
   {&__pyx_n_s__IteratorRow, __pyx_k__IteratorRow, sizeof(__pyx_k__IteratorRow), 0, 0, 1, 1},
@@ -41609,6 +43087,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s__f, __pyx_k__f, sizeof(__pyx_k__f), 0, 0, 1, 1},
   {&__pyx_n_s__fastafile, __pyx_k__fastafile, sizeof(__pyx_k__fastafile), 0, 0, 1, 1},
   {&__pyx_n_s__fd, __pyx_k__fd, sizeof(__pyx_k__fd), 0, 0, 1, 1},
+  {&__pyx_n_s__fetch, __pyx_k__fetch, sizeof(__pyx_k__fetch), 0, 0, 1, 1},
   {&__pyx_n_s__fields, __pyx_k__fields, sizeof(__pyx_k__fields), 0, 0, 1, 1},
   {&__pyx_n_s__filename, __pyx_k__filename, sizeof(__pyx_k__filename), 0, 0, 1, 1},
   {&__pyx_n_s__fileno, __pyx_k__fileno, sizeof(__pyx_k__fileno), 0, 0, 1, 1},
@@ -41750,26 +43229,27 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {0, 0, 0, 0, 0, 0, 0}
 };
 static int __Pyx_InitCachedBuiltins(void) {
-  __pyx_builtin_object = __Pyx_GetName(__pyx_b, __pyx_n_s__object); if (!__pyx_builtin_object) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_ord = __Pyx_GetName(__pyx_b, __pyx_n_s__ord); if (!__pyx_builtin_ord) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_map = __Pyx_GetName(__pyx_b, __pyx_n_s__map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_IOError = __Pyx_GetName(__pyx_b, __pyx_n_s__IOError); if (!__pyx_builtin_IOError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_OverflowError = __Pyx_GetName(__pyx_b, __pyx_n_s__OverflowError); if (!__pyx_builtin_OverflowError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 966; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_NotImplementedError = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplementedError); if (!__pyx_builtin_NotImplementedError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_OSError = __Pyx_GetName(__pyx_b, __pyx_n_s__OSError); if (!__pyx_builtin_OSError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_AttributeError = __Pyx_GetName(__pyx_b, __pyx_n_s__AttributeError); if (!__pyx_builtin_AttributeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_zip = __Pyx_GetName(__pyx_b, __pyx_n_s__zip); if (!__pyx_builtin_zip) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_sorted = __Pyx_GetName(__pyx_b, __pyx_n_s__sorted); if (!__pyx_builtin_sorted) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_min = __Pyx_GetName(__pyx_b, __pyx_n_s__min); if (!__pyx_builtin_min) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_max = __Pyx_GetName(__pyx_b, __pyx_n_s__max); if (!__pyx_builtin_max) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_chr = __Pyx_GetName(__pyx_b, __pyx_n_s__chr); if (!__pyx_builtin_chr) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_UnicodeDecodeError = __Pyx_GetName(__pyx_b, __pyx_n_s__UnicodeDecodeError); if (!__pyx_builtin_UnicodeDecodeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_object = __Pyx_GetName(__pyx_b, __pyx_n_s__object); if (!__pyx_builtin_object) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_ord = __Pyx_GetName(__pyx_b, __pyx_n_s__ord); if (!__pyx_builtin_ord) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_map = __Pyx_GetName(__pyx_b, __pyx_n_s__map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_IOError = __Pyx_GetName(__pyx_b, __pyx_n_s__IOError); if (!__pyx_builtin_IOError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_zip = __Pyx_GetName(__pyx_b, __pyx_n_s__zip); if (!__pyx_builtin_zip) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_OverflowError = __Pyx_GetName(__pyx_b, __pyx_n_s__OverflowError); if (!__pyx_builtin_OverflowError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_NotImplementedError = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplementedError); if (!__pyx_builtin_NotImplementedError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_OSError = __Pyx_GetName(__pyx_b, __pyx_n_s__OSError); if (!__pyx_builtin_OSError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_AttributeError = __Pyx_GetName(__pyx_b, __pyx_n_s__AttributeError); if (!__pyx_builtin_AttributeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_sorted = __Pyx_GetName(__pyx_b, __pyx_n_s__sorted); if (!__pyx_builtin_sorted) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_min = __Pyx_GetName(__pyx_b, __pyx_n_s__min); if (!__pyx_builtin_min) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_max = __Pyx_GetName(__pyx_b, __pyx_n_s__max); if (!__pyx_builtin_max) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_chr = __Pyx_GetName(__pyx_b, __pyx_n_s__chr); if (!__pyx_builtin_chr) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_UnicodeDecodeError = __Pyx_GetName(__pyx_b, __pyx_n_s__UnicodeDecodeError); if (!__pyx_builtin_UnicodeDecodeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   return 0;
   __pyx_L1_error:;
   return -1;
@@ -41779,1122 +43259,1136 @@ static int __Pyx_InitCachedConstants(void) {
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
 
-  /* "pysam/csamtools.pyx":64
+  /* "pysam/csamtools.pyx":63
  *         return s
  *     elif PyUnicode_Check(s):
  *         return s.encode('ascii')             # <<<<<<<<<<<<<<
  *     else:
  *         raise TypeError, u"Argument must be string, bytes or unicode."
  */
-  __pyx_k_tuple_2 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_2 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_2);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));
 
-  /* "pysam/csamtools.pyx":84
+  /* "pysam/csamtools.pyx":83
  *         return s
  *     elif PyBytes_Check(s):
  *         return s.decode('ascii')             # <<<<<<<<<<<<<<
  *     else:
  *         # assume unicode
  */
-  __pyx_k_tuple_4 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_4 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_4);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));
 
-  /* "pysam/csamtools.pyx":405
+  /* "pysam/csamtools.pyx":407
  *     def __len__(self):
  *         if self.fastafile == NULL:
  *             raise ValueError( "calling len() on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         return faidx_fetch_nseq(self.fastafile)
  */
-  __pyx_k_tuple_8 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_7)); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_8 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_7)); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_8);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8));
 
-  /* "pysam/csamtools.pyx":438
- *         '''number of :term:`filename` associated with this object.'''
- *         def __get__(self):
- *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
- *             return self._filename
+  /* "pysam/csamtools.pyx":427
+ *         # read index
+ *         if not os.path.exists( self._filename + b".fai" ):
+ *             raise ValueError("could not locate index file")             # <<<<<<<<<<<<<<
  * 
+ *         with open( self._filename + b".fai" ) as inf:
  */
-  __pyx_k_tuple_11 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_11);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_11));
+  __pyx_k_tuple_12 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_11)); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_12);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12));
 
-  /* "pysam/csamtools.pyx":463
+  /* "pysam/csamtools.pyx":430
+ * 
+ *         with open( self._filename + b".fai" ) as inf:
+ *             data = [ x.split("\t") for x in inf ]             # <<<<<<<<<<<<<<
+ *             self._references = tuple(x[0] for x in data)
+ *             self._lengths = tuple(int(x[1]) for x in data)
+ */
+  __pyx_k_tuple_13 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_5)); if (unlikely(!__pyx_k_tuple_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_13);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_13));
+
+  /* "pysam/csamtools.pyx":429
+ *             raise ValueError("could not locate index file")
+ * 
+ *         with open( self._filename + b".fai" ) as inf:             # <<<<<<<<<<<<<<
+ *             data = [ x.split("\t") for x in inf ]
+ *             self._references = tuple(x[0] for x in data)
+ */
+  __pyx_k_tuple_14 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_14);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_14));
+
+  /* "pysam/csamtools.pyx":485
  * 
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         cdef int length
  */
-  __pyx_k_tuple_12 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_12);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12));
+  __pyx_k_tuple_16 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_16);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16));
 
-  /* "pysam/csamtools.pyx":469
+  /* "pysam/csamtools.pyx":491
  * 
  *         if not region:
  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )             # <<<<<<<<<<<<<<
  *             if start is None: start = 0
  *             if end is None: end = max_pos -1
  */
-  __pyx_k_tuple_14 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_13)); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_14);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_14));
+  __pyx_k_tuple_18 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_17)); if (unlikely(!__pyx_k_tuple_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_18);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18));
 
-  /* "pysam/csamtools.pyx":488
+  /* "pysam/csamtools.pyx":510
  *             region = "%s:%i-%i" % (reference, start+1, end)
  *             if PY_MAJOR_VERSION >= 3:
  *                 region = region.encode('ascii')             # <<<<<<<<<<<<<<
  *             seq = fai_fetch( self.fastafile,
  *                              region,
  */
-  __pyx_k_tuple_20 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_20);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20));
-
-  /* "pysam/csamtools.pyx":593
- *         '''number of :term:`filename` associated with this object.'''
- *         def __get__(self):
- *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
- *             return self._filename
- * 
- */
-  __pyx_k_tuple_22 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_22);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22));
+  __pyx_k_tuple_24 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_24);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24));
 
-  /* "pysam/csamtools.pyx":597
+  /* "pysam/csamtools.pyx":626
  * 
  *     def __iter__(self):
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         return self
  * 
  */
-  __pyx_k_tuple_23 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_23);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23));
+  __pyx_k_tuple_26 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_26);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26));
 
-  /* "pysam/csamtools.pyx":789
- *         if self._filename != NULL: free(self._filename )
- *         filename = _my_encodeFilename(filename)
+  /* "pysam/csamtools.pyx":797
+ *         header_to_write = NULL
+ * 
  *         cdef bytes bmode = mode.encode('ascii')             # <<<<<<<<<<<<<<
- *         #cdef char* cfilename
- *         #cfilename = filename.encode(_FILENAME_ENCODING)
+ *         self._filename = filename = _encodeFilename(filename)
+ *         self.isstream = filename == b"-"
  */
-  __pyx_k_tuple_33 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_33);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_33));
+  __pyx_k_tuple_31 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_31);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_31));
 
-  /* "pysam/csamtools.pyx":917
+  /* "pysam/csamtools.pyx":803
+ *         self.isbam = len(mode) > 1 and mode[1] == 'b'
+ * 
+ *         self.isremote = filename.startswith(b"http:") or filename.startswith(b"ftp:")             # <<<<<<<<<<<<<<
+ * 
+ *         cdef char * ctext
+ */
+  __pyx_k_tuple_34 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_b_33)); if (unlikely(!__pyx_k_tuple_34)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_34);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_34));
+  __pyx_k_tuple_36 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_b_35)); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_36);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36));
+
+  /* "pysam/csamtools.pyx":922
  *         returns -1 if reference is not known.
  *         '''
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         reference = _force_bytes(reference)
  *         return pysam_reference2tid( self.samfile.header, reference )
  */
-  __pyx_k_tuple_47 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_47 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_47);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47));
 
-  /* "pysam/csamtools.pyx":924
+  /* "pysam/csamtools.pyx":929
  *         '''
  *         convert numerical :term:`tid` into :term:`reference` name.'''
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         if not 0 <= tid < self.samfile.header.n_targets:
  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
  */
-  __pyx_k_tuple_48 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_48)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_48 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_48)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_48);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_48));
 
-  /* "pysam/csamtools.pyx":932
+  /* "pysam/csamtools.pyx":937
  *         '''
  *         convert numerical :term:`tid` into :term:`reference` name.'''
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         if not 0 <= tid < self.samfile.header.n_targets:
  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
  */
-  __pyx_k_tuple_50 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_50 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_50);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_50));
 
-  /* "pysam/csamtools.pyx":982
+  /* "pysam/csamtools.pyx":987
  *             if len(parts) >= 3: rend = int(parts[2])
  * 
  *         if not reference: return 0, 0, 0, 0             # <<<<<<<<<<<<<<
  * 
  *         rtid = self.gettid( reference )
  */
-  __pyx_k_tuple_52 = PyTuple_Pack(4, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_int_0); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_52 = PyTuple_Pack(4, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_int_0); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_52);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52));
 
-  /* "pysam/csamtools.pyx":1002
+  /* "pysam/csamtools.pyx":1007
  * 
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         if not self.isbam:
  *             raise NotImplementedError("seek only available in bam files")
  */
-  __pyx_k_tuple_55 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_55 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_55);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_55));
 
-  /* "pysam/csamtools.pyx":1004
+  /* "pysam/csamtools.pyx":1009
  *             raise ValueError( "I/O operation on closed file" )
  *         if not self.isbam:
  *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
  *         if self.isstream:
  *             raise OSError("seek no available in streams")
  */
-  __pyx_k_tuple_57 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_57 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_57);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_57));
 
-  /* "pysam/csamtools.pyx":1006
+  /* "pysam/csamtools.pyx":1011
  *             raise NotImplementedError("seek only available in bam files")
  *         if self.isstream:
  *             raise OSError("seek no available in streams")             # <<<<<<<<<<<<<<
  * 
  *         return bam_seek( self.samfile.x.bam, offset, where )
  */
-  __pyx_k_tuple_59 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_58)); if (unlikely(!__pyx_k_tuple_59)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_59 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_58)); if (unlikely(!__pyx_k_tuple_59)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_59);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_59));
 
-  /* "pysam/csamtools.pyx":1015
+  /* "pysam/csamtools.pyx":1020
  *         '''
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         if not self.isbam:
  *             raise NotImplementedError("seek only available in bam files")
  */
-  __pyx_k_tuple_60 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_60 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_60);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60));
 
-  /* "pysam/csamtools.pyx":1017
+  /* "pysam/csamtools.pyx":1022
  *             raise ValueError( "I/O operation on closed file" )
  *         if not self.isbam:
  *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
  * 
  *         return bam_tell( self.samfile.x.bam )
  */
-  __pyx_k_tuple_61 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_k_tuple_61)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_61 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_k_tuple_61)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_61);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_61));
 
-  /* "pysam/csamtools.pyx":1052
+  /* "pysam/csamtools.pyx":1057
  * 
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
  */
-  __pyx_k_tuple_63 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_63 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_63);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_63));
 
-  /* "pysam/csamtools.pyx":1061
+  /* "pysam/csamtools.pyx":1066
  *         if self.isbam:
  *             if not until_eof and not self._hasIndex() and not self.isremote:
  *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
  * 
  *             if callback:
  */
-  __pyx_k_tuple_65 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_64)); if (unlikely(!__pyx_k_tuple_65)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_65 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_64)); if (unlikely(!__pyx_k_tuple_65)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_65);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_65));
 
-  /* "pysam/csamtools.pyx":1064
+  /* "pysam/csamtools.pyx":1069
  * 
  *             if callback:
  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
  *                 return bam_fetch(self.samfile.x.bam,
  */
-  __pyx_k_tuple_67 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_66)); if (unlikely(!__pyx_k_tuple_67)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_67 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_66)); if (unlikely(!__pyx_k_tuple_67)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_67);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_67));
 
-  /* "pysam/csamtools.pyx":1065
+  /* "pysam/csamtools.pyx":1070
  *             if callback:
  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
  *                 return bam_fetch(self.samfile.x.bam,
  *                                  self.index,
  */
-  __pyx_k_tuple_69 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_68)); if (unlikely(!__pyx_k_tuple_69)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_69 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_68)); if (unlikely(!__pyx_k_tuple_69)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_69);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_69));
 
-  /* "pysam/csamtools.pyx":1085
+  /* "pysam/csamtools.pyx":1090
  *         else:
  *             if has_coord:
  *                 raise ValueError ("fetching by region is not available for sam files" )             # <<<<<<<<<<<<<<
  * 
  *             if callback:
  */
-  __pyx_k_tuple_71 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_70)); if (unlikely(!__pyx_k_tuple_71)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_71 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_70)); if (unlikely(!__pyx_k_tuple_71)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_71);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_71));
 
-  /* "pysam/csamtools.pyx":1088
+  /* "pysam/csamtools.pyx":1093
  * 
  *             if callback:
  *                 raise NotImplementedError( "callback not implemented yet" )             # <<<<<<<<<<<<<<
  * 
  *             if self.samfile.header == NULL:
  */
-  __pyx_k_tuple_73 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_72)); if (unlikely(!__pyx_k_tuple_73)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_73 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_72)); if (unlikely(!__pyx_k_tuple_73)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_73);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_73));
 
-  /* "pysam/csamtools.pyx":1091
+  /* "pysam/csamtools.pyx":1096
  * 
  *             if self.samfile.header == NULL:
  *                 raise ValueError( "fetch called for samfile without header")             # <<<<<<<<<<<<<<
  * 
  *             # check if targets are defined
  */
-  __pyx_k_tuple_75 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_74)); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_75 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_74)); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_75);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_75));
 
-  /* "pysam/csamtools.pyx":1096
+  /* "pysam/csamtools.pyx":1101
  *             # give warning, sam_read1 segfaults
  *             if self.samfile.header.n_targets == 0:
  *                 warnings.warn( "fetch called for samfile without header")             # <<<<<<<<<<<<<<
  * 
  *             return IteratorRowAll( self, reopen=reopen )
  */
-  __pyx_k_tuple_76 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_74)); if (unlikely(!__pyx_k_tuple_76)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_76 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_74)); if (unlikely(!__pyx_k_tuple_76)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_76);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_76));
 
-  /* "pysam/csamtools.pyx":1137
+  /* "pysam/csamtools.pyx":1142
  * 
  *         if mate_data.mate == NULL:
  *             raise ValueError( "mate not found" )             # <<<<<<<<<<<<<<
  * 
  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
  */
-  __pyx_k_tuple_80 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_79)); if (unlikely(!__pyx_k_tuple_80)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_80 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_79)); if (unlikely(!__pyx_k_tuple_80)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_80);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_80));
 
-  /* "pysam/csamtools.pyx":1162
+  /* "pysam/csamtools.pyx":1167
  * 
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
  */
-  __pyx_k_tuple_82 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_82)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_82 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_82)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_82);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_82));
 
-  /* "pysam/csamtools.pyx":1171
+  /* "pysam/csamtools.pyx":1176
  *         if self.isbam:
  *             if not until_eof and not self._hasIndex() and not self.isremote:
  *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
  * 
  *             if not region:
  */
-  __pyx_k_tuple_83 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_64)); if (unlikely(!__pyx_k_tuple_83)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_83 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_64)); if (unlikely(!__pyx_k_tuple_83)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_83);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_83));
 
-  /* "pysam/csamtools.pyx":1174
+  /* "pysam/csamtools.pyx":1179
  * 
  *             if not region:
  *                 raise ValueError( "counting functionality requires a region/reference" )             # <<<<<<<<<<<<<<
  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )
  *             bam_fetch(self.samfile.x.bam,
  */
-  __pyx_k_tuple_85 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_84)); if (unlikely(!__pyx_k_tuple_85)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_85 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_84)); if (unlikely(!__pyx_k_tuple_85)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_85);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_85));
 
-  /* "pysam/csamtools.pyx":1175
+  /* "pysam/csamtools.pyx":1180
  *             if not region:
  *                 raise ValueError( "counting functionality requires a region/reference" )
  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
  *             bam_fetch(self.samfile.x.bam,
  *                              self.index,
  */
-  __pyx_k_tuple_86 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_68)); if (unlikely(!__pyx_k_tuple_86)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_86 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_68)); if (unlikely(!__pyx_k_tuple_86)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_86);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_86));
 
-  /* "pysam/csamtools.pyx":1185
+  /* "pysam/csamtools.pyx":1190
  *             return counter
  *         else:
  *             raise ValueError ("count for a region is not available for sam files" )             # <<<<<<<<<<<<<<
  * 
  *     def pileup( self,
  */
-  __pyx_k_tuple_88 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_87)); if (unlikely(!__pyx_k_tuple_88)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_88 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_87)); if (unlikely(!__pyx_k_tuple_88)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_88);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_88));
 
-  /* "pysam/csamtools.pyx":1244
+  /* "pysam/csamtools.pyx":1249
  * 
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
  */
-  __pyx_k_tuple_89 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_89)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_89 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_89)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_89);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_89));
 
-  /* "pysam/csamtools.pyx":1249
+  /* "pysam/csamtools.pyx":1254
  * 
  *         if self.isbam:
  *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )             # <<<<<<<<<<<<<<
  * 
  *             if callback:
  */
-  __pyx_k_tuple_91 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_90)); if (unlikely(!__pyx_k_tuple_91)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_91 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_90)); if (unlikely(!__pyx_k_tuple_91)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_91);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_91));
 
-  /* "pysam/csamtools.pyx":1252
+  /* "pysam/csamtools.pyx":1257
  * 
  *             if callback:
  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
  * 
  *                 buf = bam_plbuf_init( <bam_pileup_f>pileup_callback, <void*>callback )
  */
-  __pyx_k_tuple_92 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_66)); if (unlikely(!__pyx_k_tuple_92)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_92 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_66)); if (unlikely(!__pyx_k_tuple_92)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_92);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_92));
 
-  /* "pysam/csamtools.pyx":1273
+  /* "pysam/csamtools.pyx":1278
  * 
  *         else:
  *             raise NotImplementedError( "pileup of samfiles not implemented yet" )             # <<<<<<<<<<<<<<
  * 
  *     def close( self ):
  */
-  __pyx_k_tuple_94 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_93)); if (unlikely(!__pyx_k_tuple_94)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_94 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_93)); if (unlikely(!__pyx_k_tuple_94)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_94);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_94));
 
-  /* "pysam/csamtools.pyx":1317
- *         '''number of :term:`filename` associated with this object.'''
- *         def __get__(self):
- *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
- *             return self._filename
- * 
- */
-  __pyx_k_tuple_95 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_95)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_95);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_95));
-
-  /* "pysam/csamtools.pyx":1323
+  /* "pysam/csamtools.pyx":1326
  *         '''number of :term:`reference` sequences in the file.'''
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             return self.samfile.header.n_targets
  * 
  */
-  __pyx_k_tuple_96 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_96)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_96);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_96));
+  __pyx_k_tuple_95 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_95)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_95);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_95));
 
-  /* "pysam/csamtools.pyx":1329
+  /* "pysam/csamtools.pyx":1332
  *         """tuple with the names of :term:`reference` sequences."""
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             t = []
  *             for x from 0 <= x < self.samfile.header.n_targets:
  */
-  __pyx_k_tuple_97 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_97)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_97);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_97));
+  __pyx_k_tuple_96 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_96)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_96);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_96));
 
-  /* "pysam/csamtools.pyx":1340
+  /* "pysam/csamtools.pyx":1343
  *         """
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             t = []
  *             for x from 0 <= x < self.samfile.header.n_targets:
  */
-  __pyx_k_tuple_98 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_98)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_98);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_98));
+  __pyx_k_tuple_97 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_97)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_97);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_97));
 
-  /* "pysam/csamtools.pyx":1350
+  /* "pysam/csamtools.pyx":1353
  *         """
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )
  *             if self.index == NULL:
  */
-  __pyx_k_tuple_99 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_99)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_99);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_99));
+  __pyx_k_tuple_98 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_98)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_98);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_98));
 
-  /* "pysam/csamtools.pyx":1351
+  /* "pysam/csamtools.pyx":1354
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )             # <<<<<<<<<<<<<<
  *             if self.index == NULL:
  *                 raise ValueError( "mapping information not recorded in index or index not available")
  */
-  __pyx_k_tuple_101 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_100)); if (unlikely(!__pyx_k_tuple_101)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_101);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_101));
+  __pyx_k_tuple_100 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_99)); if (unlikely(!__pyx_k_tuple_100)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_100);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_100));
 
-  /* "pysam/csamtools.pyx":1353
+  /* "pysam/csamtools.pyx":1356
  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )
  *             if self.index == NULL:
  *                 raise ValueError( "mapping information not recorded in index or index not available")             # <<<<<<<<<<<<<<
  * 
  *             cdef int tid
  */
-  __pyx_k_tuple_103 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_102)); if (unlikely(!__pyx_k_tuple_103)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_103);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_103));
+  __pyx_k_tuple_102 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_101)); if (unlikely(!__pyx_k_tuple_102)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_102);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_102));
 
-  /* "pysam/csamtools.pyx":1365
+  /* "pysam/csamtools.pyx":1368
  *         """
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )
  *             cdef int tid
  */
-  __pyx_k_tuple_104 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_104)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_104);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_104));
+  __pyx_k_tuple_103 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_103)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_103);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_103));
 
-  /* "pysam/csamtools.pyx":1366
+  /* "pysam/csamtools.pyx":1369
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )             # <<<<<<<<<<<<<<
  *             cdef int tid
  *             cdef uint32_t total = 0
  */
-  __pyx_k_tuple_106 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_105)); if (unlikely(!__pyx_k_tuple_106)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_106);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_106));
+  __pyx_k_tuple_105 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_104)); if (unlikely(!__pyx_k_tuple_105)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_105);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_105));
 
-  /* "pysam/csamtools.pyx":1378
+  /* "pysam/csamtools.pyx":1381
  *         '''full contents of the :term:`sam file` header as a string.'''
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             return from_string_and_size(self.samfile.header.text, self.samfile.header.l_text)
  * 
  */
-  __pyx_k_tuple_107 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_107)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_107);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_107));
+  __pyx_k_tuple_106 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_106)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_106);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_106));
 
-  /* "pysam/csamtools.pyx":1386
+  /* "pysam/csamtools.pyx":1389
  *         '''
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *             result = {}
  */
-  __pyx_k_tuple_108 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_108)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_108);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_108));
+  __pyx_k_tuple_107 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_107)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_107);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_107));
 
-  /* "pysam/csamtools.pyx":1393
+  /* "pysam/csamtools.pyx":1396
  *                 # convert to python string (note: call self.text to create 0-terminated string)
  *                 t = self.text
  *                 for line in t.split("\n"):             # <<<<<<<<<<<<<<
  *                     if not line.strip(): continue
  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
  */
-  __pyx_k_tuple_109 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_k_tuple_109)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_109);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_109));
+  __pyx_k_tuple_108 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_k_tuple_108)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_108);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_108));
 
-  /* "pysam/csamtools.pyx":1395
+  /* "pysam/csamtools.pyx":1398
  *                 for line in t.split("\n"):
  *                     if not line.strip(): continue
  *                     assert line.startswith("@"), "header line without '@': '%s'" % line             # <<<<<<<<<<<<<<
  *                     fields = line[1:].split("\t")
  *                     record = fields[0]
  */
-  __pyx_k_tuple_111 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_110)); if (unlikely(!__pyx_k_tuple_111)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_111);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_111));
+  __pyx_k_tuple_110 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_109)); if (unlikely(!__pyx_k_tuple_110)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_110);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_110));
 
-  /* "pysam/csamtools.pyx":1396
+  /* "pysam/csamtools.pyx":1399
  *                     if not line.strip(): continue
  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
  *                     fields = line[1:].split("\t")             # <<<<<<<<<<<<<<
  *                     record = fields[0]
  *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)
  */
-  __pyx_k_tuple_113 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_5)); if (unlikely(!__pyx_k_tuple_113)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_113);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_113));
+  __pyx_k_tuple_112 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_5)); if (unlikely(!__pyx_k_tuple_112)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_112);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_112));
 
-  /* "pysam/csamtools.pyx":1409
+  /* "pysam/csamtools.pyx":1412
  *                     for field in fields[1:]:
  *                         if ":" not in field:
  *                             raise ValueError("malformatted header: no ':' in field" )             # <<<<<<<<<<<<<<
  *                         key, value = field.split(":",1)
  *                         # uppercase keys must be valid
  */
-  __pyx_k_tuple_117 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_116)); if (unlikely(!__pyx_k_tuple_117)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_117);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_117));
+  __pyx_k_tuple_116 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_115)); if (unlikely(!__pyx_k_tuple_116)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_116);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_116));
 
-  /* "pysam/csamtools.pyx":1410
+  /* "pysam/csamtools.pyx":1413
  *                         if ":" not in field:
  *                             raise ValueError("malformatted header: no ':' in field" )
  *                         key, value = field.split(":",1)             # <<<<<<<<<<<<<<
  *                         # uppercase keys must be valid
  *                         # lowercase are permitted for user fields
  */
-  __pyx_k_tuple_118 = PyTuple_Pack(2, ((PyObject *)__pyx_kp_s_115), __pyx_int_1); if (unlikely(!__pyx_k_tuple_118)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_118);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_118));
+  __pyx_k_tuple_117 = PyTuple_Pack(2, ((PyObject *)__pyx_kp_s_114), __pyx_int_1); if (unlikely(!__pyx_k_tuple_117)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_117);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_117));
 
-  /* "pysam/csamtools.pyx":1508
+  /* "pysam/csamtools.pyx":1511
  *         dest.text = <char*>calloc( len(text), sizeof(char))
  *         dest.l_text = len(text)
  *         cdef bytes btext = text.encode('ascii')             # <<<<<<<<<<<<<<
  *         strncpy( dest.text, btext, dest.l_text )
  * 
  */
-  __pyx_k_tuple_124 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_124)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_124);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_124));
+  __pyx_k_tuple_123 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_123)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_123);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_123));
 
-  /* "pysam/csamtools.pyx":1528
+  /* "pysam/csamtools.pyx":1531
  *                 seqname, seqlen = seqs[x]
  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
  *                 bseqname = seqname.encode('ascii')             # <<<<<<<<<<<<<<
  *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )
  *                 dest.target_len[x] = seqlen
  */
-  __pyx_k_tuple_126 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_126)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_126);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_126));
+  __pyx_k_tuple_125 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_125)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_125);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_125));
 
-  /* "pysam/csamtools.pyx":1543
+  /* "pysam/csamtools.pyx":1546
  *     ###############################################################
  *     def __iter__(self):
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *         if not self.isbam and self.samfile.header.n_targets == 0:
  *                 raise NotImplementedError( "can not iterate over samfile without header")
  */
-  __pyx_k_tuple_127 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_127)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_127);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_127));
+  __pyx_k_tuple_126 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_126)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_126);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_126));
 
-  /* "pysam/csamtools.pyx":1545
+  /* "pysam/csamtools.pyx":1548
  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *         if not self.isbam and self.samfile.header.n_targets == 0:
  *                 raise NotImplementedError( "can not iterate over samfile without header")             # <<<<<<<<<<<<<<
  *         return self
  * 
  */
-  __pyx_k_tuple_129 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_128)); if (unlikely(!__pyx_k_tuple_129)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_129);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_129));
+  __pyx_k_tuple_128 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_127)); if (unlikely(!__pyx_k_tuple_128)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_128);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_128));
 
-  /* "pysam/csamtools.pyx":1625
+  /* "pysam/csamtools.pyx":1628
  * 
  *         if not samfile._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         if not samfile._hasIndex():
  */
-  __pyx_k_tuple_130 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_130)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_130);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_130));
+  __pyx_k_tuple_129 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_129)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_129);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_129));
 
-  /* "pysam/csamtools.pyx":1628
+  /* "pysam/csamtools.pyx":1631
  * 
  *         if not samfile._hasIndex():
  *             raise ValueError( "no index available for iteration" )             # <<<<<<<<<<<<<<
  * 
  *         # makes sure that samfile stays alive as long as the
  */
-  __pyx_k_tuple_132 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_131)); if (unlikely(!__pyx_k_tuple_132)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_132);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_132));
+  __pyx_k_tuple_131 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_130)); if (unlikely(!__pyx_k_tuple_131)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_131);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_131));
 
-  /* "pysam/csamtools.pyx":1700
+  /* "pysam/csamtools.pyx":1703
  * 
  *         if not samfile._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         if samfile.isbam: mode = b"rb"
  */
-  __pyx_k_tuple_133 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_133)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_133);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_133));
+  __pyx_k_tuple_132 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_132)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_132);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_132));
 
-  /* "pysam/csamtools.pyx":1755
+  /* "pysam/csamtools.pyx":1758
  *     def __cinit__(self, Samfile samfile):
  *         assert samfile._isOpen()
  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
  *         self.samfile = samfile
  *         self.tid = -1
  */
-  __pyx_k_tuple_134 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_68)); if (unlikely(!__pyx_k_tuple_134)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_134);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_134));
+  __pyx_k_tuple_133 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_68)); if (unlikely(!__pyx_k_tuple_133)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_133);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_133));
 
-  /* "pysam/csamtools.pyx":1805
+  /* "pysam/csamtools.pyx":1808
  * 
  *         if not samfile._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         if not samfile._isOpen():
  */
-  __pyx_k_tuple_135 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_135)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_135);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_135));
+  __pyx_k_tuple_134 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_134)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_134);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_134));
 
-  /* "pysam/csamtools.pyx":1808
+  /* "pysam/csamtools.pyx":1811
  * 
  *         if not samfile._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
  *         assert samfile.isbam, "can only use this iterator on bam files"
  */
-  __pyx_k_tuple_136 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_10)); if (unlikely(!__pyx_k_tuple_136)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_136);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_136));
+  __pyx_k_tuple_135 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_k_tuple_135)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_135);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_135));
 
-  /* "pysam/csamtools.pyx":2106
+  /* "pysam/csamtools.pyx":2109
  *             self.cnext()
  *             if self.n_plp < 0:
  *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
  * 
  *             if self.plp == NULL:
  */
-  __pyx_k_tuple_142 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_141)); if (unlikely(!__pyx_k_tuple_142)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_142);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_142));
+  __pyx_k_tuple_141 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_140)); if (unlikely(!__pyx_k_tuple_141)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_141);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_141));
 
-  /* "pysam/csamtools.pyx":2142
+  /* "pysam/csamtools.pyx":2145
  * 
  *             if self.n_plp < 0:
  *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
  * 
  *             # return result, if within same reference
  */
-  __pyx_k_tuple_143 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_141)); if (unlikely(!__pyx_k_tuple_143)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_143);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_143));
+  __pyx_k_tuple_142 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_140)); if (unlikely(!__pyx_k_tuple_142)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_142);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_142));
 
-  /* "pysam/csamtools.pyx":2305
+  /* "pysam/csamtools.pyx":2308
  *             qual = self.qual
  *         else:
  *             seq = self.seq.decode('ascii')             # <<<<<<<<<<<<<<
  *             qual = self.qual.decode('ascii')
  *         return "\t".join(map(str, (self.qname,
  */
-  __pyx_k_tuple_145 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_145)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_145);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_145));
+  __pyx_k_tuple_144 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_144)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_144);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_144));
 
-  /* "pysam/csamtools.pyx":2306
+  /* "pysam/csamtools.pyx":2309
  *         else:
  *             seq = self.seq.decode('ascii')
  *             qual = self.qual.decode('ascii')             # <<<<<<<<<<<<<<
  *         return "\t".join(map(str, (self.qname,
  *                                    self.flag,
  */
-  __pyx_k_tuple_146 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_146)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_146);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_146));
+  __pyx_k_tuple_145 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_145)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_145);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_145));
 
-  /* "pysam/csamtools.pyx":2766
+  /* "pysam/csamtools.pyx":2773
  *                 for pytag, value in tags:
  *                     if not type(pytag) is bytes:
  *                         pytag = pytag.encode('ascii')             # <<<<<<<<<<<<<<
  *                     t = type(value)
  * 
  */
-  __pyx_k_tuple_151 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_151)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_151);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_151));
+  __pyx_k_tuple_150 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_150)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_150);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_150));
 
-  /* "pysam/csamtools.pyx":2794
+  /* "pysam/csamtools.pyx":2801
  *                         datafmt = "2sccI%i%s" % (len(value), datafmt)
  *                         args.extend( [pytag[:2],
  *                                       pytype.encode('ascii'),             # <<<<<<<<<<<<<<
  *                                       datatype.encode('ascii'),
  *                                       len(value)] + list(value) )
  */
-  __pyx_k_tuple_154 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_154)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_154);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_154));
+  __pyx_k_tuple_153 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_153)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_153);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_153));
 
-  /* "pysam/csamtools.pyx":2795
+  /* "pysam/csamtools.pyx":2802
  *                         args.extend( [pytag[:2],
  *                                       pytype.encode('ascii'),
  *                                       datatype.encode('ascii'),             # <<<<<<<<<<<<<<
  *                                       len(value)] + list(value) )
  *                         fmts.append( datafmt )
  */
-  __pyx_k_tuple_155 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_155)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_155);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_155));
+  __pyx_k_tuple_154 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_154)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_154);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_154));
 
-  /* "pysam/csamtools.pyx":2818
+  /* "pysam/csamtools.pyx":2825
  *                         # Note: hex strings (H) are not supported yet
  *                         if t is not bytes:
  *                             value = value.encode('ascii')             # <<<<<<<<<<<<<<
  *                         if len(value) == 1:
  *                             fmt, pytype = "2scc", 'A'
  */
-  __pyx_k_tuple_156 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_156)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_156);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_156));
+  __pyx_k_tuple_155 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_155)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_155);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_155));
 
-  /* "pysam/csamtools.pyx":2825
+  /* "pysam/csamtools.pyx":2832
  * 
  *                     args.extend( [pytag[:2],
  *                                   pytype.encode('ascii'),             # <<<<<<<<<<<<<<
  *                                   value ] )
  * 
  */
-  __pyx_k_tuple_158 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_158)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_158);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_158));
+  __pyx_k_tuple_157 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_157)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_157);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_157));
 
-  /* "pysam/csamtools.pyx":3264
+  /* "pysam/csamtools.pyx":3271
  *     '''
  *     def __init__(self):
  *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
  * 
  *     def __str__(self):
  */
-  __pyx_k_tuple_184 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_183)); if (unlikely(!__pyx_k_tuple_184)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_184);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_184));
+  __pyx_k_tuple_183 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_182)); if (unlikely(!__pyx_k_tuple_183)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_183);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_183));
 
-  /* "pysam/csamtools.pyx":3290
+  /* "pysam/csamtools.pyx":3297
  * 
  *             if self.plp == NULL or self.plp[0] == NULL:
  *                 raise ValueError("PileupProxy accessed after iterator finished")             # <<<<<<<<<<<<<<
  * 
  *             # warning: there could be problems if self.n and self.buf are
  */
-  __pyx_k_tuple_186 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_185)); if (unlikely(!__pyx_k_tuple_186)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_186);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_186));
+  __pyx_k_tuple_185 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_184)); if (unlikely(!__pyx_k_tuple_185)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_185);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_185));
 
-  /* "pysam/csamtools.pyx":3303
+  /* "pysam/csamtools.pyx":3310
  * 
  *     def __init__(self):
  *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
  * 
  *     def __str__(self):
  */
-  __pyx_k_tuple_187 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_183)); if (unlikely(!__pyx_k_tuple_187)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_187);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_187));
+  __pyx_k_tuple_186 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_182)); if (unlikely(!__pyx_k_tuple_186)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_186);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_186));
 
-  /* "pysam/csamtools.pyx":3416
+  /* "pysam/csamtools.pyx":3423
  *         # recover. Thus redirect output to file with -o option.
  *         if method == "view":
  *             if "-o" in args: raise ValueError("option -o is forbidden in samtools view")             # <<<<<<<<<<<<<<
  *             args = ( "-o", stdout_f ) + args
  * 
  */
-  __pyx_k_tuple_192 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_191)); if (unlikely(!__pyx_k_tuple_192)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_192);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_192));
+  __pyx_k_tuple_191 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_190)); if (unlikely(!__pyx_k_tuple_191)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_191);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_191));
 
-  /* "pysam/csamtools.pyx":3441
+  /* "pysam/csamtools.pyx":3448
  *         stdout_save.restore()
  *         try:
  *             with open( stdout_f, "r") as inf:             # <<<<<<<<<<<<<<
  *                 out_stdout = inf.readlines()
  *         except UnicodeDecodeError:
  */
-  __pyx_k_tuple_193 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_tuple_193)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_193);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_193));
+  __pyx_k_tuple_192 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_tuple_192)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_192);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_192));
 
-  /* "pysam/csamtools.pyx":3444
+  /* "pysam/csamtools.pyx":3451
  *                 out_stdout = inf.readlines()
  *         except UnicodeDecodeError:
  *             with open( stdout_f, "rb") as inf:             # <<<<<<<<<<<<<<
  *                 # read binary output
  *                 out_stdout = inf.read()
  */
-  __pyx_k_tuple_194 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_tuple_194)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_194);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_194));
+  __pyx_k_tuple_193 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_tuple_193)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_193);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_193));
 
-  /* "pysam/csamtools.pyx":3454
+  /* "pysam/csamtools.pyx":3461
  *     pysam_unset_stderr()
  *     try:
  *         with open( stderr_f, "r") as inf:             # <<<<<<<<<<<<<<
  *             out_stderr = inf.readlines()
  *     except UnicodeDecodeError:
  */
-  __pyx_k_tuple_195 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_tuple_195)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_195);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_195));
+  __pyx_k_tuple_194 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_tuple_194)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_194);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_194));
 
-  /* "pysam/csamtools.pyx":3457
+  /* "pysam/csamtools.pyx":3464
  *             out_stderr = inf.readlines()
  *     except UnicodeDecodeError:
  *         with open( stderr_f, "rb") as inf:             # <<<<<<<<<<<<<<
  *             # read binary output
  *             out_stderr = inf.read()
  */
-  __pyx_k_tuple_196 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_tuple_196)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_196);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_196));
+  __pyx_k_tuple_195 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_tuple_195)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_195);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_195));
 
-  /* "pysam/csamtools.pyx":143
+  /* "pysam/csamtools.pyx":142
  * else:
  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
  * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )             # <<<<<<<<<<<<<<
  * 
  * #####################################################################
  */
-  __pyx_k_tuple_265 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_264)); if (unlikely(!__pyx_k_tuple_265)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_265 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_264)); if (unlikely(!__pyx_k_tuple_265)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_265);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_265));
 
-  /* "pysam/csamtools.pyx":267
+  /* "pysam/csamtools.pyx":266
  *         list of reads (:class:`pysam.PileupRead`) aligned to this column
  *     '''
  *     def __str__(self):             # <<<<<<<<<<<<<<
  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
  *             "\n" + "\n".join( map(str, self.pileups) )
  */
-  __pyx_k_tuple_267 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_267)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_267 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_267)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_267);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_267));
-  __pyx_k_codeobj_268 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_267, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s____str__, 267, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_268)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_268 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_267, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s____str__, 266, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_268)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":315
+  /* "pysam/csamtools.pyx":314
  *     stderr is captured.
  *     '''
  *     def __init__(self):             # <<<<<<<<<<<<<<
  *         return
  *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
  */
-  __pyx_k_tuple_273 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_273)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_273 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_273)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_273);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_273));
-  __pyx_k_codeobj_274 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_273, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s____init__, 315, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_274)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_274 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_273, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s____init__, 314, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_274)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":321
+  /* "pysam/csamtools.pyx":320
  *         self.stderr_save.setfd( self.stderr_h )
  * 
  *     def readAndRelease( self ):             # <<<<<<<<<<<<<<
  *         return []
  *         self.stderr_save.restore()
  */
-  __pyx_k_tuple_276 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_276)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_276 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_276)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_276);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_276));
-  __pyx_k_codeobj_277 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_276, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__readAndRelease, 321, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_277)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_277 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_276, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__readAndRelease, 320, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_277)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":330
+  /* "pysam/csamtools.pyx":329
  *         return lines
  * 
  *     def release(self):             # <<<<<<<<<<<<<<
  *         return
  *         self.stderr_save.restore()
  */
-  __pyx_k_tuple_279 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_279)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_279 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_279)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_279);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_279));
-  __pyx_k_codeobj_280 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_279, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__release, 330, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_280)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_280 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_279, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__release, 329, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_280)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":336
+  /* "pysam/csamtools.pyx":335
  *             os.remove( self.stderr_f )
  * 
  *     def __del__(self):             # <<<<<<<<<<<<<<
  *         self.release()
  * 
  */
-  __pyx_k_tuple_282 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_282)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_282 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_282)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_282);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_282));
-  __pyx_k_codeobj_283 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_282, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s____del__, 336, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_283)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_283 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_282, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s____del__, 335, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_283)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":341
+  /* "pysam/csamtools.pyx":340
  * class StderrStoreWindows():
  *     '''does nothing. stderr can't be redirected on windows'''
  *     def __init__(self): pass             # <<<<<<<<<<<<<<
  *     def readAndRelease(self): return []
  *     def release(self): pass
  */
-  __pyx_k_tuple_286 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_286)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_286 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_286)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_286);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_286));
-  __pyx_k_codeobj_287 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_286, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s____init__, 341, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_287)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_287 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_286, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s____init__, 340, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_287)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":342
+  /* "pysam/csamtools.pyx":341
  *     '''does nothing. stderr can't be redirected on windows'''
  *     def __init__(self): pass
  *     def readAndRelease(self): return []             # <<<<<<<<<<<<<<
  *     def release(self): pass
  * 
  */
-  __pyx_k_tuple_289 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_289)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_289 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_289)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_289);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_289));
-  __pyx_k_codeobj_290 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_289, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__readAndRelease, 342, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_290)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_290 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_289, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__readAndRelease, 341, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_290)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":343
+  /* "pysam/csamtools.pyx":342
  *     def __init__(self): pass
  *     def readAndRelease(self): return []
  *     def release(self): pass             # <<<<<<<<<<<<<<
  * 
  * if platform.system()=='Windows':
  */
-  __pyx_k_tuple_292 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_292)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_292 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_292)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_292);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_292));
-  __pyx_k_codeobj_293 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_292, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__release, 343, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_293)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_293 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_292, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__release, 342, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_293)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":361
+  /* "pysam/csamtools.pyx":360
  * 
  * # order of records within sam headers
  * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO" )             # <<<<<<<<<<<<<<
  * 
  * # type conversions within sam header records
  */
-  __pyx_k_tuple_296 = PyTuple_Pack(5, ((PyObject *)__pyx_n_s__HD), ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_n_s__RG), ((PyObject *)__pyx_n_s__PG), ((PyObject *)__pyx_n_s__CO)); if (unlikely(!__pyx_k_tuple_296)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_296 = PyTuple_Pack(5, ((PyObject *)__pyx_n_s__HD), ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_n_s__RG), ((PyObject *)__pyx_n_s__PG), ((PyObject *)__pyx_n_s__CO)); if (unlikely(!__pyx_k_tuple_296)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_296);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_296));
 
-  /* "pysam/csamtools.pyx":371
+  /* "pysam/csamtools.pyx":370
  * 
  * # output order of fields within records
  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),             # <<<<<<<<<<<<<<
  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS", "PG" ),
  */
-  __pyx_k_tuple_297 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__VN), ((PyObject *)__pyx_n_s__SO), ((PyObject *)__pyx_n_s__GO)); if (unlikely(!__pyx_k_tuple_297)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_297 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__VN), ((PyObject *)__pyx_n_s__SO), ((PyObject *)__pyx_n_s__GO)); if (unlikely(!__pyx_k_tuple_297)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_297);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_297));
 
-  /* "pysam/csamtools.pyx":372
+  /* "pysam/csamtools.pyx":371
  * # output order of fields within records
  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),             # <<<<<<<<<<<<<<
  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS", "PG" ),
  *                        "PG" : ( "PN", "ID", "VN", "CL", "PP" ), }
  */
-  __pyx_k_tuple_298 = PyTuple_Pack(6, ((PyObject *)__pyx_n_s__SN), ((PyObject *)__pyx_n_s__LN), ((PyObject *)__pyx_n_s__AS), ((PyObject *)__pyx_n_s__M5), ((PyObject *)__pyx_n_s__UR), ((PyObject *)__pyx_n_s__SP)); if (unlikely(!__pyx_k_tuple_298)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_298 = PyTuple_Pack(6, ((PyObject *)__pyx_n_s__SN), ((PyObject *)__pyx_n_s__LN), ((PyObject *)__pyx_n_s__AS), ((PyObject *)__pyx_n_s__M5), ((PyObject *)__pyx_n_s__UR), ((PyObject *)__pyx_n_s__SP)); if (unlikely(!__pyx_k_tuple_298)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_298);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_298));
 
-  /* "pysam/csamtools.pyx":373
+  /* "pysam/csamtools.pyx":372
  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS", "PG" ),             # <<<<<<<<<<<<<<
  *                        "PG" : ( "PN", "ID", "VN", "CL", "PP" ), }
  * 
  */
-  __pyx_k_tuple_299 = PyTuple_Pack(12, ((PyObject *)__pyx_n_s__ID), ((PyObject *)__pyx_n_s__SM), ((PyObject *)__pyx_n_s__LB), ((PyObject *)__pyx_n_s__DS), ((PyObject *)__pyx_n_s__PU), ((PyObject *)__pyx_n_s__PI), ((PyObject *)__pyx_n_s__CN), ((PyObject *)__pyx_n_s__DT), ((PyObject *)__pyx_n_s__PL), ((PyObject *)__pyx_n_s__FO), ((PyObject *)__pyx_n_s__KS), ((PyObject *)__pyx_n_s__PG)); if (unlikely(!__pyx_k_tuple_299)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LI [...]
+  __pyx_k_tuple_299 = PyTuple_Pack(12, ((PyObject *)__pyx_n_s__ID), ((PyObject *)__pyx_n_s__SM), ((PyObject *)__pyx_n_s__LB), ((PyObject *)__pyx_n_s__DS), ((PyObject *)__pyx_n_s__PU), ((PyObject *)__pyx_n_s__PI), ((PyObject *)__pyx_n_s__CN), ((PyObject *)__pyx_n_s__DT), ((PyObject *)__pyx_n_s__PL), ((PyObject *)__pyx_n_s__FO), ((PyObject *)__pyx_n_s__KS), ((PyObject *)__pyx_n_s__PG)); if (unlikely(!__pyx_k_tuple_299)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LI [...]
   __Pyx_GOTREF(__pyx_k_tuple_299);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_299));
 
-  /* "pysam/csamtools.pyx":374
+  /* "pysam/csamtools.pyx":373
  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS", "PG" ),
  *                        "PG" : ( "PN", "ID", "VN", "CL", "PP" ), }             # <<<<<<<<<<<<<<
  * 
  * 
  */
-  __pyx_k_tuple_300 = PyTuple_Pack(5, ((PyObject *)__pyx_n_s__PN), ((PyObject *)__pyx_n_s__ID), ((PyObject *)__pyx_n_s__VN), ((PyObject *)__pyx_n_s__CL), ((PyObject *)__pyx_n_s__PP)); if (unlikely(!__pyx_k_tuple_300)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_300 = PyTuple_Pack(5, ((PyObject *)__pyx_n_s__PN), ((PyObject *)__pyx_n_s__ID), ((PyObject *)__pyx_n_s__VN), ((PyObject *)__pyx_n_s__CL), ((PyObject *)__pyx_n_s__PP)); if (unlikely(!__pyx_k_tuple_300)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_300);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_300));
 
-  /* "pysam/csamtools.pyx":3336
+  /* "pysam/csamtools.pyx":3343
  * class Outs:
  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
  *     def __init__(self, id = 1):             # <<<<<<<<<<<<<<
  *         self.streams = []
  *         self.id = id
  */
-  __pyx_k_tuple_301 = PyTuple_Pack(2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_n_s__id)); if (unlikely(!__pyx_k_tuple_301)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_301 = PyTuple_Pack(2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_n_s__id)); if (unlikely(!__pyx_k_tuple_301)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_301);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_301));
-  __pyx_k_codeobj_302 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_301, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s____init__, 3336, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_302)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_k_tuple_303 = PyTuple_Pack(1, ((PyObject *)__pyx_int_1)); if (unlikely(!__pyx_k_tuple_303)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_302 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_301, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s____init__, 3343, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_302)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_303 = PyTuple_Pack(1, ((PyObject *)__pyx_int_1)); if (unlikely(!__pyx_k_tuple_303)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_303);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_303));
 
-  /* "pysam/csamtools.pyx":3340
+  /* "pysam/csamtools.pyx":3347
  *         self.id = id
  * 
  *     def setdevice(self, filename):             # <<<<<<<<<<<<<<
  *         '''open an existing file, like "/dev/null"'''
  *         fd = os.open(filename, os.O_WRONLY)
  */
-  __pyx_k_tuple_305 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_n_s__filename), ((PyObject *)__pyx_n_s__fd)); if (unlikely(!__pyx_k_tuple_305)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_305 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_n_s__filename), ((PyObject *)__pyx_n_s__fd)); if (unlikely(!__pyx_k_tuple_305)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_305);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_305));
-  __pyx_k_codeobj_306 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_305, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__setdevice, 3340, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_306)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_306 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_305, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__setdevice, 3347, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_306)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":3345
+  /* "pysam/csamtools.pyx":3352
  *         self.setfd(fd)
  * 
  *     def setfile(self, filename):             # <<<<<<<<<<<<<<
  *         '''open a new file.'''
  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
  */
-  __pyx_k_tuple_308 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_n_s__filename), ((PyObject *)__pyx_n_s__fd)); if (unlikely(!__pyx_k_tuple_308)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_308 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_n_s__filename), ((PyObject *)__pyx_n_s__fd)); if (unlikely(!__pyx_k_tuple_308)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_308);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_308));
-  __pyx_k_codeobj_309 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_308, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__setfile, 3345, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_309)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_309 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_308, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__setfile, 3352, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_309)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":3350
+  /* "pysam/csamtools.pyx":3357
  *         self.setfd(fd)
  * 
  *     def setfd(self, fd):             # <<<<<<<<<<<<<<
  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
  *         self.streams.append(ofd)
  */
-  __pyx_k_tuple_311 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_n_s__fd), ((PyObject *)__pyx_n_s__ofd)); if (unlikely(!__pyx_k_tuple_311)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_311 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_n_s__fd), ((PyObject *)__pyx_n_s__ofd)); if (unlikely(!__pyx_k_tuple_311)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_311);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_311));
-  __pyx_k_codeobj_312 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_311, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__setfd, 3350, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_312)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_312 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_311, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__setfd, 3357, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_312)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":3358
+  /* "pysam/csamtools.pyx":3365
  *         os.close(fd)                #  Close other unit (look out, caller.)
  * 
  *     def restore(self):             # <<<<<<<<<<<<<<
  *         '''restore previous output stream'''
  *         if self.streams:
  */
-  __pyx_k_tuple_314 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_314)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_314 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_314)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_314);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_314));
-  __pyx_k_codeobj_315 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_314, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__restore, 3358, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_315)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_315 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_314, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s__restore, 3365, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_315)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":3369
+  /* "pysam/csamtools.pyx":3376
  *             del self.streams[-1]
  * 
  * def _samtools_dispatch( method,             # <<<<<<<<<<<<<<
  *                         args = (),
  *                         catch_stdout = True ):
  */
-  __pyx_k_tuple_318 = PyTuple_Pack(16, ((PyObject *)__pyx_n_s__method), ((PyObject *)__pyx_n_s__args), ((PyObject *)__pyx_n_s__catch_stdout), ((PyObject *)__pyx_n_s__stderr_h), ((PyObject *)__pyx_n_s__stderr_f), ((PyObject *)__pyx_n_s__stdout_h), ((PyObject *)__pyx_n_s__stdout_f), ((PyObject *)__pyx_n_s__stdout_save), ((PyObject *)__pyx_n_s__cargs), ((PyObject *)__pyx_n_s__i), ((PyObject *)__pyx_n_s__n), ((PyObject *)__pyx_n_s__retval), ((PyObject *)__pyx_n_s__inf), ((PyObject *)__pyx_n_ [...]
+  __pyx_k_tuple_318 = PyTuple_Pack(16, ((PyObject *)__pyx_n_s__method), ((PyObject *)__pyx_n_s__args), ((PyObject *)__pyx_n_s__catch_stdout), ((PyObject *)__pyx_n_s__stderr_h), ((PyObject *)__pyx_n_s__stderr_f), ((PyObject *)__pyx_n_s__stdout_h), ((PyObject *)__pyx_n_s__stdout_f), ((PyObject *)__pyx_n_s__stdout_save), ((PyObject *)__pyx_n_s__cargs), ((PyObject *)__pyx_n_s__i), ((PyObject *)__pyx_n_s__n), ((PyObject *)__pyx_n_s__retval), ((PyObject *)__pyx_n_s__inf), ((PyObject *)__pyx_n_ [...]
   __Pyx_GOTREF(__pyx_k_tuple_318);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_318));
-  __pyx_k_codeobj_319 = (PyObject*)__Pyx_PyCode_New(3, 0, 16, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_318, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s___samtools_dispatch, 3369, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_319)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_319 = (PyObject*)__Pyx_PyCode_New(3, 0, 16, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_318, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_269, __pyx_n_s___samtools_dispatch, 3376, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_319)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_RefNannyFinishContext();
   return 0;
   __pyx_L1_error:;
@@ -43009,20 +44503,30 @@ PyMODINIT_FUNC PyInit_csamtools(void)
   /*--- Type init code ---*/
   __pyx_vtabptr_5pysam_9csamtools_Fastafile = &__pyx_vtable_5pysam_9csamtools_Fastafile;
   __pyx_vtable_5pysam_9csamtools_Fastafile._fetch = (char *(*)(struct __pyx_obj_5pysam_9csamtools_Fastafile *, char *, int, int, int *))__pyx_f_5pysam_9csamtools_9Fastafile__fetch;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_Fastafile.tp_dict, __pyx_vtabptr_5pysam_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "Fastafile", (PyObject *)&__pyx_type_5pysam_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  #if CYTHON_COMPILING_IN_CPYTHON
+  {
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_Fastafile, "__contains__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
+      __pyx_wrapperbase_5pysam_9csamtools_9Fastafile_18__contains__ = *((PyWrapperDescrObject *)wrapper)->d_base;
+      __pyx_wrapperbase_5pysam_9csamtools_9Fastafile_18__contains__.doc = __pyx_doc_5pysam_9csamtools_9Fastafile_18__contains__;
+      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_9csamtools_9Fastafile_18__contains__;
+    }
+  }
+  #endif
+  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_Fastafile.tp_dict, __pyx_vtabptr_5pysam_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "Fastafile", (PyObject *)&__pyx_type_5pysam_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_Fastafile = &__pyx_type_5pysam_9csamtools_Fastafile;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_FastqProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "FastqProxy", (PyObject *)&__pyx_type_5pysam_9csamtools_FastqProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_FastqProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "FastqProxy", (PyObject *)&__pyx_type_5pysam_9csamtools_FastqProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_FastqProxy = &__pyx_type_5pysam_9csamtools_FastqProxy;
   __pyx_vtabptr_5pysam_9csamtools_Fastqfile = &__pyx_vtable_5pysam_9csamtools_Fastqfile;
   __pyx_vtable_5pysam_9csamtools_Fastqfile.getCurrent = (kseq_t *(*)(struct __pyx_obj_5pysam_9csamtools_Fastqfile *))__pyx_f_5pysam_9csamtools_9Fastqfile_getCurrent;
   __pyx_vtable_5pysam_9csamtools_Fastqfile.cnext = (int (*)(struct __pyx_obj_5pysam_9csamtools_Fastqfile *))__pyx_f_5pysam_9csamtools_9Fastqfile_cnext;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_Fastqfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_Fastqfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_CPYTHON
   {
-    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_Fastqfile, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_Fastqfile, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
       __pyx_wrapperbase_5pysam_9csamtools_9Fastqfile_12__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
       __pyx_wrapperbase_5pysam_9csamtools_9Fastqfile_12__next__.doc = __pyx_doc_5pysam_9csamtools_9Fastqfile_12__next__;
@@ -43030,13 +44534,13 @@ PyMODINIT_FUNC PyInit_csamtools(void)
     }
   }
   #endif
-  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_Fastqfile.tp_dict, __pyx_vtabptr_5pysam_9csamtools_Fastqfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "Fastqfile", (PyObject *)&__pyx_type_5pysam_9csamtools_Fastqfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_Fastqfile.tp_dict, __pyx_vtabptr_5pysam_9csamtools_Fastqfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "Fastqfile", (PyObject *)&__pyx_type_5pysam_9csamtools_Fastqfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_Fastqfile = &__pyx_type_5pysam_9csamtools_Fastqfile;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_CPYTHON
   {
-    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_AlignedRead, "__str__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_AlignedRead, "__str__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
       __pyx_wrapperbase_5pysam_9csamtools_11AlignedRead_4__str__ = *((PyWrapperDescrObject *)wrapper)->d_base;
       __pyx_wrapperbase_5pysam_9csamtools_11AlignedRead_4__str__.doc = __pyx_doc_5pysam_9csamtools_11AlignedRead_4__str__;
@@ -43044,7 +44548,7 @@ PyMODINIT_FUNC PyInit_csamtools(void)
     }
   }
   #endif
-  if (__Pyx_SetAttrString(__pyx_m, "AlignedRead", (PyObject *)&__pyx_type_5pysam_9csamtools_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "AlignedRead", (PyObject *)&__pyx_type_5pysam_9csamtools_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_AlignedRead = &__pyx_type_5pysam_9csamtools_AlignedRead;
   __pyx_vtabptr_5pysam_9csamtools_Samfile = &__pyx_vtable_5pysam_9csamtools_Samfile;
   __pyx_vtable_5pysam_9csamtools_Samfile._buildHeader = (bam_header_t *(*)(struct __pyx_obj_5pysam_9csamtools_Samfile *, PyObject *))__pyx_f_5pysam_9csamtools_7Samfile__buildHeader;
@@ -43052,10 +44556,10 @@ PyMODINIT_FUNC PyInit_csamtools(void)
   __pyx_vtable_5pysam_9csamtools_Samfile.cnext = (int (*)(struct __pyx_obj_5pysam_9csamtools_Samfile *))__pyx_f_5pysam_9csamtools_7Samfile_cnext;
   __pyx_vtable_5pysam_9csamtools_Samfile.write = (int (*)(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_AlignedRead *, int __pyx_skip_dispatch))__pyx_f_5pysam_9csamtools_7Samfile_write;
   __pyx_vtable_5pysam_9csamtools_Samfile._getrname = (char *(*)(struct __pyx_obj_5pysam_9csamtools_Samfile *, int))__pyx_f_5pysam_9csamtools_7Samfile__getrname;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_CPYTHON
   {
-    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_Samfile, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_Samfile, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
       __pyx_wrapperbase_5pysam_9csamtools_7Samfile_42__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
       __pyx_wrapperbase_5pysam_9csamtools_7Samfile_42__next__.doc = __pyx_doc_5pysam_9csamtools_7Samfile_42__next__;
@@ -43063,26 +44567,26 @@ PyMODINIT_FUNC PyInit_csamtools(void)
     }
   }
   #endif
-  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_Samfile.tp_dict, __pyx_vtabptr_5pysam_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "Samfile", (PyObject *)&__pyx_type_5pysam_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_Samfile.tp_dict, __pyx_vtabptr_5pysam_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "Samfile", (PyObject *)&__pyx_type_5pysam_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_Samfile = &__pyx_type_5pysam_9csamtools_Samfile;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_PileupProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "PileupProxy", (PyObject *)&__pyx_type_5pysam_9csamtools_PileupProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_PileupProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "PileupProxy", (PyObject *)&__pyx_type_5pysam_9csamtools_PileupProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_PileupProxy = &__pyx_type_5pysam_9csamtools_PileupProxy;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "PileupRead", (PyObject *)&__pyx_type_5pysam_9csamtools_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "PileupRead", (PyObject *)&__pyx_type_5pysam_9csamtools_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_PileupRead = &__pyx_type_5pysam_9csamtools_PileupRead;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1572; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "IteratorRow", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1572; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "IteratorRow", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_IteratorRow = &__pyx_type_5pysam_9csamtools_IteratorRow;
   __pyx_vtabptr_5pysam_9csamtools_IteratorRowRegion = &__pyx_vtable_5pysam_9csamtools_IteratorRowRegion;
   __pyx_vtable_5pysam_9csamtools_IteratorRowRegion.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *))__pyx_f_5pysam_9csamtools_17IteratorRowRegion_getCurrent;
   __pyx_vtable_5pysam_9csamtools_IteratorRowRegion.cnext = (int (*)(struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *))__pyx_f_5pysam_9csamtools_17IteratorRowRegion_cnext;
   __pyx_type_5pysam_9csamtools_IteratorRowRegion.tp_base = __pyx_ptype_5pysam_9csamtools_IteratorRow;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_CPYTHON
   {
-    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowRegion, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowRegion, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
       __pyx_wrapperbase_5pysam_9csamtools_17IteratorRowRegion_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
       __pyx_wrapperbase_5pysam_9csamtools_17IteratorRowRegion_4__next__.doc = __pyx_doc_5pysam_9csamtools_17IteratorRowRegion_4__next__;
@@ -43090,17 +44594,17 @@ PyMODINIT_FUNC PyInit_csamtools(void)
     }
   }
   #endif
-  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_IteratorRowRegion.tp_dict, __pyx_vtabptr_5pysam_9csamtools_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowRegion", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_IteratorRowRegion.tp_dict, __pyx_vtabptr_5pysam_9csamtools_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowRegion", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_IteratorRowRegion = &__pyx_type_5pysam_9csamtools_IteratorRowRegion;
   __pyx_vtabptr_5pysam_9csamtools_IteratorRowAll = &__pyx_vtable_5pysam_9csamtools_IteratorRowAll;
   __pyx_vtable_5pysam_9csamtools_IteratorRowAll.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_9csamtools_IteratorRowAll *))__pyx_f_5pysam_9csamtools_14IteratorRowAll_getCurrent;
   __pyx_vtable_5pysam_9csamtools_IteratorRowAll.cnext = (int (*)(struct __pyx_obj_5pysam_9csamtools_IteratorRowAll *))__pyx_f_5pysam_9csamtools_14IteratorRowAll_cnext;
   __pyx_type_5pysam_9csamtools_IteratorRowAll.tp_base = __pyx_ptype_5pysam_9csamtools_IteratorRow;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_CPYTHON
   {
-    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowAll, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowAll, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
       __pyx_wrapperbase_5pysam_9csamtools_14IteratorRowAll_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
       __pyx_wrapperbase_5pysam_9csamtools_14IteratorRowAll_4__next__.doc = __pyx_doc_5pysam_9csamtools_14IteratorRowAll_4__next__;
@@ -43108,14 +44612,14 @@ PyMODINIT_FUNC PyInit_csamtools(void)
     }
   }
   #endif
-  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_IteratorRowAll.tp_dict, __pyx_vtabptr_5pysam_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowAll", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_IteratorRowAll.tp_dict, __pyx_vtabptr_5pysam_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowAll", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_IteratorRowAll = &__pyx_type_5pysam_9csamtools_IteratorRowAll;
   __pyx_type_5pysam_9csamtools_IteratorRowAllRefs.tp_base = __pyx_ptype_5pysam_9csamtools_IteratorRow;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorRowAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorRowAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_CPYTHON
   {
-    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowAllRefs, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowAllRefs, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
       __pyx_wrapperbase_5pysam_9csamtools_18IteratorRowAllRefs_6__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
       __pyx_wrapperbase_5pysam_9csamtools_18IteratorRowAllRefs_6__next__.doc = __pyx_doc_5pysam_9csamtools_18IteratorRowAllRefs_6__next__;
@@ -43123,16 +44627,16 @@ PyMODINIT_FUNC PyInit_csamtools(void)
     }
   }
   #endif
-  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowAllRefs", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowAllRefs", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_IteratorRowAllRefs = &__pyx_type_5pysam_9csamtools_IteratorRowAllRefs;
   __pyx_vtabptr_5pysam_9csamtools_IteratorRowSelection = &__pyx_vtable_5pysam_9csamtools_IteratorRowSelection;
   __pyx_vtable_5pysam_9csamtools_IteratorRowSelection.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_9csamtools_IteratorRowSelection *))__pyx_f_5pysam_9csamtools_20IteratorRowSelection_getCurrent;
   __pyx_vtable_5pysam_9csamtools_IteratorRowSelection.cnext = (int (*)(struct __pyx_obj_5pysam_9csamtools_IteratorRowSelection *))__pyx_f_5pysam_9csamtools_20IteratorRowSelection_cnext;
   __pyx_type_5pysam_9csamtools_IteratorRowSelection.tp_base = __pyx_ptype_5pysam_9csamtools_IteratorRow;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_CPYTHON
   {
-    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowSelection, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowSelection, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
       __pyx_wrapperbase_5pysam_9csamtools_20IteratorRowSelection_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
       __pyx_wrapperbase_5pysam_9csamtools_20IteratorRowSelection_4__next__.doc = __pyx_doc_5pysam_9csamtools_20IteratorRowSelection_4__next__;
@@ -43140,8 +44644,8 @@ PyMODINIT_FUNC PyInit_csamtools(void)
     }
   }
   #endif
-  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_IteratorRowSelection.tp_dict, __pyx_vtabptr_5pysam_9csamtools_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowSelection", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_IteratorRowSelection.tp_dict, __pyx_vtabptr_5pysam_9csamtools_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowSelection", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_IteratorRowSelection = &__pyx_type_5pysam_9csamtools_IteratorRowSelection;
   __pyx_vtabptr_5pysam_9csamtools_IteratorColumn = &__pyx_vtable_5pysam_9csamtools_IteratorColumn;
   __pyx_vtable_5pysam_9csamtools_IteratorColumn.cnext = (int (*)(struct __pyx_obj_5pysam_9csamtools_IteratorColumn *))__pyx_f_5pysam_9csamtools_14IteratorColumn_cnext;
@@ -43149,17 +44653,17 @@ PyMODINIT_FUNC PyInit_csamtools(void)
   __pyx_vtable_5pysam_9csamtools_IteratorColumn.setMask = (PyObject *(*)(struct __pyx_obj_5pysam_9csamtools_IteratorColumn *, PyObject *))__pyx_f_5pysam_9csamtools_14IteratorColumn_setMask;
   __pyx_vtable_5pysam_9csamtools_IteratorColumn.setupIteratorData = (PyObject *(*)(struct __pyx_obj_5pysam_9csamtools_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_9csamtools_14IteratorColumn_setupIteratorData *__pyx_optional_args))__pyx_f_5pysam_9csamtools_14IteratorColumn_setupIteratorData;
   __pyx_vtable_5pysam_9csamtools_IteratorColumn.reset = (PyObject *(*)(struct __pyx_obj_5pysam_9csamtools_IteratorColumn *, PyObject *, PyObject *, PyObject *))__pyx_f_5pysam_9csamtools_14IteratorColumn_reset;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_IteratorColumn.tp_dict, __pyx_vtabptr_5pysam_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "IteratorColumn", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_IteratorColumn.tp_dict, __pyx_vtabptr_5pysam_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "IteratorColumn", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_IteratorColumn = &__pyx_type_5pysam_9csamtools_IteratorColumn;
   __pyx_vtabptr_5pysam_9csamtools_IteratorColumnRegion = &__pyx_vtable_5pysam_9csamtools_IteratorColumnRegion;
   __pyx_vtable_5pysam_9csamtools_IteratorColumnRegion.__pyx_base = *__pyx_vtabptr_5pysam_9csamtools_IteratorColumn;
   __pyx_type_5pysam_9csamtools_IteratorColumnRegion.tp_base = __pyx_ptype_5pysam_9csamtools_IteratorColumn;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_CPYTHON
   {
-    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_IteratorColumnRegion, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_IteratorColumnRegion, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
       __pyx_wrapperbase_5pysam_9csamtools_20IteratorColumnRegion_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
       __pyx_wrapperbase_5pysam_9csamtools_20IteratorColumnRegion_2__next__.doc = __pyx_doc_5pysam_9csamtools_20IteratorColumnRegion_2__next__;
@@ -43167,16 +44671,16 @@ PyMODINIT_FUNC PyInit_csamtools(void)
     }
   }
   #endif
-  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_IteratorColumnRegion.tp_dict, __pyx_vtabptr_5pysam_9csamtools_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "IteratorColumnRegion", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_IteratorColumnRegion.tp_dict, __pyx_vtabptr_5pysam_9csamtools_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "IteratorColumnRegion", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_IteratorColumnRegion = &__pyx_type_5pysam_9csamtools_IteratorColumnRegion;
   __pyx_vtabptr_5pysam_9csamtools_IteratorColumnAllRefs = &__pyx_vtable_5pysam_9csamtools_IteratorColumnAllRefs;
   __pyx_vtable_5pysam_9csamtools_IteratorColumnAllRefs.__pyx_base = *__pyx_vtabptr_5pysam_9csamtools_IteratorColumn;
   __pyx_type_5pysam_9csamtools_IteratorColumnAllRefs.tp_base = __pyx_ptype_5pysam_9csamtools_IteratorColumn;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_CPYTHON
   {
-    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_IteratorColumnAllRefs, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_9csamtools_IteratorColumnAllRefs, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
       __pyx_wrapperbase_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
       __pyx_wrapperbase_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__.doc = __pyx_doc_5pysam_9csamtools_21IteratorColumnAllRefs_2__next__;
@@ -43184,19 +44688,25 @@ PyMODINIT_FUNC PyInit_csamtools(void)
     }
   }
   #endif
-  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_IteratorColumnAllRefs.tp_dict, __pyx_vtabptr_5pysam_9csamtools_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "IteratorColumnAllRefs", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_9csamtools_IteratorColumnAllRefs.tp_dict, __pyx_vtabptr_5pysam_9csamtools_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "IteratorColumnAllRefs", (PyObject *)&__pyx_type_5pysam_9csamtools_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_IteratorColumnAllRefs = &__pyx_type_5pysam_9csamtools_IteratorColumnAllRefs;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IndexedReads) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4021; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "IndexedReads", (PyObject *)&__pyx_type_5pysam_9csamtools_IndexedReads) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4021; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_IndexedReads) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "IndexedReads", (PyObject *)&__pyx_type_5pysam_9csamtools_IndexedReads) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_IndexedReads = &__pyx_type_5pysam_9csamtools_IndexedReads;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_SNPCall) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "SNPCall", (PyObject *)&__pyx_type_5pysam_9csamtools_SNPCall) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools_SNPCall) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "SNPCall", (PyObject *)&__pyx_type_5pysam_9csamtools_SNPCall) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools_SNPCall = &__pyx_type_5pysam_9csamtools_SNPCall;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools___pyx_scope_struct__genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools___pyx_scope_struct__genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools___pyx_scope_struct__genexpr = &__pyx_type_5pysam_9csamtools___pyx_scope_struct__genexpr;
-  if (PyType_Ready(&__pyx_type_5pysam_9csamtools___pyx_scope_struct_1_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools___pyx_scope_struct_1_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_9csamtools___pyx_scope_struct_1_genexpr = &__pyx_type_5pysam_9csamtools___pyx_scope_struct_1_genexpr;
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools___pyx_scope_struct_2__open) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_9csamtools___pyx_scope_struct_2__open = &__pyx_type_5pysam_9csamtools___pyx_scope_struct_2__open;
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools___pyx_scope_struct_3_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_9csamtools___pyx_scope_struct_3_genexpr = &__pyx_type_5pysam_9csamtools___pyx_scope_struct_3_genexpr;
+  if (PyType_Ready(&__pyx_type_5pysam_9csamtools___pyx_scope_struct_4_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_9csamtools___pyx_scope_struct_4_genexpr = &__pyx_type_5pysam_9csamtools___pyx_scope_struct_4_genexpr;
   /*--- Type import code ---*/
   __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
   #if CYTHON_COMPILING_IN_PYPY
@@ -43438,7 +44948,7 @@ PyMODINIT_FUNC PyInit_csamtools(void)
   }
   __pyx_L3:;
 
-  /* "pysam/csamtools.pyx":138
+  /* "pysam/csamtools.pyx":137
  * DEF BAM_CDIFF      = 8
  * 
  * cdef char* CODE2CIGAR= "MIDNSHP=X"             # <<<<<<<<<<<<<<
@@ -43447,83 +44957,83 @@ PyMODINIT_FUNC PyInit_csamtools(void)
  */
   __pyx_v_5pysam_9csamtools_CODE2CIGAR = __pyx_k_263;
 
-  /* "pysam/csamtools.pyx":139
+  /* "pysam/csamtools.pyx":138
  * 
  * cdef char* CODE2CIGAR= "MIDNSHP=X"
  * if IS_PYTHON3:             # <<<<<<<<<<<<<<
  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
  * else:
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__IS_PYTHON3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__IS_PYTHON3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":140
+    /* "pysam/csamtools.pyx":139
  * cdef char* CODE2CIGAR= "MIDNSHP=X"
  * if IS_PYTHON3:
  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
  * else:
  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
  */
-    __pyx_t_1 = __pyx_pf_5pysam_9csamtools_2genexpr(NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __pyx_pf_5pysam_9csamtools_2genexpr(NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
     __Pyx_GIVEREF(__pyx_t_1);
     __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
-    if (PyObject_SetAttr(__pyx_m, __pyx_n_s__CIGAR2CODE, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyObject_SetAttr(__pyx_m, __pyx_n_s__CIGAR2CODE, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     goto __pyx_L4;
   }
   /*else*/ {
 
-    /* "pysam/csamtools.pyx":142
+    /* "pysam/csamtools.pyx":141
  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
  * else:
  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
  * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )
  * 
  */
-    __pyx_t_1 = __pyx_pf_5pysam_9csamtools_5genexpr(NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __pyx_pf_5pysam_9csamtools_5genexpr(NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
     __Pyx_GIVEREF(__pyx_t_1);
     __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
-    if (PyObject_SetAttr(__pyx_m, __pyx_n_s__CIGAR2CODE, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyObject_SetAttr(__pyx_m, __pyx_n_s__CIGAR2CODE, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   }
   __pyx_L4:;
 
-  /* "pysam/csamtools.pyx":143
+  /* "pysam/csamtools.pyx":142
  * else:
  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
  * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )             # <<<<<<<<<<<<<<
  * 
  * #####################################################################
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__re); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__re); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__compile); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__compile); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __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_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_265), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_265), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__CIGAR_REGEX, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__CIGAR_REGEX, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":147
+  /* "pysam/csamtools.pyx":146
  * #####################################################################
  * ## set pysam stderr to /dev/null
  * pysam_unset_stderr()             # <<<<<<<<<<<<<<
@@ -43532,7 +45042,7 @@ PyMODINIT_FUNC PyInit_csamtools(void)
  */
   pysam_unset_stderr();
 
-  /* "pysam/csamtools.pyx":151
+  /* "pysam/csamtools.pyx":150
  * #####################################################################
  * # hard-coded constants
  * cdef char * bam_nt16_rev_table = "=ACMGRSVTWYHKDBN"             # <<<<<<<<<<<<<<
@@ -43541,7 +45051,7 @@ PyMODINIT_FUNC PyInit_csamtools(void)
  */
   __pyx_v_5pysam_9csamtools_bam_nt16_rev_table = __pyx_k_266;
 
-  /* "pysam/csamtools.pyx":152
+  /* "pysam/csamtools.pyx":151
  * # hard-coded constants
  * cdef char * bam_nt16_rev_table = "=ACMGRSVTWYHKDBN"
  * cdef int max_pos = 2 << 29             # <<<<<<<<<<<<<<
@@ -43550,601 +45060,601 @@ PyMODINIT_FUNC PyInit_csamtools(void)
  */
   __pyx_v_5pysam_9csamtools_max_pos = 1073741824;
 
-  /* "pysam/csamtools.pyx":254
+  /* "pysam/csamtools.pyx":253
  *     (<object>f)(a)
  * 
  * class PileupColumn(object):             # <<<<<<<<<<<<<<
  *     '''A pileup column. A pileup column contains
  *     all the reads that map to a certain target base.
  */
-  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
 
-  /* "pysam/csamtools.pyx":267
+  /* "pysam/csamtools.pyx":266
  *         list of reads (:class:`pysam.PileupRead`) aligned to this column
  *     '''
  *     def __str__(self):             # <<<<<<<<<<<<<<
  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
  *             "\n" + "\n".join( map(str, self.pileups) )
  */
-  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_12PileupColumn_1__str__, 0, __pyx_n_s_270, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_268)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_12PileupColumn_1__str__, 0, __pyx_n_s_270, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_268)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____str__, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____str__, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/csamtools.pyx":254
+  /* "pysam/csamtools.pyx":253
  *     (<object>f)(a)
  * 
  * class PileupColumn(object):             # <<<<<<<<<<<<<<
  *     '''A pileup column. A pileup column contains
  *     all the reads that map to a certain target base.
  */
-  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_INCREF(__pyx_builtin_object);
   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_builtin_object);
   __Pyx_GIVEREF(__pyx_builtin_object);
-  if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_272)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_4 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__PileupColumn, __pyx_n_s__PileupColumn, __pyx_n_s_271); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_272)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__PileupColumn, __pyx_n_s__PileupColumn, __pyx_n_s_271); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__PileupColumn, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__PileupColumn, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":311
+  /* "pysam/csamtools.pyx":310
  *     return 0
  * 
  * class StderrStore():             # <<<<<<<<<<<<<<
  *     '''
  *     stderr is captured.
  */
-  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
 
-  /* "pysam/csamtools.pyx":315
+  /* "pysam/csamtools.pyx":314
  *     stderr is captured.
  *     '''
  *     def __init__(self):             # <<<<<<<<<<<<<<
  *         return
  *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
  */
-  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_11StderrStore_1__init__, 0, __pyx_n_s_275, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_274)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_11StderrStore_1__init__, 0, __pyx_n_s_275, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_274)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____init__, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____init__, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":321
+  /* "pysam/csamtools.pyx":320
  *         self.stderr_save.setfd( self.stderr_h )
  * 
  *     def readAndRelease( self ):             # <<<<<<<<<<<<<<
  *         return []
  *         self.stderr_save.restore()
  */
-  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_11StderrStore_3readAndRelease, 0, __pyx_n_s_278, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_277)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_11StderrStore_3readAndRelease, 0, __pyx_n_s_278, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_277)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__readAndRelease, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__readAndRelease, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":330
+  /* "pysam/csamtools.pyx":329
  *         return lines
  * 
  *     def release(self):             # <<<<<<<<<<<<<<
  *         return
  *         self.stderr_save.restore()
  */
-  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_11StderrStore_5release, 0, __pyx_n_s_281, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_280)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_11StderrStore_5release, 0, __pyx_n_s_281, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_280)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__release, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__release, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":336
+  /* "pysam/csamtools.pyx":335
  *             os.remove( self.stderr_f )
  * 
  *     def __del__(self):             # <<<<<<<<<<<<<<
  *         self.release()
  * 
  */
-  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_11StderrStore_7__del__, 0, __pyx_n_s_284, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_283)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_11StderrStore_7__del__, 0, __pyx_n_s_284, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_283)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____del__, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____del__, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":311
+  /* "pysam/csamtools.pyx":310
  *     return 0
  * 
  * class StderrStore():             # <<<<<<<<<<<<<<
  *     '''
  *     stderr is captured.
  */
-  if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_285)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_4 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s__StderrStore, __pyx_n_s__StderrStore, __pyx_n_s_271); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_285)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s__StderrStore, __pyx_n_s__StderrStore, __pyx_n_s_271); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStore, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStore, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":339
+  /* "pysam/csamtools.pyx":338
  *         self.release()
  * 
  * class StderrStoreWindows():             # <<<<<<<<<<<<<<
  *     '''does nothing. stderr can't be redirected on windows'''
  *     def __init__(self): pass
  */
-  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
 
-  /* "pysam/csamtools.pyx":341
+  /* "pysam/csamtools.pyx":340
  * class StderrStoreWindows():
  *     '''does nothing. stderr can't be redirected on windows'''
  *     def __init__(self): pass             # <<<<<<<<<<<<<<
  *     def readAndRelease(self): return []
  *     def release(self): pass
  */
-  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_18StderrStoreWindows_1__init__, 0, __pyx_n_s_288, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_287)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_18StderrStoreWindows_1__init__, 0, __pyx_n_s_288, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_287)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____init__, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____init__, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":342
+  /* "pysam/csamtools.pyx":341
  *     '''does nothing. stderr can't be redirected on windows'''
  *     def __init__(self): pass
  *     def readAndRelease(self): return []             # <<<<<<<<<<<<<<
  *     def release(self): pass
  * 
  */
-  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_18StderrStoreWindows_3readAndRelease, 0, __pyx_n_s_291, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_290)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_18StderrStoreWindows_3readAndRelease, 0, __pyx_n_s_291, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_290)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__readAndRelease, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__readAndRelease, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":343
+  /* "pysam/csamtools.pyx":342
  *     def __init__(self): pass
  *     def readAndRelease(self): return []
  *     def release(self): pass             # <<<<<<<<<<<<<<
  * 
  * if platform.system()=='Windows':
  */
-  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_18StderrStoreWindows_5release, 0, __pyx_n_s_294, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_293)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_18StderrStoreWindows_5release, 0, __pyx_n_s_294, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_293)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__release, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__release, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":339
+  /* "pysam/csamtools.pyx":338
  *         self.release()
  * 
  * class StderrStoreWindows():             # <<<<<<<<<<<<<<
  *     '''does nothing. stderr can't be redirected on windows'''
  *     def __init__(self): pass
  */
-  if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_295)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_4 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s__StderrStoreWindows, __pyx_n_s__StderrStoreWindows, __pyx_n_s_271); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_295)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s__StderrStoreWindows, __pyx_n_s__StderrStoreWindows, __pyx_n_s_271); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStoreWindows, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStoreWindows, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":345
+  /* "pysam/csamtools.pyx":344
  *     def release(self): pass
  * 
  * if platform.system()=='Windows':             # <<<<<<<<<<<<<<
  *     del StderrStore
  *     StderrStore = StderrStoreWindows
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__platform); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__platform); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__system); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__system); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__Windows), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__Windows), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   if (__pyx_t_3) {
 
-    /* "pysam/csamtools.pyx":346
+    /* "pysam/csamtools.pyx":345
  * 
  * if platform.system()=='Windows':
  *     del StderrStore             # <<<<<<<<<<<<<<
  *     StderrStore = StderrStoreWindows
  * 
  */
-    if (__Pyx_DelAttrString(__pyx_m, "StderrStore") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (__Pyx_DelAttrString(__pyx_m, "StderrStore") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "pysam/csamtools.pyx":347
+    /* "pysam/csamtools.pyx":346
  * if platform.system()=='Windows':
  *     del StderrStore
  *     StderrStore = StderrStoreWindows             # <<<<<<<<<<<<<<
  * 
  * 
  */
-    __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStoreWindows); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStoreWindows); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
-    if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStore, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStore, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
     goto __pyx_L5;
   }
   __pyx_L5:;
 
-  /* "pysam/csamtools.pyx":354
+  /* "pysam/csamtools.pyx":353
  * ######################################################################
  * # valid types for sam headers
  * VALID_HEADER_TYPES = { "HD" : dict,             # <<<<<<<<<<<<<<
  *                        "SQ" : list,
  *                        "RG" : list,
  */
-  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__HD), ((PyObject *)((PyObject*)(&PyDict_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__HD), ((PyObject *)((PyObject*)(&PyDict_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":355
+  /* "pysam/csamtools.pyx":354
  * # valid types for sam headers
  * VALID_HEADER_TYPES = { "HD" : dict,
  *                        "SQ" : list,             # <<<<<<<<<<<<<<
  *                        "RG" : list,
  *                        "PG" : list,
  */
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":356
+  /* "pysam/csamtools.pyx":355
  * VALID_HEADER_TYPES = { "HD" : dict,
  *                        "SQ" : list,
  *                        "RG" : list,             # <<<<<<<<<<<<<<
  *                        "PG" : list,
  *                        "CO" : list }
  */
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__RG), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__RG), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":357
+  /* "pysam/csamtools.pyx":356
  *                        "SQ" : list,
  *                        "RG" : list,
  *                        "PG" : list,             # <<<<<<<<<<<<<<
  *                        "CO" : list }
  * 
  */
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__PG), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__PG), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":358
+  /* "pysam/csamtools.pyx":357
  *                        "RG" : list,
  *                        "PG" : list,
  *                        "CO" : list }             # <<<<<<<<<<<<<<
  * 
  * # order of records within sam headers
  */
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__CO), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES, ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__CO), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES, ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":361
+  /* "pysam/csamtools.pyx":360
  * 
  * # order of records within sam headers
  * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO" )             # <<<<<<<<<<<<<<
  * 
  * # type conversions within sam header records
  */
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADERS, ((PyObject *)__pyx_k_tuple_296)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADERS, ((PyObject *)__pyx_k_tuple_296)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":364
+  /* "pysam/csamtools.pyx":363
  * 
  * # type conversions within sam header records
  * VALID_HEADER_FIELDS = { "HD" : { "VN" : str, "SO" : str, "GO" : str },             # <<<<<<<<<<<<<<
  *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },
  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str,
  */
-  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
-  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__VN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SO), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__GO), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__HD), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__VN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SO), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__GO), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__HD), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":365
+  /* "pysam/csamtools.pyx":364
  * # type conversions within sam header records
  * VALID_HEADER_FIELDS = { "HD" : { "VN" : str, "SO" : str, "GO" : str },
  *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },             # <<<<<<<<<<<<<<
  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str,
  *                                  "CN" : str, "DT" : str, "PL" : str, "FO" : str, "KS" : str, "PG" : str,},
  */
-  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__LN), ((PyObject *)((PyObject*)(&PyInt_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__AS), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__M5), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__UR), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SP), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__LN), ((PyObject *)((PyObject*)(&PyInt_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__AS), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__M5), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__UR), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SP), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":366
+  /* "pysam/csamtools.pyx":365
  * VALID_HEADER_FIELDS = { "HD" : { "VN" : str, "SO" : str, "GO" : str },
  *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },
  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str,             # <<<<<<<<<<<<<<
  *                                  "CN" : str, "DT" : str, "PL" : str, "FO" : str, "KS" : str, "PG" : str,},
  *                         "PG" : { "PN" : str, "ID" : str, "VN" : str, "CL" : str, "PP" : str }, }
  */
-  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__ID), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SM), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__LB), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__DS), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PU), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PI), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__ID), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SM), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__LB), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__DS), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PU), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PI), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":367
+  /* "pysam/csamtools.pyx":366
  *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },
  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str,
  *                                  "CN" : str, "DT" : str, "PL" : str, "FO" : str, "KS" : str, "PG" : str,},             # <<<<<<<<<<<<<<
  *                         "PG" : { "PN" : str, "ID" : str, "VN" : str, "CL" : str, "PP" : str }, }
  * 
  */
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__CN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__DT), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PL), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__FO), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__KS), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PG), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__RG), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__CN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__DT), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PL), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__FO), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__KS), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PG), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__RG), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":368
+  /* "pysam/csamtools.pyx":367
  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str,
  *                                  "CN" : str, "DT" : str, "PL" : str, "FO" : str, "KS" : str, "PG" : str,},
  *                         "PG" : { "PN" : str, "ID" : str, "VN" : str, "CL" : str, "PP" : str }, }             # <<<<<<<<<<<<<<
  * 
  * # output order of fields within records
  */
-  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__ID), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__VN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__CL), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PP), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__PG), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__ID), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__VN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__CL), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PP), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__PG), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_FIELDS, ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_FIELDS, ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":371
+  /* "pysam/csamtools.pyx":370
  * 
  * # output order of fields within records
  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),             # <<<<<<<<<<<<<<
  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS", "PG" ),
  */
-  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__HD), ((PyObject *)__pyx_k_tuple_297)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__HD), ((PyObject *)__pyx_k_tuple_297)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":372
+  /* "pysam/csamtools.pyx":371
  * # output order of fields within records
  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),             # <<<<<<<<<<<<<<
  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS", "PG" ),
  *                        "PG" : ( "PN", "ID", "VN", "CL", "PP" ), }
  */
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_k_tuple_298)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_k_tuple_298)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":373
+  /* "pysam/csamtools.pyx":372
  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS", "PG" ),             # <<<<<<<<<<<<<<
  *                        "PG" : ( "PN", "ID", "VN", "CL", "PP" ), }
  * 
  */
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__RG), ((PyObject *)__pyx_k_tuple_299)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__RG), ((PyObject *)__pyx_k_tuple_299)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/csamtools.pyx":374
+  /* "pysam/csamtools.pyx":373
  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS", "PG" ),
  *                        "PG" : ( "PN", "ID", "VN", "CL", "PP" ), }             # <<<<<<<<<<<<<<
  * 
  * 
  */
-  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__PG), ((PyObject *)__pyx_k_tuple_300)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_ORDER, ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__PG), ((PyObject *)__pyx_k_tuple_300)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_ORDER, ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":745
+  /* "pysam/csamtools.pyx":758
  *                header = None,
  *                port = None,
  *                add_sq_text = True,             # <<<<<<<<<<<<<<
  *                check_header = True,
  *                check_sq = True,
  */
-  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  __pyx_k_29 = __pyx_t_4;
+  __pyx_k_27 = __pyx_t_4;
   __Pyx_GIVEREF(__pyx_t_4);
   __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":746
+  /* "pysam/csamtools.pyx":759
  *                port = None,
  *                add_sq_text = True,
  *                check_header = True,             # <<<<<<<<<<<<<<
  *                check_sq = True,
  *               ):
  */
-  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  __pyx_k_30 = __pyx_t_4;
+  __pyx_k_28 = __pyx_t_4;
   __Pyx_GIVEREF(__pyx_t_4);
   __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":747
+  /* "pysam/csamtools.pyx":760
  *                add_sq_text = True,
  *                check_header = True,
  *                check_sq = True,             # <<<<<<<<<<<<<<
  *               ):
  *         '''open a sam/bam file.
  */
-  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  __pyx_k_31 = __pyx_t_4;
+  __pyx_k_29 = __pyx_t_4;
   __Pyx_GIVEREF(__pyx_t_4);
   __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":1027
+  /* "pysam/csamtools.pyx":1032
  *                region = None,
  *                callback = None,
  *                until_eof = False ):             # <<<<<<<<<<<<<<
  *         '''
  *         fetch aligned reads in a :term:`region` using 0-based indexing. The region is specified by
  */
-  __pyx_t_4 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __pyx_k_62 = __pyx_t_4;
   __Pyx_GIVEREF(__pyx_t_4);
   __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":1148
+  /* "pysam/csamtools.pyx":1153
  *                end = None,
  *                region = None,
  *                until_eof = False ):             # <<<<<<<<<<<<<<
  *         '''*(reference = None, start = None, end = None, region = None, callback = None, until_eof = False)*
  * 
  */
-  __pyx_t_4 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __pyx_k_81 = __pyx_t_4;
   __Pyx_GIVEREF(__pyx_t_4);
   __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":2089
+  /* "pysam/csamtools.pyx":2092
  *                   int tid = 0,
  *                   int start = 0,
  *                   int end = max_pos,             # <<<<<<<<<<<<<<
  *                   int truncate = False,
  *                   **kwargs ):
  */
-  __pyx_k_140 = __pyx_v_5pysam_9csamtools_max_pos;
+  __pyx_k_139 = __pyx_v_5pysam_9csamtools_max_pos;
 
-  /* "pysam/csamtools.pyx":3334
+  /* "pysam/csamtools.pyx":3341
  *             return self._level
  * 
  * class Outs:             # <<<<<<<<<<<<<<
  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
  *     def __init__(self, id = 1):
  */
-  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
 
-  /* "pysam/csamtools.pyx":3336
+  /* "pysam/csamtools.pyx":3343
  * class Outs:
  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
  *     def __init__(self, id = 1):             # <<<<<<<<<<<<<<
  *         self.streams = []
  *         self.id = id
  */
-  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_4Outs_1__init__, 0, __pyx_n_s_304, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_302)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_4Outs_1__init__, 0, __pyx_n_s_304, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_302)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_1, ((PyObject *)__pyx_k_tuple_303));
-  if (PyObject_SetItem(__pyx_t_4, __pyx_n_s____init__, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_4, __pyx_n_s____init__, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3340
+  /* "pysam/csamtools.pyx":3347
  *         self.id = id
  * 
  *     def setdevice(self, filename):             # <<<<<<<<<<<<<<
  *         '''open an existing file, like "/dev/null"'''
  *         fd = os.open(filename, os.O_WRONLY)
  */
-  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_4Outs_3setdevice, 0, __pyx_n_s_307, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_306)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_4Outs_3setdevice, 0, __pyx_n_s_307, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_306)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyObject_SetItem(__pyx_t_4, __pyx_n_s__setdevice, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_4, __pyx_n_s__setdevice, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3345
+  /* "pysam/csamtools.pyx":3352
  *         self.setfd(fd)
  * 
  *     def setfile(self, filename):             # <<<<<<<<<<<<<<
  *         '''open a new file.'''
  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
  */
-  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_4Outs_5setfile, 0, __pyx_n_s_310, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_309)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_4Outs_5setfile, 0, __pyx_n_s_310, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_309)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyObject_SetItem(__pyx_t_4, __pyx_n_s__setfile, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_4, __pyx_n_s__setfile, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3350
+  /* "pysam/csamtools.pyx":3357
  *         self.setfd(fd)
  * 
  *     def setfd(self, fd):             # <<<<<<<<<<<<<<
  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
  *         self.streams.append(ofd)
  */
-  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_4Outs_7setfd, 0, __pyx_n_s_313, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_312)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_4Outs_7setfd, 0, __pyx_n_s_313, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_312)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyObject_SetItem(__pyx_t_4, __pyx_n_s__setfd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_4, __pyx_n_s__setfd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3358
+  /* "pysam/csamtools.pyx":3365
  *         os.close(fd)                #  Close other unit (look out, caller.)
  * 
  *     def restore(self):             # <<<<<<<<<<<<<<
  *         '''restore previous output stream'''
  *         if self.streams:
  */
-  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_4Outs_9restore, 0, __pyx_n_s_316, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_315)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_4Outs_9restore, 0, __pyx_n_s_316, NULL, __pyx_n_s_271, ((PyObject *)__pyx_k_codeobj_315)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyObject_SetItem(__pyx_t_4, __pyx_n_s__restore, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_4, __pyx_n_s__restore, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/csamtools.pyx":3334
+  /* "pysam/csamtools.pyx":3341
  *             return self._level
  * 
  * class Outs:             # <<<<<<<<<<<<<<
  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
  *     def __init__(self, id = 1):
  */
-  if (PyDict_SetItemString(((PyObject *)__pyx_t_4), "__doc__", ((PyObject *)__pyx_kp_s_317)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_1 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_4), __pyx_n_s__Outs, __pyx_n_s__Outs, __pyx_n_s_271); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItemString(((PyObject *)__pyx_t_4), "__doc__", ((PyObject *)__pyx_kp_s_317)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_4), __pyx_n_s__Outs, __pyx_n_s__Outs, __pyx_n_s_271); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Outs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Outs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":3371
+  /* "pysam/csamtools.pyx":3378
  * def _samtools_dispatch( method,
  *                         args = (),
  *                         catch_stdout = True ):             # <<<<<<<<<<<<<<
  *     '''call ``method`` in samtools providing arguments in args.
  * 
  */
-  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  __pyx_k_188 = __pyx_t_4;
+  __pyx_k_187 = __pyx_t_4;
   __Pyx_GIVEREF(__pyx_t_4);
   __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":3369
+  /* "pysam/csamtools.pyx":3376
  *             del self.streams[-1]
  * 
  * def _samtools_dispatch( method,             # <<<<<<<<<<<<<<
  *                         args = (),
  *                         catch_stdout = True ):
  */
-  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_1_samtools_dispatch, NULL, __pyx_n_s_271); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9csamtools_1_samtools_dispatch, NULL, __pyx_n_s_271); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s___samtools_dispatch, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s___samtools_dispatch, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "pysam/csamtools.pyx":4081
+  /* "pysam/csamtools.pyx":4088
  *         if self.owns_samfile: samclose( self.fp )
  * 
  * __all__ = ["Samfile",             # <<<<<<<<<<<<<<
  *            "Fastafile",
  *            "Fastqfile",
  */
-  __pyx_t_4 = PyList_New(10); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4081; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyList_New(10); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_INCREF(((PyObject *)__pyx_n_s__Samfile));
   PyList_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_n_s__Samfile));
@@ -44176,7 +45686,7 @@ PyMODINIT_FUNC PyInit_csamtools(void)
   __Pyx_INCREF(((PyObject *)__pyx_n_s__IndexedReads));
   PyList_SET_ITEM(__pyx_t_4, 9, ((PyObject *)__pyx_n_s__IndexedReads));
   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IndexedReads));
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4081; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
 
   /* "pysam/csamtools.pyx":1
@@ -44560,6 +46070,67 @@ invalid_keyword:
     return 0;
 }
 
+static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) {
+    PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname);
+}
+
+static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
+    PyObject *local_type, *local_value, *local_tb;
+#if CYTHON_COMPILING_IN_CPYTHON
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+    PyThreadState *tstate = PyThreadState_GET();
+    local_type = tstate->curexc_type;
+    local_value = tstate->curexc_value;
+    local_tb = tstate->curexc_traceback;
+    tstate->curexc_type = 0;
+    tstate->curexc_value = 0;
+    tstate->curexc_traceback = 0;
+#else
+    PyErr_Fetch(&local_type, &local_value, &local_tb);
+#endif
+    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
+#if CYTHON_COMPILING_IN_CPYTHON
+    if (unlikely(tstate->curexc_type))
+#else
+    if (unlikely(PyErr_Occurred()))
+#endif
+        goto bad;
+    #if PY_MAJOR_VERSION >= 3
+    if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
+        goto bad;
+    #endif
+    Py_INCREF(local_type);
+    Py_INCREF(local_value);
+    Py_INCREF(local_tb);
+    *type = local_type;
+    *value = local_value;
+    *tb = local_tb;
+#if CYTHON_COMPILING_IN_CPYTHON
+    tmp_type = tstate->exc_type;
+    tmp_value = tstate->exc_value;
+    tmp_tb = tstate->exc_traceback;
+    tstate->exc_type = local_type;
+    tstate->exc_value = local_value;
+    tstate->exc_traceback = local_tb;
+    /* Make sure tstate is in a consistent state when we XDECREF
+       these objects (DECREF may run arbitrary code). */
+    Py_XDECREF(tmp_type);
+    Py_XDECREF(tmp_value);
+    Py_XDECREF(tmp_tb);
+#else
+    PyErr_SetExcInfo(local_type, local_value, local_tb);
+#endif
+    return 0;
+bad:
+    *type = 0;
+    *value = 0;
+    *tb = 0;
+    Py_XDECREF(local_type);
+    Py_XDECREF(local_value);
+    Py_XDECREF(local_tb);
+    return -1;
+}
+
 static void __Pyx_RaiseDoubleKeywordsError(
     const char* func_name,
     PyObject* kw_name)
@@ -44719,63 +46290,6 @@ static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed
     return 0;
 }
 
-static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
-    PyObject *local_type, *local_value, *local_tb;
-#if CYTHON_COMPILING_IN_CPYTHON
-    PyObject *tmp_type, *tmp_value, *tmp_tb;
-    PyThreadState *tstate = PyThreadState_GET();
-    local_type = tstate->curexc_type;
-    local_value = tstate->curexc_value;
-    local_tb = tstate->curexc_traceback;
-    tstate->curexc_type = 0;
-    tstate->curexc_value = 0;
-    tstate->curexc_traceback = 0;
-#else
-    PyErr_Fetch(&local_type, &local_value, &local_tb);
-#endif
-    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
-#if CYTHON_COMPILING_IN_CPYTHON
-    if (unlikely(tstate->curexc_type))
-#else
-    if (unlikely(PyErr_Occurred()))
-#endif
-        goto bad;
-    #if PY_MAJOR_VERSION >= 3
-    if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
-        goto bad;
-    #endif
-    Py_INCREF(local_type);
-    Py_INCREF(local_value);
-    Py_INCREF(local_tb);
-    *type = local_type;
-    *value = local_value;
-    *tb = local_tb;
-#if CYTHON_COMPILING_IN_CPYTHON
-    tmp_type = tstate->exc_type;
-    tmp_value = tstate->exc_value;
-    tmp_tb = tstate->exc_traceback;
-    tstate->exc_type = local_type;
-    tstate->exc_value = local_value;
-    tstate->exc_traceback = local_tb;
-    /* Make sure tstate is in a consistent state when we XDECREF
-       these objects (DECREF may run arbitrary code). */
-    Py_XDECREF(tmp_type);
-    Py_XDECREF(tmp_value);
-    Py_XDECREF(tmp_tb);
-#else
-    PyErr_SetExcInfo(local_type, local_value, local_tb);
-#endif
-    return 0;
-bad:
-    *type = 0;
-    *value = 0;
-    *tb = 0;
-    Py_XDECREF(local_type);
-    Py_XDECREF(local_value);
-    Py_XDECREF(local_tb);
-    return -1;
-}
-
 static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
     PyErr_Format(PyExc_ValueError,
                  "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
diff --git a/pysam/csamtools.pxd b/pysam/csamtools.pxd
index 8341814..ecd08ae 100644
--- a/pysam/csamtools.pxd
+++ b/pysam/csamtools.pxd
@@ -426,17 +426,15 @@ ctypedef struct __iterdata:
 # Note: need to declare all C fields and methods here
 #
 cdef class Fastafile:
-    cdef char * _filename
-    # pointer to fastafile
-    cdef faidx_t * fastafile
-
-    cdef char * _fetch( self, char * reference, int start, int end, int * length )
+    cdef object _filename, _references, _lengths, reference2length
+    cdef faidx_t* fastafile
+    cdef char* _fetch(self, char* reference, int start, int end, int* length)
 
 cdef class FastqProxy:
     cdef kseq_t * _delegate
 
 cdef class Fastqfile:
-    cdef char * _filename
+    cdef object _filename
     cdef gzFile fastqfile
     cdef kseq_t * entry 
 
@@ -449,7 +447,7 @@ cdef class AlignedRead:
     cdef bam1_t * _delegate
 
 cdef class Samfile:
-    cdef char * _filename
+    cdef object _filename
     # pointer to samfile
     cdef samfile_t * samfile
     # pointer to index
diff --git a/pysam/csamtools.pyx b/pysam/csamtools.pyx
index 763798f..90033bd 100644
--- a/pysam/csamtools.pyx
+++ b/pysam/csamtools.pyx
@@ -38,9 +38,8 @@ if _FILENAME_ENCODING is None:
 #cdef char* _C_FILENAME_ENCODING
 #_C_FILENAME_ENCODING = <char*>_FILENAME_ENCODING
 
-cdef bytes _my_encodeFilename(object filename):
-    u"""Make sure a filename is 8-bit encoded (or None).
-    """
+cdef bytes _encodeFilename(object filename):
+    """Make sure a filename is 8-bit encoded (or None)."""
     if filename is None:
         return None
     elif PyBytes_Check(filename):
@@ -393,7 +392,10 @@ cdef class Fastafile:
 
     def __cinit__(self, *args, **kwargs ):
         self.fastafile = NULL
-        self._filename = NULL
+        self._filename = None
+        self._references = None
+        self._lengths = None
+        self.reference2length = None
         self._open( *args, **kwargs )
 
     def _isOpen( self ):
@@ -406,8 +408,7 @@ cdef class Fastafile:
 
         return faidx_fetch_nseq(self.fastafile)
 
-    def _open( self,
-               filename ):
+    def _open(self, filename):
         '''open an indexed fasta file.
 
         This method expects an indexed fasta file.
@@ -415,13 +416,21 @@ cdef class Fastafile:
 
         # close a previously opened file
         if self.fastafile != NULL: self.close()
-        if self._filename != NULL: free(self._filename)
-        filename = _my_encodeFilename(filename)
-        self._filename = strdup(filename)
-        self.fastafile = fai_load( filename )
+        self._filename = _encodeFilename(filename)
+        self.fastafile = fai_load(self._filename)
 
         if self.fastafile == NULL:
-            raise IOError("could not open file `%s`" % filename )
+            raise IOError("could not open file `%s`" % filename)
+
+        # read index
+        if not os.path.exists( self._filename + b".fai" ):
+            raise ValueError("could not locate index file")
+
+        with open( self._filename + b".fai" ) as inf:
+            data = [ x.split("\t") for x in inf ]
+            self._references = tuple(x[0] for x in data)
+            self._lengths = tuple(int(x[1]) for x in data)
+            self.reference2length = dict(zip(self._references, self._lengths))
 
     def close( self ):
         if self.fastafile != NULL:
@@ -430,14 +439,27 @@ cdef class Fastafile:
 
     def __dealloc__(self):
         self.close()
-        if self._filename != NULL: free(self._filename)
 
     property filename:
         '''number of :term:`filename` associated with this object.'''
         def __get__(self):
-            if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
             return self._filename
 
+    property references:
+        '''tuple with the names of :term:`reference` sequences.'''
+        def __get__(self):
+            return self._references
+
+    property nreferences:
+        '''number of :term:`reference` sequences in the file.'''
+        def __get__(self):
+            return len(self._references) if self.references else None
+
+    property lengths:
+        '''tuple with the lengths of :term:`reference` sequences.'''
+        def __get__(self):
+            return self._lengths
+
     def fetch( self,
                reference = None,
                start = None,
@@ -473,8 +495,8 @@ cdef class Fastafile:
             if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )
             if start == end: return b""
             # valid ranges are from 0 to 2^29-1
-            if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )
-            if not 0 <= end < max_pos: raise ValueError( 'end out of range (%i)' % end )
+            if not 0 <= start < max_pos: raise IndexError( 'start out of range (%i)' % start )
+            if not 0 <= end < max_pos: raise IndexError( 'end out of range (%i)' % end )
             # note: faidx_fetch_seq has a bug such that out-of-range access
             # always returns the last residue. Hence do not use faidx_fetch_seq,
             # but use fai_fetch instead
@@ -513,6 +535,16 @@ cdef class Fastafile:
                                end-1,
                                length )
 
+    def getReferenceLength( self, reference ):
+        '''return the length of reference.'''
+        return self.reference2length[reference]
+
+    def __getitem__(self, reference):
+        return self.fetch(reference)
+
+    def __contains__( self, reference ):
+        '''return true if reference in fasta file.'''
+        return reference in self.reference2length
 
 ######################################################################
 ######################################################################
@@ -549,48 +581,45 @@ cdef class Fastqfile:
     A *FASTQ* file. The file is automatically opened.
 
     '''
-
     def __cinit__(self, *args, **kwargs ):
-        # self.fastqfile = NULL
-        self._filename = NULL
+        # self.fastqfile = <gzFile*>NULL
+        self._filename = None
+        self.entry = NULL
         self._open( *args, **kwargs )
 
     def _isOpen( self ):
         '''return true if samfile has been opened.'''
-        return self._filename != NULL
+        return self.entry != NULL
 
-    def _open( self,
-               filename ):
+    def _open(self, filename):
         '''open an indexed fasta file.
 
         This method expects an indexed fasta file.
         '''
+        self.close()
 
         if not os.path.exists( filename ):
             raise IOError( "No such file or directory: %s" % filename )
 
-        # close a previously opened file
-        # if self.fastqfile != NULL: self.close()
-        if self._filename != NULL: free(self._filename)
-        filename = _my_encodeFilename(filename)
-        self._filename = strdup(filename)
+        filename = _encodeFilename(filename)
         self.fastqfile = gzopen( filename, "r" )
         self.entry = kseq_init( self.fastqfile )
+        self._filename = filename
 
     def close( self ):
         '''close file.'''
-        if self._filename != NULL:
+        if self.entry != NULL:
             gzclose( self.fastqfile )
-            free(self._filename)
+            if self.entry:
+                kseq_destroy(self.entry)
+                self.entry = NULL
 
     def __dealloc__(self):
-        kseq_destroy(self.entry)
         self.close()
 
     property filename:
         '''number of :term:`filename` associated with this object.'''
         def __get__(self):
-            if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
             return self._filename
 
     def __iter__(self):
@@ -701,7 +730,7 @@ cdef class Samfile:
 
     def __cinit__(self, *args, **kwargs ):
         self.samfile = NULL
-        self._filename = NULL
+        self._filename = None
         self.isbam = False
         self.isstream = False
         self._open( *args, **kwargs )
@@ -759,27 +788,19 @@ cdef class Samfile:
 
         assert mode in ( "r","w","rb","wb", "wh", "wbu", "rU" ), "invalid file opening mode `%s`" % mode
 
-        #assert filename != NULL
-
         # close a previously opened file
         if self.samfile != NULL: self.close()
-        self.samfile = NULL
 
         cdef bam_header_t * header_to_write
         header_to_write = NULL
 
-        if self._filename != NULL: free(self._filename )
-        filename = _my_encodeFilename(filename)
         cdef bytes bmode = mode.encode('ascii')
-        #cdef char* cfilename
-        #cfilename = filename.encode(_FILENAME_ENCODING)
-        self._filename = strdup(filename)
-        self.isstream = strcmp( filename, "-" ) == 0
+        self._filename = filename = _encodeFilename(filename)
+        self.isstream = filename == b"-"
 
         self.isbam = len(mode) > 1 and mode[1] == 'b'
 
-        self.isremote = strncmp(filename,"http:",5) == 0 or \
-            strncmp(filename,"ftp:",4) == 0
+        self.isremote = filename.startswith(b"http:") or filename.startswith(b"ftp:")
 
         cdef char * ctext
         ctext = NULL
@@ -819,7 +840,9 @@ cdef class Samfile:
                 if text is None and add_sq_text:
                     text = []
                     for x from 0 <= x < header_to_write.n_targets:
-                        text.append( "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] ) )
+                        text.append( "@SQ\tSN:%s\tLN:%s\n" % \
+                                         (_force_str(referencenames[x]), 
+                                          referencelengths[x] ) )
                     text = ''.join(text)
 
                 if text != None:
@@ -845,9 +868,7 @@ cdef class Samfile:
 
         elif mode[0] == "r":
             # open file for reading
-            if strncmp( filename, "-", 1) != 0 and \
-                    not self.isremote and \
-                    not os.path.exists( filename ):
+            if filename != b"-" and not self.isremote and not os.path.exists( filename ):
                 raise IOError( "file `%s` not found" % filename)
 
             # try to detect errors
@@ -1270,7 +1291,6 @@ cdef class Samfile:
         # note: __del__ is not called.
         self.close()
         bam_destroy1(self.b)
-        if self._filename != NULL: free( self._filename )
 
     cpdef int write( self, AlignedRead read ) except -1:
         '''
@@ -1298,7 +1318,6 @@ cdef class Samfile:
     property filename:
         '''number of :term:`filename` associated with this object.'''
         def __get__(self):
-            if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
             return self._filename
 
     property nreferences:
@@ -2604,9 +2623,12 @@ cdef class AlignedRead:
                 p[k] = <uint8_t>q[k] - 33
 
     property query:
-        """aligned portion of the read and excludes any flanking bases that were :term:`soft clipped` (None if not present).
+        """aligned portion of the read and excludes any flanking bases
+        that were :term:`soft clipped` (None if not present).
 
-        In Python 3, this property is of type bytes. Assigning a unicode string to it consisting of ASCII characters only will work, but is inefficient.
+        In Python 3, this property is of type bytes. Assigning a
+        unicode string to it consisting of ASCII characters only will
+        work, but is inefficient.
 
         SAM/BAM files may included extra flanking bases sequences that were
         not part of the alignment.  These bases may be the result of the
@@ -2630,7 +2652,8 @@ cdef class AlignedRead:
             return get_seq_range(src, start, end)
 
     property qqual:
-        """aligned query sequence quality values (None if not present). This property is read-only.
+        """aligned query sequence quality values (None if not
+        present). This property is read-only.
 
         In Python 3, this property is of type bytes."""
         def __get__(self):
diff --git a/pysam/ctabix.c b/pysam/ctabix.c
index 3d639f2..6231c76 100644
--- a/pysam/ctabix.c
+++ b/pysam/ctabix.c
@@ -1,4 +1,4 @@
-/* Generated by Cython 0.18 on Fri Sep 20 00:20:26 2013 */
+/* Generated by Cython 0.18 on Sat Nov 16 01:37:33 2013 */
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
@@ -260,10 +260,12 @@
 #include "fcntl.h"
 #include "unistd.h"
 #include "stdint.h"
+#include "zlib.h"
 #include "bgzf.h"
 #include "tabix.h"
 #include "tabix_util.h"
 #include "pythread.h"
+#include "errno.h"
 #ifdef _OPENMP
 #include <omp.h>
 #endif /* _OPENMP */
@@ -348,79 +350,25 @@ static const char *__pyx_f[] = {
 };
 
 /*--- Type declarations ---*/
-struct __pyx_obj_5pysam_6ctabix_Parser;
-struct __pyx_obj_5pysam_6ctabix_asBed;
-struct __pyx_obj_5pysam_6ctabix_asVCF;
-struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator;
 struct __pyx_obj_5pysam_6ctabix_TabixIterator;
-struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator;
+struct __pyx_obj_5pysam_6ctabix_Parser;
+struct __pyx_obj_5pysam_6ctabix_asGTF;
 struct __pyx_obj_5pysam_10TabProxies_TupleProxy;
 struct __pyx_obj_5pysam_10TabProxies_GTFProxy;
-struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy;
-struct __pyx_obj_5pysam_10TabProxies_VCFProxy;
-struct __pyx_obj_5pysam_6ctabix_asGTF;
+struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator;
+struct __pyx_obj_5pysam_6ctabix_asVCF;
 struct __pyx_obj_5pysam_6ctabix_Tabixfile;
+struct __pyx_obj_5pysam_6ctabix_asTuple;
 struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed;
+struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy;
+struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator;
 struct __pyx_obj_5pysam_10TabProxies_BedProxy;
-struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator;
-struct __pyx_obj_5pysam_6ctabix_asTuple;
-
-/* "pysam/ctabix.pxd":190
- *     cdef tabix_t * tabixfile
- * 
- * cdef class Parser:             # <<<<<<<<<<<<<<
- *      pass
- * 
- */
-struct __pyx_obj_5pysam_6ctabix_Parser {
-  PyObject_HEAD
-};
-
-
-/* "pysam/ctabix.pxd":199
- *      pass
- * 
- * cdef class asBed(Parser):             # <<<<<<<<<<<<<<
- *      pass
- * 
- */
-struct __pyx_obj_5pysam_6ctabix_asBed {
-  struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
-};
-
-
-/* "pysam/ctabix.pxd":202
- *      pass
- * 
- * cdef class asVCF(Parser):             # <<<<<<<<<<<<<<
- *      pass
- * 
- */
-struct __pyx_obj_5pysam_6ctabix_asVCF {
-  struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
-};
-
+struct __pyx_obj_5pysam_6ctabix_asBed;
+struct __pyx_obj_5pysam_10TabProxies_VCFProxy;
 
-/* "pysam/ctabix.pxd":210
+/* "pysam/ctabix.pxd":224
  *     cdef Parser parser
  * 
- * cdef class tabix_inplace_iterator:             # <<<<<<<<<<<<<<
- *     cdef FILE * infile
- *     cdef char * buffer
- */
-struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator {
-  PyObject_HEAD
-  struct __pyx_vtabstruct_5pysam_6ctabix_tabix_inplace_iterator *__pyx_vtab;
-  FILE *infile;
-  char *buffer;
-  size_t size;
-  struct __pyx_obj_5pysam_6ctabix_Parser *parser;
-};
-
-
-/* "pysam/ctabix.pxd":182
- *     cdef char * _filename
- * 
  * cdef class TabixIterator:             # <<<<<<<<<<<<<<
  *     cdef ti_iter_t iterator
  *     cdef tabix_t * tabixfile
@@ -432,17 +380,28 @@ struct __pyx_obj_5pysam_6ctabix_TabixIterator {
 };
 
 
-/* "pysam/ctabix.pxd":186
+/* "pysam/ctabix.pxd":232
  *     cdef tabix_t * tabixfile
  * 
- * cdef class TabixHeaderIterator:             # <<<<<<<<<<<<<<
- *     cdef ti_iter_t iterator
- *     cdef tabix_t * tabixfile
+ * cdef class Parser:             # <<<<<<<<<<<<<<
+ *      cdef parse( self, char * buffer, int len )
+ * 
  */
-struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator {
+struct __pyx_obj_5pysam_6ctabix_Parser {
   PyObject_HEAD
-  ti_iter_t iterator;
-  tabix_t *tabixfile;
+  struct __pyx_vtabstruct_5pysam_6ctabix_Parser *__pyx_vtab;
+};
+
+
+/* "pysam/ctabix.pxd":239
+ * 
+ * 
+ * cdef class asGTF(Parser):             # <<<<<<<<<<<<<<
+ *      pass
+ * 
+ */
+struct __pyx_obj_5pysam_6ctabix_asGTF {
+  struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
 };
 
 
@@ -480,46 +439,40 @@ struct __pyx_obj_5pysam_10TabProxies_GTFProxy {
 };
 
 
-/* "TabProxies.pxd":69
- *     cdef char * getAttributes( self )
- * 
- * cdef class NamedTupleProxy( TupleProxy) :             # <<<<<<<<<<<<<<
- *     pass
- * 
- */
-struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy {
-  struct __pyx_obj_5pysam_10TabProxies_TupleProxy __pyx_base;
-};
-
-
-/* "TabProxies.pxd":83
- *     cdef update( self, char * buffer, size_t nbytes )
- * 
- * cdef class VCFProxy( NamedTupleProxy) :             # <<<<<<<<<<<<<<
+/* "pysam/ctabix.pxd":201
+ *     int ks_getuntil( kstream_t *, int, kstring_t *, int * )
  * 
- *     cdef:
+ * cdef class tabix_file_iterator:             # <<<<<<<<<<<<<<
+ *     cdef gzFile fh
+ *     cdef kstream_t * ks
  */
-struct __pyx_obj_5pysam_10TabProxies_VCFProxy {
-  struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy __pyx_base;
-  char *contig;
-  uint32_t pos;
+struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_5pysam_6ctabix_tabix_file_iterator *__pyx_vtab;
+  gzFile fh;
+  kstream_t *ks;
+  kstring_t buffer;
+  size_t size;
+  struct __pyx_obj_5pysam_6ctabix_Parser *parser;
+  int fd;
+  PyObject *infile;
 };
 
 
-/* "pysam/ctabix.pxd":196
+/* "pysam/ctabix.pxd":245
  *      pass
  * 
- * cdef class asGTF(Parser):             # <<<<<<<<<<<<<<
+ * cdef class asVCF(Parser):             # <<<<<<<<<<<<<<
  *      pass
  * 
  */
-struct __pyx_obj_5pysam_6ctabix_asGTF {
+struct __pyx_obj_5pysam_6ctabix_asVCF {
   struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
 };
 
 
-/* "pysam/ctabix.pxd":172
- *   # char *ti_iter_read(BGZF *fp, ti_iter_t iter, int *len)
+/* "pysam/ctabix.pxd":212
+ *     cdef __cnext__(self)
  * 
  * cdef class Tabixfile:             # <<<<<<<<<<<<<<
  * 
@@ -530,10 +483,23 @@ struct __pyx_obj_5pysam_6ctabix_Tabixfile {
   tabix_t *tabixfile;
   int isremote;
   char *_filename;
+  struct __pyx_obj_5pysam_6ctabix_Parser *parser;
+};
+
+
+/* "pysam/ctabix.pxd":235
+ *      cdef parse( self, char * buffer, int len )
+ * 
+ * cdef class asTuple(Parser):             # <<<<<<<<<<<<<<
+ *      cdef parse( self, char * buffer, int len )
+ * 
+ */
+struct __pyx_obj_5pysam_6ctabix_asTuple {
+  struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
 };
 
 
-/* "pysam/ctabix.pxd":205
+/* "pysam/ctabix.pxd":248
  *      pass
  * 
  * cdef class TabixIteratorParsed:             # <<<<<<<<<<<<<<
@@ -548,6 +514,32 @@ struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed {
 };
 
 
+/* "TabProxies.pxd":69
+ *     cdef char * getAttributes( self )
+ * 
+ * cdef class NamedTupleProxy( TupleProxy) :             # <<<<<<<<<<<<<<
+ *     pass
+ * 
+ */
+struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy {
+  struct __pyx_obj_5pysam_10TabProxies_TupleProxy __pyx_base;
+};
+
+
+/* "pysam/ctabix.pxd":228
+ *     cdef tabix_t * tabixfile
+ * 
+ * cdef class TabixHeaderIterator:             # <<<<<<<<<<<<<<
+ *     cdef ti_iter_t iterator
+ *     cdef tabix_t * tabixfile
+ */
+struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator {
+  PyObject_HEAD
+  ti_iter_t iterator;
+  tabix_t *tabixfile;
+};
+
+
 /* "TabProxies.pxd":72
  *     pass
  * 
@@ -564,32 +556,101 @@ struct __pyx_obj_5pysam_10TabProxies_BedProxy {
 };
 
 
-/* "pysam/ctabix.pxd":218
- *     cdef __cnext__(self)
+/* "pysam/ctabix.pxd":242
+ *      pass
+ * 
+ * cdef class asBed(Parser):             # <<<<<<<<<<<<<<
+ *      pass
  * 
- * cdef class tabix_copy_iterator:             # <<<<<<<<<<<<<<
- *     cdef FILE * infile
- *     cdef Parser parser
  */
-struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator {
-  PyObject_HEAD
-  struct __pyx_vtabstruct_5pysam_6ctabix_tabix_copy_iterator *__pyx_vtab;
-  FILE *infile;
-  struct __pyx_obj_5pysam_6ctabix_Parser *parser;
+struct __pyx_obj_5pysam_6ctabix_asBed {
+  struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
 };
 
 
-/* "pysam/ctabix.pxd":193
- *      pass
+/* "TabProxies.pxd":83
+ *     cdef update( self, char * buffer, size_t nbytes )
+ * 
+ * cdef class VCFProxy( NamedTupleProxy) :             # <<<<<<<<<<<<<<
+ * 
+ *     cdef:
+ */
+struct __pyx_obj_5pysam_10TabProxies_VCFProxy {
+  struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy __pyx_base;
+  char *contig;
+  uint32_t pos;
+};
+
+
+
+/* "pysam/ctabix.pyx":392
+ * #########################################################
+ * #########################################################
+ * cdef class Parser:             # <<<<<<<<<<<<<<
+ * 
+ *     cdef parse(self, char * buffer, int length):
+ */
+
+struct __pyx_vtabstruct_5pysam_6ctabix_Parser {
+  PyObject *(*parse)(struct __pyx_obj_5pysam_6ctabix_Parser *, char *, int);
+};
+static struct __pyx_vtabstruct_5pysam_6ctabix_Parser *__pyx_vtabptr_5pysam_6ctabix_Parser;
+
+
+/* "pysam/ctabix.pyx":400
+ *         return self.parse( buffer, length )
  * 
  * cdef class asTuple(Parser):             # <<<<<<<<<<<<<<
- *      pass
+ *     '''converts a :term:`tabix row` into a python tuple.
  * 
  */
-struct __pyx_obj_5pysam_6ctabix_asTuple {
-  struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
+
+struct __pyx_vtabstruct_5pysam_6ctabix_asTuple {
+  struct __pyx_vtabstruct_5pysam_6ctabix_Parser __pyx_base;
+};
+static struct __pyx_vtabstruct_5pysam_6ctabix_asTuple *__pyx_vtabptr_5pysam_6ctabix_asTuple;
+
+
+/* "pysam/ctabix.pyx":450
+ *         return r
+ * 
+ * cdef class asBed( Parser ):             # <<<<<<<<<<<<<<
+ *     '''converts a :term:`tabix row` into a bed record
+ *     with the following fields:
+ */
+
+struct __pyx_vtabstruct_5pysam_6ctabix_asBed {
+  struct __pyx_vtabstruct_5pysam_6ctabix_Parser __pyx_base;
+};
+static struct __pyx_vtabstruct_5pysam_6ctabix_asBed *__pyx_vtabptr_5pysam_6ctabix_asBed;
+
+
+/* "pysam/ctabix.pyx":802
+ * 
+ * 
+ * cdef class tabix_file_iterator:             # <<<<<<<<<<<<<<
+ *     '''iterate over a compressed or uncompressed ``infile``.
+ *     '''
+ */
+
+struct __pyx_vtabstruct_5pysam_6ctabix_tabix_file_iterator {
+  PyObject *(*__pyx___cnext__)(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *);
 };
+static struct __pyx_vtabstruct_5pysam_6ctabix_tabix_file_iterator *__pyx_vtabptr_5pysam_6ctabix_tabix_file_iterator;
+
+
+/* "pysam/ctabix.pyx":490
+ *         return r
+ * 
+ * cdef class asVCF( Parser ):             # <<<<<<<<<<<<<<
+ *     '''converts a :term:`tabix row` into a VCF record with
+ *     the following fields:
+ */
 
+struct __pyx_vtabstruct_5pysam_6ctabix_asVCF {
+  struct __pyx_vtabstruct_5pysam_6ctabix_Parser __pyx_base;
+};
+static struct __pyx_vtabstruct_5pysam_6ctabix_asVCF *__pyx_vtabptr_5pysam_6ctabix_asVCF;
 
 
 /* "TabProxies.pxd":41
@@ -624,34 +685,6 @@ struct __pyx_vtabstruct_5pysam_10TabProxies_NamedTupleProxy {
 static struct __pyx_vtabstruct_5pysam_10TabProxies_NamedTupleProxy *__pyx_vtabptr_5pysam_10TabProxies_NamedTupleProxy;
 
 
-/* "TabProxies.pxd":83
- *     cdef update( self, char * buffer, size_t nbytes )
- * 
- * cdef class VCFProxy( NamedTupleProxy) :             # <<<<<<<<<<<<<<
- * 
- *     cdef:
- */
-
-struct __pyx_vtabstruct_5pysam_10TabProxies_VCFProxy {
-  struct __pyx_vtabstruct_5pysam_10TabProxies_NamedTupleProxy __pyx_base;
-};
-static struct __pyx_vtabstruct_5pysam_10TabProxies_VCFProxy *__pyx_vtabptr_5pysam_10TabProxies_VCFProxy;
-
-
-/* "pysam/ctabix.pyx":709
- * ## Iterators for parsing through unindexed files.
- * #########################################################
- * ctypedef class tabix_inplace_iterator:             # <<<<<<<<<<<<<<
- *     '''iterate over ``infile``.
- * 
- */
-
-struct __pyx_vtabstruct_5pysam_6ctabix_tabix_inplace_iterator {
-  PyObject *(*__pyx___cnext__)(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *);
-};
-static struct __pyx_vtabstruct_5pysam_6ctabix_tabix_inplace_iterator *__pyx_vtabptr_5pysam_6ctabix_tabix_inplace_iterator;
-
-
 /* "TabProxies.pxd":72
  *     pass
  * 
@@ -666,18 +699,18 @@ struct __pyx_vtabstruct_5pysam_10TabProxies_BedProxy {
 static struct __pyx_vtabstruct_5pysam_10TabProxies_BedProxy *__pyx_vtabptr_5pysam_10TabProxies_BedProxy;
 
 
-/* "pysam/ctabix.pyx":771
- *         return self.__cnext__()
- * 
- * ctypedef class tabix_copy_iterator:             # <<<<<<<<<<<<<<
- *     '''iterate over ``infile``.
+/* "pysam/ctabix.pyx":413
+ *         return r
  * 
+ * cdef class asGTF(Parser):             # <<<<<<<<<<<<<<
+ *     '''converts a :term:`tabix row` into a GTF record with the following
+ *     fields:
  */
 
-struct __pyx_vtabstruct_5pysam_6ctabix_tabix_copy_iterator {
-  PyObject *(*__pyx___cnext__)(struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *);
+struct __pyx_vtabstruct_5pysam_6ctabix_asGTF {
+  struct __pyx_vtabstruct_5pysam_6ctabix_Parser __pyx_base;
 };
-static struct __pyx_vtabstruct_5pysam_6ctabix_tabix_copy_iterator *__pyx_vtabptr_5pysam_6ctabix_tabix_copy_iterator;
+static struct __pyx_vtabstruct_5pysam_6ctabix_asGTF *__pyx_vtabptr_5pysam_6ctabix_asGTF;
 
 
 /* "TabProxies.pxd":60
@@ -693,6 +726,20 @@ struct __pyx_vtabstruct_5pysam_10TabProxies_GTFProxy {
   char *(*getAttributes)(struct __pyx_obj_5pysam_10TabProxies_GTFProxy *);
 };
 static struct __pyx_vtabstruct_5pysam_10TabProxies_GTFProxy *__pyx_vtabptr_5pysam_10TabProxies_GTFProxy;
+
+
+/* "TabProxies.pxd":83
+ *     cdef update( self, char * buffer, size_t nbytes )
+ * 
+ * cdef class VCFProxy( NamedTupleProxy) :             # <<<<<<<<<<<<<<
+ * 
+ *     cdef:
+ */
+
+struct __pyx_vtabstruct_5pysam_10TabProxies_VCFProxy {
+  struct __pyx_vtabstruct_5pysam_10TabProxies_NamedTupleProxy __pyx_base;
+};
+static struct __pyx_vtabstruct_5pysam_10TabProxies_VCFProxy *__pyx_vtabptr_5pysam_10TabProxies_VCFProxy;
 #ifndef CYTHON_REFNANNY
   #define CYTHON_REFNANNY 0
 #endif
@@ -770,6 +817,8 @@ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
 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 int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
+
 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
     PyObject *r;
     if (!j) return NULL;
@@ -1100,7 +1149,12 @@ static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0;
 
 /* Module declarations from 'cpython' */
 
+/* Module declarations from 'libc.errno' */
+
+/* Module declarations from 'libc.stdint' */
+
 /* Module declarations from 'pysam.ctabix' */
+static PyTypeObject *__pyx_ptype_5pysam_6ctabix_tabix_file_iterator = 0;
 static PyTypeObject *__pyx_ptype_5pysam_6ctabix_Tabixfile = 0;
 static PyTypeObject *__pyx_ptype_5pysam_6ctabix_TabixIterator = 0;
 static PyTypeObject *__pyx_ptype_5pysam_6ctabix_TabixHeaderIterator = 0;
@@ -1110,8 +1164,6 @@ static PyTypeObject *__pyx_ptype_5pysam_6ctabix_asGTF = 0;
 static PyTypeObject *__pyx_ptype_5pysam_6ctabix_asBed = 0;
 static PyTypeObject *__pyx_ptype_5pysam_6ctabix_asVCF = 0;
 static PyTypeObject *__pyx_ptype_5pysam_6ctabix_TabixIteratorParsed = 0;
-static PyTypeObject *__pyx_ptype_5pysam_6ctabix_tabix_inplace_iterator = 0;
-static PyTypeObject *__pyx_ptype_5pysam_6ctabix_tabix_copy_iterator = 0;
 static PyObject *__pyx_v_5pysam_6ctabix__FILENAME_ENCODING = 0;
 static PyObject *__pyx_f_5pysam_6ctabix__my_encodeFilename(PyObject *); /*proto*/
 static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *); /*proto*/
@@ -1123,13 +1175,14 @@ int __pyx_module_is_main_pysam__ctabix = 0;
 static PyObject *__pyx_builtin_TypeError;
 static PyObject *__pyx_builtin_NotImplementedError;
 static PyObject *__pyx_builtin_IOError;
+static PyObject *__pyx_builtin_KeyError;
 static PyObject *__pyx_builtin_ValueError;
+static PyObject *__pyx_builtin_IndexError;
 static PyObject *__pyx_builtin_StopIteration;
 static PyObject *__pyx_builtin_OSError;
 static PyObject *__pyx_builtin_ord;
-static PyObject *__pyx_builtin_KeyError;
 static PyObject *__pyx_builtin_MemoryError;
-static int __pyx_pf_5pysam_6ctabix_9Tabixfile___cinit__(struct __pyx_obj_5pysam_6ctabix_Tabixfile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
+static int __pyx_pf_5pysam_6ctabix_9Tabixfile___cinit__(struct __pyx_obj_5pysam_6ctabix_Tabixfile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_parser, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
 static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_2_isOpen(struct __pyx_obj_5pysam_6ctabix_Tabixfile *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_4_open(struct __pyx_obj_5pysam_6ctabix_Tabixfile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode); /* proto */
 static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_obj_5pysam_6ctabix_Tabixfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region); /* proto */
@@ -1147,23 +1200,18 @@ static int __pyx_pf_5pysam_6ctabix_19TabixHeaderIterator___cinit__(struct __pyx_
 static PyObject *__pyx_pf_5pysam_6ctabix_19TabixHeaderIterator_2__iter__(struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_6ctabix_19TabixHeaderIterator_4__next__(struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator *__pyx_v_self); /* proto */
 static void __pyx_pf_5pysam_6ctabix_19TabixHeaderIterator_6__dealloc__(struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_5pysam_6ctabix_7asTuple___call__(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_asTuple *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len); /* proto */
-static PyObject *__pyx_pf_5pysam_6ctabix_5asGTF___call__(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_asGTF *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len); /* proto */
-static PyObject *__pyx_pf_5pysam_6ctabix_5asBed___call__(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_asBed *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len); /* proto */
-static PyObject *__pyx_pf_5pysam_6ctabix_5asVCF___call__(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_asVCF *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len); /* proto */
+static PyObject *__pyx_pf_5pysam_6ctabix_6Parser___call__(struct __pyx_obj_5pysam_6ctabix_Parser *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_length); /* proto */
 static int __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed___cinit__(struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *__pyx_v_self, struct __pyx_obj_5pysam_6ctabix_Tabixfile *__pyx_v_tabixfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, struct __pyx_obj_5pysam_6ctabix_Parser *__pyx_v_parser); /* proto */
 static PyObject *__pyx_pf_5pysam_6ctabix_19TabixIteratorParsed_2__iter__(struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_6ctabix_19TabixIteratorParsed_4__next__(struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *__pyx_v_self); /* proto */
 static void __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed_6__dealloc__(struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename_in, PyObject *__pyx_v_filename_out, PyObject *__pyx_v_force); /* proto */
 static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_force, PyObject *__pyx_v_seq_col, PyObject *__pyx_v_start_col, PyObject *__pyx_v_end_col, PyObject *__pyx_v_preset, PyObject *__pyx_v_meta_char, PyObject *__pyx_v_zerobased); /* proto */
-static int __pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator___cinit__(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *__pyx_v_self, PyObject *__pyx_v_infile, int __pyx_v_buffer_size); /* proto */
-static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_2__iter__(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *__pyx_v_self); /* proto */
-static void __pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_4__dealloc__(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_6__next__(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *__pyx_v_self); /* proto */
-static int __pyx_pf_5pysam_6ctabix_19tabix_copy_iterator___cinit__(struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *__pyx_v_self, PyObject *__pyx_v_infile, struct __pyx_obj_5pysam_6ctabix_Parser *__pyx_v_parser); /* proto */
-static PyObject *__pyx_pf_5pysam_6ctabix_19tabix_copy_iterator_2__iter__(struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_5pysam_6ctabix_19tabix_copy_iterator_4__next__(struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *__pyx_v_self); /* proto */
+static int __pyx_pf_5pysam_6ctabix_19tabix_file_iterator___cinit__(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *__pyx_v_self, PyObject *__pyx_v_infile, struct __pyx_obj_5pysam_6ctabix_Parser *__pyx_v_parser, int __pyx_v_buffer_size); /* proto */
+static PyObject *__pyx_pf_5pysam_6ctabix_19tabix_file_iterator_2__iter__(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *__pyx_v_self); /* proto */
+static void __pyx_pf_5pysam_6ctabix_19tabix_file_iterator_4__dealloc__(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_5pysam_6ctabix_19tabix_file_iterator_6__next__(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_5pysam_6ctabix_19tabix_file_iterator_8next(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_infile, PyObject *__pyx_v_parser); /* proto */
 static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_2__iter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
 static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_4__next__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
@@ -1180,26 +1228,27 @@ static char __pyx_k_14[] = "file `%s` not found";
 static char __pyx_k_15[] = "index `%s` not found";
 static char __pyx_k_16[] = "could not open file `%s`";
 static char __pyx_k_17[] = "%s:%i-%i";
-static char __pyx_k_18[] = "invalid region `%s`";
-static char __pyx_k_19[] = "invalid region: start (%i) > end (%i)";
-static char __pyx_k_20[] = "start out of range (%i)";
-static char __pyx_k_21[] = "end out of range (%i)";
-static char __pyx_k_22[] = "I/O operation on closed file";
-static char __pyx_k_25[] = "malformatted query or wrong sequence name.\n";
-static char __pyx_k_27[] = "can't open header.\n";
-static char __pyx_k_31[] = "Filename '%s' already exists, use *force* to overwrite";
-static char __pyx_k_32[] = "could not open '%s' for writing";
-static char __pyx_k_34[] = "could not open '%s' for reading";
-static char __pyx_k_36[] = "writing failed";
-static char __pyx_k_40[] = "#";
-static char __pyx_k_42[] = "No such file '%s'";
-static char __pyx_k_43[] = "neither preset nor seq_col,start_col and end_col given";
-static char __pyx_k_45[] = ".gz";
-static char __pyx_k_47[] = "Filename '%s.tbi' already exists, use *force* to overwrite";
-static char __pyx_k_49[] = "unknown preset '%s', valid presets are '%s'";
-static char __pyx_k_50[] = ",";
+static char __pyx_k_18[] = "invalid region: start (%i) > end (%i)";
+static char __pyx_k_19[] = "start out of range (%i)";
+static char __pyx_k_20[] = "end out of range (%i)";
+static char __pyx_k_21[] = "I/O operation on closed file";
+static char __pyx_k_24[] = "malformatted query or wrong sequence name.\n";
+static char __pyx_k_26[] = "can't open header.\n";
+static char __pyx_k_30[] = "Filename '%s' already exists, use *force* to overwrite";
+static char __pyx_k_31[] = "could not open '%s' for writing";
+static char __pyx_k_33[] = "could not open '%s' for reading";
+static char __pyx_k_35[] = "writing failed";
+static char __pyx_k_39[] = "#";
+static char __pyx_k_41[] = "No such file '%s'";
+static char __pyx_k_42[] = "neither preset nor seq_col,start_col and end_col given";
+static char __pyx_k_44[] = ".gz";
+static char __pyx_k_46[] = "Filename '%s.tbi' already exists, use *force* to overwrite";
+static char __pyx_k_48[] = "unknown preset '%s', valid presets are '%s'";
+static char __pyx_k_49[] = ",";
+static char __pyx_k_50[] = "error (%d): %s (%d: %s)";
 static char __pyx_k_51[] = "I/O operation on closed file.";
-static char __pyx_k_54[] = "incomplete line at %s";
+static char __pyx_k_54[] = "%s";
+static char __pyx_k_57[] = "incomplete line at %s";
 static char __pyx_k_58[] = "tabix_generic_iterator";
 static char __pyx_k_59[] = "filename associated with this object.";
 static char __pyx_k_60[] = "the file header.\n          \n        .. note::\n            The header is returned as an iterator over lines without the\n            newline character.\n        ";
@@ -1212,7 +1261,6 @@ static char __pyx_k_74[] = "tabix_generic_iterator.__iter__";
 static char __pyx_k_77[] = "tabix_generic_iterator.__next__";
 static char __pyx_k_80[] = "tabix_generic_iterator.next";
 static char __pyx_k_81[] = "iterate over ``infile``.\n    \n    Permits the use of file-like objects for example from the gzip module.\n    ";
-static char __pyx_k_84[] = "tabix_inplace_iterator";
 static char __pyx_k__b[] = "b";
 static char __pyx_k__c[] = "c";
 static char __pyx_k__r[] = "r";
@@ -1226,7 +1274,6 @@ static char __pyx_k__bed[] = "bed";
 static char __pyx_k__cpy[] = "cpy";
 static char __pyx_k__end[] = "end";
 static char __pyx_k__gff[] = "gff";
-static char __pyx_k__len[] = "len";
 static char __pyx_k__ord[] = "ord";
 static char __pyx_k__sam[] = "sam";
 static char __pyx_k__sys[] = "sys";
@@ -1249,7 +1296,6 @@ static char __pyx_k__close[] = "close";
 static char __pyx_k__force[] = "force";
 static char __pyx_k__start[] = "start";
 static char __pyx_k__types[] = "types";
-static char __pyx_k__Parser[] = "Parser";
 static char __pyx_k__buffer[] = "buffer";
 static char __pyx_k__closed[] = "closed";
 static char __pyx_k__ctypes[] = "ctypes";
@@ -1258,6 +1304,7 @@ static char __pyx_k__encode[] = "encode";
 static char __pyx_k__exists[] = "exists";
 static char __pyx_k__fd_src[] = "fd_src";
 static char __pyx_k__infile[] = "infile";
+static char __pyx_k__length[] = "length";
 static char __pyx_k__nbytes[] = "nbytes";
 static char __pyx_k__parser[] = "parser";
 static char __pyx_k__pileup[] = "pileup";
@@ -1273,7 +1320,6 @@ static char __pyx_k____all__[] = "__all__";
 static char __pyx_k___isOpen[] = "_isOpen";
 static char __pyx_k__asTuple[] = "asTuple";
 static char __pyx_k__end_col[] = "end_col";
-static char __pyx_k__present[] = "present";
 static char __pyx_k__seq_col[] = "seq_col";
 static char __pyx_k__KeyError[] = "KeyError";
 static char __pyx_k__O_RDONLY[] = "O_RDONLY";
@@ -1295,6 +1341,7 @@ static char __pyx_k__reference[] = "reference";
 static char __pyx_k__start_col[] = "start_col";
 static char __pyx_k__tabixfile[] = "tabixfile";
 static char __pyx_k__zerobased[] = "zerobased";
+static char __pyx_k__IndexError[] = "IndexError";
 static char __pyx_k__ValueError[] = "ValueError";
 static char __pyx_k__startswith[] = "startswith";
 static char __pyx_k__MemoryError[] = "MemoryError";
@@ -1310,6 +1357,7 @@ static char __pyx_k__tabix_compress[] = "tabix_compress";
 static char __pyx_k__tabix_iterator[] = "tabix_iterator";
 static char __pyx_k__getdefaultencoding[] = "getdefaultencoding";
 static char __pyx_k__NotImplementedError[] = "NotImplementedError";
+static char __pyx_k__tabix_file_iterator[] = "tabix_file_iterator";
 static PyObject *__pyx_kp_u_1;
 static PyObject *__pyx_kp_s_12;
 static PyObject *__pyx_kp_s_14;
@@ -1320,24 +1368,25 @@ static PyObject *__pyx_kp_s_18;
 static PyObject *__pyx_kp_s_19;
 static PyObject *__pyx_kp_s_20;
 static PyObject *__pyx_kp_s_21;
-static PyObject *__pyx_kp_s_22;
-static PyObject *__pyx_kp_s_25;
-static PyObject *__pyx_kp_s_27;
+static PyObject *__pyx_kp_s_24;
+static PyObject *__pyx_kp_s_26;
 static PyObject *__pyx_kp_u_3;
+static PyObject *__pyx_kp_s_30;
 static PyObject *__pyx_kp_s_31;
-static PyObject *__pyx_kp_s_32;
-static PyObject *__pyx_kp_s_34;
-static PyObject *__pyx_kp_s_36;
-static PyObject *__pyx_kp_s_40;
+static PyObject *__pyx_kp_s_33;
+static PyObject *__pyx_kp_s_35;
+static PyObject *__pyx_kp_s_39;
+static PyObject *__pyx_kp_s_41;
 static PyObject *__pyx_kp_s_42;
-static PyObject *__pyx_kp_s_43;
-static PyObject *__pyx_kp_s_45;
-static PyObject *__pyx_kp_s_47;
+static PyObject *__pyx_kp_s_44;
+static PyObject *__pyx_kp_s_46;
+static PyObject *__pyx_kp_s_48;
 static PyObject *__pyx_kp_s_49;
 static PyObject *__pyx_kp_s_5;
 static PyObject *__pyx_kp_s_50;
 static PyObject *__pyx_kp_s_51;
 static PyObject *__pyx_kp_s_54;
+static PyObject *__pyx_kp_s_57;
 static PyObject *__pyx_n_s_58;
 static PyObject *__pyx_kp_s_6;
 static PyObject *__pyx_n_s_62;
@@ -1349,16 +1398,15 @@ static PyObject *__pyx_n_s_74;
 static PyObject *__pyx_n_s_77;
 static PyObject *__pyx_n_s_80;
 static PyObject *__pyx_kp_s_81;
-static PyObject *__pyx_n_s_84;
 static PyObject *__pyx_kp_s_9;
 static PyObject *__pyx_n_s__IOError;
+static PyObject *__pyx_n_s__IndexError;
 static PyObject *__pyx_n_s__KeyError;
 static PyObject *__pyx_n_s__MemoryError;
 static PyObject *__pyx_n_s__NotImplementedError;
 static PyObject *__pyx_n_s__OSError;
 static PyObject *__pyx_n_s__O_RDONLY;
 static PyObject *__pyx_n_s__PYTHON3;
-static PyObject *__pyx_n_s__Parser;
 static PyObject *__pyx_n_s__StopIteration;
 static PyObject *__pyx_n_s__Tabixfile;
 static PyObject *__pyx_n_s__TypeError;
@@ -1409,7 +1457,7 @@ static PyObject *__pyx_n_s__infile;
 static PyObject *__pyx_n_s__io;
 static PyObject *__pyx_n_s__itertools;
 static PyObject *__pyx_n_s__join;
-static PyObject *__pyx_n_s__len;
+static PyObject *__pyx_n_s__length;
 static PyObject *__pyx_n_s__line;
 static PyObject *__pyx_n_s__meta_char;
 static PyObject *__pyx_n_s__mode;
@@ -1420,7 +1468,6 @@ static PyObject *__pyx_n_s__os;
 static PyObject *__pyx_n_s__parser;
 static PyObject *__pyx_n_s__path;
 static PyObject *__pyx_n_s__pileup;
-static PyObject *__pyx_n_s__present;
 static PyObject *__pyx_n_s__preset;
 static PyObject *__pyx_n_s__preset2conf;
 static PyObject *__pyx_n_s__psltbl;
@@ -1438,6 +1485,7 @@ static PyObject *__pyx_n_s__startswith;
 static PyObject *__pyx_n_s__struct;
 static PyObject *__pyx_n_s__sys;
 static PyObject *__pyx_n_s__tabix_compress;
+static PyObject *__pyx_n_s__tabix_file_iterator;
 static PyObject *__pyx_n_s__tabix_index;
 static PyObject *__pyx_n_s__tabix_iterator;
 static PyObject *__pyx_n_s__tabixfile;
@@ -1459,33 +1507,33 @@ static PyObject *__pyx_int_15;
 static PyObject *__pyx_int_17;
 static PyObject *__pyx_int_18;
 static PyObject *__pyx_int_35;
+static PyObject *__pyx_int_64;
 static PyObject *__pyx_int_65536;
-static PyObject *__pyx_k_30;
-static PyObject *__pyx_k_39;
-static PyObject *__pyx_k_41;
+static PyObject *__pyx_k_29;
+static PyObject *__pyx_k_38;
+static PyObject *__pyx_k_40;
 static PyObject *__pyx_k_tuple_2;
 static PyObject *__pyx_k_tuple_4;
 static PyObject *__pyx_k_tuple_8;
 static PyObject *__pyx_k_tuple_10;
 static PyObject *__pyx_k_tuple_11;
 static PyObject *__pyx_k_tuple_13;
+static PyObject *__pyx_k_tuple_22;
 static PyObject *__pyx_k_tuple_23;
-static PyObject *__pyx_k_tuple_24;
-static PyObject *__pyx_k_tuple_26;
+static PyObject *__pyx_k_tuple_25;
+static PyObject *__pyx_k_tuple_27;
 static PyObject *__pyx_k_tuple_28;
-static PyObject *__pyx_k_tuple_29;
-static PyObject *__pyx_k_tuple_33;
-static PyObject *__pyx_k_tuple_35;
+static PyObject *__pyx_k_tuple_32;
+static PyObject *__pyx_k_tuple_34;
+static PyObject *__pyx_k_tuple_36;
 static PyObject *__pyx_k_tuple_37;
-static PyObject *__pyx_k_tuple_38;
-static PyObject *__pyx_k_tuple_44;
-static PyObject *__pyx_k_tuple_46;
-static PyObject *__pyx_k_tuple_48;
+static PyObject *__pyx_k_tuple_43;
+static PyObject *__pyx_k_tuple_45;
+static PyObject *__pyx_k_tuple_47;
 static PyObject *__pyx_k_tuple_52;
 static PyObject *__pyx_k_tuple_53;
 static PyObject *__pyx_k_tuple_55;
 static PyObject *__pyx_k_tuple_56;
-static PyObject *__pyx_k_tuple_57;
 static PyObject *__pyx_k_tuple_63;
 static PyObject *__pyx_k_tuple_67;
 static PyObject *__pyx_k_tuple_69;
@@ -1501,7 +1549,7 @@ static PyObject *__pyx_k_codeobj_76;
 static PyObject *__pyx_k_codeobj_79;
 static PyObject *__pyx_k_codeobj_83;
 
-/* "pysam/ctabix.pyx":19
+/* "pysam/ctabix.pyx":24
  * from cpython.version cimport PY_MAJOR_VERSION
  * 
  * cdef from_string_and_size(char* s, size_t length):             # <<<<<<<<<<<<<<
@@ -1519,7 +1567,7 @@ static PyObject *__pyx_f_5pysam_6ctabix_from_string_and_size(char *__pyx_v_s, si
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("from_string_and_size", 0);
 
-  /* "pysam/ctabix.pyx":20
+  /* "pysam/ctabix.pyx":25
  * 
  * cdef from_string_and_size(char* s, size_t length):
  *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
@@ -1529,7 +1577,7 @@ static PyObject *__pyx_f_5pysam_6ctabix_from_string_and_size(char *__pyx_v_s, si
   __pyx_t_1 = (PY_MAJOR_VERSION < 3);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":21
+    /* "pysam/ctabix.pyx":26
  * cdef from_string_and_size(char* s, size_t length):
  *     if PY_MAJOR_VERSION < 3:
  *         return s[:length]             # <<<<<<<<<<<<<<
@@ -1537,7 +1585,7 @@ static PyObject *__pyx_f_5pysam_6ctabix_from_string_and_size(char *__pyx_v_s, si
  *         return s[:length].decode("ascii")
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = PyBytes_FromStringAndSize(__pyx_v_s + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyBytes_FromStringAndSize(__pyx_v_s + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
     __pyx_r = ((PyObject *)__pyx_t_2);
     __pyx_t_2 = 0;
@@ -1546,7 +1594,7 @@ static PyObject *__pyx_f_5pysam_6ctabix_from_string_and_size(char *__pyx_v_s, si
   }
   /*else*/ {
 
-    /* "pysam/ctabix.pyx":23
+    /* "pysam/ctabix.pyx":28
  *         return s[:length]
  *     else:
  *         return s[:length].decode("ascii")             # <<<<<<<<<<<<<<
@@ -1554,7 +1602,7 @@ static PyObject *__pyx_f_5pysam_6ctabix_from_string_and_size(char *__pyx_v_s, si
  * # filename encoding (copied from lxml.etree.pyx)
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_s, 0, __pyx_v_length, NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_s, 0, __pyx_v_length, NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
     __pyx_r = ((PyObject *)__pyx_t_2);
     __pyx_t_2 = 0;
@@ -1574,7 +1622,7 @@ static PyObject *__pyx_f_5pysam_6ctabix_from_string_and_size(char *__pyx_v_s, si
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":36
+/* "pysam/ctabix.pyx":41
  * #_C_FILENAME_ENCODING = <char*>_FILENAME_ENCODING
  * 
  * cdef bytes _my_encodeFilename(object filename):             # <<<<<<<<<<<<<<
@@ -1594,7 +1642,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__my_encodeFilename(PyObject *__pyx_v_fil
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("_my_encodeFilename", 0);
 
-  /* "pysam/ctabix.pyx":39
+  /* "pysam/ctabix.pyx":44
  *     u"""Make sure a filename is 8-bit encoded (or None).
  *     """
  *     if filename is None:             # <<<<<<<<<<<<<<
@@ -1604,7 +1652,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__my_encodeFilename(PyObject *__pyx_v_fil
   __pyx_t_1 = (__pyx_v_filename == Py_None);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":40
+    /* "pysam/ctabix.pyx":45
  *     """
  *     if filename is None:
  *         return None             # <<<<<<<<<<<<<<
@@ -1618,7 +1666,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__my_encodeFilename(PyObject *__pyx_v_fil
     goto __pyx_L3;
   }
 
-  /* "pysam/ctabix.pyx":41
+  /* "pysam/ctabix.pyx":46
  *     if filename is None:
  *         return None
  *     elif PyBytes_Check(filename):             # <<<<<<<<<<<<<<
@@ -1628,7 +1676,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__my_encodeFilename(PyObject *__pyx_v_fil
   __pyx_t_1 = PyBytes_Check(__pyx_v_filename);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":42
+    /* "pysam/ctabix.pyx":47
  *         return None
  *     elif PyBytes_Check(filename):
  *         return filename             # <<<<<<<<<<<<<<
@@ -1636,14 +1684,14 @@ static PyObject *__pyx_f_5pysam_6ctabix__my_encodeFilename(PyObject *__pyx_v_fil
  *         return filename.encode(_FILENAME_ENCODING)
  */
     __Pyx_XDECREF(((PyObject *)__pyx_r));
-    if (!(likely(PyBytes_CheckExact(__pyx_v_filename))||((__pyx_v_filename) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_filename)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_v_filename))||((__pyx_v_filename) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_filename)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_INCREF(__pyx_v_filename);
     __pyx_r = ((PyObject*)__pyx_v_filename);
     goto __pyx_L0;
     goto __pyx_L3;
   }
 
-  /* "pysam/ctabix.pyx":43
+  /* "pysam/ctabix.pyx":48
  *     elif PyBytes_Check(filename):
  *         return filename
  *     elif PyUnicode_Check(filename):             # <<<<<<<<<<<<<<
@@ -1653,7 +1701,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__my_encodeFilename(PyObject *__pyx_v_fil
   __pyx_t_1 = PyUnicode_Check(__pyx_v_filename);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":44
+    /* "pysam/ctabix.pyx":49
  *         return filename
  *     elif PyUnicode_Check(filename):
  *         return filename.encode(_FILENAME_ENCODING)             # <<<<<<<<<<<<<<
@@ -1661,18 +1709,18 @@ static PyObject *__pyx_f_5pysam_6ctabix__my_encodeFilename(PyObject *__pyx_v_fil
  *         raise TypeError, u"Argument must be string or unicode."
  */
     __Pyx_XDECREF(((PyObject *)__pyx_r));
-    __pyx_t_2 = PyObject_GetAttr(__pyx_v_filename, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_v_filename, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_INCREF(((PyObject *)__pyx_v_5pysam_6ctabix__FILENAME_ENCODING));
     PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_5pysam_6ctabix__FILENAME_ENCODING));
     __Pyx_GIVEREF(((PyObject *)__pyx_v_5pysam_6ctabix__FILENAME_ENCODING));
-    __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __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_3)); __pyx_t_3 = 0;
-    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_r = ((PyObject*)__pyx_t_4);
     __pyx_t_4 = 0;
     goto __pyx_L0;
@@ -1680,7 +1728,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__my_encodeFilename(PyObject *__pyx_v_fil
   }
   /*else*/ {
 
-    /* "pysam/ctabix.pyx":46
+    /* "pysam/ctabix.pyx":51
  *         return filename.encode(_FILENAME_ENCODING)
  *     else:
  *         raise TypeError, u"Argument must be string or unicode."             # <<<<<<<<<<<<<<
@@ -1688,7 +1736,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__my_encodeFilename(PyObject *__pyx_v_fil
  * cdef bytes _force_bytes(object s):
  */
     __Pyx_Raise(__pyx_builtin_TypeError, ((PyObject *)__pyx_kp_u_1), 0, 0);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L3:;
 
@@ -1706,7 +1754,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__my_encodeFilename(PyObject *__pyx_v_fil
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":48
+/* "pysam/ctabix.pyx":53
  *         raise TypeError, u"Argument must be string or unicode."
  * 
  * cdef bytes _force_bytes(object s):             # <<<<<<<<<<<<<<
@@ -1725,7 +1773,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *__pyx_v_s) {
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("_force_bytes", 0);
 
-  /* "pysam/ctabix.pyx":51
+  /* "pysam/ctabix.pyx":56
  *     u"""convert string or unicode object to bytes, assuming ascii encoding.
  *     """
  *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
@@ -1735,7 +1783,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *__pyx_v_s) {
   __pyx_t_1 = (PY_MAJOR_VERSION < 3);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":52
+    /* "pysam/ctabix.pyx":57
  *     """
  *     if PY_MAJOR_VERSION < 3:
  *         return s             # <<<<<<<<<<<<<<
@@ -1743,14 +1791,14 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *__pyx_v_s) {
  *         return None
  */
     __Pyx_XDECREF(((PyObject *)__pyx_r));
-    if (!(likely(PyBytes_CheckExact(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_s)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_s)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_INCREF(__pyx_v_s);
     __pyx_r = ((PyObject*)__pyx_v_s);
     goto __pyx_L0;
     goto __pyx_L3;
   }
 
-  /* "pysam/ctabix.pyx":53
+  /* "pysam/ctabix.pyx":58
  *     if PY_MAJOR_VERSION < 3:
  *         return s
  *     elif s is None:             # <<<<<<<<<<<<<<
@@ -1760,7 +1808,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *__pyx_v_s) {
   __pyx_t_1 = (__pyx_v_s == Py_None);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":54
+    /* "pysam/ctabix.pyx":59
  *         return s
  *     elif s is None:
  *         return None             # <<<<<<<<<<<<<<
@@ -1774,7 +1822,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *__pyx_v_s) {
     goto __pyx_L3;
   }
 
-  /* "pysam/ctabix.pyx":55
+  /* "pysam/ctabix.pyx":60
  *     elif s is None:
  *         return None
  *     elif PyBytes_Check(s):             # <<<<<<<<<<<<<<
@@ -1784,7 +1832,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *__pyx_v_s) {
   __pyx_t_1 = PyBytes_Check(__pyx_v_s);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":56
+    /* "pysam/ctabix.pyx":61
  *         return None
  *     elif PyBytes_Check(s):
  *         return s             # <<<<<<<<<<<<<<
@@ -1792,14 +1840,14 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *__pyx_v_s) {
  *         return s.encode('ascii')
  */
     __Pyx_XDECREF(((PyObject *)__pyx_r));
-    if (!(likely(PyBytes_CheckExact(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_s)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_s)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_INCREF(__pyx_v_s);
     __pyx_r = ((PyObject*)__pyx_v_s);
     goto __pyx_L0;
     goto __pyx_L3;
   }
 
-  /* "pysam/ctabix.pyx":57
+  /* "pysam/ctabix.pyx":62
  *     elif PyBytes_Check(s):
  *         return s
  *     elif PyUnicode_Check(s):             # <<<<<<<<<<<<<<
@@ -1809,7 +1857,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *__pyx_v_s) {
   __pyx_t_1 = PyUnicode_Check(__pyx_v_s);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":58
+    /* "pysam/ctabix.pyx":63
  *         return s
  *     elif PyUnicode_Check(s):
  *         return s.encode('ascii')             # <<<<<<<<<<<<<<
@@ -1817,12 +1865,12 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *__pyx_v_s) {
  *         raise TypeError, u"Argument must be string, bytes or unicode."
  */
     __Pyx_XDECREF(((PyObject *)__pyx_r));
-    __pyx_t_2 = PyObject_GetAttr(__pyx_v_s, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_v_s, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_r = ((PyObject*)__pyx_t_3);
     __pyx_t_3 = 0;
     goto __pyx_L0;
@@ -1830,7 +1878,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *__pyx_v_s) {
   }
   /*else*/ {
 
-    /* "pysam/ctabix.pyx":60
+    /* "pysam/ctabix.pyx":65
  *         return s.encode('ascii')
  *     else:
  *         raise TypeError, u"Argument must be string, bytes or unicode."             # <<<<<<<<<<<<<<
@@ -1838,7 +1886,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *__pyx_v_s) {
  * cdef inline bytes _force_cmdline_bytes(object s):
  */
     __Pyx_Raise(__pyx_builtin_TypeError, ((PyObject *)__pyx_kp_u_3), 0, 0);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __pyx_L3:;
 
@@ -1855,7 +1903,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_bytes(PyObject *__pyx_v_s) {
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":62
+/* "pysam/ctabix.pyx":67
  *         raise TypeError, u"Argument must be string, bytes or unicode."
  * 
  * cdef inline bytes _force_cmdline_bytes(object s):             # <<<<<<<<<<<<<<
@@ -1872,7 +1920,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_6ctabix__force_cmdline_bytes(PyObj
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("_force_cmdline_bytes", 0);
 
-  /* "pysam/ctabix.pyx":63
+  /* "pysam/ctabix.pyx":68
  * 
  * cdef inline bytes _force_cmdline_bytes(object s):
  *     return _force_bytes(s)             # <<<<<<<<<<<<<<
@@ -1880,7 +1928,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_6ctabix__force_cmdline_bytes(PyObj
  * cdef _charptr_to_str(char* s):
  */
   __Pyx_XDECREF(((PyObject *)__pyx_r));
-  __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_6ctabix__force_bytes(__pyx_v_s)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_6ctabix__force_bytes(__pyx_v_s)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
@@ -1898,7 +1946,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_6ctabix__force_cmdline_bytes(PyObj
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":65
+/* "pysam/ctabix.pyx":70
  *     return _force_bytes(s)
  * 
  * cdef _charptr_to_str(char* s):             # <<<<<<<<<<<<<<
@@ -1916,7 +1964,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__charptr_to_str(char *__pyx_v_s) {
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("_charptr_to_str", 0);
 
-  /* "pysam/ctabix.pyx":66
+  /* "pysam/ctabix.pyx":71
  * 
  * cdef _charptr_to_str(char* s):
  *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
@@ -1926,7 +1974,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__charptr_to_str(char *__pyx_v_s) {
   __pyx_t_1 = (PY_MAJOR_VERSION < 3);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":67
+    /* "pysam/ctabix.pyx":72
  * cdef _charptr_to_str(char* s):
  *     if PY_MAJOR_VERSION < 3:
  *         return s             # <<<<<<<<<<<<<<
@@ -1934,7 +1982,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__charptr_to_str(char *__pyx_v_s) {
  *         return s.decode("ascii")
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
     __pyx_r = ((PyObject *)__pyx_t_2);
     __pyx_t_2 = 0;
@@ -1943,7 +1991,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__charptr_to_str(char *__pyx_v_s) {
   }
   /*else*/ {
 
-    /* "pysam/ctabix.pyx":69
+    /* "pysam/ctabix.pyx":74
  *         return s
  *     else:
  *         return s.decode("ascii")             # <<<<<<<<<<<<<<
@@ -1951,7 +1999,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__charptr_to_str(char *__pyx_v_s) {
  * cdef _force_str(object s):
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_s, 0, strlen(__pyx_v_s), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = ((PyObject *)__Pyx_decode_c_string(__pyx_v_s, 0, strlen(__pyx_v_s), NULL, NULL, PyUnicode_DecodeASCII)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
     __pyx_r = ((PyObject *)__pyx_t_2);
     __pyx_t_2 = 0;
@@ -1971,7 +2019,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__charptr_to_str(char *__pyx_v_s) {
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":71
+/* "pysam/ctabix.pyx":76
  *         return s.decode("ascii")
  * 
  * cdef _force_str(object s):             # <<<<<<<<<<<<<<
@@ -1990,7 +2038,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_str(PyObject *__pyx_v_s) {
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("_force_str", 0);
 
-  /* "pysam/ctabix.pyx":73
+  /* "pysam/ctabix.pyx":78
  * cdef _force_str(object s):
  *     """Return s converted to str type of current Python (bytes in Py2, unicode in Py3)"""
  *     if s is None:             # <<<<<<<<<<<<<<
@@ -2000,7 +2048,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_str(PyObject *__pyx_v_s) {
   __pyx_t_1 = (__pyx_v_s == Py_None);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":74
+    /* "pysam/ctabix.pyx":79
  *     """Return s converted to str type of current Python (bytes in Py2, unicode in Py3)"""
  *     if s is None:
  *         return None             # <<<<<<<<<<<<<<
@@ -2015,7 +2063,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_str(PyObject *__pyx_v_s) {
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":75
+  /* "pysam/ctabix.pyx":80
  *     if s is None:
  *         return None
  *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
@@ -2025,7 +2073,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_str(PyObject *__pyx_v_s) {
   __pyx_t_1 = (PY_MAJOR_VERSION < 3);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":76
+    /* "pysam/ctabix.pyx":81
  *         return None
  *     if PY_MAJOR_VERSION < 3:
  *         return s             # <<<<<<<<<<<<<<
@@ -2039,7 +2087,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_str(PyObject *__pyx_v_s) {
     goto __pyx_L4;
   }
 
-  /* "pysam/ctabix.pyx":77
+  /* "pysam/ctabix.pyx":82
  *     if PY_MAJOR_VERSION < 3:
  *         return s
  *     elif PyBytes_Check(s):             # <<<<<<<<<<<<<<
@@ -2049,7 +2097,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_str(PyObject *__pyx_v_s) {
   __pyx_t_1 = PyBytes_Check(__pyx_v_s);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":78
+    /* "pysam/ctabix.pyx":83
  *         return s
  *     elif PyBytes_Check(s):
  *         return s.decode('ascii')             # <<<<<<<<<<<<<<
@@ -2057,9 +2105,9 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_str(PyObject *__pyx_v_s) {
  *         # assume unicode
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_2 = PyObject_GetAttr(__pyx_v_s, __pyx_n_s__decode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_v_s, __pyx_n_s__decode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __pyx_r = __pyx_t_3;
@@ -2069,7 +2117,7 @@ static PyObject *__pyx_f_5pysam_6ctabix__force_str(PyObject *__pyx_v_s) {
   }
   /*else*/ {
 
-    /* "pysam/ctabix.pyx":81
+    /* "pysam/ctabix.pyx":86
  *     else:
  *         # assume unicode
  *         return s             # <<<<<<<<<<<<<<
@@ -2101,6 +2149,7 @@ static int __pyx_pw_5pysam_6ctabix_9Tabixfile_1__cinit__(PyObject *__pyx_v_self,
 static int __pyx_pw_5pysam_6ctabix_9Tabixfile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
   PyObject *__pyx_v_filename = 0;
   PyObject *__pyx_v_mode = 0;
+  PyObject *__pyx_v_parser = 0;
   PyObject *__pyx_v_args = 0;
   PyObject *__pyx_v_kwargs = 0;
   int __pyx_r;
@@ -2108,8 +2157,8 @@ static int __pyx_pw_5pysam_6ctabix_9Tabixfile_1__cinit__(PyObject *__pyx_v_self,
   __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
   __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
   __Pyx_GOTREF(__pyx_v_kwargs);
-  if (PyTuple_GET_SIZE(__pyx_args) > 2) {
-    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 2, PyTuple_GET_SIZE(__pyx_args));
+  if (PyTuple_GET_SIZE(__pyx_args) > 3) {
+    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 3, PyTuple_GET_SIZE(__pyx_args));
     if (unlikely(!__pyx_v_args)) {
       __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
       __Pyx_RefNannyFinishContext();
@@ -2120,14 +2169,24 @@ static int __pyx_pw_5pysam_6ctabix_9Tabixfile_1__cinit__(PyObject *__pyx_v_self,
     __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
   }
   {
-    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__filename,&__pyx_n_s__mode,0};
-    PyObject* values[2] = {0,0};
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__filename,&__pyx_n_s__mode,&__pyx_n_s__parser,0};
+    PyObject* values[3] = {0,0,0};
     values[1] = ((PyObject *)__pyx_n_s__r);
+
+    /* "pysam/ctabix.pyx":101
+ *     '''
+ *     def __cinit__(self, filename, mode = 'r',
+ *                   parser = None, *args, **kwargs ):             # <<<<<<<<<<<<<<
+ *         self.tabixfile = NULL
+ *         self.parser = parser
+ */
+    values[2] = ((PyObject *)Py_None);
     if (unlikely(__pyx_kwds)) {
       Py_ssize_t kw_args;
       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
       switch (pos_args) {
         default:
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
         case  0: break;
@@ -2142,14 +2201,20 @@ static int __pyx_pw_5pysam_6ctabix_9Tabixfile_1__cinit__(PyObject *__pyx_v_self,
           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mode);
           if (value) { values[1] = value; kw_args--; }
         }
+        case  2:
+        if (kw_args > 0) {
+          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__parser);
+          if (value) { values[2] = value; kw_args--; }
+        }
       }
       if (unlikely(kw_args > 0)) {
-        const Py_ssize_t used_pos_args = (pos_args < 2) ? pos_args : 2;
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, used_pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        const Py_ssize_t used_pos_args = (pos_args < 3) ? pos_args : 3;
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, used_pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
         default:
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
         break;
@@ -2159,10 +2224,11 @@ static int __pyx_pw_5pysam_6ctabix_9Tabixfile_1__cinit__(PyObject *__pyx_v_self,
     }
     __pyx_v_filename = values[0];
     __pyx_v_mode = values[1];
+    __pyx_v_parser = values[2];
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_DECREF(__pyx_v_args); __pyx_v_args = 0;
   __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
@@ -2170,22 +2236,22 @@ static int __pyx_pw_5pysam_6ctabix_9Tabixfile_1__cinit__(PyObject *__pyx_v_self,
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  __pyx_r = __pyx_pf_5pysam_6ctabix_9Tabixfile___cinit__(((struct __pyx_obj_5pysam_6ctabix_Tabixfile *)__pyx_v_self), __pyx_v_filename, __pyx_v_mode, __pyx_v_args, __pyx_v_kwargs);
+  __pyx_r = __pyx_pf_5pysam_6ctabix_9Tabixfile___cinit__(((struct __pyx_obj_5pysam_6ctabix_Tabixfile *)__pyx_v_self), __pyx_v_filename, __pyx_v_mode, __pyx_v_parser, __pyx_v_args, __pyx_v_kwargs);
   __Pyx_XDECREF(__pyx_v_args);
   __Pyx_XDECREF(__pyx_v_kwargs);
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":90
- *     index (*filename* + ".tbi") will raise an exception.
+/* "pysam/ctabix.pyx":100
+ *     parsed data (see for example :meth:`asTuple` and :meth:`asGTF`).
  *     '''
- *     def __cinit__(self, filename, mode = 'r', *args, **kwargs ):             # <<<<<<<<<<<<<<
+ *     def __cinit__(self, filename, mode = 'r',             # <<<<<<<<<<<<<<
+ *                   parser = None, *args, **kwargs ):
  *         self.tabixfile = NULL
- *         self._open( filename, mode, *args, **kwargs )
  */
 
-static int __pyx_pf_5pysam_6ctabix_9Tabixfile___cinit__(struct __pyx_obj_5pysam_6ctabix_Tabixfile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
+static int __pyx_pf_5pysam_6ctabix_9Tabixfile___cinit__(struct __pyx_obj_5pysam_6ctabix_Tabixfile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_parser, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
   int __pyx_r;
   __Pyx_RefNannyDeclarations
   PyObject *__pyx_t_1 = NULL;
@@ -2197,25 +2263,39 @@ static int __pyx_pf_5pysam_6ctabix_9Tabixfile___cinit__(struct __pyx_obj_5pysam_
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__cinit__", 0);
 
-  /* "pysam/ctabix.pyx":91
- *     '''
- *     def __cinit__(self, filename, mode = 'r', *args, **kwargs ):
+  /* "pysam/ctabix.pyx":102
+ *     def __cinit__(self, filename, mode = 'r',
+ *                   parser = None, *args, **kwargs ):
  *         self.tabixfile = NULL             # <<<<<<<<<<<<<<
+ *         self.parser = parser
  *         self._open( filename, mode, *args, **kwargs )
- * 
  */
   __pyx_v_self->tabixfile = NULL;
 
-  /* "pysam/ctabix.pyx":92
- *     def __cinit__(self, filename, mode = 'r', *args, **kwargs ):
+  /* "pysam/ctabix.pyx":103
+ *                   parser = None, *args, **kwargs ):
+ *         self.tabixfile = NULL
+ *         self.parser = parser             # <<<<<<<<<<<<<<
+ *         self._open( filename, mode, *args, **kwargs )
+ * 
+ */
+  if (!(likely(((__pyx_v_parser) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_parser, __pyx_ptype_5pysam_6ctabix_Parser))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_INCREF(__pyx_v_parser);
+  __Pyx_GIVEREF(__pyx_v_parser);
+  __Pyx_GOTREF(__pyx_v_self->parser);
+  __Pyx_DECREF(((PyObject *)__pyx_v_self->parser));
+  __pyx_v_self->parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)__pyx_v_parser);
+
+  /* "pysam/ctabix.pyx":104
  *         self.tabixfile = NULL
+ *         self.parser = parser
  *         self._open( filename, mode, *args, **kwargs )             # <<<<<<<<<<<<<<
  * 
  *     def _isOpen( self ):
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __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 = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_INCREF(__pyx_v_filename);
   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_filename);
@@ -2223,15 +2303,15 @@ static int __pyx_pf_5pysam_6ctabix_9Tabixfile___cinit__(struct __pyx_obj_5pysam_
   __Pyx_INCREF(__pyx_v_mode);
   PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_mode);
   __Pyx_GIVEREF(__pyx_v_mode);
-  __pyx_t_3 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
-  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
   __pyx_t_3 = ((PyObject *)__pyx_v_kwargs);
   __Pyx_INCREF(__pyx_t_3);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
@@ -2264,7 +2344,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_3_isOpen(PyObject *__pyx_v_s
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":94
+/* "pysam/ctabix.pyx":106
  *         self._open( filename, mode, *args, **kwargs )
  * 
  *     def _isOpen( self ):             # <<<<<<<<<<<<<<
@@ -2281,7 +2361,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_2_isOpen(struct __pyx_obj_5p
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("_isOpen", 0);
 
-  /* "pysam/ctabix.pyx":96
+  /* "pysam/ctabix.pyx":108
  *     def _isOpen( self ):
  *         '''return true if samfile has been opened.'''
  *         return self.tabixfile != NULL             # <<<<<<<<<<<<<<
@@ -2289,7 +2369,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_2_isOpen(struct __pyx_obj_5p
  *     def _open( self,
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->tabixfile != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->tabixfile != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -2341,7 +2421,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_5_open(PyObject *__pyx_v_sel
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -2356,7 +2436,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_5_open(PyObject *__pyx_v_sel
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.ctabix.Tabixfile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -2367,7 +2447,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_5_open(PyObject *__pyx_v_sel
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":98
+/* "pysam/ctabix.pyx":110
  *         return self.tabixfile != NULL
  * 
  *     def _open( self,             # <<<<<<<<<<<<<<
@@ -2394,7 +2474,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_4_open(struct __pyx_obj_5pys
   __Pyx_RefNannySetupContext("_open", 0);
   __Pyx_INCREF(__pyx_v_filename);
 
-  /* "pysam/ctabix.pyx":105
+  /* "pysam/ctabix.pyx":117
  *         '''
  * 
  *         assert mode in ( "r",), "invalid file opening mode `%s`" % mode             # <<<<<<<<<<<<<<
@@ -2404,20 +2484,20 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_4_open(struct __pyx_obj_5pys
   #ifndef CYTHON_WITHOUT_ASSERTIONS
   __Pyx_INCREF(__pyx_v_mode);
   __pyx_t_1 = __pyx_v_mode;
-  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__r), Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__r), Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (unlikely(!((int)__pyx_t_3))) {
-    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_5), __pyx_v_mode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_5), __pyx_v_mode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
     PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_1));
     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #endif
 
-  /* "pysam/ctabix.pyx":108
+  /* "pysam/ctabix.pyx":120
  * 
  *         # close a previously opened file
  *         if self.tabixfile != NULL: self.close()             # <<<<<<<<<<<<<<
@@ -2426,9 +2506,9 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_4_open(struct __pyx_obj_5pys
  */
   __pyx_t_3 = (__pyx_v_self->tabixfile != NULL);
   if (__pyx_t_3) {
-    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
@@ -2436,7 +2516,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_4_open(struct __pyx_obj_5pys
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":109
+  /* "pysam/ctabix.pyx":121
  *         # close a previously opened file
  *         if self.tabixfile != NULL: self.close()
  *         self.tabixfile = NULL             # <<<<<<<<<<<<<<
@@ -2445,36 +2525,36 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_4_open(struct __pyx_obj_5pys
  */
   __pyx_v_self->tabixfile = NULL;
 
-  /* "pysam/ctabix.pyx":111
+  /* "pysam/ctabix.pyx":123
  *         self.tabixfile = NULL
  * 
  *         filename_index = filename + ".tbi"             # <<<<<<<<<<<<<<
  *         self.isremote = filename.startswith( "http:") or filename.startswith( "ftp:" )
  * 
  */
-  __pyx_t_2 = PyNumber_Add(__pyx_v_filename, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_Add(__pyx_v_filename, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_v_filename_index = __pyx_t_2;
   __pyx_t_2 = 0;
 
-  /* "pysam/ctabix.pyx":112
+  /* "pysam/ctabix.pyx":124
  * 
  *         filename_index = filename + ".tbi"
  *         self.isremote = filename.startswith( "http:") or filename.startswith( "ftp:" )             # <<<<<<<<<<<<<<
  * 
  *         # encode all the strings
  */
-  __pyx_t_2 = PyObject_GetAttr(__pyx_v_filename, __pyx_n_s__startswith); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_v_filename, __pyx_n_s__startswith); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (!__pyx_t_3) {
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    __pyx_t_2 = PyObject_GetAttr(__pyx_v_filename, __pyx_n_s__startswith); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_v_filename, __pyx_n_s__startswith); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __pyx_t_2 = __pyx_t_4;
@@ -2483,53 +2563,53 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_4_open(struct __pyx_obj_5pys
     __pyx_t_2 = __pyx_t_1;
     __pyx_t_1 = 0;
   }
-  __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_v_self->isremote = __pyx_t_5;
 
-  /* "pysam/ctabix.pyx":115
+  /* "pysam/ctabix.pyx":127
  * 
  *         # encode all the strings
  *         filename = _my_encodeFilename(filename)             # <<<<<<<<<<<<<<
  *         filename_index = _my_encodeFilename(filename_index)
  *         cdef bytes bmode = mode.encode('ascii')
  */
-  __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_6ctabix__my_encodeFilename(__pyx_v_filename)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_6ctabix__my_encodeFilename(__pyx_v_filename)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_v_filename);
   __pyx_v_filename = __pyx_t_2;
   __pyx_t_2 = 0;
 
-  /* "pysam/ctabix.pyx":116
+  /* "pysam/ctabix.pyx":128
  *         # encode all the strings
  *         filename = _my_encodeFilename(filename)
  *         filename_index = _my_encodeFilename(filename_index)             # <<<<<<<<<<<<<<
  *         cdef bytes bmode = mode.encode('ascii')
  * 
  */
-  __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_6ctabix__my_encodeFilename(__pyx_v_filename_index)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_6ctabix__my_encodeFilename(__pyx_v_filename_index)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_v_filename_index);
   __pyx_v_filename_index = __pyx_t_2;
   __pyx_t_2 = 0;
 
-  /* "pysam/ctabix.pyx":117
+  /* "pysam/ctabix.pyx":129
  *         filename = _my_encodeFilename(filename)
  *         filename_index = _my_encodeFilename(filename_index)
  *         cdef bytes bmode = mode.encode('ascii')             # <<<<<<<<<<<<<<
  * 
  *         if self._filename != NULL: free(self._filename )
  */
-  __pyx_t_2 = PyObject_GetAttr(__pyx_v_mode, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_v_mode, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_11), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_11), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_bmode = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":119
+  /* "pysam/ctabix.pyx":131
  *         cdef bytes bmode = mode.encode('ascii')
  * 
  *         if self._filename != NULL: free(self._filename )             # <<<<<<<<<<<<<<
@@ -2543,62 +2623,62 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_4_open(struct __pyx_obj_5pys
   }
   __pyx_L4:;
 
-  /* "pysam/ctabix.pyx":121
+  /* "pysam/ctabix.pyx":133
  *         if self._filename != NULL: free(self._filename )
  * 
  *         self._filename = strdup(filename)             # <<<<<<<<<<<<<<
  * 
  *         if mode[0] == 'w':
  */
-  __pyx_t_6 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_6 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->_filename = strdup(__pyx_t_6);
 
-  /* "pysam/ctabix.pyx":123
+  /* "pysam/ctabix.pyx":135
  *         self._filename = strdup(filename)
  * 
  *         if mode[0] == 'w':             # <<<<<<<<<<<<<<
  *             # open file for writing
  *             raise NotImplementedError("writing to tabix files not implemented" )
  */
-  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__w), Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__w), Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   if (__pyx_t_3) {
 
-    /* "pysam/ctabix.pyx":125
+    /* "pysam/ctabix.pyx":137
  *         if mode[0] == 'w':
  *             # open file for writing
  *             raise NotImplementedError("writing to tabix files not implemented" )             # <<<<<<<<<<<<<<
  * 
  *         elif mode[0] == "r":
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_13), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_13), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L5;
   }
 
-  /* "pysam/ctabix.pyx":127
+  /* "pysam/ctabix.pyx":139
  *             raise NotImplementedError("writing to tabix files not implemented" )
  * 
  *         elif mode[0] == "r":             # <<<<<<<<<<<<<<
  *             # open file for reading
  * 
  */
-  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__r), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__r), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   if (__pyx_t_3) {
 
-    /* "pysam/ctabix.pyx":130
+    /* "pysam/ctabix.pyx":142
  *             # open file for reading
  * 
  *             if not self.isremote:             # <<<<<<<<<<<<<<
@@ -2608,108 +2688,108 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_4_open(struct __pyx_obj_5pys
     __pyx_t_3 = (!__pyx_v_self->isremote);
     if (__pyx_t_3) {
 
-      /* "pysam/ctabix.pyx":131
+      /* "pysam/ctabix.pyx":143
  * 
  *             if not self.isremote:
  *                 if not os.path.exists( filename ):             # <<<<<<<<<<<<<<
  *                     raise IOError( "file `%s` not found" % filename)
  * 
  */
-      __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __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 = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __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__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __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 = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_INCREF(__pyx_v_filename);
       PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_filename);
       __Pyx_GIVEREF(__pyx_v_filename);
-      __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_4);
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
-      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
       __pyx_t_7 = (!__pyx_t_3);
       if (__pyx_t_7) {
 
-        /* "pysam/ctabix.pyx":132
+        /* "pysam/ctabix.pyx":144
  *             if not self.isremote:
  *                 if not os.path.exists( filename ):
  *                     raise IOError( "file `%s` not found" % filename)             # <<<<<<<<<<<<<<
  * 
  *                 if not os.path.exists( filename_index ):
  */
-        __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_14), __pyx_v_filename); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_14), __pyx_v_filename); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_4));
-        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
         PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_4));
         __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
         __pyx_t_4 = 0;
-        __pyx_t_4 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_4 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_4);
         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
         __Pyx_Raise(__pyx_t_4, 0, 0, 0);
         __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         goto __pyx_L7;
       }
       __pyx_L7:;
 
-      /* "pysam/ctabix.pyx":134
+      /* "pysam/ctabix.pyx":146
  *                     raise IOError( "file `%s` not found" % filename)
  * 
  *                 if not os.path.exists( filename_index ):             # <<<<<<<<<<<<<<
  *                     raise IOError( "index `%s` not found" % filename_index)
  * 
  */
-      __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_4);
-      __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-      __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_4);
       __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 = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_INCREF(__pyx_v_filename_index);
       PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_filename_index);
       __Pyx_GIVEREF(__pyx_v_filename_index);
-      __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
-      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_t_3 = (!__pyx_t_7);
       if (__pyx_t_3) {
 
-        /* "pysam/ctabix.pyx":135
+        /* "pysam/ctabix.pyx":147
  * 
  *                 if not os.path.exists( filename_index ):
  *                     raise IOError( "index `%s` not found" % filename_index)             # <<<<<<<<<<<<<<
  * 
  *             # open file and load index
  */
-        __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_15), __pyx_v_filename_index); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_15), __pyx_v_filename_index); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
         PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
         __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
         __pyx_t_1 = 0;
-        __pyx_t_1 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
         __Pyx_Raise(__pyx_t_1, 0, 0, 0);
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         goto __pyx_L8;
       }
       __pyx_L8:;
@@ -2717,21 +2797,21 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_4_open(struct __pyx_obj_5pys
     }
     __pyx_L6:;
 
-    /* "pysam/ctabix.pyx":138
+    /* "pysam/ctabix.pyx":150
  * 
  *             # open file and load index
  *             self.tabixfile = ti_open( filename, filename_index )             # <<<<<<<<<<<<<<
  * 
  *         if self.tabixfile == NULL:
  */
-    __pyx_t_6 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_8 = PyBytes_AsString(__pyx_v_filename_index); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyBytes_AsString(__pyx_v_filename_index); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_v_self->tabixfile = ti_open(__pyx_t_6, __pyx_t_8);
     goto __pyx_L5;
   }
   __pyx_L5:;
 
-  /* "pysam/ctabix.pyx":140
+  /* "pysam/ctabix.pyx":152
  *             self.tabixfile = ti_open( filename, filename_index )
  * 
  *         if self.tabixfile == NULL:             # <<<<<<<<<<<<<<
@@ -2741,26 +2821,26 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_4_open(struct __pyx_obj_5pys
   __pyx_t_3 = (__pyx_v_self->tabixfile == NULL);
   if (__pyx_t_3) {
 
-    /* "pysam/ctabix.pyx":141
+    /* "pysam/ctabix.pyx":153
  * 
  *         if self.tabixfile == NULL:
  *             raise IOError("could not open file `%s`" % filename )             # <<<<<<<<<<<<<<
  * 
  *     def _parseRegion( self,
  */
-    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_16), __pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_16), __pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
     __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L9;
   }
   __pyx_L9:;
@@ -2797,7 +2877,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_7_parseRegion(PyObject *__py
     static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,0};
     PyObject* values[4] = {0,0,0,0};
 
-    /* "pysam/ctabix.pyx":144
+    /* "pysam/ctabix.pyx":156
  * 
  *     def _parseRegion( self,
  *                       reference = None,             # <<<<<<<<<<<<<<
@@ -2806,7 +2886,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_7_parseRegion(PyObject *__py
  */
     values[0] = ((PyObject *)Py_None);
 
-    /* "pysam/ctabix.pyx":145
+    /* "pysam/ctabix.pyx":157
  *     def _parseRegion( self,
  *                       reference = None,
  *                       start = None,             # <<<<<<<<<<<<<<
@@ -2815,7 +2895,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_7_parseRegion(PyObject *__py
  */
     values[1] = ((PyObject *)Py_None);
 
-    /* "pysam/ctabix.pyx":146
+    /* "pysam/ctabix.pyx":158
  *                       reference = None,
  *                       start = None,
  *                       end = None,             # <<<<<<<<<<<<<<
@@ -2824,7 +2904,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_7_parseRegion(PyObject *__py
  */
     values[2] = ((PyObject *)Py_None);
 
-    /* "pysam/ctabix.pyx":147
+    /* "pysam/ctabix.pyx":159
  *                       start = None,
  *                       end = None,
  *                       region = None ):             # <<<<<<<<<<<<<<
@@ -2867,7 +2947,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_7_parseRegion(PyObject *__py
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_parseRegion") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_parseRegion") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -2886,7 +2966,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_7_parseRegion(PyObject *__py
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("_parseRegion", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("_parseRegion", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.ctabix.Tabixfile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -2897,7 +2977,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_7_parseRegion(PyObject *__py
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":143
+/* "pysam/ctabix.pyx":155
  *             raise IOError("could not open file `%s`" % filename )
  * 
  *     def _parseRegion( self,             # <<<<<<<<<<<<<<
@@ -2926,7 +3006,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
   __Pyx_RefNannySetupContext("_parseRegion", 0);
   __Pyx_INCREF(__pyx_v_region);
 
-  /* "pysam/ctabix.pyx":158
+  /* "pysam/ctabix.pyx":170
  *         Note that regions are 1-based, while start,end are python coordinates.
  *         '''
  *         ti_lazy_index_load( self.tabixfile )             # <<<<<<<<<<<<<<
@@ -2935,7 +3015,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
  */
   ti_lazy_index_load(__pyx_v_self->tabixfile);
 
-  /* "pysam/ctabix.pyx":164
+  /* "pysam/ctabix.pyx":176
  *         cdef int rend
  *         cdef int max_pos
  *         max_pos = 2 << 29             # <<<<<<<<<<<<<<
@@ -2944,7 +3024,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
  */
   __pyx_v_max_pos = 1073741824;
 
-  /* "pysam/ctabix.pyx":166
+  /* "pysam/ctabix.pyx":178
  *         max_pos = 2 << 29
  * 
  *         rtid = rstart = rend = 0             # <<<<<<<<<<<<<<
@@ -2955,29 +3035,29 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
   __pyx_v_rstart = 0;
   __pyx_v_rend = 0;
 
-  /* "pysam/ctabix.pyx":169
+  /* "pysam/ctabix.pyx":181
  * 
  *         # translate to a region
  *         if reference:             # <<<<<<<<<<<<<<
  *             if start != None and end != None:
  *                 region = "%s:%i-%i" % (reference, start+1, end)
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":170
+    /* "pysam/ctabix.pyx":182
  *         # translate to a region
  *         if reference:
  *             if start != None and end != None:             # <<<<<<<<<<<<<<
  *                 region = "%s:%i-%i" % (reference, start+1, end)
  *             elif start == None and end != None:
  */
-    __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     if (__pyx_t_1) {
-      __pyx_t_2 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
       __pyx_t_4 = __pyx_t_3;
     } else {
@@ -2985,16 +3065,16 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
     }
     if (__pyx_t_4) {
 
-      /* "pysam/ctabix.pyx":171
+      /* "pysam/ctabix.pyx":183
  *         if reference:
  *             if start != None and end != None:
  *                 region = "%s:%i-%i" % (reference, start+1, end)             # <<<<<<<<<<<<<<
  *             elif start == None and end != None:
  *                 region = "%s:%i-%i" % (reference, 1, end)
  */
-      __pyx_t_2 = PyNumber_Add(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyNumber_Add(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
-      __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
       __Pyx_INCREF(__pyx_v_reference);
       PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_reference);
@@ -3005,7 +3085,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
       PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_end);
       __Pyx_GIVEREF(__pyx_v_end);
       __pyx_t_2 = 0;
-      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_17), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_17), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
       __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
       __Pyx_DECREF(__pyx_v_region);
@@ -3014,19 +3094,19 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
       goto __pyx_L4;
     }
 
-    /* "pysam/ctabix.pyx":172
+    /* "pysam/ctabix.pyx":184
  *             if start != None and end != None:
  *                 region = "%s:%i-%i" % (reference, start+1, end)
  *             elif start == None and end != None:             # <<<<<<<<<<<<<<
  *                 region = "%s:%i-%i" % (reference, 1, end)
  *             elif end == None and start != None:
  */
-    __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __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 = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     if (__pyx_t_4) {
-      __pyx_t_2 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
       __pyx_t_3 = __pyx_t_1;
     } else {
@@ -3034,14 +3114,14 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
     }
     if (__pyx_t_3) {
 
-      /* "pysam/ctabix.pyx":173
+      /* "pysam/ctabix.pyx":185
  *                 region = "%s:%i-%i" % (reference, start+1, end)
  *             elif start == None and end != None:
  *                 region = "%s:%i-%i" % (reference, 1, end)             # <<<<<<<<<<<<<<
  *             elif end == None and start != None:
  *                 region = "%s:%i-%i" % (reference, start+1, max_pos-1)
  */
-      __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_INCREF(__pyx_v_reference);
       PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_reference);
@@ -3052,7 +3132,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
       __Pyx_INCREF(__pyx_v_end);
       PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_end);
       __Pyx_GIVEREF(__pyx_v_end);
-      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_17), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_17), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_5));
       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
       __Pyx_DECREF(__pyx_v_region);
@@ -3061,19 +3141,19 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
       goto __pyx_L4;
     }
 
-    /* "pysam/ctabix.pyx":174
+    /* "pysam/ctabix.pyx":186
  *             elif start == None and end != None:
  *                 region = "%s:%i-%i" % (reference, 1, end)
  *             elif end == None and start != None:             # <<<<<<<<<<<<<<
  *                 region = "%s:%i-%i" % (reference, start+1, max_pos-1)
  *             else:
  */
-    __pyx_t_5 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     if (__pyx_t_3) {
-      __pyx_t_5 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __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 = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __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 = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
       __pyx_t_1 = __pyx_t_4;
     } else {
@@ -3081,18 +3161,18 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
     }
     if (__pyx_t_1) {
 
-      /* "pysam/ctabix.pyx":175
+      /* "pysam/ctabix.pyx":187
  *                 region = "%s:%i-%i" % (reference, 1, end)
  *             elif end == None and start != None:
  *                 region = "%s:%i-%i" % (reference, start+1, max_pos-1)             # <<<<<<<<<<<<<<
  *             else:
  *                 region = reference
  */
-      __pyx_t_5 = PyNumber_Add(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyNumber_Add(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __pyx_t_2 = PyInt_FromLong((__pyx_v_max_pos - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyInt_FromLong((__pyx_v_max_pos - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
-      __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       __Pyx_INCREF(__pyx_v_reference);
       PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_reference);
@@ -3103,7 +3183,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
       __Pyx_GIVEREF(__pyx_t_2);
       __pyx_t_5 = 0;
       __pyx_t_2 = 0;
-      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_17), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_17), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
       __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
       __Pyx_DECREF(__pyx_v_region);
@@ -3113,7 +3193,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
     }
     /*else*/ {
 
-      /* "pysam/ctabix.pyx":177
+      /* "pysam/ctabix.pyx":189
  *                 region = "%s:%i-%i" % (reference, start+1, max_pos-1)
  *             else:
  *                 region = reference             # <<<<<<<<<<<<<<
@@ -3129,117 +3209,115 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":179
+  /* "pysam/ctabix.pyx":191
  *                 region = reference
  * 
  *         if region:             # <<<<<<<<<<<<<<
  *             region = _force_bytes(region)
  *             ti_parse_region( self.tabixfile.idx, region,
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":180
+    /* "pysam/ctabix.pyx":192
  * 
  *         if region:
  *             region = _force_bytes(region)             # <<<<<<<<<<<<<<
  *             ti_parse_region( self.tabixfile.idx, region,
  *                              &rtid, &rstart, &rend)
  */
-    __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_6ctabix__force_bytes(__pyx_v_region)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_6ctabix__force_bytes(__pyx_v_region)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_v_region);
     __pyx_v_region = __pyx_t_2;
     __pyx_t_2 = 0;
 
-    /* "pysam/ctabix.pyx":181
+    /* "pysam/ctabix.pyx":193
  *         if region:
  *             region = _force_bytes(region)
  *             ti_parse_region( self.tabixfile.idx, region,             # <<<<<<<<<<<<<<
  *                              &rtid, &rstart, &rend)
- *             if rtid < 0: raise ValueError( "invalid region `%s`" % region )
+ *             if rtid < 0: raise KeyError( reference )
  */
-    __pyx_t_7 = PyBytes_AsString(__pyx_v_region); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = PyBytes_AsString(__pyx_v_region); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "pysam/ctabix.pyx":182
+    /* "pysam/ctabix.pyx":194
  *             region = _force_bytes(region)
  *             ti_parse_region( self.tabixfile.idx, region,
  *                              &rtid, &rstart, &rend)             # <<<<<<<<<<<<<<
- *             if rtid < 0: raise ValueError( "invalid region `%s`" % region )
+ *             if rtid < 0: raise KeyError( reference )
  *             if rstart > rend: raise ValueError( 'invalid region: start (%i) > end (%i)' % (rstart, rend) )
  */
     ti_parse_region(__pyx_v_self->tabixfile->idx, __pyx_t_7, (&__pyx_v_rtid), (&__pyx_v_rstart), (&__pyx_v_rend));
 
-    /* "pysam/ctabix.pyx":183
+    /* "pysam/ctabix.pyx":195
  *             ti_parse_region( self.tabixfile.idx, region,
  *                              &rtid, &rstart, &rend)
- *             if rtid < 0: raise ValueError( "invalid region `%s`" % region )             # <<<<<<<<<<<<<<
+ *             if rtid < 0: raise KeyError( reference )             # <<<<<<<<<<<<<<
  *             if rstart > rend: raise ValueError( 'invalid region: start (%i) > end (%i)' % (rstart, rend) )
- *             if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
+ *             if not 0 <= rstart < max_pos: raise IndexError( 'start out of range (%i)' % rstart )
  */
     __pyx_t_1 = (__pyx_v_rtid < 0);
     if (__pyx_t_1) {
-      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_region); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_6);
-      PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_2));
-      __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
-      __pyx_t_2 = 0;
-      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
-      __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
-      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
-      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_INCREF(__pyx_v_reference);
+      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_reference);
+      __Pyx_GIVEREF(__pyx_v_reference);
+      __pyx_t_6 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L6;
     }
     __pyx_L6:;
 
-    /* "pysam/ctabix.pyx":184
+    /* "pysam/ctabix.pyx":196
  *                              &rtid, &rstart, &rend)
- *             if rtid < 0: raise ValueError( "invalid region `%s`" % region )
+ *             if rtid < 0: raise KeyError( reference )
  *             if rstart > rend: raise ValueError( 'invalid region: start (%i) > end (%i)' % (rstart, rend) )             # <<<<<<<<<<<<<<
- *             if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
- *             if not 0 <= rend < max_pos: raise ValueError( 'end out of range (%i)' % rend )
+ *             if not 0 <= rstart < max_pos: raise IndexError( 'start out of range (%i)' % rstart )
+ *             if not 0 <= rend < max_pos: raise IndexError( 'end out of range (%i)' % rend )
  */
     __pyx_t_1 = (__pyx_v_rstart > __pyx_v_rend);
     if (__pyx_t_1) {
-      __pyx_t_2 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_2);
-      __pyx_t_6 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
-      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
-      __Pyx_GIVEREF(__pyx_t_2);
-      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6);
+      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
       __Pyx_GIVEREF(__pyx_t_6);
-      __pyx_t_2 = 0;
+      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+      __Pyx_GIVEREF(__pyx_t_2);
       __pyx_t_6 = 0;
-      __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_19), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(((PyObject *)__pyx_t_6));
+      __pyx_t_2 = 0;
+      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
       __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
-      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_6));
-      __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
-      __pyx_t_6 = 0;
-      __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_6);
+      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_2));
+      __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
+      __pyx_t_2 = 0;
+      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
-      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
-      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L7;
     }
     __pyx_L7:;
 
-    /* "pysam/ctabix.pyx":185
- *             if rtid < 0: raise ValueError( "invalid region `%s`" % region )
+    /* "pysam/ctabix.pyx":197
+ *             if rtid < 0: raise KeyError( reference )
  *             if rstart > rend: raise ValueError( 'invalid region: start (%i) > end (%i)' % (rstart, rend) )
- *             if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )             # <<<<<<<<<<<<<<
- *             if not 0 <= rend < max_pos: raise ValueError( 'end out of range (%i)' % rend )
+ *             if not 0 <= rstart < max_pos: raise IndexError( 'start out of range (%i)' % rstart )             # <<<<<<<<<<<<<<
+ *             if not 0 <= rend < max_pos: raise IndexError( 'end out of range (%i)' % rend )
  * 
  */
     __pyx_t_1 = (0 <= __pyx_v_rstart);
@@ -3248,30 +3326,30 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
     }
     __pyx_t_3 = (!__pyx_t_1);
     if (__pyx_t_3) {
-      __pyx_t_6 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_6);
-      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_20), __pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_19), __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(((PyObject *)__pyx_t_5));
-      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_6);
-      PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5));
+      __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 = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_2);
+      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_5));
       __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
       __pyx_t_5 = 0;
-      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
+      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
       __Pyx_Raise(__pyx_t_5, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L8;
     }
     __pyx_L8:;
 
-    /* "pysam/ctabix.pyx":186
+    /* "pysam/ctabix.pyx":198
  *             if rstart > rend: raise ValueError( 'invalid region: start (%i) > end (%i)' % (rstart, rend) )
- *             if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
- *             if not 0 <= rend < max_pos: raise ValueError( 'end out of range (%i)' % rend )             # <<<<<<<<<<<<<<
+ *             if not 0 <= rstart < max_pos: raise IndexError( 'start out of range (%i)' % rstart )
+ *             if not 0 <= rend < max_pos: raise IndexError( 'end out of range (%i)' % rend )             # <<<<<<<<<<<<<<
  * 
  *         return region, rtid, rstart, rend
  */
@@ -3281,22 +3359,22 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
     }
     __pyx_t_1 = (!__pyx_t_3);
     if (__pyx_t_1) {
-      __pyx_t_5 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(((PyObject *)__pyx_t_6));
+      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_20), __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_6));
-      __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
-      __pyx_t_6 = 0;
-      __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_6);
+      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_2));
+      __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
+      __pyx_t_2 = 0;
+      __pyx_t_2 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
-      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
-      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L9;
     }
     __pyx_L9:;
@@ -3304,34 +3382,34 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
   }
   __pyx_L5:;
 
-  /* "pysam/ctabix.pyx":188
- *             if not 0 <= rend < max_pos: raise ValueError( 'end out of range (%i)' % rend )
+  /* "pysam/ctabix.pyx":200
+ *             if not 0 <= rend < max_pos: raise IndexError( 'end out of range (%i)' % rend )
  * 
  *         return region, rtid, rstart, rend             # <<<<<<<<<<<<<<
  * 
  *     def fetch( self,
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_6 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_6);
-  __pyx_t_5 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_5);
-  __pyx_t_2 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_8 = PyTuple_New(4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_6);
+  __pyx_t_8 = PyTuple_New(4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
   __Pyx_INCREF(__pyx_v_region);
   PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_region);
   __Pyx_GIVEREF(__pyx_v_region);
-  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
-  __Pyx_GIVEREF(__pyx_t_6);
+  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_2);
+  __Pyx_GIVEREF(__pyx_t_2);
   PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_5);
   __Pyx_GIVEREF(__pyx_t_5);
-  PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_2);
-  __Pyx_GIVEREF(__pyx_t_2);
-  __pyx_t_6 = 0;
-  __pyx_t_5 = 0;
+  PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_6);
+  __Pyx_GIVEREF(__pyx_t_6);
   __pyx_t_2 = 0;
+  __pyx_t_5 = 0;
+  __pyx_t_6 = 0;
   __pyx_r = ((PyObject *)__pyx_t_8);
   __pyx_t_8 = 0;
   goto __pyx_L0;
@@ -3354,7 +3432,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6_parseRegion(struct __pyx_o
 
 /* Python wrapper */
 static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_9fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_5pysam_6ctabix_9Tabixfile_8fetch[] = "Tabixfile.fetch(self, reference=None, start=None, end=None, region=None, parser=None)\n\n               \n        fetch one or more rows in a :term:`region` using 0-based indexing. The region is specified by\n        :term:`reference`, *start* and *end*. Alternatively, a samtools :term:`region` string can be supplied.\n\n        Without *reference* or *region* all entries will be fetched. \n        \n        If only *reference*  [...]
+static char __pyx_doc_5pysam_6ctabix_9Tabixfile_8fetch[] = "Tabixfile.fetch(self, reference=None, start=None, end=None, region=None, parser=None)\n\n               \n        fetch one or more rows in a :term:`region` using 0-based indexing. The region is specified by\n        :term:`reference`, *start* and *end*. Alternatively, a samtools :term:`region` string can be supplied.\n\n        Without *reference* or *region* all entries will be fetched. \n        \n        If only *reference*  [...]
 static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_9fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
   PyObject *__pyx_v_reference = 0;
   PyObject *__pyx_v_start = 0;
@@ -3368,7 +3446,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_9fetch(PyObject *__pyx_v_sel
     static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,&__pyx_n_s__parser,0};
     PyObject* values[5] = {0,0,0,0,0};
 
-    /* "pysam/ctabix.pyx":191
+    /* "pysam/ctabix.pyx":203
  * 
  *     def fetch( self,
  *                reference = None,             # <<<<<<<<<<<<<<
@@ -3377,7 +3455,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_9fetch(PyObject *__pyx_v_sel
  */
     values[0] = ((PyObject *)Py_None);
 
-    /* "pysam/ctabix.pyx":192
+    /* "pysam/ctabix.pyx":204
  *     def fetch( self,
  *                reference = None,
  *                start = None,             # <<<<<<<<<<<<<<
@@ -3386,7 +3464,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_9fetch(PyObject *__pyx_v_sel
  */
     values[1] = ((PyObject *)Py_None);
 
-    /* "pysam/ctabix.pyx":193
+    /* "pysam/ctabix.pyx":205
  *                reference = None,
  *                start = None,
  *                end = None,             # <<<<<<<<<<<<<<
@@ -3395,7 +3473,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_9fetch(PyObject *__pyx_v_sel
  */
     values[2] = ((PyObject *)Py_None);
 
-    /* "pysam/ctabix.pyx":194
+    /* "pysam/ctabix.pyx":206
  *                start = None,
  *                end = None,
  *                region = None,             # <<<<<<<<<<<<<<
@@ -3404,7 +3482,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_9fetch(PyObject *__pyx_v_sel
  */
     values[3] = ((PyObject *)Py_None);
 
-    /* "pysam/ctabix.pyx":195
+    /* "pysam/ctabix.pyx":207
  *                end = None,
  *                region = None,
  *                parser = None ):             # <<<<<<<<<<<<<<
@@ -3453,7 +3531,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_9fetch(PyObject *__pyx_v_sel
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -3474,7 +3552,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_9fetch(PyObject *__pyx_v_sel
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.ctabix.Tabixfile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -3485,7 +3563,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_9fetch(PyObject *__pyx_v_sel
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":190
+/* "pysam/ctabix.pyx":202
  *         return region, rtid, rstart, rend
  * 
  *     def fetch( self,             # <<<<<<<<<<<<<<
@@ -3513,9 +3591,10 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("fetch", 0);
   __Pyx_INCREF(__pyx_v_region);
+  __Pyx_INCREF(__pyx_v_parser);
 
-  /* "pysam/ctabix.pyx":209
- *         data (see for example :meth:`asTuple` and :meth:`asGTF`).
+  /* "pysam/ctabix.pyx":219
+ *         If *parser* is None, the default parser will be used for parsing.
  *         '''
  *         ti_lazy_index_load( self.tabixfile )             # <<<<<<<<<<<<<<
  * 
@@ -3523,49 +3602,49 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
  */
   ti_lazy_index_load(__pyx_v_self->tabixfile);
 
-  /* "pysam/ctabix.pyx":211
+  /* "pysam/ctabix.pyx":221
  *         ti_lazy_index_load( self.tabixfile )
  * 
  *         if not self._isOpen():             # <<<<<<<<<<<<<<
  *             raise ValueError( "I/O operation on closed file" )
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
 
-    /* "pysam/ctabix.pyx":212
+    /* "pysam/ctabix.pyx":222
  * 
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
- *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
+ *         # the following will raise errors for invalid regions
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __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 = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":214
- *             raise ValueError( "I/O operation on closed file" )
+  /* "pysam/ctabix.pyx":225
  * 
+ *         # the following will raise errors for invalid regions
  *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )             # <<<<<<<<<<<<<<
  * 
- *         if parser == None:
+ *         # use default parser if no parser is specified
  */
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__pyx_v_reference);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
@@ -3579,7 +3658,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
   __Pyx_INCREF(__pyx_v_region);
   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_region);
   __Pyx_GIVEREF(__pyx_v_region);
-  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
@@ -3593,7 +3672,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
     if (unlikely(size != 4)) {
       if (size > 4) __Pyx_RaiseTooManyValuesError(4);
       else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     #if CYTHON_COMPILING_IN_CPYTHON
     if (likely(PyTuple_CheckExact(sequence))) {
@@ -3615,7 +3694,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
     Py_ssize_t i;
     PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7};
     for (i=0; i < 4; i++) {
-      PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(item);
       *(temps[i]) = item;
     }
@@ -3625,7 +3704,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
   {
     Py_ssize_t index = -1;
     PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7};
-    __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_8);
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
@@ -3634,7 +3713,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
       __Pyx_GOTREF(item);
       *(temps[index]) = item;
     }
-    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_9 = NULL;
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     goto __pyx_L5_unpacking_done;
@@ -3642,7 +3721,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     __pyx_t_9 = NULL;
     if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_L5_unpacking_done:;
   }
   __Pyx_DECREF(__pyx_v_region);
@@ -3655,29 +3734,49 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
   __pyx_v_rend = __pyx_t_7;
   __pyx_t_7 = 0;
 
-  /* "pysam/ctabix.pyx":216
- *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
+  /* "pysam/ctabix.pyx":228
+ * 
+ *         # use default parser if no parser is specified
+ *         if parser == None: parser = self.parser             # <<<<<<<<<<<<<<
+ * 
+ *         if parser == None:
+ */
+  __pyx_t_5 = PyObject_RichCompare(__pyx_v_parser, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __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 = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (__pyx_t_4) {
+    __pyx_t_5 = ((PyObject *)__pyx_v_self->parser);
+    __Pyx_INCREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_v_parser);
+    __pyx_v_parser = __pyx_t_5;
+    __pyx_t_5 = 0;
+    goto __pyx_L6;
+  }
+  __pyx_L6:;
+
+  /* "pysam/ctabix.pyx":230
+ *         if parser == None: parser = self.parser
  * 
  *         if parser == None:             # <<<<<<<<<<<<<<
  *             if region:
  *                 return TabixIterator( self, rtid, rstart, rend )
  */
-  __pyx_t_5 = PyObject_RichCompare(__pyx_v_parser, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __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 = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_RichCompare(__pyx_v_parser, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __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 = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
   if (__pyx_t_4) {
 
-    /* "pysam/ctabix.pyx":217
+    /* "pysam/ctabix.pyx":231
  * 
  *         if parser == None:
  *             if region:             # <<<<<<<<<<<<<<
  *                 return TabixIterator( self, rtid, rstart, rend )
  *             else:
  */
-    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (__pyx_t_4) {
 
-      /* "pysam/ctabix.pyx":218
+      /* "pysam/ctabix.pyx":232
  *         if parser == None:
  *             if region:
  *                 return TabixIterator( self, rtid, rstart, rend )             # <<<<<<<<<<<<<<
@@ -3685,7 +3784,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
  *                 return TabixIterator( self, -1, 0, 0 )
  */
       __Pyx_XDECREF(__pyx_r);
-      __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
       __Pyx_INCREF(((PyObject *)__pyx_v_self));
       PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_self));
@@ -3699,17 +3798,17 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
       __Pyx_INCREF(__pyx_v_rend);
       PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_rend);
       __Pyx_GIVEREF(__pyx_v_rend);
-      __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6ctabix_TabixIterator)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6ctabix_TabixIterator)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
       __pyx_r = __pyx_t_7;
       __pyx_t_7 = 0;
       goto __pyx_L0;
-      goto __pyx_L7;
+      goto __pyx_L8;
     }
     /*else*/ {
 
-      /* "pysam/ctabix.pyx":220
+      /* "pysam/ctabix.pyx":234
  *                 return TabixIterator( self, rtid, rstart, rend )
  *             else:
  *                 return TabixIterator( self, -1, 0, 0 )             # <<<<<<<<<<<<<<
@@ -3717,7 +3816,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
  *             if region:
  */
       __Pyx_XDECREF(__pyx_r);
-      __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_INCREF(((PyObject *)__pyx_v_self));
       PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self));
@@ -3731,37 +3830,45 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
       __Pyx_INCREF(__pyx_int_0);
       PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_int_0);
       __Pyx_GIVEREF(__pyx_int_0);
-      __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6ctabix_TabixIterator)), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6ctabix_TabixIterator)), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
       __pyx_r = __pyx_t_5;
       __pyx_t_5 = 0;
       goto __pyx_L0;
     }
-    __pyx_L7:;
-    goto __pyx_L6;
+    __pyx_L8:;
+    goto __pyx_L7;
   }
   /*else*/ {
 
-    /* "pysam/ctabix.pyx":222
+    /* "pysam/ctabix.pyx":236
  *                 return TabixIterator( self, -1, 0, 0 )
  *         else:
  *             if region:             # <<<<<<<<<<<<<<
- *                 return TabixIteratorParsed( self, rtid, rstart, rend, parser )
- *             else:
+ *                 return TabixIteratorParsed( self, rtid, rstart,
+ *                                             rend, parser )
  */
-    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (__pyx_t_4) {
 
-      /* "pysam/ctabix.pyx":223
+      /* "pysam/ctabix.pyx":237
  *         else:
  *             if region:
- *                 return TabixIteratorParsed( self, rtid, rstart, rend, parser )             # <<<<<<<<<<<<<<
+ *                 return TabixIteratorParsed( self, rtid, rstart,             # <<<<<<<<<<<<<<
+ *                                             rend, parser )
  *             else:
- *                 return TabixIteratorParsed( self, -1, 0, 0, parser )
  */
       __Pyx_XDECREF(__pyx_r);
-      __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+      /* "pysam/ctabix.pyx":238
+ *             if region:
+ *                 return TabixIteratorParsed( self, rtid, rstart,
+ *                                             rend, parser )             # <<<<<<<<<<<<<<
+ *             else:
+ *                 return TabixIteratorParsed( self, -1, 0, 0, parser )
+ */
+      __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
       __Pyx_INCREF(((PyObject *)__pyx_v_self));
       PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_self));
@@ -3778,25 +3885,25 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
       __Pyx_INCREF(__pyx_v_parser);
       PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_v_parser);
       __Pyx_GIVEREF(__pyx_v_parser);
-      __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6ctabix_TabixIteratorParsed)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6ctabix_TabixIteratorParsed)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
       __pyx_r = __pyx_t_7;
       __pyx_t_7 = 0;
       goto __pyx_L0;
-      goto __pyx_L8;
+      goto __pyx_L9;
     }
     /*else*/ {
 
-      /* "pysam/ctabix.pyx":225
- *                 return TabixIteratorParsed( self, rtid, rstart, rend, parser )
+      /* "pysam/ctabix.pyx":240
+ *                                             rend, parser )
  *             else:
  *                 return TabixIteratorParsed( self, -1, 0, 0, parser )             # <<<<<<<<<<<<<<
  * 
  *     ###############################################################
  */
       __Pyx_XDECREF(__pyx_r);
-      __pyx_t_7 = PyTuple_New(5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyTuple_New(5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_INCREF(((PyObject *)__pyx_v_self));
       PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self));
@@ -3813,16 +3920,16 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
       __Pyx_INCREF(__pyx_v_parser);
       PyTuple_SET_ITEM(__pyx_t_7, 4, __pyx_v_parser);
       __Pyx_GIVEREF(__pyx_v_parser);
-      __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6ctabix_TabixIteratorParsed)), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6ctabix_TabixIteratorParsed)), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
       __pyx_r = __pyx_t_5;
       __pyx_t_5 = 0;
       goto __pyx_L0;
     }
-    __pyx_L8:;
+    __pyx_L9:;
   }
-  __pyx_L6:;
+  __pyx_L7:;
 
   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
   goto __pyx_L0;
@@ -3840,6 +3947,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8fetch(struct __pyx_obj_5pys
   __Pyx_XDECREF(__pyx_v_rstart);
   __Pyx_XDECREF(__pyx_v_rend);
   __Pyx_XDECREF(__pyx_v_region);
+  __Pyx_XDECREF(__pyx_v_parser);
   __Pyx_XGIVEREF(__pyx_r);
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
@@ -3856,7 +3964,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_8filename_1__get__(PyObject
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":234
+/* "pysam/ctabix.pyx":249
  *     property filename:
  *         '''filename associated with this object.'''
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -3876,32 +3984,32 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8filename___get__(struct __p
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__get__", 0);
 
-  /* "pysam/ctabix.pyx":235
+  /* "pysam/ctabix.pyx":250
  *         '''filename associated with this object.'''
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             return self._filename
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_4 = (!__pyx_t_3);
   if (__pyx_t_4) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __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 = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":236
+  /* "pysam/ctabix.pyx":251
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
  *             return self._filename             # <<<<<<<<<<<<<<
@@ -3909,7 +4017,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_8filename___get__(struct __p
  *     property header:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = PyBytes_FromString(__pyx_v_self->_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyBytes_FromString(__pyx_v_self->_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
   __pyx_r = ((PyObject *)__pyx_t_2);
   __pyx_t_2 = 0;
@@ -3939,7 +4047,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_6header_1__get__(PyObject *_
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":246
+/* "pysam/ctabix.pyx":261
  *         '''
  * 
  *         def __get__( self ):             # <<<<<<<<<<<<<<
@@ -3957,7 +4065,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6header___get__(struct __pyx
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__get__", 0);
 
-  /* "pysam/ctabix.pyx":247
+  /* "pysam/ctabix.pyx":262
  * 
  *         def __get__( self ):
  *             return TabixHeaderIterator( self )             # <<<<<<<<<<<<<<
@@ -3965,12 +4073,12 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_6header___get__(struct __pyx
  *     property contigs:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __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 = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(((PyObject *)__pyx_v_self));
   PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self));
   __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
-  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6ctabix_TabixHeaderIterator)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6ctabix_TabixHeaderIterator)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
   __pyx_r = __pyx_t_2;
@@ -4001,7 +4109,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_7contigs_1__get__(PyObject *
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":251
+/* "pysam/ctabix.pyx":266
  *     property contigs:
  *         '''chromosome names'''
  *         def __get__(self):             # <<<<<<<<<<<<<<
@@ -4024,7 +4132,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_7contigs___get__(struct __py
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__get__", 0);
 
-  /* "pysam/ctabix.pyx":255
+  /* "pysam/ctabix.pyx":270
  *             cdef int nsequences
  * 
  *             ti_lazy_index_load( self.tabixfile )             # <<<<<<<<<<<<<<
@@ -4033,7 +4141,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_7contigs___get__(struct __py
  */
   ti_lazy_index_load(__pyx_v_self->tabixfile);
 
-  /* "pysam/ctabix.pyx":256
+  /* "pysam/ctabix.pyx":271
  * 
  *             ti_lazy_index_load( self.tabixfile )
  *             sequences = ti_seqname( self.tabixfile.idx, &nsequences )             # <<<<<<<<<<<<<<
@@ -4042,19 +4150,19 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_7contigs___get__(struct __py
  */
   __pyx_v_sequences = ti_seqname(__pyx_v_self->tabixfile->idx, (&__pyx_v_nsequences));
 
-  /* "pysam/ctabix.pyx":258
+  /* "pysam/ctabix.pyx":273
  *             sequences = ti_seqname( self.tabixfile.idx, &nsequences )
  *             cdef int x
  *             result = []             # <<<<<<<<<<<<<<
  *             for x from 0 <= x < nsequences:
  *                 result.append( sequences[x] )
  */
-  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_result = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":259
+  /* "pysam/ctabix.pyx":274
  *             cdef int x
  *             result = []
  *             for x from 0 <= x < nsequences:             # <<<<<<<<<<<<<<
@@ -4064,20 +4172,20 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_7contigs___get__(struct __py
   __pyx_t_2 = __pyx_v_nsequences;
   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) {
 
-    /* "pysam/ctabix.pyx":260
+    /* "pysam/ctabix.pyx":275
  *             result = []
  *             for x from 0 <= x < nsequences:
  *                 result.append( sequences[x] )             # <<<<<<<<<<<<<<
  *             return result
  * 
  */
-    __pyx_t_1 = PyBytes_FromString((__pyx_v_sequences[__pyx_v_x])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyBytes_FromString((__pyx_v_sequences[__pyx_v_x])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-    __pyx_t_3 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
   }
 
-  /* "pysam/ctabix.pyx":261
+  /* "pysam/ctabix.pyx":276
  *             for x from 0 <= x < nsequences:
  *                 result.append( sequences[x] )
  *             return result             # <<<<<<<<<<<<<<
@@ -4114,7 +4222,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_9Tabixfile_11close(PyObject *__pyx_v_se
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":263
+/* "pysam/ctabix.pyx":278
  *             return result
  * 
  *     def close( self ):             # <<<<<<<<<<<<<<
@@ -4128,7 +4236,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_10close(struct __pyx_obj_5py
   int __pyx_t_1;
   __Pyx_RefNannySetupContext("close", 0);
 
-  /* "pysam/ctabix.pyx":266
+  /* "pysam/ctabix.pyx":281
  *         '''
  *         closes the :class:`pysam.Tabixfile`.'''
  *         if self.tabixfile != NULL:             # <<<<<<<<<<<<<<
@@ -4138,7 +4246,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_10close(struct __pyx_obj_5py
   __pyx_t_1 = (__pyx_v_self->tabixfile != NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":267
+    /* "pysam/ctabix.pyx":282
  *         closes the :class:`pysam.Tabixfile`.'''
  *         if self.tabixfile != NULL:
  *             ti_close( self.tabixfile )             # <<<<<<<<<<<<<<
@@ -4147,7 +4255,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_9Tabixfile_10close(struct __pyx_obj_5py
  */
     ti_close(__pyx_v_self->tabixfile);
 
-    /* "pysam/ctabix.pyx":268
+    /* "pysam/ctabix.pyx":283
  *         if self.tabixfile != NULL:
  *             ti_close( self.tabixfile )
  *             self.tabixfile = NULL             # <<<<<<<<<<<<<<
@@ -4174,7 +4282,7 @@ static void __pyx_pw_5pysam_6ctabix_9Tabixfile_13__dealloc__(PyObject *__pyx_v_s
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/ctabix.pyx":270
+/* "pysam/ctabix.pyx":285
  *             self.tabixfile = NULL
  * 
  *     def __dealloc__( self ):             # <<<<<<<<<<<<<<
@@ -4187,7 +4295,7 @@ static void __pyx_pf_5pysam_6ctabix_9Tabixfile_12__dealloc__(struct __pyx_obj_5p
   int __pyx_t_1;
   __Pyx_RefNannySetupContext("__dealloc__", 0);
 
-  /* "pysam/ctabix.pyx":274
+  /* "pysam/ctabix.pyx":289
  *         # note: no doc string
  *         # note: __del__ is not called.
  *         if self.tabixfile != NULL:             # <<<<<<<<<<<<<<
@@ -4197,7 +4305,7 @@ static void __pyx_pf_5pysam_6ctabix_9Tabixfile_12__dealloc__(struct __pyx_obj_5p
   __pyx_t_1 = (__pyx_v_self->tabixfile != NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":275
+    /* "pysam/ctabix.pyx":290
  *         # note: __del__ is not called.
  *         if self.tabixfile != NULL:
  *             ti_close( self.tabixfile )             # <<<<<<<<<<<<<<
@@ -4206,7 +4314,7 @@ static void __pyx_pf_5pysam_6ctabix_9Tabixfile_12__dealloc__(struct __pyx_obj_5p
  */
     ti_close(__pyx_v_self->tabixfile);
 
-    /* "pysam/ctabix.pyx":276
+    /* "pysam/ctabix.pyx":291
  *         if self.tabixfile != NULL:
  *             ti_close( self.tabixfile )
  *             self.tabixfile = NULL             # <<<<<<<<<<<<<<
@@ -4218,7 +4326,7 @@ static void __pyx_pf_5pysam_6ctabix_9Tabixfile_12__dealloc__(struct __pyx_obj_5p
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":277
+  /* "pysam/ctabix.pyx":292
  *             ti_close( self.tabixfile )
  *             self.tabixfile = NULL
  *         if self._filename != NULL: free( self._filename )             # <<<<<<<<<<<<<<
@@ -4267,21 +4375,21 @@ static int __pyx_pw_5pysam_6ctabix_13TabixIterator_1__cinit__(PyObject *__pyx_v_
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tid)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  2:
         if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  3:
         if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
       goto __pyx_L5_argtuple_error;
@@ -4292,19 +4400,19 @@ static int __pyx_pw_5pysam_6ctabix_13TabixIterator_1__cinit__(PyObject *__pyx_v_
       values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
     }
     __pyx_v_tabixfile = ((struct __pyx_obj_5pysam_6ctabix_Tabixfile *)values[0]);
-    __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    __pyx_v_start = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_start = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.ctabix.TabixIterator.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tabixfile), __pyx_ptype_5pysam_6ctabix_Tabixfile, 1, "tabixfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tabixfile), __pyx_ptype_5pysam_6ctabix_Tabixfile, 1, "tabixfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_6ctabix_13TabixIterator___cinit__(((struct __pyx_obj_5pysam_6ctabix_TabixIterator *)__pyx_v_self), __pyx_v_tabixfile, __pyx_v_tid, __pyx_v_start, __pyx_v_end);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -4314,7 +4422,7 @@ static int __pyx_pw_5pysam_6ctabix_13TabixIterator_1__cinit__(PyObject *__pyx_v_
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":284
+/* "pysam/ctabix.pyx":299
  *     """
  * 
  *     def __cinit__(self, Tabixfile tabixfile,             # <<<<<<<<<<<<<<
@@ -4334,7 +4442,7 @@ static int __pyx_pf_5pysam_6ctabix_13TabixIterator___cinit__(struct __pyx_obj_5p
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__cinit__", 0);
 
-  /* "pysam/ctabix.pyx":287
+  /* "pysam/ctabix.pyx":302
  *                   int tid, int start, int end ):
  * 
  *         assert tabixfile._isOpen()             # <<<<<<<<<<<<<<
@@ -4342,20 +4450,20 @@ static int __pyx_pf_5pysam_6ctabix_13TabixIterator___cinit__(struct __pyx_obj_5p
  *         # makes sure that samfile stays alive as long as the
  */
   #ifndef CYTHON_WITHOUT_ASSERTIONS
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_tabixfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_tabixfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   if (unlikely(!__pyx_t_3)) {
     PyErr_SetNone(PyExc_AssertionError);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #endif
 
-  /* "pysam/ctabix.pyx":291
+  /* "pysam/ctabix.pyx":306
  *         # makes sure that samfile stays alive as long as the
  *         # iterator is alive.
  *         self.tabixfile = tabixfile.tabixfile             # <<<<<<<<<<<<<<
@@ -4365,7 +4473,7 @@ static int __pyx_pf_5pysam_6ctabix_13TabixIterator___cinit__(struct __pyx_obj_5p
   __pyx_t_4 = __pyx_v_tabixfile->tabixfile;
   __pyx_v_self->tabixfile = __pyx_t_4;
 
-  /* "pysam/ctabix.pyx":293
+  /* "pysam/ctabix.pyx":308
  *         self.tabixfile = tabixfile.tabixfile
  * 
  *         if tid < 0:             # <<<<<<<<<<<<<<
@@ -4375,7 +4483,7 @@ static int __pyx_pf_5pysam_6ctabix_13TabixIterator___cinit__(struct __pyx_obj_5p
   __pyx_t_3 = (__pyx_v_tid < 0);
   if (__pyx_t_3) {
 
-    /* "pysam/ctabix.pyx":296
+    /* "pysam/ctabix.pyx":311
  *             # seek to start of file to ensure iteration is over
  *             # all entries.
  *             bgzf_seek( self.tabixfile.fp, 0, 0)             # <<<<<<<<<<<<<<
@@ -4384,7 +4492,7 @@ static int __pyx_pf_5pysam_6ctabix_13TabixIterator___cinit__(struct __pyx_obj_5p
  */
     bgzf_seek(__pyx_v_self->tabixfile->fp, 0, 0);
 
-    /* "pysam/ctabix.pyx":297
+    /* "pysam/ctabix.pyx":312
  *             # all entries.
  *             bgzf_seek( self.tabixfile.fp, 0, 0)
  *             self.iterator = ti_iter_first()             # <<<<<<<<<<<<<<
@@ -4396,7 +4504,7 @@ static int __pyx_pf_5pysam_6ctabix_13TabixIterator___cinit__(struct __pyx_obj_5p
   }
   /*else*/ {
 
-    /* "pysam/ctabix.pyx":299
+    /* "pysam/ctabix.pyx":314
  *             self.iterator = ti_iter_first()
  *         else:
  *             self.iterator = ti_queryi(self.tabixfile, tid, start, end)             # <<<<<<<<<<<<<<
@@ -4407,7 +4515,7 @@ static int __pyx_pf_5pysam_6ctabix_13TabixIterator___cinit__(struct __pyx_obj_5p
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":301
+  /* "pysam/ctabix.pyx":316
  *             self.iterator = ti_queryi(self.tabixfile, tid, start, end)
  * 
  *         if <void*>self.iterator == NULL:             # <<<<<<<<<<<<<<
@@ -4417,18 +4525,18 @@ static int __pyx_pf_5pysam_6ctabix_13TabixIterator___cinit__(struct __pyx_obj_5p
   __pyx_t_3 = (((void *)__pyx_v_self->iterator) == NULL);
   if (__pyx_t_3) {
 
-    /* "pysam/ctabix.pyx":302
+    /* "pysam/ctabix.pyx":317
  * 
  *         if <void*>self.iterator == NULL:
  *             raise ValueError("malformatted query or wrong sequence name.\n")             # <<<<<<<<<<<<<<
  * 
  *     def __iter__(self):
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __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 = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
@@ -4456,7 +4564,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_13TabixIterator_3__iter__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":304
+/* "pysam/ctabix.pyx":319
  *             raise ValueError("malformatted query or wrong sequence name.\n")
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
@@ -4469,7 +4577,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_13TabixIterator_2__iter__(struct __pyx_
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__iter__", 0);
 
-  /* "pysam/ctabix.pyx":305
+  /* "pysam/ctabix.pyx":320
  * 
  *     def __iter__(self):
  *         return self             # <<<<<<<<<<<<<<
@@ -4503,7 +4611,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_13TabixIterator_5__next__(PyObject *__p
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":307
+/* "pysam/ctabix.pyx":322
  *         return self
  * 
  *     def __next__(self):             # <<<<<<<<<<<<<<
@@ -4524,8 +4632,8 @@ static PyObject *__pyx_pf_5pysam_6ctabix_13TabixIterator_4__next__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__next__", 0);
 
-  /* "pysam/ctabix.pyx":320
- * 
+  /* "pysam/ctabix.pyx":334
+ *         # as ti_index_t is incomplete type.
  *         # simply use '#' for now.
  *         while 1:             # <<<<<<<<<<<<<<
  *             s = ti_read(self.tabixfile, self.iterator, &len)
@@ -4534,7 +4642,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_13TabixIterator_4__next__(struct __pyx_
   while (1) {
     if (!1) break;
 
-    /* "pysam/ctabix.pyx":321
+    /* "pysam/ctabix.pyx":335
  *         # simply use '#' for now.
  *         while 1:
  *             s = ti_read(self.tabixfile, self.iterator, &len)             # <<<<<<<<<<<<<<
@@ -4543,7 +4651,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_13TabixIterator_4__next__(struct __pyx_
  */
     __pyx_v_s = ti_read(__pyx_v_self->tabixfile, __pyx_v_self->iterator, (&__pyx_v_len));
 
-    /* "pysam/ctabix.pyx":322
+    /* "pysam/ctabix.pyx":336
  *         while 1:
  *             s = ti_read(self.tabixfile, self.iterator, &len)
  *             if s == NULL: raise StopIteration             # <<<<<<<<<<<<<<
@@ -4553,12 +4661,12 @@ static PyObject *__pyx_pf_5pysam_6ctabix_13TabixIterator_4__next__(struct __pyx_
     __pyx_t_1 = (__pyx_v_s == NULL);
     if (__pyx_t_1) {
       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L5;
     }
     __pyx_L5:;
 
-    /* "pysam/ctabix.pyx":323
+    /* "pysam/ctabix.pyx":337
  *             s = ti_read(self.tabixfile, self.iterator, &len)
  *             if s == NULL: raise StopIteration
  *             if s[0] != '#': break             # <<<<<<<<<<<<<<
@@ -4574,19 +4682,19 @@ static PyObject *__pyx_pf_5pysam_6ctabix_13TabixIterator_4__next__(struct __pyx_
   }
   __pyx_L4_break:;
 
-  /* "pysam/ctabix.pyx":325
+  /* "pysam/ctabix.pyx":339
  *             if s[0] != '#': break
  * 
  *         retval = _charptr_to_str( s )             # <<<<<<<<<<<<<<
  *         return retval
  * 
  */
-  __pyx_t_2 = __pyx_f_5pysam_6ctabix__charptr_to_str(__pyx_v_s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __pyx_f_5pysam_6ctabix__charptr_to_str(__pyx_v_s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_v_retval = __pyx_t_2;
   __pyx_t_2 = 0;
 
-  /* "pysam/ctabix.pyx":326
+  /* "pysam/ctabix.pyx":340
  * 
  *         retval = _charptr_to_str( s )
  *         return retval             # <<<<<<<<<<<<<<
@@ -4620,7 +4728,7 @@ static void __pyx_pw_5pysam_6ctabix_13TabixIterator_7__dealloc__(PyObject *__pyx
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/ctabix.pyx":328
+/* "pysam/ctabix.pyx":342
  *         return retval
  * 
  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
@@ -4633,7 +4741,7 @@ static void __pyx_pf_5pysam_6ctabix_13TabixIterator_6__dealloc__(struct __pyx_ob
   int __pyx_t_1;
   __Pyx_RefNannySetupContext("__dealloc__", 0);
 
-  /* "pysam/ctabix.pyx":329
+  /* "pysam/ctabix.pyx":343
  * 
  *     def __dealloc__(self):
  *         if <void*>self.iterator != NULL:             # <<<<<<<<<<<<<<
@@ -4643,7 +4751,7 @@ static void __pyx_pf_5pysam_6ctabix_13TabixIterator_6__dealloc__(struct __pyx_ob
   __pyx_t_1 = (((void *)__pyx_v_self->iterator) != NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":330
+    /* "pysam/ctabix.pyx":344
  *     def __dealloc__(self):
  *         if <void*>self.iterator != NULL:
  *             ti_iter_destroy(self.iterator)             # <<<<<<<<<<<<<<
@@ -4683,7 +4791,7 @@ static int __pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_1__cinit__(PyObject *__
         else goto __pyx_L5_argtuple_error;
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
       goto __pyx_L5_argtuple_error;
@@ -4694,13 +4802,13 @@ static int __pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_1__cinit__(PyObject *__
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.ctabix.TabixHeaderIterator.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tabixfile), __pyx_ptype_5pysam_6ctabix_Tabixfile, 1, "tabixfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tabixfile), __pyx_ptype_5pysam_6ctabix_Tabixfile, 1, "tabixfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_6ctabix_19TabixHeaderIterator___cinit__(((struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator *)__pyx_v_self), __pyx_v_tabixfile);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -4710,7 +4818,7 @@ static int __pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_1__cinit__(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":336
+/* "pysam/ctabix.pyx":350
  *     """
  * 
  *     def __cinit__(self, Tabixfile tabixfile ):             # <<<<<<<<<<<<<<
@@ -4730,7 +4838,7 @@ static int __pyx_pf_5pysam_6ctabix_19TabixHeaderIterator___cinit__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__cinit__", 0);
 
-  /* "pysam/ctabix.pyx":338
+  /* "pysam/ctabix.pyx":352
  *     def __cinit__(self, Tabixfile tabixfile ):
  * 
  *         assert tabixfile._isOpen()             # <<<<<<<<<<<<<<
@@ -4738,20 +4846,20 @@ static int __pyx_pf_5pysam_6ctabix_19TabixHeaderIterator___cinit__(struct __pyx_
  *         # makes sure that samfile stays alive as long as the
  */
   #ifndef CYTHON_WITHOUT_ASSERTIONS
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_tabixfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_tabixfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   if (unlikely(!__pyx_t_3)) {
     PyErr_SetNone(PyExc_AssertionError);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #endif
 
-  /* "pysam/ctabix.pyx":342
+  /* "pysam/ctabix.pyx":356
  *         # makes sure that samfile stays alive as long as the
  *         # iterator is alive.
  *         self.tabixfile = tabixfile.tabixfile             # <<<<<<<<<<<<<<
@@ -4761,7 +4869,7 @@ static int __pyx_pf_5pysam_6ctabix_19TabixHeaderIterator___cinit__(struct __pyx_
   __pyx_t_4 = __pyx_v_tabixfile->tabixfile;
   __pyx_v_self->tabixfile = __pyx_t_4;
 
-  /* "pysam/ctabix.pyx":344
+  /* "pysam/ctabix.pyx":358
  *         self.tabixfile = tabixfile.tabixfile
  * 
  *         self.iterator = ti_query(self.tabixfile, NULL, 0, 0)             # <<<<<<<<<<<<<<
@@ -4770,7 +4878,7 @@ static int __pyx_pf_5pysam_6ctabix_19TabixHeaderIterator___cinit__(struct __pyx_
  */
   __pyx_v_self->iterator = ti_query(__pyx_v_self->tabixfile, NULL, 0, 0);
 
-  /* "pysam/ctabix.pyx":346
+  /* "pysam/ctabix.pyx":360
  *         self.iterator = ti_query(self.tabixfile, NULL, 0, 0)
  * 
  *         if <void*>self.iterator == NULL:             # <<<<<<<<<<<<<<
@@ -4780,18 +4888,18 @@ static int __pyx_pf_5pysam_6ctabix_19TabixHeaderIterator___cinit__(struct __pyx_
   __pyx_t_3 = (((void *)__pyx_v_self->iterator) == NULL);
   if (__pyx_t_3) {
 
-    /* "pysam/ctabix.pyx":347
+    /* "pysam/ctabix.pyx":361
  * 
  *         if <void*>self.iterator == NULL:
  *             raise ValueError("can't open header.\n")             # <<<<<<<<<<<<<<
  * 
  *     def __iter__(self):
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_28), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_27), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __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 = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
@@ -4819,7 +4927,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_3__iter__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":349
+/* "pysam/ctabix.pyx":363
  *             raise ValueError("can't open header.\n")
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
@@ -4832,7 +4940,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_19TabixHeaderIterator_2__iter__(struct
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__iter__", 0);
 
-  /* "pysam/ctabix.pyx":350
+  /* "pysam/ctabix.pyx":364
  * 
  *     def __iter__(self):
  *         return self             # <<<<<<<<<<<<<<
@@ -4866,7 +4974,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_5__next__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":352
+/* "pysam/ctabix.pyx":366
  *         return self
  * 
  *     def __next__(self):             # <<<<<<<<<<<<<<
@@ -4886,7 +4994,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_19TabixHeaderIterator_4__next__(struct
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__next__", 0);
 
-  /* "pysam/ctabix.pyx":363
+  /* "pysam/ctabix.pyx":377
  *         # Getting the metachar is a pain as ti_index_t is incomplete type.
  *         # simply use '#' for now.
  *         s = ti_read(self.tabixfile, self.iterator, &len)             # <<<<<<<<<<<<<<
@@ -4895,7 +5003,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_19TabixHeaderIterator_4__next__(struct
  */
   __pyx_v_s = ti_read(__pyx_v_self->tabixfile, __pyx_v_self->iterator, (&__pyx_v_len));
 
-  /* "pysam/ctabix.pyx":364
+  /* "pysam/ctabix.pyx":378
  *         # simply use '#' for now.
  *         s = ti_read(self.tabixfile, self.iterator, &len)
  *         if s == NULL: raise StopIteration             # <<<<<<<<<<<<<<
@@ -4905,12 +5013,12 @@ static PyObject *__pyx_pf_5pysam_6ctabix_19TabixHeaderIterator_4__next__(struct
   __pyx_t_1 = (__pyx_v_s == NULL);
   if (__pyx_t_1) {
     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":366
+  /* "pysam/ctabix.pyx":380
  *         if s == NULL: raise StopIteration
  *         # stop at first non-header line
  *         if s[0] != '#': raise StopIteration             # <<<<<<<<<<<<<<
@@ -4920,12 +5028,12 @@ static PyObject *__pyx_pf_5pysam_6ctabix_19TabixHeaderIterator_4__next__(struct
   __pyx_t_1 = ((__pyx_v_s[0]) != '#');
   if (__pyx_t_1) {
     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/ctabix.pyx":368
+  /* "pysam/ctabix.pyx":382
  *         if s[0] != '#': raise StopIteration
  * 
  *         return s             # <<<<<<<<<<<<<<
@@ -4933,7 +5041,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_19TabixHeaderIterator_4__next__(struct
  *     def __dealloc__(self):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
   __pyx_r = ((PyObject *)__pyx_t_2);
   __pyx_t_2 = 0;
@@ -4960,7 +5068,7 @@ static void __pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_7__dealloc__(PyObject
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/ctabix.pyx":370
+/* "pysam/ctabix.pyx":384
  *         return s
  * 
  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
@@ -4973,7 +5081,7 @@ static void __pyx_pf_5pysam_6ctabix_19TabixHeaderIterator_6__dealloc__(struct __
   int __pyx_t_1;
   __Pyx_RefNannySetupContext("__dealloc__", 0);
 
-  /* "pysam/ctabix.pyx":371
+  /* "pysam/ctabix.pyx":385
  * 
  *     def __dealloc__(self):
  *         if <void*>self.iterator != NULL:             # <<<<<<<<<<<<<<
@@ -4983,7 +5091,7 @@ static void __pyx_pf_5pysam_6ctabix_19TabixHeaderIterator_6__dealloc__(struct __
   __pyx_t_1 = (((void *)__pyx_v_self->iterator) != NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":372
+    /* "pysam/ctabix.pyx":386
  *     def __dealloc__(self):
  *         if <void*>self.iterator != NULL:
  *             ti_iter_destroy(self.iterator)             # <<<<<<<<<<<<<<
@@ -4998,16 +5106,53 @@ static void __pyx_pf_5pysam_6ctabix_19TabixHeaderIterator_6__dealloc__(struct __
   __Pyx_RefNannyFinishContext();
 }
 
+/* "pysam/ctabix.pyx":394
+ * cdef class Parser:
+ * 
+ *     cdef parse(self, char * buffer, int length):             # <<<<<<<<<<<<<<
+ *         raise NotImplementedError
+ * 
+ */
+
+static PyObject *__pyx_f_5pysam_6ctabix_6Parser_parse(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_Parser *__pyx_v_self, CYTHON_UNUSED char *__pyx_v_buffer, CYTHON_UNUSED int __pyx_v_length) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("parse", 0);
+
+  /* "pysam/ctabix.pyx":395
+ * 
+ *     cdef parse(self, char * buffer, int length):
+ *         raise NotImplementedError             # <<<<<<<<<<<<<<
+ * 
+ *     def __call__(self, char * buffer, int length):
+ */
+  __Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
+  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("pysam.ctabix.Parser.parse", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
 /* Python wrapper */
-static PyObject *__pyx_pw_5pysam_6ctabix_7asTuple_1__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static PyObject *__pyx_pw_5pysam_6ctabix_7asTuple_1__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pw_5pysam_6ctabix_6Parser_1__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_5pysam_6ctabix_6Parser_1__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
   char *__pyx_v_buffer;
-  int __pyx_v_len;
+  int __pyx_v_length;
   PyObject *__pyx_r = 0;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__call__ (wrapper)", 0);
   {
-    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__buffer,&__pyx_n_s__len,0};
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__buffer,&__pyx_n_s__length,0};
     PyObject* values[2] = {0,0};
     if (unlikely(__pyx_kwds)) {
       Py_ssize_t kw_args;
@@ -5024,13 +5169,13 @@ static PyObject *__pyx_pw_5pysam_6ctabix_7asTuple_1__call__(PyObject *__pyx_v_se
         if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__buffer)) != 0)) kw_args--;
         else goto __pyx_L5_argtuple_error;
         case  1:
-        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__len)) != 0)) kw_args--;
+        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__length)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
       goto __pyx_L5_argtuple_error;
@@ -5038,31 +5183,74 @@ static PyObject *__pyx_pw_5pysam_6ctabix_7asTuple_1__call__(PyObject *__pyx_v_se
       values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
       values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
     }
-    __pyx_v_buffer = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_buffer) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    __pyx_v_len = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_len == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_buffer = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_buffer) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_length = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_length == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
-  __Pyx_AddTraceback("pysam.ctabix.asTuple.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_AddTraceback("pysam.ctabix.Parser.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return NULL;
   __pyx_L4_argument_unpacking_done:;
-  __pyx_r = __pyx_pf_5pysam_6ctabix_7asTuple___call__(((struct __pyx_obj_5pysam_6ctabix_asTuple *)__pyx_v_self), __pyx_v_buffer, __pyx_v_len);
+  __pyx_r = __pyx_pf_5pysam_6ctabix_6Parser___call__(((struct __pyx_obj_5pysam_6ctabix_Parser *)__pyx_v_self), __pyx_v_buffer, __pyx_v_length);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "pysam/ctabix.pyx":397
+ *         raise NotImplementedError
+ * 
+ *     def __call__(self, char * buffer, int length):             # <<<<<<<<<<<<<<
+ *         return self.parse( buffer, length )
+ * 
+ */
+
+static PyObject *__pyx_pf_5pysam_6ctabix_6Parser___call__(struct __pyx_obj_5pysam_6ctabix_Parser *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_length) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("__call__", 0);
+
+  /* "pysam/ctabix.pyx":398
+ * 
+ *     def __call__(self, char * buffer, int length):
+ *         return self.parse( buffer, length )             # <<<<<<<<<<<<<<
+ * 
+ * cdef class asTuple(Parser):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_6ctabix_Parser *)__pyx_v_self->__pyx_vtab)->parse(__pyx_v_self, __pyx_v_buffer, __pyx_v_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("pysam.ctabix.Parser.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":386
+/* "pysam/ctabix.pyx":405
  *     Access is by numeric index.
  *     '''
- *     def __call__(self, char * buffer, int len):             # <<<<<<<<<<<<<<
+ *     cdef parse(self, char * buffer, int len):             # <<<<<<<<<<<<<<
  *         cdef TabProxies.TupleProxy r
  *         r = TabProxies.TupleProxy()
  */
 
-static PyObject *__pyx_pf_5pysam_6ctabix_7asTuple___call__(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_asTuple *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) {
+static PyObject *__pyx_f_5pysam_6ctabix_7asTuple_parse(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_asTuple *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) {
   struct __pyx_obj_5pysam_10TabProxies_TupleProxy *__pyx_v_r = 0;
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
@@ -5070,32 +5258,32 @@ static PyObject *__pyx_pf_5pysam_6ctabix_7asTuple___call__(CYTHON_UNUSED struct
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
-  __Pyx_RefNannySetupContext("__call__", 0);
+  __Pyx_RefNannySetupContext("parse", 0);
 
-  /* "pysam/ctabix.pyx":388
- *     def __call__(self, char * buffer, int len):
+  /* "pysam/ctabix.pyx":407
+ *     cdef parse(self, char * buffer, int len):
  *         cdef TabProxies.TupleProxy r
  *         r = TabProxies.TupleProxy()             # <<<<<<<<<<<<<<
  *         # need to copy - there were some
  *         # persistence issues with "present"
  */
-  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_10TabProxies_TupleProxy)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_10TabProxies_TupleProxy)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_r = ((struct __pyx_obj_5pysam_10TabProxies_TupleProxy *)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":391
+  /* "pysam/ctabix.pyx":410
  *         # need to copy - there were some
  *         # persistence issues with "present"
  *         r.copy( buffer, len )             # <<<<<<<<<<<<<<
  *         return r
  * 
  */
-  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_10TabProxies_TupleProxy *)__pyx_v_r->__pyx_vtab)->copy(__pyx_v_r, __pyx_v_buffer, __pyx_v_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_10TabProxies_TupleProxy *)__pyx_v_r->__pyx_vtab)->copy(__pyx_v_r, __pyx_v_buffer, __pyx_v_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":392
+  /* "pysam/ctabix.pyx":411
  *         # persistence issues with "present"
  *         r.copy( buffer, len )
  *         return r             # <<<<<<<<<<<<<<
@@ -5111,8 +5299,8 @@ static PyObject *__pyx_pf_5pysam_6ctabix_7asTuple___call__(CYTHON_UNUSED struct
   goto __pyx_L0;
   __pyx_L1_error:;
   __Pyx_XDECREF(__pyx_t_1);
-  __Pyx_AddTraceback("pysam.ctabix.asTuple.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
+  __Pyx_AddTraceback("pysam.ctabix.asTuple.parse", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
   __pyx_L0:;
   __Pyx_XDECREF((PyObject *)__pyx_v_r);
   __Pyx_XGIVEREF(__pyx_r);
@@ -5120,104 +5308,48 @@ static PyObject *__pyx_pf_5pysam_6ctabix_7asTuple___call__(CYTHON_UNUSED struct
   return __pyx_r;
 }
 
-/* Python wrapper */
-static PyObject *__pyx_pw_5pysam_6ctabix_5asGTF_1__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static PyObject *__pyx_pw_5pysam_6ctabix_5asGTF_1__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
-  char *__pyx_v_buffer;
-  int __pyx_v_len;
-  PyObject *__pyx_r = 0;
-  __Pyx_RefNannyDeclarations
-  __Pyx_RefNannySetupContext("__call__ (wrapper)", 0);
-  {
-    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__buffer,&__pyx_n_s__len,0};
-    PyObject* values[2] = {0,0};
-    if (unlikely(__pyx_kwds)) {
-      Py_ssize_t kw_args;
-      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
-      switch (pos_args) {
-        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
-        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
-        case  0: break;
-        default: goto __pyx_L5_argtuple_error;
-      }
-      kw_args = PyDict_Size(__pyx_kwds);
-      switch (pos_args) {
-        case  0:
-        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__buffer)) != 0)) kw_args--;
-        else goto __pyx_L5_argtuple_error;
-        case  1:
-        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__len)) != 0)) kw_args--;
-        else {
-          __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-        }
-      }
-      if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-      }
-    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
-      goto __pyx_L5_argtuple_error;
-    } else {
-      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
-      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
-    }
-    __pyx_v_buffer = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_buffer) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    __pyx_v_len = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_len == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-  }
-  goto __pyx_L4_argument_unpacking_done;
-  __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-  __pyx_L3_error:;
-  __Pyx_AddTraceback("pysam.ctabix.asGTF.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __Pyx_RefNannyFinishContext();
-  return NULL;
-  __pyx_L4_argument_unpacking_done:;
-  __pyx_r = __pyx_pf_5pysam_6ctabix_5asGTF___call__(((struct __pyx_obj_5pysam_6ctabix_asGTF *)__pyx_v_self), __pyx_v_buffer, __pyx_v_len);
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* "pysam/ctabix.pyx":425
- * 
- *     '''
- *     def __call__(self, char * buffer, int len):             # <<<<<<<<<<<<<<
- *         cdef TabProxies.GTFProxy r
- *         r = TabProxies.GTFProxy()
- */
-
-static PyObject *__pyx_pf_5pysam_6ctabix_5asGTF___call__(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_asGTF *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) {
-  struct __pyx_obj_5pysam_10TabProxies_GTFProxy *__pyx_v_r = 0;
-  PyObject *__pyx_r = NULL;
+/* "pysam/ctabix.pyx":444
+ * 
+ *     '''
+ *     cdef parse(self, char * buffer, int len):             # <<<<<<<<<<<<<<
+ *         cdef TabProxies.GTFProxy r
+ *         r = TabProxies.GTFProxy()
+ */
+
+static PyObject *__pyx_f_5pysam_6ctabix_5asGTF_parse(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_asGTF *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) {
+  struct __pyx_obj_5pysam_10TabProxies_GTFProxy *__pyx_v_r = 0;
+  PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
   PyObject *__pyx_t_1 = NULL;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
-  __Pyx_RefNannySetupContext("__call__", 0);
+  __Pyx_RefNannySetupContext("parse", 0);
 
-  /* "pysam/ctabix.pyx":427
- *     def __call__(self, char * buffer, int len):
+  /* "pysam/ctabix.pyx":446
+ *     cdef parse(self, char * buffer, int len):
  *         cdef TabProxies.GTFProxy r
  *         r = TabProxies.GTFProxy()             # <<<<<<<<<<<<<<
  *         r.copy( buffer, len )
  *         return r
  */
-  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_10TabProxies_GTFProxy)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_10TabProxies_GTFProxy)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_r = ((struct __pyx_obj_5pysam_10TabProxies_GTFProxy *)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":428
+  /* "pysam/ctabix.pyx":447
  *         cdef TabProxies.GTFProxy r
  *         r = TabProxies.GTFProxy()
  *         r.copy( buffer, len )             # <<<<<<<<<<<<<<
  *         return r
  * 
  */
-  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_10TabProxies_GTFProxy *)__pyx_v_r->__pyx_base.__pyx_vtab)->__pyx_base.copy(((struct __pyx_obj_5pysam_10TabProxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_10TabProxies_GTFProxy *)__pyx_v_r->__pyx_base.__pyx_vtab)->__pyx_base.copy(((struct __pyx_obj_5pysam_10TabProxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":429
+  /* "pysam/ctabix.pyx":448
  *         r = TabProxies.GTFProxy()
  *         r.copy( buffer, len )
  *         return r             # <<<<<<<<<<<<<<
@@ -5233,8 +5365,8 @@ static PyObject *__pyx_pf_5pysam_6ctabix_5asGTF___call__(CYTHON_UNUSED struct __
   goto __pyx_L0;
   __pyx_L1_error:;
   __Pyx_XDECREF(__pyx_t_1);
-  __Pyx_AddTraceback("pysam.ctabix.asGTF.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
+  __Pyx_AddTraceback("pysam.ctabix.asGTF.parse", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
   __pyx_L0:;
   __Pyx_XDECREF((PyObject *)__pyx_v_r);
   __Pyx_XGIVEREF(__pyx_r);
@@ -5242,71 +5374,15 @@ static PyObject *__pyx_pf_5pysam_6ctabix_5asGTF___call__(CYTHON_UNUSED struct __
   return __pyx_r;
 }
 
-/* Python wrapper */
-static PyObject *__pyx_pw_5pysam_6ctabix_5asBed_1__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static PyObject *__pyx_pw_5pysam_6ctabix_5asBed_1__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
-  char *__pyx_v_buffer;
-  int __pyx_v_len;
-  PyObject *__pyx_r = 0;
-  __Pyx_RefNannyDeclarations
-  __Pyx_RefNannySetupContext("__call__ (wrapper)", 0);
-  {
-    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__buffer,&__pyx_n_s__len,0};
-    PyObject* values[2] = {0,0};
-    if (unlikely(__pyx_kwds)) {
-      Py_ssize_t kw_args;
-      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
-      switch (pos_args) {
-        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
-        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
-        case  0: break;
-        default: goto __pyx_L5_argtuple_error;
-      }
-      kw_args = PyDict_Size(__pyx_kwds);
-      switch (pos_args) {
-        case  0:
-        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__buffer)) != 0)) kw_args--;
-        else goto __pyx_L5_argtuple_error;
-        case  1:
-        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__len)) != 0)) kw_args--;
-        else {
-          __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-        }
-      }
-      if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-      }
-    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
-      goto __pyx_L5_argtuple_error;
-    } else {
-      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
-      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
-    }
-    __pyx_v_buffer = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_buffer) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    __pyx_v_len = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_len == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-  }
-  goto __pyx_L4_argument_unpacking_done;
-  __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-  __pyx_L3_error:;
-  __Pyx_AddTraceback("pysam.ctabix.asBed.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __Pyx_RefNannyFinishContext();
-  return NULL;
-  __pyx_L4_argument_unpacking_done:;
-  __pyx_r = __pyx_pf_5pysam_6ctabix_5asBed___call__(((struct __pyx_obj_5pysam_6ctabix_asBed *)__pyx_v_self), __pyx_v_buffer, __pyx_v_len);
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* "pysam/ctabix.pyx":465
+/* "pysam/ctabix.pyx":484
  * 
  *     '''
- *     def __call__(self, char * buffer, int len):             # <<<<<<<<<<<<<<
+ *     cdef parse(self, char * buffer, int len):             # <<<<<<<<<<<<<<
  *         cdef TabProxies.BedProxy r
  *         r = TabProxies.BedProxy()
  */
 
-static PyObject *__pyx_pf_5pysam_6ctabix_5asBed___call__(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_asBed *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) {
+static PyObject *__pyx_f_5pysam_6ctabix_5asBed_parse(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_asBed *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) {
   struct __pyx_obj_5pysam_10TabProxies_BedProxy *__pyx_v_r = 0;
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
@@ -5314,32 +5390,32 @@ static PyObject *__pyx_pf_5pysam_6ctabix_5asBed___call__(CYTHON_UNUSED struct __
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
-  __Pyx_RefNannySetupContext("__call__", 0);
+  __Pyx_RefNannySetupContext("parse", 0);
 
-  /* "pysam/ctabix.pyx":467
- *     def __call__(self, char * buffer, int len):
+  /* "pysam/ctabix.pyx":486
+ *     cdef parse(self, char * buffer, int len):
  *         cdef TabProxies.BedProxy r
  *         r = TabProxies.BedProxy()             # <<<<<<<<<<<<<<
  *         r.copy( buffer, len )
  *         return r
  */
-  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_10TabProxies_BedProxy)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_10TabProxies_BedProxy)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_r = ((struct __pyx_obj_5pysam_10TabProxies_BedProxy *)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":468
+  /* "pysam/ctabix.pyx":487
  *         cdef TabProxies.BedProxy r
  *         r = TabProxies.BedProxy()
  *         r.copy( buffer, len )             # <<<<<<<<<<<<<<
  *         return r
  * 
  */
-  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_10TabProxies_BedProxy *)__pyx_v_r->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.__pyx_base.copy(((struct __pyx_obj_5pysam_10TabProxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_10TabProxies_BedProxy *)__pyx_v_r->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.__pyx_base.copy(((struct __pyx_obj_5pysam_10TabProxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":469
+  /* "pysam/ctabix.pyx":488
  *         r = TabProxies.BedProxy()
  *         r.copy( buffer, len )
  *         return r             # <<<<<<<<<<<<<<
@@ -5355,8 +5431,8 @@ static PyObject *__pyx_pf_5pysam_6ctabix_5asBed___call__(CYTHON_UNUSED struct __
   goto __pyx_L0;
   __pyx_L1_error:;
   __Pyx_XDECREF(__pyx_t_1);
-  __Pyx_AddTraceback("pysam.ctabix.asBed.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
+  __Pyx_AddTraceback("pysam.ctabix.asBed.parse", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
   __pyx_L0:;
   __Pyx_XDECREF((PyObject *)__pyx_v_r);
   __Pyx_XGIVEREF(__pyx_r);
@@ -5364,71 +5440,15 @@ static PyObject *__pyx_pf_5pysam_6ctabix_5asBed___call__(CYTHON_UNUSED struct __
   return __pyx_r;
 }
 
-/* Python wrapper */
-static PyObject *__pyx_pw_5pysam_6ctabix_5asVCF_1__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static PyObject *__pyx_pw_5pysam_6ctabix_5asVCF_1__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
-  char *__pyx_v_buffer;
-  int __pyx_v_len;
-  PyObject *__pyx_r = 0;
-  __Pyx_RefNannyDeclarations
-  __Pyx_RefNannySetupContext("__call__ (wrapper)", 0);
-  {
-    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__buffer,&__pyx_n_s__len,0};
-    PyObject* values[2] = {0,0};
-    if (unlikely(__pyx_kwds)) {
-      Py_ssize_t kw_args;
-      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
-      switch (pos_args) {
-        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
-        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
-        case  0: break;
-        default: goto __pyx_L5_argtuple_error;
-      }
-      kw_args = PyDict_Size(__pyx_kwds);
-      switch (pos_args) {
-        case  0:
-        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__buffer)) != 0)) kw_args--;
-        else goto __pyx_L5_argtuple_error;
-        case  1:
-        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__len)) != 0)) kw_args--;
-        else {
-          __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-        }
-      }
-      if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-      }
-    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
-      goto __pyx_L5_argtuple_error;
-    } else {
-      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
-      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
-    }
-    __pyx_v_buffer = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_buffer) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    __pyx_v_len = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_len == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-  }
-  goto __pyx_L4_argument_unpacking_done;
-  __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-  __pyx_L3_error:;
-  __Pyx_AddTraceback("pysam.ctabix.asVCF.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __Pyx_RefNannyFinishContext();
-  return NULL;
-  __pyx_L4_argument_unpacking_done:;
-  __pyx_r = __pyx_pf_5pysam_6ctabix_5asVCF___call__(((struct __pyx_obj_5pysam_6ctabix_asVCF *)__pyx_v_self), __pyx_v_buffer, __pyx_v_len);
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* "pysam/ctabix.pyx":501
+/* "pysam/ctabix.pyx":520
  * 
  *     '''
- *     def __call__(self, char * buffer, int len ):             # <<<<<<<<<<<<<<
+ *     cdef parse(self, char * buffer, int len ):             # <<<<<<<<<<<<<<
  *         cdef TabProxies.VCFProxy r
  *         r = TabProxies.VCFProxy()
  */
 
-static PyObject *__pyx_pf_5pysam_6ctabix_5asVCF___call__(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_asVCF *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) {
+static PyObject *__pyx_f_5pysam_6ctabix_5asVCF_parse(CYTHON_UNUSED struct __pyx_obj_5pysam_6ctabix_asVCF *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) {
   struct __pyx_obj_5pysam_10TabProxies_VCFProxy *__pyx_v_r = 0;
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
@@ -5436,32 +5456,32 @@ static PyObject *__pyx_pf_5pysam_6ctabix_5asVCF___call__(CYTHON_UNUSED struct __
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
-  __Pyx_RefNannySetupContext("__call__", 0);
+  __Pyx_RefNannySetupContext("parse", 0);
 
-  /* "pysam/ctabix.pyx":503
- *     def __call__(self, char * buffer, int len ):
+  /* "pysam/ctabix.pyx":522
+ *     cdef parse(self, char * buffer, int len ):
  *         cdef TabProxies.VCFProxy r
  *         r = TabProxies.VCFProxy()             # <<<<<<<<<<<<<<
  *         r.copy( buffer, len )
  *         return r
  */
-  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_10TabProxies_VCFProxy)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_10TabProxies_VCFProxy)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 522; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_v_r = ((struct __pyx_obj_5pysam_10TabProxies_VCFProxy *)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":504
+  /* "pysam/ctabix.pyx":523
  *         cdef TabProxies.VCFProxy r
  *         r = TabProxies.VCFProxy()
  *         r.copy( buffer, len )             # <<<<<<<<<<<<<<
  *         return r
  * 
  */
-  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_10TabProxies_VCFProxy *)__pyx_v_r->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.__pyx_base.copy(((struct __pyx_obj_5pysam_10TabProxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_10TabProxies_VCFProxy *)__pyx_v_r->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.__pyx_base.copy(((struct __pyx_obj_5pysam_10TabProxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":505
+  /* "pysam/ctabix.pyx":524
  *         r = TabProxies.VCFProxy()
  *         r.copy( buffer, len )
  *         return r             # <<<<<<<<<<<<<<
@@ -5477,8 +5497,8 @@ static PyObject *__pyx_pf_5pysam_6ctabix_5asVCF___call__(CYTHON_UNUSED struct __
   goto __pyx_L0;
   __pyx_L1_error:;
   __Pyx_XDECREF(__pyx_t_1);
-  __Pyx_AddTraceback("pysam.ctabix.asVCF.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
+  __Pyx_AddTraceback("pysam.ctabix.asVCF.parse", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
   __pyx_L0:;
   __Pyx_XDECREF((PyObject *)__pyx_v_r);
   __Pyx_XGIVEREF(__pyx_r);
@@ -5520,26 +5540,26 @@ static int __pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_1__cinit__(PyObject *__
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tid)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  2:
         if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  3:
         if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  4:
         if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__parser)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
       goto __pyx_L5_argtuple_error;
@@ -5551,21 +5571,21 @@ static int __pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_1__cinit__(PyObject *__
       values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
     }
     __pyx_v_tabixfile = ((struct __pyx_obj_5pysam_6ctabix_Tabixfile *)values[0]);
-    __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    __pyx_v_start = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 519; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 537; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_start = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     __pyx_v_parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)values[4]);
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.ctabix.TabixIteratorParsed.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tabixfile), __pyx_ptype_5pysam_6ctabix_Tabixfile, 1, "tabixfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_parser), __pyx_ptype_5pysam_6ctabix_Parser, 1, "parser", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tabixfile), __pyx_ptype_5pysam_6ctabix_Tabixfile, 1, "tabixfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_parser), __pyx_ptype_5pysam_6ctabix_Parser, 1, "parser", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed___cinit__(((struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *)__pyx_v_self), __pyx_v_tabixfile, __pyx_v_tid, __pyx_v_start, __pyx_v_end, __pyx_v_parser);
   goto __pyx_L0;
   __pyx_L1_error:;
@@ -5575,7 +5595,7 @@ static int __pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_1__cinit__(PyObject *__
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":516
+/* "pysam/ctabix.pyx":535
  *     """
  * 
  *     def __cinit__(self,             # <<<<<<<<<<<<<<
@@ -5595,7 +5615,7 @@ static int __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed___cinit__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__cinit__", 0);
 
-  /* "pysam/ctabix.pyx":523
+  /* "pysam/ctabix.pyx":542
  *                   Parser parser ):
  * 
  *         assert tabixfile._isOpen()             # <<<<<<<<<<<<<<
@@ -5603,20 +5623,20 @@ static int __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed___cinit__(struct __pyx_
  * 
  */
   #ifndef CYTHON_WITHOUT_ASSERTIONS
-  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_tabixfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_tabixfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   if (unlikely(!__pyx_t_3)) {
     PyErr_SetNone(PyExc_AssertionError);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #endif
 
-  /* "pysam/ctabix.pyx":524
+  /* "pysam/ctabix.pyx":543
  * 
  *         assert tabixfile._isOpen()
  *         self.parser = parser             # <<<<<<<<<<<<<<
@@ -5629,7 +5649,7 @@ static int __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed___cinit__(struct __pyx_
   __Pyx_DECREF(((PyObject *)__pyx_v_self->parser));
   __pyx_v_self->parser = __pyx_v_parser;
 
-  /* "pysam/ctabix.pyx":528
+  /* "pysam/ctabix.pyx":547
  *         # makes sure that samfile stays alive as long as the
  *         # iterator is alive.
  *         self.tabixfile = tabixfile.tabixfile             # <<<<<<<<<<<<<<
@@ -5639,7 +5659,7 @@ static int __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed___cinit__(struct __pyx_
   __pyx_t_4 = __pyx_v_tabixfile->tabixfile;
   __pyx_v_self->tabixfile = __pyx_t_4;
 
-  /* "pysam/ctabix.pyx":530
+  /* "pysam/ctabix.pyx":549
  *         self.tabixfile = tabixfile.tabixfile
  * 
  *         if tid < 0:             # <<<<<<<<<<<<<<
@@ -5649,7 +5669,7 @@ static int __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed___cinit__(struct __pyx_
   __pyx_t_3 = (__pyx_v_tid < 0);
   if (__pyx_t_3) {
 
-    /* "pysam/ctabix.pyx":533
+    /* "pysam/ctabix.pyx":552
  *             # seek to start of file to ensure iteration is over
  *             # all entries.
  *             bgzf_seek( self.tabixfile.fp, 0, 0)             # <<<<<<<<<<<<<<
@@ -5658,7 +5678,7 @@ static int __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed___cinit__(struct __pyx_
  */
     bgzf_seek(__pyx_v_self->tabixfile->fp, 0, 0);
 
-    /* "pysam/ctabix.pyx":534
+    /* "pysam/ctabix.pyx":553
  *             # all entries.
  *             bgzf_seek( self.tabixfile.fp, 0, 0)
  *             self.iterator = ti_iter_first()             # <<<<<<<<<<<<<<
@@ -5670,7 +5690,7 @@ static int __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed___cinit__(struct __pyx_
   }
   /*else*/ {
 
-    /* "pysam/ctabix.pyx":536
+    /* "pysam/ctabix.pyx":555
  *             self.iterator = ti_iter_first()
  *         else:
  *             self.iterator = ti_queryi(self.tabixfile, tid, start, end)             # <<<<<<<<<<<<<<
@@ -5681,7 +5701,7 @@ static int __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed___cinit__(struct __pyx_
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":538
+  /* "pysam/ctabix.pyx":557
  *             self.iterator = ti_queryi(self.tabixfile, tid, start, end)
  * 
  *         if <void*>self.iterator == NULL:             # <<<<<<<<<<<<<<
@@ -5691,18 +5711,18 @@ static int __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed___cinit__(struct __pyx_
   __pyx_t_3 = (((void *)__pyx_v_self->iterator) == NULL);
   if (__pyx_t_3) {
 
-    /* "pysam/ctabix.pyx":539
+    /* "pysam/ctabix.pyx":558
  * 
  *         if <void*>self.iterator == NULL:
  *             raise ValueError("malformatted query or wrong sequence name.\n")             # <<<<<<<<<<<<<<
  * 
  *     def __iter__(self):
  */
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_29), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_28), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __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 = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
@@ -5730,7 +5750,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_3__iter__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":541
+/* "pysam/ctabix.pyx":560
  *             raise ValueError("malformatted query or wrong sequence name.\n")
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
@@ -5743,7 +5763,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_19TabixIteratorParsed_2__iter__(struct
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__iter__", 0);
 
-  /* "pysam/ctabix.pyx":542
+  /* "pysam/ctabix.pyx":561
  * 
  *     def __iter__(self):
  *         return self             # <<<<<<<<<<<<<<
@@ -5777,7 +5797,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_5__next__(PyObjec
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":544
+/* "pysam/ctabix.pyx":563
  *         return self
  * 
  *     def __next__(self):             # <<<<<<<<<<<<<<
@@ -5792,14 +5812,12 @@ static PyObject *__pyx_pf_5pysam_6ctabix_19TabixIteratorParsed_4__next__(struct
   __Pyx_RefNannyDeclarations
   int __pyx_t_1;
   PyObject *__pyx_t_2 = NULL;
-  PyObject *__pyx_t_3 = NULL;
-  PyObject *__pyx_t_4 = NULL;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__next__", 0);
 
-  /* "pysam/ctabix.pyx":552
+  /* "pysam/ctabix.pyx":571
  *         cdef char * s
  *         cdef int len
  *         while 1:             # <<<<<<<<<<<<<<
@@ -5809,36 +5827,36 @@ static PyObject *__pyx_pf_5pysam_6ctabix_19TabixIteratorParsed_4__next__(struct
   while (1) {
     if (!1) break;
 
-    /* "pysam/ctabix.pyx":553
+    /* "pysam/ctabix.pyx":572
  *         cdef int len
  *         while 1:
  *             s = ti_read(self.tabixfile, self.iterator, &len)             # <<<<<<<<<<<<<<
  *             if s == NULL: raise StopIteration
- *             # todo: read metachar from configuration
+ *             if s[0] != '#': break
  */
     __pyx_v_s = ti_read(__pyx_v_self->tabixfile, __pyx_v_self->iterator, (&__pyx_v_len));
 
-    /* "pysam/ctabix.pyx":554
+    /* "pysam/ctabix.pyx":573
  *         while 1:
  *             s = ti_read(self.tabixfile, self.iterator, &len)
  *             if s == NULL: raise StopIteration             # <<<<<<<<<<<<<<
- *             # todo: read metachar from configuration
  *             if s[0] != '#': break
+ * 
  */
     __pyx_t_1 = (__pyx_v_s == NULL);
     if (__pyx_t_1) {
       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 554; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L5;
     }
     __pyx_L5:;
 
-    /* "pysam/ctabix.pyx":556
+    /* "pysam/ctabix.pyx":574
+ *             s = ti_read(self.tabixfile, self.iterator, &len)
  *             if s == NULL: raise StopIteration
- *             # todo: read metachar from configuration
  *             if s[0] != '#': break             # <<<<<<<<<<<<<<
  * 
- *         return self.parser(s, len)
+ *         return self.parser.parse(s, len)
  */
     __pyx_t_1 = ((__pyx_v_s[0]) != '#');
     if (__pyx_t_1) {
@@ -5849,39 +5867,24 @@ static PyObject *__pyx_pf_5pysam_6ctabix_19TabixIteratorParsed_4__next__(struct
   }
   __pyx_L4_break:;
 
-  /* "pysam/ctabix.pyx":558
+  /* "pysam/ctabix.pyx":576
  *             if s[0] != '#': break
  * 
- *         return self.parser(s, len)             # <<<<<<<<<<<<<<
+ *         return self.parser.parse(s, len)             # <<<<<<<<<<<<<<
  * 
  *     def __dealloc__(self):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_2 = PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-  __pyx_t_3 = PyInt_FromLong(__pyx_v_len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __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 = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_4);
-  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_2));
-  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
-  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
-  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_5pysam_6ctabix_Parser *)__pyx_v_self->parser->__pyx_vtab)->parse(__pyx_v_self->parser, __pyx_v_s, __pyx_v_len); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
-  __pyx_t_3 = 0;
-  __pyx_t_3 = PyObject_Call(((PyObject *)__pyx_v_self->parser), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_3);
-  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
-  __pyx_r = __pyx_t_3;
-  __pyx_t_3 = 0;
   goto __pyx_L0;
 
   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
   goto __pyx_L0;
   __pyx_L1_error:;
   __Pyx_XDECREF(__pyx_t_2);
-  __Pyx_XDECREF(__pyx_t_3);
-  __Pyx_XDECREF(__pyx_t_4);
   __Pyx_AddTraceback("pysam.ctabix.TabixIteratorParsed.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __pyx_r = NULL;
   __pyx_L0:;
@@ -5899,8 +5902,8 @@ static void __pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_7__dealloc__(PyObject
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/ctabix.pyx":560
- *         return self.parser(s, len)
+/* "pysam/ctabix.pyx":578
+ *         return self.parser.parse(s, len)
  * 
  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
  *         if <void*>self.iterator != NULL:
@@ -5912,7 +5915,7 @@ static void __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed_6__dealloc__(struct __
   int __pyx_t_1;
   __Pyx_RefNannySetupContext("__dealloc__", 0);
 
-  /* "pysam/ctabix.pyx":561
+  /* "pysam/ctabix.pyx":579
  * 
  *     def __dealloc__(self):
  *         if <void*>self.iterator != NULL:             # <<<<<<<<<<<<<<
@@ -5922,7 +5925,7 @@ static void __pyx_pf_5pysam_6ctabix_19TabixIteratorParsed_6__dealloc__(struct __
   __pyx_t_1 = (((void *)__pyx_v_self->iterator) != NULL);
   if (__pyx_t_1) {
 
-    /* "pysam/ctabix.pyx":562
+    /* "pysam/ctabix.pyx":580
  *     def __dealloc__(self):
  *         if <void*>self.iterator != NULL:
  *             ti_iter_destroy(self.iterator)             # <<<<<<<<<<<<<<
@@ -5951,7 +5954,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_1tabix_compress(PyObject *__pyx_self, P
   {
     static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__filename_in,&__pyx_n_s__filename_out,&__pyx_n_s__force,0};
     PyObject* values[3] = {0,0,0};
-    values[2] = __pyx_k_30;
+    values[2] = __pyx_k_29;
     if (unlikely(__pyx_kwds)) {
       Py_ssize_t kw_args;
       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
@@ -5970,7 +5973,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_1tabix_compress(PyObject *__pyx_self, P
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename_out)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("tabix_compress", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("tabix_compress", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  2:
         if (kw_args > 0) {
@@ -5979,7 +5982,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_1tabix_compress(PyObject *__pyx_self, P
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tabix_compress") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tabix_compress") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -5996,7 +5999,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_1tabix_compress(PyObject *__pyx_self, P
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("tabix_compress", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("tabix_compress", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.ctabix.tabix_compress", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -6007,7 +6010,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_1tabix_compress(PyObject *__pyx_self, P
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":564
+/* "pysam/ctabix.pyx":582
  *             ti_iter_destroy(self.iterator)
  * 
  * def tabix_compress( filename_in,             # <<<<<<<<<<<<<<
@@ -6039,34 +6042,34 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("tabix_compress", 0);
 
-  /* "pysam/ctabix.pyx":573
+  /* "pysam/ctabix.pyx":591
  *     '''
  * 
  *     if not force and os.path.exists(filename_out ):             # <<<<<<<<<<<<<<
  *         raise IOError( "Filename '%s' already exists, use *force* to overwrite" % filename_out)
  * 
  */
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_force); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_force); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_t_2 = (!__pyx_t_1);
   if (__pyx_t_2) {
-    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__path); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__path); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__exists); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__exists); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_INCREF(__pyx_v_filename_out);
     PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_filename_out);
     __Pyx_GIVEREF(__pyx_v_filename_out);
-    __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __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_4)); __pyx_t_4 = 0;
-    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     __pyx_t_6 = __pyx_t_1;
   } else {
@@ -6074,47 +6077,47 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
   }
   if (__pyx_t_6) {
 
-    /* "pysam/ctabix.pyx":574
+    /* "pysam/ctabix.pyx":592
  * 
  *     if not force and os.path.exists(filename_out ):
  *         raise IOError( "Filename '%s' already exists, use *force* to overwrite" % filename_out)             # <<<<<<<<<<<<<<
  * 
  *     cdef int WINDOW_SIZE
  */
-    __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_31), __pyx_v_filename_out); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_30), __pyx_v_filename_out); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_5));
-    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_5));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
     __pyx_t_5 = 0;
-    __pyx_t_5 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
     __Pyx_Raise(__pyx_t_5, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":583
+  /* "pysam/ctabix.pyx":601
  * 
  *     cdef int O_RDONLY
  *     O_RDONLY = os.O_RDONLY             # <<<<<<<<<<<<<<
  * 
  *     WINDOW_SIZE = 64 * 1024
  */
-  __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
-  __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__O_RDONLY); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__O_RDONLY); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-  __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   __pyx_v_O_RDONLY = __pyx_t_7;
 
-  /* "pysam/ctabix.pyx":585
+  /* "pysam/ctabix.pyx":603
  *     O_RDONLY = os.O_RDONLY
  * 
  *     WINDOW_SIZE = 64 * 1024             # <<<<<<<<<<<<<<
@@ -6123,29 +6126,29 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
  */
   __pyx_v_WINDOW_SIZE = 65536;
 
-  /* "pysam/ctabix.pyx":587
+  /* "pysam/ctabix.pyx":605
  *     WINDOW_SIZE = 64 * 1024
  * 
  *     fn = _force_bytes(filename_out)             # <<<<<<<<<<<<<<
  *     fp = bgzf_open( fn, "w")
  *     if fp == NULL:
  */
-  __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_6ctabix__force_bytes(__pyx_v_filename_out)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_6ctabix__force_bytes(__pyx_v_filename_out)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __pyx_v_fn = ((PyObject*)__pyx_t_4);
   __pyx_t_4 = 0;
 
-  /* "pysam/ctabix.pyx":588
+  /* "pysam/ctabix.pyx":606
  * 
  *     fn = _force_bytes(filename_out)
  *     fp = bgzf_open( fn, "w")             # <<<<<<<<<<<<<<
  *     if fp == NULL:
  *         raise IOError( "could not open '%s' for writing" )
  */
-  __pyx_t_8 = PyBytes_AsString(((PyObject *)__pyx_v_fn)); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = PyBytes_AsString(((PyObject *)__pyx_v_fn)); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_fp = bgzf_open(__pyx_t_8, __pyx_k__w);
 
-  /* "pysam/ctabix.pyx":589
+  /* "pysam/ctabix.pyx":607
  *     fn = _force_bytes(filename_out)
  *     fp = bgzf_open( fn, "w")
  *     if fp == NULL:             # <<<<<<<<<<<<<<
@@ -6155,46 +6158,46 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
   __pyx_t_6 = (__pyx_v_fp == NULL);
   if (__pyx_t_6) {
 
-    /* "pysam/ctabix.pyx":590
+    /* "pysam/ctabix.pyx":608
  *     fp = bgzf_open( fn, "w")
  *     if fp == NULL:
  *         raise IOError( "could not open '%s' for writing" )             # <<<<<<<<<<<<<<
  * 
  *     fn = _force_bytes(filename_in)
  */
-    __pyx_t_4 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_k_tuple_33), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_k_tuple_32), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_Raise(__pyx_t_4, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/ctabix.pyx":592
+  /* "pysam/ctabix.pyx":610
  *         raise IOError( "could not open '%s' for writing" )
  * 
  *     fn = _force_bytes(filename_in)             # <<<<<<<<<<<<<<
  *     fd_src = open(fn, O_RDONLY)
  *     if fd_src == 0:
  */
-  __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_6ctabix__force_bytes(__pyx_v_filename_in)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_6ctabix__force_bytes(__pyx_v_filename_in)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(((PyObject *)__pyx_v_fn));
   __pyx_v_fn = ((PyObject*)__pyx_t_4);
   __pyx_t_4 = 0;
 
-  /* "pysam/ctabix.pyx":593
+  /* "pysam/ctabix.pyx":611
  * 
  *     fn = _force_bytes(filename_in)
  *     fd_src = open(fn, O_RDONLY)             # <<<<<<<<<<<<<<
  *     if fd_src == 0:
  *         raise IOError( "could not open '%s' for reading" )
  */
-  __pyx_t_8 = PyBytes_AsString(((PyObject *)__pyx_v_fn)); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = PyBytes_AsString(((PyObject *)__pyx_v_fn)); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_fd_src = open(__pyx_t_8, __pyx_v_O_RDONLY);
 
-  /* "pysam/ctabix.pyx":594
+  /* "pysam/ctabix.pyx":612
  *     fn = _force_bytes(filename_in)
  *     fd_src = open(fn, O_RDONLY)
  *     if fd_src == 0:             # <<<<<<<<<<<<<<
@@ -6204,23 +6207,23 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
   __pyx_t_6 = (__pyx_v_fd_src == 0);
   if (__pyx_t_6) {
 
-    /* "pysam/ctabix.pyx":595
+    /* "pysam/ctabix.pyx":613
  *     fd_src = open(fn, O_RDONLY)
  *     if fd_src == 0:
  *         raise IOError( "could not open '%s' for reading" )             # <<<<<<<<<<<<<<
  * 
  *     buffer = malloc(WINDOW_SIZE)
  */
-    __pyx_t_4 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_k_tuple_35), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 595; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_k_tuple_34), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_Raise(__pyx_t_4, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 595; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L5;
   }
   __pyx_L5:;
 
-  /* "pysam/ctabix.pyx":597
+  /* "pysam/ctabix.pyx":615
  *         raise IOError( "could not open '%s' for reading" )
  * 
  *     buffer = malloc(WINDOW_SIZE)             # <<<<<<<<<<<<<<
@@ -6229,7 +6232,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
  */
   __pyx_v_buffer = malloc(__pyx_v_WINDOW_SIZE);
 
-  /* "pysam/ctabix.pyx":598
+  /* "pysam/ctabix.pyx":616
  * 
  *     buffer = malloc(WINDOW_SIZE)
  *     c = 1             # <<<<<<<<<<<<<<
@@ -6238,7 +6241,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
  */
   __pyx_v_c = 1;
 
-  /* "pysam/ctabix.pyx":600
+  /* "pysam/ctabix.pyx":618
  *     c = 1
  * 
  *     while c > 0:             # <<<<<<<<<<<<<<
@@ -6249,7 +6252,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
     __pyx_t_6 = (__pyx_v_c > 0);
     if (!__pyx_t_6) break;
 
-    /* "pysam/ctabix.pyx":601
+    /* "pysam/ctabix.pyx":619
  * 
  *     while c > 0:
  *         c = read(fd_src, buffer, WINDOW_SIZE)             # <<<<<<<<<<<<<<
@@ -6258,7 +6261,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
  */
     __pyx_v_c = read(__pyx_v_fd_src, __pyx_v_buffer, __pyx_v_WINDOW_SIZE);
 
-    /* "pysam/ctabix.pyx":602
+    /* "pysam/ctabix.pyx":620
  *     while c > 0:
  *         c = read(fd_src, buffer, WINDOW_SIZE)
  *         r = bgzf_write(fp, buffer, c)             # <<<<<<<<<<<<<<
@@ -6267,7 +6270,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
  */
     __pyx_v_r = bgzf_write(__pyx_v_fp, __pyx_v_buffer, __pyx_v_c);
 
-    /* "pysam/ctabix.pyx":603
+    /* "pysam/ctabix.pyx":621
  *         c = read(fd_src, buffer, WINDOW_SIZE)
  *         r = bgzf_write(fp, buffer, c)
  *         if r < 0:             # <<<<<<<<<<<<<<
@@ -6277,7 +6280,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
     __pyx_t_6 = (__pyx_v_r < 0);
     if (__pyx_t_6) {
 
-      /* "pysam/ctabix.pyx":604
+      /* "pysam/ctabix.pyx":622
  *         r = bgzf_write(fp, buffer, c)
  *         if r < 0:
  *             free( buffer )             # <<<<<<<<<<<<<<
@@ -6286,24 +6289,24 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
  */
       free(__pyx_v_buffer);
 
-      /* "pysam/ctabix.pyx":605
+      /* "pysam/ctabix.pyx":623
  *         if r < 0:
  *             free( buffer )
  *             raise OSError("writing failed")             # <<<<<<<<<<<<<<
  * 
  *     free( buffer )
  */
-      __pyx_t_4 = PyObject_Call(__pyx_builtin_OSError, ((PyObject *)__pyx_k_tuple_37), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = PyObject_Call(__pyx_builtin_OSError, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_4);
       __Pyx_Raise(__pyx_t_4, 0, 0, 0);
       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       goto __pyx_L8;
     }
     __pyx_L8:;
   }
 
-  /* "pysam/ctabix.pyx":607
+  /* "pysam/ctabix.pyx":625
  *             raise OSError("writing failed")
  * 
  *     free( buffer )             # <<<<<<<<<<<<<<
@@ -6312,7 +6315,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
  */
   free(__pyx_v_buffer);
 
-  /* "pysam/ctabix.pyx":608
+  /* "pysam/ctabix.pyx":626
  * 
  *     free( buffer )
  *     r = bgzf_close(fp)             # <<<<<<<<<<<<<<
@@ -6321,7 +6324,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
  */
   __pyx_v_r = bgzf_close(__pyx_v_fp);
 
-  /* "pysam/ctabix.pyx":609
+  /* "pysam/ctabix.pyx":627
  *     free( buffer )
  *     r = bgzf_close(fp)
  *     if r < 0: raise OSError("writing failed")             # <<<<<<<<<<<<<<
@@ -6330,11 +6333,11 @@ static PyObject *__pyx_pf_5pysam_6ctabix_tabix_compress(CYTHON_UNUSED PyObject *
  */
   __pyx_t_6 = (__pyx_v_r < 0);
   if (__pyx_t_6) {
-    __pyx_t_4 = PyObject_Call(__pyx_builtin_OSError, ((PyObject *)__pyx_k_tuple_38), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = PyObject_Call(__pyx_builtin_OSError, ((PyObject *)__pyx_k_tuple_37), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_Raise(__pyx_t_4, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L9;
   }
   __pyx_L9:;
@@ -6373,9 +6376,9 @@ static PyObject *__pyx_pw_5pysam_6ctabix_3tabix_index(PyObject *__pyx_self, PyOb
   {
     static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__filename,&__pyx_n_s__force,&__pyx_n_s__seq_col,&__pyx_n_s__start_col,&__pyx_n_s__end_col,&__pyx_n_s__preset,&__pyx_n_s__meta_char,&__pyx_n_s__zerobased,0};
     PyObject* values[8] = {0,0,0,0,0,0,0,0};
-    values[1] = __pyx_k_39;
+    values[1] = __pyx_k_38;
 
-    /* "pysam/ctabix.pyx":613
+    /* "pysam/ctabix.pyx":631
  * def tabix_index( filename,
  *                  force = False,
  *                  seq_col = None,             # <<<<<<<<<<<<<<
@@ -6384,7 +6387,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_3tabix_index(PyObject *__pyx_self, PyOb
  */
     values[2] = ((PyObject *)Py_None);
 
-    /* "pysam/ctabix.pyx":614
+    /* "pysam/ctabix.pyx":632
  *                  force = False,
  *                  seq_col = None,
  *                  start_col = None,             # <<<<<<<<<<<<<<
@@ -6393,7 +6396,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_3tabix_index(PyObject *__pyx_self, PyOb
  */
     values[3] = ((PyObject *)Py_None);
 
-    /* "pysam/ctabix.pyx":615
+    /* "pysam/ctabix.pyx":633
  *                  seq_col = None,
  *                  start_col = None,
  *                  end_col = None,             # <<<<<<<<<<<<<<
@@ -6402,7 +6405,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_3tabix_index(PyObject *__pyx_self, PyOb
  */
     values[4] = ((PyObject *)Py_None);
 
-    /* "pysam/ctabix.pyx":616
+    /* "pysam/ctabix.pyx":634
  *                  start_col = None,
  *                  end_col = None,
  *                  preset = None,             # <<<<<<<<<<<<<<
@@ -6410,8 +6413,8 @@ static PyObject *__pyx_pw_5pysam_6ctabix_3tabix_index(PyObject *__pyx_self, PyOb
  *                  zerobased = False,
  */
     values[5] = ((PyObject *)Py_None);
-    values[6] = ((PyObject *)__pyx_kp_s_40);
-    values[7] = __pyx_k_41;
+    values[6] = ((PyObject *)__pyx_kp_s_39);
+    values[7] = __pyx_k_40;
     if (unlikely(__pyx_kwds)) {
       Py_ssize_t kw_args;
       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
@@ -6469,7 +6472,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_3tabix_index(PyObject *__pyx_self, PyOb
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tabix_index") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tabix_index") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -6496,7 +6499,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_3tabix_index(PyObject *__pyx_self, PyOb
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("tabix_index", 0, 1, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("tabix_index", 0, 1, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.ctabix.tabix_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -6507,7 +6510,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_3tabix_index(PyObject *__pyx_self, PyOb
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":611
+/* "pysam/ctabix.pyx":629
  *     if r < 0: raise OSError("writing failed")
  * 
  * def tabix_index( filename,             # <<<<<<<<<<<<<<
@@ -6554,72 +6557,72 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   __Pyx_INCREF(__pyx_v_end_col);
   __Pyx_INCREF(__pyx_v_preset);
 
-  /* "pysam/ctabix.pyx":653
+  /* "pysam/ctabix.pyx":671
  *     '''
  * 
  *     if not os.path.exists(filename): raise IOError("No such file '%s'" % filename)             # <<<<<<<<<<<<<<
  * 
  *     if preset == None and (seq_col == None or start_col == None or end_col == None):
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __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 = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __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__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __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 = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_INCREF(__pyx_v_filename);
   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_filename);
   __Pyx_GIVEREF(__pyx_v_filename);
-  __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 = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __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 = 671; __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_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   __pyx_t_5 = (!__pyx_t_4);
   if (__pyx_t_5) {
-    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_42), __pyx_v_filename); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_41), __pyx_v_filename); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
-    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
     __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
     __pyx_t_3 = 0;
-    __pyx_t_3 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
     __Pyx_Raise(__pyx_t_3, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":655
+  /* "pysam/ctabix.pyx":673
  *     if not os.path.exists(filename): raise IOError("No such file '%s'" % filename)
  * 
  *     if preset == None and (seq_col == None or start_col == None or end_col == None):             # <<<<<<<<<<<<<<
  *         raise ValueError("neither preset nor seq_col,start_col and end_col given" )
  * 
  */
-  __pyx_t_3 = PyObject_RichCompare(__pyx_v_preset, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_RichCompare(__pyx_v_preset, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   if (__pyx_t_5) {
-    __pyx_t_3 = PyObject_RichCompare(__pyx_v_seq_col, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_RichCompare(__pyx_v_seq_col, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
     if (!__pyx_t_4) {
-      __pyx_t_3 = PyObject_RichCompare(__pyx_v_start_col, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = PyObject_RichCompare(__pyx_v_start_col, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
       if (!__pyx_t_6) {
-        __pyx_t_3 = PyObject_RichCompare(__pyx_v_end_col, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_3 = PyObject_RichCompare(__pyx_v_end_col, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
         __pyx_t_8 = __pyx_t_7;
       } else {
@@ -6635,51 +6638,51 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   }
   if (__pyx_t_4) {
 
-    /* "pysam/ctabix.pyx":656
+    /* "pysam/ctabix.pyx":674
  * 
  *     if preset == None and (seq_col == None or start_col == None or end_col == None):
  *         raise ValueError("neither preset nor seq_col,start_col and end_col given" )             # <<<<<<<<<<<<<<
  * 
  *     if not filename.endswith(".gz"):
  */
-    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_44), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_43), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_Raise(__pyx_t_3, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/ctabix.pyx":658
+  /* "pysam/ctabix.pyx":676
  *         raise ValueError("neither preset nor seq_col,start_col and end_col given" )
  * 
  *     if not filename.endswith(".gz"):             # <<<<<<<<<<<<<<
  *         tabix_compress( filename, filename + ".gz", force = force )
  *         os.unlink( filename )
  */
-  __pyx_t_3 = PyObject_GetAttr(__pyx_v_filename, __pyx_n_s__endswith); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 658; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyObject_GetAttr(__pyx_v_filename, __pyx_n_s__endswith); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_46), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 658; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_45), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 658; __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 = 676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_5 = (!__pyx_t_4);
   if (__pyx_t_5) {
 
-    /* "pysam/ctabix.pyx":659
+    /* "pysam/ctabix.pyx":677
  * 
  *     if not filename.endswith(".gz"):
  *         tabix_compress( filename, filename + ".gz", force = force )             # <<<<<<<<<<<<<<
  *         os.unlink( filename )
  *         filename += ".gz"
  */
-    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__tabix_compress); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__tabix_compress); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyNumber_Add(__pyx_v_filename, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyNumber_Add(__pyx_v_filename, ((PyObject *)__pyx_kp_s_44)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_INCREF(__pyx_v_filename);
     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_filename);
@@ -6687,47 +6690,47 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
     PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
     __Pyx_GIVEREF(__pyx_t_3);
     __pyx_t_3 = 0;
-    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
-    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__force), __pyx_v_force) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_9 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__force), __pyx_v_force) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __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_9); __pyx_t_9 = 0;
 
-    /* "pysam/ctabix.pyx":660
+    /* "pysam/ctabix.pyx":678
  *     if not filename.endswith(".gz"):
  *         tabix_compress( filename, filename + ".gz", force = force )
  *         os.unlink( filename )             # <<<<<<<<<<<<<<
  *         filename += ".gz"
  * 
  */
-    __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
-    __pyx_t_3 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__unlink); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__unlink); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __Pyx_INCREF(__pyx_v_filename);
     PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_filename);
     __Pyx_GIVEREF(__pyx_v_filename);
-    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-    /* "pysam/ctabix.pyx":661
+    /* "pysam/ctabix.pyx":679
  *         tabix_compress( filename, filename + ".gz", force = force )
  *         os.unlink( filename )
  *         filename += ".gz"             # <<<<<<<<<<<<<<
  * 
  *     if not force and os.path.exists(filename + ".tbi" ):
  */
-    __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_filename, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_filename, ((PyObject *)__pyx_kp_s_44)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_v_filename);
     __pyx_v_filename = __pyx_t_1;
@@ -6736,36 +6739,36 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   }
   __pyx_L5:;
 
-  /* "pysam/ctabix.pyx":663
+  /* "pysam/ctabix.pyx":681
  *         filename += ".gz"
  * 
  *     if not force and os.path.exists(filename + ".tbi" ):             # <<<<<<<<<<<<<<
  *         raise IOError( "Filename '%s.tbi' already exists, use *force* to overwrite" )
  * 
  */
-  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_force); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_force); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_t_4 = (!__pyx_t_5);
   if (__pyx_t_4) {
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_9 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-    __pyx_t_9 = PyNumber_Add(__pyx_v_filename, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyNumber_Add(__pyx_v_filename, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
-    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9);
     __Pyx_GIVEREF(__pyx_t_9);
     __pyx_t_9 = 0;
-    __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
-    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
     __pyx_t_6 = __pyx_t_5;
   } else {
@@ -6773,40 +6776,40 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   }
   if (__pyx_t_6) {
 
-    /* "pysam/ctabix.pyx":664
+    /* "pysam/ctabix.pyx":682
  * 
  *     if not force and os.path.exists(filename + ".tbi" ):
  *         raise IOError( "Filename '%s.tbi' already exists, use *force* to overwrite" )             # <<<<<<<<<<<<<<
  * 
  *     # columns (1-based)
  */
-    __pyx_t_9 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_k_tuple_48), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_k_tuple_47), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
     __Pyx_Raise(__pyx_t_9, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L6;
   }
   __pyx_L6:;
 
-  /* "pysam/ctabix.pyx":669
+  /* "pysam/ctabix.pyx":687
  *     # preset-code, contig, start, end, metachar for commends, lines to ignore at beginning
  *     # 0 is a missing column
  *     preset2conf = {             # <<<<<<<<<<<<<<
  *         'gff' : ( 0, 1, 4, 5, ord('#'), 0 ),
  *         'bed' : ( 0x10000, 1, 2, 3, ord('#'), 0 ),
  */
-  __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_9));
 
-  /* "pysam/ctabix.pyx":670
+  /* "pysam/ctabix.pyx":688
  *     # 0 is a missing column
  *     preset2conf = {
  *         'gff' : ( 0, 1, 4, 5, ord('#'), 0 ),             # <<<<<<<<<<<<<<
  *         'bed' : ( 0x10000, 1, 2, 3, ord('#'), 0 ),
  *         'psltbl' : ( 0x10000, 15, 17, 18, ord('#'), 0 ),
  */
-  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 670; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_INCREF(__pyx_int_0);
   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_0);
@@ -6826,17 +6829,17 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   __Pyx_INCREF(__pyx_int_0);
   PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_int_0);
   __Pyx_GIVEREF(__pyx_int_0);
-  if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__gff), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__gff), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 
-  /* "pysam/ctabix.pyx":671
+  /* "pysam/ctabix.pyx":689
  *     preset2conf = {
  *         'gff' : ( 0, 1, 4, 5, ord('#'), 0 ),
  *         'bed' : ( 0x10000, 1, 2, 3, ord('#'), 0 ),             # <<<<<<<<<<<<<<
  *         'psltbl' : ( 0x10000, 15, 17, 18, ord('#'), 0 ),
- *         'sam' : ( 1, 3, 4, 0, ord('#'), 0 ),
+ *         'sam' : ( 1, 3, 4, 0, ord('@'), 0 ),
  */
-  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_INCREF(__pyx_int_65536);
   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_65536);
@@ -6856,17 +6859,17 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   __Pyx_INCREF(__pyx_int_0);
   PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_int_0);
   __Pyx_GIVEREF(__pyx_int_0);
-  if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__bed), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__bed), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 
-  /* "pysam/ctabix.pyx":672
+  /* "pysam/ctabix.pyx":690
  *         'gff' : ( 0, 1, 4, 5, ord('#'), 0 ),
  *         'bed' : ( 0x10000, 1, 2, 3, ord('#'), 0 ),
  *         'psltbl' : ( 0x10000, 15, 17, 18, ord('#'), 0 ),             # <<<<<<<<<<<<<<
- *         'sam' : ( 1, 3, 4, 0, ord('#'), 0 ),
+ *         'sam' : ( 1, 3, 4, 0, ord('@'), 0 ),
  *         'vcf' : ( 2, 1, 2, 0, ord('#'), 0 ),
  */
-  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 672; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_INCREF(__pyx_int_65536);
   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_65536);
@@ -6886,17 +6889,17 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   __Pyx_INCREF(__pyx_int_0);
   PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_int_0);
   __Pyx_GIVEREF(__pyx_int_0);
-  if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__psltbl), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__psltbl), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 
-  /* "pysam/ctabix.pyx":673
+  /* "pysam/ctabix.pyx":691
  *         'bed' : ( 0x10000, 1, 2, 3, ord('#'), 0 ),
  *         'psltbl' : ( 0x10000, 15, 17, 18, ord('#'), 0 ),
- *         'sam' : ( 1, 3, 4, 0, ord('#'), 0 ),             # <<<<<<<<<<<<<<
+ *         'sam' : ( 1, 3, 4, 0, ord('@'), 0 ),             # <<<<<<<<<<<<<<
  *         'vcf' : ( 2, 1, 2, 0, ord('#'), 0 ),
  *         'pileup': (3, 1, 2, 0, ord('#'), 0 ),
  */
-  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_INCREF(__pyx_int_1);
   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_1);
@@ -6910,23 +6913,23 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   __Pyx_INCREF(__pyx_int_0);
   PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_int_0);
   __Pyx_GIVEREF(__pyx_int_0);
-  __Pyx_INCREF(__pyx_int_35);
-  PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_int_35);
-  __Pyx_GIVEREF(__pyx_int_35);
+  __Pyx_INCREF(__pyx_int_64);
+  PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_int_64);
+  __Pyx_GIVEREF(__pyx_int_64);
   __Pyx_INCREF(__pyx_int_0);
   PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_int_0);
   __Pyx_GIVEREF(__pyx_int_0);
-  if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__sam), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__sam), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 
-  /* "pysam/ctabix.pyx":674
+  /* "pysam/ctabix.pyx":692
  *         'psltbl' : ( 0x10000, 15, 17, 18, ord('#'), 0 ),
- *         'sam' : ( 1, 3, 4, 0, ord('#'), 0 ),
+ *         'sam' : ( 1, 3, 4, 0, ord('@'), 0 ),
  *         'vcf' : ( 2, 1, 2, 0, ord('#'), 0 ),             # <<<<<<<<<<<<<<
  *         'pileup': (3, 1, 2, 0, ord('#'), 0 ),
  *         }
  */
-  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_INCREF(__pyx_int_2);
   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_2);
@@ -6946,17 +6949,17 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   __Pyx_INCREF(__pyx_int_0);
   PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_int_0);
   __Pyx_GIVEREF(__pyx_int_0);
-  if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__vcf), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__vcf), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 
-  /* "pysam/ctabix.pyx":675
- *         'sam' : ( 1, 3, 4, 0, ord('#'), 0 ),
+  /* "pysam/ctabix.pyx":693
+ *         'sam' : ( 1, 3, 4, 0, ord('@'), 0 ),
  *         'vcf' : ( 2, 1, 2, 0, ord('#'), 0 ),
  *         'pileup': (3, 1, 2, 0, ord('#'), 0 ),             # <<<<<<<<<<<<<<
  *         }
  * 
  */
-  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_INCREF(__pyx_int_3);
   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_3);
@@ -6976,22 +6979,22 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   __Pyx_INCREF(__pyx_int_0);
   PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_int_0);
   __Pyx_GIVEREF(__pyx_int_0);
-  if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__pileup), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__pileup), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
   __pyx_v_preset2conf = ((PyObject*)__pyx_t_9);
   __pyx_t_9 = 0;
 
-  /* "pysam/ctabix.pyx":678
+  /* "pysam/ctabix.pyx":696
  *         }
  * 
  *     if preset:             # <<<<<<<<<<<<<<
  *         try:
  *             conf_data = preset2conf[preset]
  */
-  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_preset); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_preset); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_6) {
 
-    /* "pysam/ctabix.pyx":679
+    /* "pysam/ctabix.pyx":697
  * 
  *     if preset:
  *         try:             # <<<<<<<<<<<<<<
@@ -7005,14 +7008,14 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
       __Pyx_XGOTREF(__pyx_t_12);
       /*try:*/ {
 
-        /* "pysam/ctabix.pyx":680
+        /* "pysam/ctabix.pyx":698
  *     if preset:
  *         try:
  *             conf_data = preset2conf[preset]             # <<<<<<<<<<<<<<
  *         except KeyError:
  *             raise KeyError( "unknown preset '%s', valid presets are '%s'" % (preset, ",".join(preset2conf.keys() )))
  */
-        __pyx_t_9 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_preset2conf), __pyx_v_preset); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L8_error;}
+        __pyx_t_9 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_preset2conf), __pyx_v_preset); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L8_error;}
         __Pyx_GOTREF(__pyx_t_9);
         __pyx_v_conf_data = __pyx_t_9;
         __pyx_t_9 = 0;
@@ -7027,7 +7030,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
       __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
       __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
 
-      /* "pysam/ctabix.pyx":681
+      /* "pysam/ctabix.pyx":699
  *         try:
  *             conf_data = preset2conf[preset]
  *         except KeyError:             # <<<<<<<<<<<<<<
@@ -7037,32 +7040,32 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
       __pyx_t_13 = PyErr_ExceptionMatches(__pyx_builtin_KeyError);
       if (__pyx_t_13) {
         __Pyx_AddTraceback("pysam.ctabix.tabix_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
-        if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_3, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
+        if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_3, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
         __Pyx_GOTREF(__pyx_t_9);
         __Pyx_GOTREF(__pyx_t_3);
         __Pyx_GOTREF(__pyx_t_1);
 
-        /* "pysam/ctabix.pyx":682
+        /* "pysam/ctabix.pyx":700
  *             conf_data = preset2conf[preset]
  *         except KeyError:
  *             raise KeyError( "unknown preset '%s', valid presets are '%s'" % (preset, ",".join(preset2conf.keys() )))             # <<<<<<<<<<<<<<
  *     else:
  *         if end_col == None: end_col = -1
  */
-        __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_50), __pyx_n_s__join); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
+        __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_49), __pyx_n_s__join); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
         __Pyx_GOTREF(__pyx_t_2);
-        __pyx_t_14 = PyDict_Keys(__pyx_v_preset2conf); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
+        __pyx_t_14 = PyDict_Keys(__pyx_v_preset2conf); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
         __Pyx_GOTREF(__pyx_t_14);
-        __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
+        __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
         __Pyx_GOTREF(__pyx_t_15);
         PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14);
         __Pyx_GIVEREF(__pyx_t_14);
         __pyx_t_14 = 0;
-        __pyx_t_14 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
+        __pyx_t_14 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
         __Pyx_GOTREF(__pyx_t_14);
         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
         __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0;
-        __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
+        __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
         __Pyx_GOTREF(__pyx_t_15);
         __Pyx_INCREF(__pyx_v_preset);
         PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_preset);
@@ -7070,20 +7073,20 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
         PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_14);
         __Pyx_GIVEREF(__pyx_t_14);
         __pyx_t_14 = 0;
-        __pyx_t_14 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
+        __pyx_t_14 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_48), ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
         __Pyx_GOTREF(((PyObject *)__pyx_t_14));
         __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0;
-        __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
+        __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
         __Pyx_GOTREF(__pyx_t_15);
         PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_t_14));
         __Pyx_GIVEREF(((PyObject *)__pyx_t_14));
         __pyx_t_14 = 0;
-        __pyx_t_14 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
+        __pyx_t_14 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
         __Pyx_GOTREF(__pyx_t_14);
         __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0;
         __Pyx_Raise(__pyx_t_14, 0, 0, 0);
         __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -7106,15 +7109,15 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   }
   /*else*/ {
 
-    /* "pysam/ctabix.pyx":684
+    /* "pysam/ctabix.pyx":702
  *             raise KeyError( "unknown preset '%s', valid presets are '%s'" % (preset, ",".join(preset2conf.keys() )))
  *     else:
  *         if end_col == None: end_col = -1             # <<<<<<<<<<<<<<
  *         preset = 0
  * 
  */
-    __pyx_t_1 = PyObject_RichCompare(__pyx_v_end_col, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_RichCompare(__pyx_v_end_col, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     if (__pyx_t_6) {
       __Pyx_INCREF(__pyx_int_neg_1);
@@ -7124,7 +7127,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
     }
     __pyx_L18:;
 
-    /* "pysam/ctabix.pyx":685
+    /* "pysam/ctabix.pyx":703
  *     else:
  *         if end_col == None: end_col = -1
  *         preset = 0             # <<<<<<<<<<<<<<
@@ -7135,16 +7138,16 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
     __Pyx_DECREF(__pyx_v_preset);
     __pyx_v_preset = __pyx_int_0;
 
-    /* "pysam/ctabix.pyx":692
+    /* "pysam/ctabix.pyx":710
  *         # -1 is subtracted from the start coordinate. To avoid doing this, set
  *         # the TI_FLAG_UCSC=0x10000 flag:
  *         if zerobased: preset = preset | 0x10000             # <<<<<<<<<<<<<<
  * 
  *         conf_data = (preset, seq_col+1, start_col+1, end_col+1, ord(meta_char), 0)
  */
-    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_zerobased); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_zerobased); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (__pyx_t_6) {
-      __pyx_t_1 = PyNumber_Or(__pyx_v_preset, __pyx_int_65536); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PyNumber_Or(__pyx_v_preset, __pyx_int_65536); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_DECREF(__pyx_v_preset);
       __pyx_v_preset = __pyx_t_1;
@@ -7153,28 +7156,28 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
     }
     __pyx_L19:;
 
-    /* "pysam/ctabix.pyx":694
+    /* "pysam/ctabix.pyx":712
  *         if zerobased: preset = preset | 0x10000
  * 
  *         conf_data = (preset, seq_col+1, start_col+1, end_col+1, ord(meta_char), 0)             # <<<<<<<<<<<<<<
  * 
  *     cdef ti_conf_t conf
  */
-    __pyx_t_1 = PyNumber_Add(__pyx_v_seq_col, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyNumber_Add(__pyx_v_seq_col, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_3 = PyNumber_Add(__pyx_v_start_col, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = PyNumber_Add(__pyx_v_start_col, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_9 = PyNumber_Add(__pyx_v_end_col, __pyx_int_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyNumber_Add(__pyx_v_end_col, __pyx_int_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
-    __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_14);
     __Pyx_INCREF(__pyx_v_meta_char);
     PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_meta_char);
     __Pyx_GIVEREF(__pyx_v_meta_char);
-    __pyx_t_15 = PyObject_Call(__pyx_builtin_ord, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_15 = PyObject_Call(__pyx_builtin_ord, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_15);
     __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0;
-    __pyx_t_14 = PyTuple_New(6); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_14 = PyTuple_New(6); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_14);
     __Pyx_INCREF(__pyx_v_preset);
     PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_preset);
@@ -7199,7 +7202,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   }
   __pyx_L7:;
 
-  /* "pysam/ctabix.pyx":697
+  /* "pysam/ctabix.pyx":715
  * 
  *     cdef ti_conf_t conf
  *     conf.preset, conf.sc, conf.bc, conf.ec, conf.meta_char, conf.line_skip = conf_data             # <<<<<<<<<<<<<<
@@ -7216,7 +7219,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
     if (unlikely(size != 6)) {
       if (size > 6) __Pyx_RaiseTooManyValuesError(6);
       else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     #if CYTHON_COMPILING_IN_CPYTHON
     if (likely(PyTuple_CheckExact(sequence))) {
@@ -7244,7 +7247,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
     Py_ssize_t i;
     PyObject** temps[6] = {&__pyx_t_14,&__pyx_t_15,&__pyx_t_9,&__pyx_t_3,&__pyx_t_1,&__pyx_t_2};
     for (i=0; i < 6; i++) {
-      PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(item);
       *(temps[i]) = item;
     }
@@ -7253,7 +7256,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   {
     Py_ssize_t index = -1;
     PyObject** temps[6] = {&__pyx_t_14,&__pyx_t_15,&__pyx_t_9,&__pyx_t_3,&__pyx_t_1,&__pyx_t_2};
-    __pyx_t_16 = PyObject_GetIter(__pyx_v_conf_data); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_16 = PyObject_GetIter(__pyx_v_conf_data); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_16);
     __pyx_t_17 = Py_TYPE(__pyx_t_16)->tp_iternext;
     for (index=0; index < 6; index++) {
@@ -7261,7 +7264,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
       __Pyx_GOTREF(item);
       *(temps[index]) = item;
     }
-    if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_16), 6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_16), 6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_17 = NULL;
     __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
     goto __pyx_L21_unpacking_done;
@@ -7269,20 +7272,20 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
     __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
     __pyx_t_17 = NULL;
     if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_L21_unpacking_done:;
   }
-  __pyx_t_18 = __Pyx_PyInt_from_py_int32_t(__pyx_t_14); if (unlikely((__pyx_t_18 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_18 = __Pyx_PyInt_from_py_int32_t(__pyx_t_14); if (unlikely((__pyx_t_18 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
-  __pyx_t_19 = __Pyx_PyInt_from_py_int32_t(__pyx_t_15); if (unlikely((__pyx_t_19 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_19 = __Pyx_PyInt_from_py_int32_t(__pyx_t_15); if (unlikely((__pyx_t_19 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-  __pyx_t_20 = __Pyx_PyInt_from_py_int32_t(__pyx_t_9); if (unlikely((__pyx_t_20 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_20 = __Pyx_PyInt_from_py_int32_t(__pyx_t_9); if (unlikely((__pyx_t_20 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-  __pyx_t_21 = __Pyx_PyInt_from_py_int32_t(__pyx_t_3); if (unlikely((__pyx_t_21 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_21 = __Pyx_PyInt_from_py_int32_t(__pyx_t_3); if (unlikely((__pyx_t_21 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-  __pyx_t_22 = __Pyx_PyInt_from_py_int32_t(__pyx_t_1); if (unlikely((__pyx_t_22 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_22 = __Pyx_PyInt_from_py_int32_t(__pyx_t_1); if (unlikely((__pyx_t_22 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_23 = __Pyx_PyInt_from_py_int32_t(__pyx_t_2); if (unlikely((__pyx_t_23 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_23 = __Pyx_PyInt_from_py_int32_t(__pyx_t_2); if (unlikely((__pyx_t_23 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_v_conf.preset = __pyx_t_18;
   __pyx_v_conf.sc = __pyx_t_19;
@@ -7291,34 +7294,34 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   __pyx_v_conf.meta_char = __pyx_t_22;
   __pyx_v_conf.line_skip = __pyx_t_23;
 
-  /* "pysam/ctabix.pyx":699
+  /* "pysam/ctabix.pyx":717
  *     conf.preset, conf.sc, conf.bc, conf.ec, conf.meta_char, conf.line_skip = conf_data
  * 
  *     fn = _my_encodeFilename( filename )             # <<<<<<<<<<<<<<
  *     ti_index_build( fn, &conf)
  * 
  */
-  __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_6ctabix__my_encodeFilename(__pyx_v_filename)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_6ctabix__my_encodeFilename(__pyx_v_filename)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_v_fn = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "pysam/ctabix.pyx":700
+  /* "pysam/ctabix.pyx":718
  * 
  *     fn = _my_encodeFilename( filename )
  *     ti_index_build( fn, &conf)             # <<<<<<<<<<<<<<
  * 
  *     return filename
  */
-  __pyx_t_24 = PyBytes_AsString(((PyObject *)__pyx_v_fn)); if (unlikely((!__pyx_t_24) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_24 = PyBytes_AsString(((PyObject *)__pyx_v_fn)); if (unlikely((!__pyx_t_24) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   ti_index_build(__pyx_t_24, (&__pyx_v_conf));
 
-  /* "pysam/ctabix.pyx":702
+  /* "pysam/ctabix.pyx":720
  *     ti_index_build( fn, &conf)
  * 
  *     return filename             # <<<<<<<<<<<<<<
  * 
- * #########################################################
+ * # #########################################################
  */
   __Pyx_XDECREF(__pyx_r);
   __Pyx_INCREF(__pyx_v_filename);
@@ -7349,21 +7352,117 @@ static PyObject *__pyx_pf_5pysam_6ctabix_2tabix_index(CYTHON_UNUSED PyObject *__
   return __pyx_r;
 }
 
+/* "pysam/ctabix.pyx":796
+ * ## Iterators for parsing through unindexed files.
+ * #########################################################
+ * cdef buildGzipError(void *gzfp):             # <<<<<<<<<<<<<<
+ *     cdef int errnum = 0
+ *     cdef const char *s = gzerror(gzfp, &errnum)
+ */
+
+static PyObject *__pyx_f_5pysam_6ctabix_buildGzipError(void *__pyx_v_gzfp) {
+  int __pyx_v_errnum;
+  char const *__pyx_v_s;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("buildGzipError", 0);
+
+  /* "pysam/ctabix.pyx":797
+ * #########################################################
+ * cdef buildGzipError(void *gzfp):
+ *     cdef int errnum = 0             # <<<<<<<<<<<<<<
+ *     cdef const char *s = gzerror(gzfp, &errnum)
+ *     return "error (%d): %s (%d: %s)" % (errno, strerror(errno), errnum, s)
+ */
+  __pyx_v_errnum = 0;
+
+  /* "pysam/ctabix.pyx":798
+ * cdef buildGzipError(void *gzfp):
+ *     cdef int errnum = 0
+ *     cdef const char *s = gzerror(gzfp, &errnum)             # <<<<<<<<<<<<<<
+ *     return "error (%d): %s (%d: %s)" % (errno, strerror(errno), errnum, s)
+ * 
+ */
+  __pyx_v_s = gzerror(__pyx_v_gzfp, (&__pyx_v_errnum));
+
+  /* "pysam/ctabix.pyx":799
+ *     cdef int errnum = 0
+ *     cdef const char *s = gzerror(gzfp, &errnum)
+ *     return "error (%d): %s (%d: %s)" % (errno, strerror(errno), errnum, s)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyInt_FromLong(errno); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+  __pyx_t_3 = PyInt_FromLong(__pyx_v_errnum); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+  __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_5);
+  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_t_2));
+  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
+  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_5, 3, ((PyObject *)__pyx_t_4));
+  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
+  __pyx_t_1 = 0;
+  __pyx_t_2 = 0;
+  __pyx_t_3 = 0;
+  __pyx_t_4 = 0;
+  __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_50), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
+  __pyx_r = ((PyObject *)__pyx_t_4);
+  __pyx_t_4 = 0;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("pysam.ctabix.buildGzipError", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
 /* Python wrapper */
-static int __pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static int __pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static int __pyx_pw_5pysam_6ctabix_19tabix_file_iterator_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_5pysam_6ctabix_19tabix_file_iterator_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
   PyObject *__pyx_v_infile = 0;
+  struct __pyx_obj_5pysam_6ctabix_Parser *__pyx_v_parser = 0;
   int __pyx_v_buffer_size;
   int __pyx_r;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
   {
-    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__infile,&__pyx_n_s__buffer_size,0};
-    PyObject* values[2] = {0,0};
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__infile,&__pyx_n_s__parser,&__pyx_n_s__buffer_size,0};
+    PyObject* values[3] = {0,0,0};
     if (unlikely(__pyx_kwds)) {
       Py_ssize_t kw_args;
       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
       switch (pos_args) {
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
         case  0: break;
@@ -7375,140 +7474,228 @@ static int __pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_1__cinit__(PyObject
         if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__infile)) != 0)) kw_args--;
         else goto __pyx_L5_argtuple_error;
         case  1:
+        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__parser)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        }
+        case  2:
         if (kw_args > 0) {
           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__buffer_size);
-          if (value) { values[1] = value; kw_args--; }
+          if (value) { values[2] = value; kw_args--; }
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
-        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
         break;
         default: goto __pyx_L5_argtuple_error;
       }
     }
     __pyx_v_infile = values[0];
-    if (values[1]) {
-      __pyx_v_buffer_size = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_buffer_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)values[1]);
+    if (values[2]) {
+      __pyx_v_buffer_size = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_buffer_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
       __pyx_v_buffer_size = ((int)65536);
     }
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
-  __Pyx_AddTraceback("pysam.ctabix.tabix_inplace_iterator.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_AddTraceback("pysam.ctabix.tabix_file_iterator.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  __pyx_r = __pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator___cinit__(((struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *)__pyx_v_self), __pyx_v_infile, __pyx_v_buffer_size);
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_parser), __pyx_ptype_5pysam_6ctabix_Parser, 1, "parser", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_r = __pyx_pf_5pysam_6ctabix_19tabix_file_iterator___cinit__(((struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *)__pyx_v_self), __pyx_v_infile, __pyx_v_parser, __pyx_v_buffer_size);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
 
-/* "pysam/ctabix.pyx":719
- * 
- * 
- *     def __cinit__(self, infile, int buffer_size = 65536 ):             # <<<<<<<<<<<<<<
+/* "pysam/ctabix.pyx":806
+ *     '''
  * 
- *         cdef int fd = PyObject_AsFileDescriptor( infile )
+ *     def __cinit__(self,             # <<<<<<<<<<<<<<
+ *                   infile,
+ *                   Parser parser,
  */
 
-static int __pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator___cinit__(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *__pyx_v_self, PyObject *__pyx_v_infile, int __pyx_v_buffer_size) {
+static int __pyx_pf_5pysam_6ctabix_19tabix_file_iterator___cinit__(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *__pyx_v_self, PyObject *__pyx_v_infile, struct __pyx_obj_5pysam_6ctabix_Parser *__pyx_v_parser, int __pyx_v_buffer_size) {
   int __pyx_v_fd;
   int __pyx_r;
   __Pyx_RefNannyDeclarations
-  int __pyx_t_1;
+  PyObject *__pyx_t_1 = NULL;
   int __pyx_t_2;
-  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__cinit__", 0);
 
-  /* "pysam/ctabix.pyx":721
- *     def __cinit__(self, infile, int buffer_size = 65536 ):
+  /* "pysam/ctabix.pyx":811
+ *                   int buffer_size = 65536 ):
+ * 
+ *         if infile.closed:             # <<<<<<<<<<<<<<
+ *             raise ValueError( "I/O operation on closed file." )
  * 
- *         cdef int fd = PyObject_AsFileDescriptor( infile )             # <<<<<<<<<<<<<<
- *         if fd == -1: raise ValueError( "I/O operation on closed file." )
- *         self.infile = fdopen( fd, 'r')
  */
-  __pyx_t_1 = PyObject_AsFileDescriptor(__pyx_v_infile); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_v_fd = __pyx_t_1;
+  __pyx_t_1 = PyObject_GetAttr(__pyx_v_infile, __pyx_n_s__closed); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (__pyx_t_2) {
 
-  /* "pysam/ctabix.pyx":722
+    /* "pysam/ctabix.pyx":812
  * 
- *         cdef int fd = PyObject_AsFileDescriptor( infile )
- *         if fd == -1: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
- *         self.infile = fdopen( fd, 'r')
+ *         if infile.closed:
+ *             raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
  * 
+ *         self.infile = infile
  */
-  __pyx_t_2 = (__pyx_v_fd == -1);
-  if (__pyx_t_2) {
-    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_52), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 722; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_3);
-    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
-    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 722; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_52), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":723
+  /* "pysam/ctabix.pyx":814
+ *             raise ValueError( "I/O operation on closed file." )
+ * 
+ *         self.infile = infile             # <<<<<<<<<<<<<<
+ * 
  *         cdef int fd = PyObject_AsFileDescriptor( infile )
+ */
+  __Pyx_INCREF(__pyx_v_infile);
+  __Pyx_GIVEREF(__pyx_v_infile);
+  __Pyx_GOTREF(__pyx_v_self->infile);
+  __Pyx_DECREF(__pyx_v_self->infile);
+  __pyx_v_self->infile = __pyx_v_infile;
+
+  /* "pysam/ctabix.pyx":816
+ *         self.infile = infile
+ * 
+ *         cdef int fd = PyObject_AsFileDescriptor( infile )             # <<<<<<<<<<<<<<
  *         if fd == -1: raise ValueError( "I/O operation on closed file." )
- *         self.infile = fdopen( fd, 'r')             # <<<<<<<<<<<<<<
  * 
- *         if self.infile == NULL: raise ValueError( "I/O operation on closed file." )
  */
-  __pyx_v_self->infile = fdopen(__pyx_v_fd, __pyx_k__r);
+  __pyx_t_3 = PyObject_AsFileDescriptor(__pyx_v_infile); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_v_fd = __pyx_t_3;
 
-  /* "pysam/ctabix.pyx":725
- *         self.infile = fdopen( fd, 'r')
+  /* "pysam/ctabix.pyx":817
  * 
- *         if self.infile == NULL: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
+ *         cdef int fd = PyObject_AsFileDescriptor( infile )
+ *         if fd == -1: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
  * 
- *         self.buffer = <char*>malloc( buffer_size )
+ *         # From the manual:
  */
-  __pyx_t_2 = (__pyx_v_self->infile == NULL);
+  __pyx_t_2 = (__pyx_v_fd == -1);
   if (__pyx_t_2) {
-    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_53), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_3);
-    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
-    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_53), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L4;
   }
   __pyx_L4:;
 
-  /* "pysam/ctabix.pyx":727
- *         if self.infile == NULL: raise ValueError( "I/O operation on closed file." )
+  /* "pysam/ctabix.pyx":824
+ *         # When reading, this will be detected automatically by looking
+ *         # for the magic two-byte gzip header.
+ *         self.fh = gzdopen( fd, 'r')             # <<<<<<<<<<<<<<
+ * 
+ *         if self.fh == NULL:
+ */
+  __pyx_v_self->fh = gzdopen(__pyx_v_fd, __pyx_k__r);
+
+  /* "pysam/ctabix.pyx":826
+ *         self.fh = gzdopen( fd, 'r')
+ * 
+ *         if self.fh == NULL:             # <<<<<<<<<<<<<<
+ *             raise IOError('%s' % strerror(errno))
+ * 
+ */
+  __pyx_t_2 = (__pyx_v_self->fh == NULL);
+  if (__pyx_t_2) {
+
+    /* "pysam/ctabix.pyx":827
+ * 
+ *         if self.fh == NULL:
+ *             raise IOError('%s' % strerror(errno))             # <<<<<<<<<<<<<<
+ * 
+ *         self.ks = ks_init( self.fh)
+ */
+    __pyx_t_1 = PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_54), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+    __Pyx_DECREF(((PyObject *)__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 = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_1);
+    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4));
+    __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
+    __pyx_t_4 = 0;
+    __pyx_t_4 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    goto __pyx_L5;
+  }
+  __pyx_L5:;
+
+  /* "pysam/ctabix.pyx":829
+ *             raise IOError('%s' % strerror(errno))
  * 
- *         self.buffer = <char*>malloc( buffer_size )             # <<<<<<<<<<<<<<
- *         self.size = buffer_size
+ *         self.ks = ks_init( self.fh)             # <<<<<<<<<<<<<<
  * 
+ *         self.buffer.s = <char*>malloc( buffer_size )
  */
-  __pyx_v_self->buffer = ((char *)malloc(__pyx_v_buffer_size));
+  __pyx_v_self->ks = ks_init(__pyx_v_self->fh);
 
-  /* "pysam/ctabix.pyx":728
+  /* "pysam/ctabix.pyx":831
+ *         self.ks = ks_init( self.fh)
  * 
- *         self.buffer = <char*>malloc( buffer_size )
- *         self.size = buffer_size             # <<<<<<<<<<<<<<
+ *         self.buffer.s = <char*>malloc( buffer_size )             # <<<<<<<<<<<<<<
+ *         #if self.buffer == NULL:
+ *         #    raise MemoryError( "tabix_file_iterator: could not allocate %i bytes" % buffer_size)
+ */
+  __pyx_v_self->buffer.s = ((char *)malloc(__pyx_v_buffer_size));
+
+  /* "pysam/ctabix.pyx":835
+ *         #    raise MemoryError( "tabix_file_iterator: could not allocate %i bytes" % buffer_size)
+ *         #self.size = buffer_size
+ *         self.parser = parser             # <<<<<<<<<<<<<<
  * 
  *     def __iter__(self):
  */
-  __pyx_v_self->size = __pyx_v_buffer_size;
+  __Pyx_INCREF(((PyObject *)__pyx_v_parser));
+  __Pyx_GIVEREF(((PyObject *)__pyx_v_parser));
+  __Pyx_GOTREF(__pyx_v_self->parser);
+  __Pyx_DECREF(((PyObject *)__pyx_v_self->parser));
+  __pyx_v_self->parser = __pyx_v_parser;
 
   __pyx_r = 0;
   goto __pyx_L0;
   __pyx_L1_error:;
-  __Pyx_XDECREF(__pyx_t_3);
-  __Pyx_AddTraceback("pysam.ctabix.tabix_inplace_iterator.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("pysam.ctabix.tabix_file_iterator.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __pyx_r = -1;
   __pyx_L0:;
   __Pyx_RefNannyFinishContext();
@@ -7516,30 +7703,30 @@ static int __pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator___cinit__(struct __p
 }
 
 /* Python wrapper */
-static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_3__iter__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_3__iter__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_pw_5pysam_6ctabix_19tabix_file_iterator_3__iter__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_5pysam_6ctabix_19tabix_file_iterator_3__iter__(PyObject *__pyx_v_self) {
   PyObject *__pyx_r = 0;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
-  __pyx_r = __pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_2__iter__(((struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *)__pyx_v_self));
+  __pyx_r = __pyx_pf_5pysam_6ctabix_19tabix_file_iterator_2__iter__(((struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *)__pyx_v_self));
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":730
- *         self.size = buffer_size
+/* "pysam/ctabix.pyx":837
+ *         self.parser = parser
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
  *         return self
  * 
  */
 
-static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_2__iter__(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *__pyx_v_self) {
+static PyObject *__pyx_pf_5pysam_6ctabix_19tabix_file_iterator_2__iter__(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *__pyx_v_self) {
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__iter__", 0);
 
-  /* "pysam/ctabix.pyx":731
+  /* "pysam/ctabix.pyx":838
  * 
  *     def __iter__(self):
  *         return self             # <<<<<<<<<<<<<<
@@ -7558,7 +7745,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_2__iter__(stru
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":733
+/* "pysam/ctabix.pyx":840
  *         return self
  * 
  *     cdef __cnext__(self):             # <<<<<<<<<<<<<<
@@ -7566,299 +7753,224 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_2__iter__(stru
  *         cdef char * b
  */
 
-static PyObject *__pyx_f_5pysam_6ctabix_22tabix_inplace_iterator___cnext__(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *__pyx_v_self) {
+static PyObject *__pyx_f_5pysam_6ctabix_19tabix_file_iterator___cnext__(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *__pyx_v_self) {
   char *__pyx_v_b;
-  size_t __pyx_v_nbytes;
-  PyObject *__pyx_v_r = NULL;
-  char *__pyx_v_result;
+  int __pyx_v_dret;
+  int __pyx_v_retval;
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
-  char *__pyx_t_1;
-  PyObject *__pyx_t_2 = NULL;
-  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_1;
+  char *__pyx_t_2;
+  int __pyx_t_3;
   int __pyx_t_4;
   int __pyx_t_5;
-  int __pyx_t_6;
-  int __pyx_t_7;
-  PyObject *__pyx_t_8 = NULL;
-  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_6 = NULL;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__cnext__", 0);
 
-  /* "pysam/ctabix.pyx":737
- *         cdef char * b
- *         cdef size_t nbytes
- *         b = self.buffer             # <<<<<<<<<<<<<<
- *         r = self.Parser()
+  /* "pysam/ctabix.pyx":843
  * 
+ *         cdef char * b
+ *         cdef int dret = 0             # <<<<<<<<<<<<<<
+ *         cdef int retval = 0
+ *         while 1:
  */
-  __pyx_t_1 = __pyx_v_self->buffer;
-  __pyx_v_b = __pyx_t_1;
+  __pyx_v_dret = 0;
 
-  /* "pysam/ctabix.pyx":738
- *         cdef size_t nbytes
- *         b = self.buffer
- *         r = self.Parser()             # <<<<<<<<<<<<<<
+  /* "pysam/ctabix.pyx":844
+ *         cdef char * b
+ *         cdef int dret = 0
+ *         cdef int retval = 0             # <<<<<<<<<<<<<<
+ *         while 1:
  * 
- *         while not feof( self.infile ):
  */
-  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__Parser); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_3);
-  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_v_r = __pyx_t_3;
-  __pyx_t_3 = 0;
+  __pyx_v_retval = 0;
 
-  /* "pysam/ctabix.pyx":740
- *         r = self.Parser()
- * 
- *         while not feof( self.infile ):             # <<<<<<<<<<<<<<
- *             nbytes = getline( &b, &self.size, self.infile)
+  /* "pysam/ctabix.pyx":845
+ *         cdef int dret = 0
+ *         cdef int retval = 0
+ *         while 1:             # <<<<<<<<<<<<<<
  * 
+ *             retval = ks_getuntil(self.ks, '\n', &self.buffer, &dret)
  */
   while (1) {
-    __pyx_t_4 = (!feof(__pyx_v_self->infile));
-    if (!__pyx_t_4) break;
+    if (!1) break;
 
-    /* "pysam/ctabix.pyx":741
+    /* "pysam/ctabix.pyx":847
+ *         while 1:
  * 
- *         while not feof( self.infile ):
- *             nbytes = getline( &b, &self.size, self.infile)             # <<<<<<<<<<<<<<
+ *             retval = ks_getuntil(self.ks, '\n', &self.buffer, &dret)             # <<<<<<<<<<<<<<
  * 
- *             # stop at first error or eof
+ *             if retval < 0:
  */
-    __pyx_v_nbytes = getline((&__pyx_v_b), (&__pyx_v_self->size), __pyx_v_self->infile);
+    __pyx_v_retval = ks_getuntil(__pyx_v_self->ks, '\n', (&__pyx_v_self->buffer), (&__pyx_v_dret));
 
-    /* "pysam/ctabix.pyx":744
+    /* "pysam/ctabix.pyx":849
+ *             retval = ks_getuntil(self.ks, '\n', &self.buffer, &dret)
+ * 
+ *             if retval < 0:             # <<<<<<<<<<<<<<
+ *                 break
+ *                 #raise IOError('gzip error: %s' % buildGzipError( self.fh ))
+ */
+    __pyx_t_1 = (__pyx_v_retval < 0);
+    if (__pyx_t_1) {
+
+      /* "pysam/ctabix.pyx":850
+ * 
+ *             if retval < 0:
+ *                 break             # <<<<<<<<<<<<<<
+ *                 #raise IOError('gzip error: %s' % buildGzipError( self.fh ))
  * 
- *             # stop at first error or eof
- *             if (nbytes == -1): break             # <<<<<<<<<<<<<<
- *             # skip comments
- *             if (b[0] == '#'): continue
  */
-    __pyx_t_4 = (__pyx_v_nbytes == -1);
-    if (__pyx_t_4) {
       goto __pyx_L4_break;
       goto __pyx_L5;
     }
     __pyx_L5:;
 
-    /* "pysam/ctabix.pyx":746
- *             if (nbytes == -1): break
+    /* "pysam/ctabix.pyx":853
+ *                 #raise IOError('gzip error: %s' % buildGzipError( self.fh ))
+ * 
+ *             b = self.buffer.s             # <<<<<<<<<<<<<<
+ * 
+ *             # skip comments
+ */
+    __pyx_t_2 = __pyx_v_self->buffer.s;
+    __pyx_v_b = __pyx_t_2;
+
+    /* "pysam/ctabix.pyx":856
+ * 
  *             # skip comments
  *             if (b[0] == '#'): continue             # <<<<<<<<<<<<<<
  * 
  *             # skip empty lines
  */
-    __pyx_t_4 = ((__pyx_v_b[0]) == '#');
-    if (__pyx_t_4) {
+    __pyx_t_1 = ((__pyx_v_b[0]) == '#');
+    if (__pyx_t_1) {
       goto __pyx_L3_continue;
       goto __pyx_L6;
     }
     __pyx_L6:;
 
-    /* "pysam/ctabix.pyx":749
+    /* "pysam/ctabix.pyx":859
  * 
  *             # skip empty lines
  *             if b[0] == '\0' or b[0] == '\n' or b[0] == '\r': continue             # <<<<<<<<<<<<<<
  * 
- *             # make sure that entry is complete
+ *             # gzgets terminates at \n, no need to test
  */
-    __pyx_t_4 = ((__pyx_v_b[0]) == '\x00');
-    if (!__pyx_t_4) {
-      __pyx_t_5 = ((__pyx_v_b[0]) == '\n');
-      if (!__pyx_t_5) {
-        __pyx_t_6 = ((__pyx_v_b[0]) == '\r');
-        __pyx_t_7 = __pyx_t_6;
+    __pyx_t_1 = ((__pyx_v_b[0]) == '\x00');
+    if (!__pyx_t_1) {
+      __pyx_t_3 = ((__pyx_v_b[0]) == '\n');
+      if (!__pyx_t_3) {
+        __pyx_t_4 = ((__pyx_v_b[0]) == '\r');
+        __pyx_t_5 = __pyx_t_4;
       } else {
-        __pyx_t_7 = __pyx_t_5;
+        __pyx_t_5 = __pyx_t_3;
       }
-      __pyx_t_5 = __pyx_t_7;
+      __pyx_t_3 = __pyx_t_5;
     } else {
-      __pyx_t_5 = __pyx_t_4;
+      __pyx_t_3 = __pyx_t_1;
     }
-    if (__pyx_t_5) {
+    if (__pyx_t_3) {
       goto __pyx_L3_continue;
       goto __pyx_L7;
     }
     __pyx_L7:;
 
-    /* "pysam/ctabix.pyx":752
- * 
- *             # make sure that entry is complete
- *             if b[nbytes-1] != '\n' and b[nbytes-1] != '\r':             # <<<<<<<<<<<<<<
- *                 result = b
- *                 raise ValueError( "incomplete line at %s" % result )
- */
-    __pyx_t_5 = ((__pyx_v_b[(__pyx_v_nbytes - 1)]) != '\n');
-    if (__pyx_t_5) {
-      __pyx_t_4 = ((__pyx_v_b[(__pyx_v_nbytes - 1)]) != '\r');
-      __pyx_t_7 = __pyx_t_4;
-    } else {
-      __pyx_t_7 = __pyx_t_5;
-    }
-    if (__pyx_t_7) {
-
-      /* "pysam/ctabix.pyx":753
- *             # make sure that entry is complete
- *             if b[nbytes-1] != '\n' and b[nbytes-1] != '\r':
- *                 result = b             # <<<<<<<<<<<<<<
- *                 raise ValueError( "incomplete line at %s" % result )
- * 
- */
-      __pyx_v_result = __pyx_v_b;
-
-      /* "pysam/ctabix.pyx":754
- *             if b[nbytes-1] != '\n' and b[nbytes-1] != '\r':
- *                 result = b
- *                 raise ValueError( "incomplete line at %s" % result )             # <<<<<<<<<<<<<<
- * 
- *             # make sure that this goes fully through C
- */
-      __pyx_t_3 = PyBytes_FromString(__pyx_v_result); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
-      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_54), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
-      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_3);
-      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
-      __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
-      __pyx_t_2 = 0;
-      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_2);
-      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
-      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
-      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      goto __pyx_L8;
-    }
-    __pyx_L8:;
-
-    /* "pysam/ctabix.pyx":760
- *             # Python object causing segfaults as
- *             # the wrong memory is freed
- *             r.present( b, nbytes )             # <<<<<<<<<<<<<<
- *             return r
+    /* "pysam/ctabix.pyx":864
  * 
- */
-    __pyx_t_2 = PyObject_GetAttr(__pyx_v_r, __pyx_n_s__present); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_3 = PyBytes_FromString(__pyx_v_b); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
-    __pyx_t_8 = __Pyx_PyInt_FromSize_t(__pyx_v_nbytes); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_8);
-    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_9);
-    PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_3));
-    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
-    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8);
-    __Pyx_GIVEREF(__pyx_t_8);
-    __pyx_t_3 = 0;
-    __pyx_t_8 = 0;
-    __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_8);
-    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
-    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
-
-    /* "pysam/ctabix.pyx":761
- *             # the wrong memory is freed
- *             r.present( b, nbytes )
- *             return r             # <<<<<<<<<<<<<<
+ *             # parser creates a copy
+ *             return self.parser.parse( b, self.buffer.l )             # <<<<<<<<<<<<<<
  * 
  *         raise StopIteration
  */
     __Pyx_XDECREF(__pyx_r);
-    __Pyx_INCREF(__pyx_v_r);
-    __pyx_r = __pyx_v_r;
+    __pyx_t_6 = ((struct __pyx_vtabstruct_5pysam_6ctabix_Parser *)__pyx_v_self->parser->__pyx_vtab)->parse(__pyx_v_self->parser, __pyx_v_b, __pyx_v_self->buffer.l); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_r = __pyx_t_6;
+    __pyx_t_6 = 0;
     goto __pyx_L0;
     __pyx_L3_continue:;
   }
   __pyx_L4_break:;
 
-  /* "pysam/ctabix.pyx":763
- *             return r
+  /* "pysam/ctabix.pyx":866
+ *             return self.parser.parse( b, self.buffer.l )
  * 
  *         raise StopIteration             # <<<<<<<<<<<<<<
  * 
  *     def __dealloc__(self):
  */
   __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
   goto __pyx_L0;
   __pyx_L1_error:;
-  __Pyx_XDECREF(__pyx_t_2);
-  __Pyx_XDECREF(__pyx_t_3);
-  __Pyx_XDECREF(__pyx_t_8);
-  __Pyx_XDECREF(__pyx_t_9);
-  __Pyx_AddTraceback("pysam.ctabix.tabix_inplace_iterator.__cnext__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("pysam.ctabix.tabix_file_iterator.__cnext__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __pyx_r = 0;
   __pyx_L0:;
-  __Pyx_XDECREF(__pyx_v_r);
   __Pyx_XGIVEREF(__pyx_r);
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
 /* Python wrapper */
-static void __pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_5__dealloc__(PyObject *__pyx_v_self); /*proto*/
-static void __pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_5__dealloc__(PyObject *__pyx_v_self) {
+static void __pyx_pw_5pysam_6ctabix_19tabix_file_iterator_5__dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pw_5pysam_6ctabix_19tabix_file_iterator_5__dealloc__(PyObject *__pyx_v_self) {
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
-  __pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_4__dealloc__(((struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *)__pyx_v_self));
+  __pyx_pf_5pysam_6ctabix_19tabix_file_iterator_4__dealloc__(((struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *)__pyx_v_self));
   __Pyx_RefNannyFinishContext();
 }
 
-/* "pysam/ctabix.pyx":765
+/* "pysam/ctabix.pyx":868
  *         raise StopIteration
  * 
  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
- *         free(self.buffer)
+ *         free(self.buffer.s)
  * 
  */
 
-static void __pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_4__dealloc__(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *__pyx_v_self) {
+static void __pyx_pf_5pysam_6ctabix_19tabix_file_iterator_4__dealloc__(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *__pyx_v_self) {
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__dealloc__", 0);
 
-  /* "pysam/ctabix.pyx":766
+  /* "pysam/ctabix.pyx":869
  * 
  *     def __dealloc__(self):
- *         free(self.buffer)             # <<<<<<<<<<<<<<
+ *         free(self.buffer.s)             # <<<<<<<<<<<<<<
  * 
  *     def __next__(self):
  */
-  free(__pyx_v_self->buffer);
+  free(__pyx_v_self->buffer.s);
 
   __Pyx_RefNannyFinishContext();
 }
 
 /* Python wrapper */
-static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_7__next__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_7__next__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_pw_5pysam_6ctabix_19tabix_file_iterator_7__next__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_5pysam_6ctabix_19tabix_file_iterator_7__next__(PyObject *__pyx_v_self) {
   PyObject *__pyx_r = 0;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
-  __pyx_r = __pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_6__next__(((struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *)__pyx_v_self));
+  __pyx_r = __pyx_pf_5pysam_6ctabix_19tabix_file_iterator_6__next__(((struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *)__pyx_v_self));
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":768
- *         free(self.buffer)
+/* "pysam/ctabix.pyx":871
+ *         free(self.buffer.s)
  * 
  *     def __next__(self):             # <<<<<<<<<<<<<<
  *         return self.__cnext__()
  * 
  */
 
-static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_6__next__(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *__pyx_v_self) {
+static PyObject *__pyx_pf_5pysam_6ctabix_19tabix_file_iterator_6__next__(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *__pyx_v_self) {
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
   PyObject *__pyx_t_1 = NULL;
@@ -7867,15 +7979,70 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_6__next__(stru
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__next__", 0);
 
-  /* "pysam/ctabix.pyx":769
+  /* "pysam/ctabix.pyx":872
  * 
  *     def __next__(self):
  *         return self.__cnext__()             # <<<<<<<<<<<<<<
  * 
- * ctypedef class tabix_copy_iterator:
+ *     def next(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_6ctabix_tabix_file_iterator *)__pyx_v_self->__pyx_vtab)->__pyx___cnext__(__pyx_v_self); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("pysam.ctabix.tabix_file_iterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_5pysam_6ctabix_19tabix_file_iterator_9next(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static char __pyx_doc_5pysam_6ctabix_19tabix_file_iterator_8next[] = "tabix_file_iterator.next(self)";
+static PyObject *__pyx_pw_5pysam_6ctabix_19tabix_file_iterator_9next(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("next (wrapper)", 0);
+  __pyx_r = __pyx_pf_5pysam_6ctabix_19tabix_file_iterator_8next(((struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *)__pyx_v_self));
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "pysam/ctabix.pyx":874
+ *         return self.__cnext__()
+ * 
+ *     def next(self):             # <<<<<<<<<<<<<<
+ *         return self.__cnext__()
+ * 
+ */
+
+static PyObject *__pyx_pf_5pysam_6ctabix_19tabix_file_iterator_8next(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("next", 0);
+
+  /* "pysam/ctabix.pyx":875
+ * 
+ *     def next(self):
+ *         return self.__cnext__()             # <<<<<<<<<<<<<<
+ * 
+ * class tabix_generic_iterator:
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_6ctabix_tabix_inplace_iterator *)__pyx_v_self->__pyx_vtab)->__pyx___cnext__(__pyx_v_self); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_6ctabix_tabix_file_iterator *)__pyx_v_self->__pyx_vtab)->__pyx___cnext__(__pyx_v_self); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -7885,7 +8052,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_6__next__(stru
   goto __pyx_L0;
   __pyx_L1_error:;
   __Pyx_XDECREF(__pyx_t_1);
-  __Pyx_AddTraceback("pysam.ctabix.tabix_inplace_iterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_AddTraceback("pysam.ctabix.tabix_file_iterator.next", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __pyx_r = NULL;
   __pyx_L0:;
   __Pyx_XGIVEREF(__pyx_r);
@@ -7894,20 +8061,24 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_inplace_iterator_6__next__(stru
 }
 
 /* Python wrapper */
-static int __pyx_pw_5pysam_6ctabix_19tabix_copy_iterator_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static int __pyx_pw_5pysam_6ctabix_19tabix_copy_iterator_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_generic_iterator_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_5pysam_6ctabix_22tabix_generic_iterator___init__[] = "tabix_generic_iterator.__init__(self, infile, parser)";
+static PyMethodDef __pyx_mdef_5pysam_6ctabix_22tabix_generic_iterator_1__init__ = {__Pyx_NAMESTR("__init__"), (PyCFunction)__pyx_pw_5pysam_6ctabix_22tabix_generic_iterator_1__init__, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_22tabix_generic_iterator___init__)};
+static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_generic_iterator_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_self = 0;
   PyObject *__pyx_v_infile = 0;
-  struct __pyx_obj_5pysam_6ctabix_Parser *__pyx_v_parser = 0;
-  int __pyx_r;
+  PyObject *__pyx_v_parser = 0;
+  PyObject *__pyx_r = 0;
   __Pyx_RefNannyDeclarations
-  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
   {
-    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__infile,&__pyx_n_s__parser,0};
-    PyObject* values[2] = {0,0};
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__infile,&__pyx_n_s__parser,0};
+    PyObject* values[3] = {0,0,0};
     if (unlikely(__pyx_kwds)) {
       Py_ssize_t kw_args;
       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
       switch (pos_args) {
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
         case  0: break;
@@ -7916,515 +8087,21 @@ static int __pyx_pw_5pysam_6ctabix_19tabix_copy_iterator_1__cinit__(PyObject *__
       kw_args = PyDict_Size(__pyx_kwds);
       switch (pos_args) {
         case  0:
-        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__infile)) != 0)) kw_args--;
+        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self)) != 0)) kw_args--;
         else goto __pyx_L5_argtuple_error;
         case  1:
-        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__parser)) != 0)) kw_args--;
+        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__infile)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-        }
-      }
-      if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-      }
-    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
-      goto __pyx_L5_argtuple_error;
-    } else {
-      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
-      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
-    }
-    __pyx_v_infile = values[0];
-    __pyx_v_parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)values[1]);
-  }
-  goto __pyx_L4_argument_unpacking_done;
-  __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-  __pyx_L3_error:;
-  __Pyx_AddTraceback("pysam.ctabix.tabix_copy_iterator.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __Pyx_RefNannyFinishContext();
-  return -1;
-  __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_parser), __pyx_ptype_5pysam_6ctabix_Parser, 1, "parser", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_r = __pyx_pf_5pysam_6ctabix_19tabix_copy_iterator___cinit__(((struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *)__pyx_v_self), __pyx_v_infile, __pyx_v_parser);
-  goto __pyx_L0;
-  __pyx_L1_error:;
-  __pyx_r = -1;
-  __pyx_L0:;
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* "pysam/ctabix.pyx":780
- *     '''
- * 
- *     def __cinit__(self, infile, Parser parser ):             # <<<<<<<<<<<<<<
- * 
- *         cdef int fd = PyObject_AsFileDescriptor( infile )
- */
-
-static int __pyx_pf_5pysam_6ctabix_19tabix_copy_iterator___cinit__(struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *__pyx_v_self, PyObject *__pyx_v_infile, struct __pyx_obj_5pysam_6ctabix_Parser *__pyx_v_parser) {
-  int __pyx_v_fd;
-  int __pyx_r;
-  __Pyx_RefNannyDeclarations
-  int __pyx_t_1;
-  int __pyx_t_2;
-  PyObject *__pyx_t_3 = NULL;
-  int __pyx_lineno = 0;
-  const char *__pyx_filename = NULL;
-  int __pyx_clineno = 0;
-  __Pyx_RefNannySetupContext("__cinit__", 0);
-
-  /* "pysam/ctabix.pyx":782
- *     def __cinit__(self, infile, Parser parser ):
- * 
- *         cdef int fd = PyObject_AsFileDescriptor( infile )             # <<<<<<<<<<<<<<
- *         if fd == -1: raise ValueError( "I/O operation on closed file." )
- *         self.infile = fdopen( fd, 'r')
- */
-  __pyx_t_1 = PyObject_AsFileDescriptor(__pyx_v_infile); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_v_fd = __pyx_t_1;
-
-  /* "pysam/ctabix.pyx":783
- * 
- *         cdef int fd = PyObject_AsFileDescriptor( infile )
- *         if fd == -1: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
- *         self.infile = fdopen( fd, 'r')
- *         if self.infile == NULL: raise ValueError( "I/O operation on closed file." )
- */
-  __pyx_t_2 = (__pyx_v_fd == -1);
-  if (__pyx_t_2) {
-    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_55), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_3);
-    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
-    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    goto __pyx_L3;
-  }
-  __pyx_L3:;
-
-  /* "pysam/ctabix.pyx":784
- *         cdef int fd = PyObject_AsFileDescriptor( infile )
- *         if fd == -1: raise ValueError( "I/O operation on closed file." )
- *         self.infile = fdopen( fd, 'r')             # <<<<<<<<<<<<<<
- *         if self.infile == NULL: raise ValueError( "I/O operation on closed file." )
- *         self.parser = parser
- */
-  __pyx_v_self->infile = fdopen(__pyx_v_fd, __pyx_k__r);
-
-  /* "pysam/ctabix.pyx":785
- *         if fd == -1: raise ValueError( "I/O operation on closed file." )
- *         self.infile = fdopen( fd, 'r')
- *         if self.infile == NULL: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
- *         self.parser = parser
- * 
- */
-  __pyx_t_2 = (__pyx_v_self->infile == NULL);
-  if (__pyx_t_2) {
-    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_56), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_3);
-    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
-    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    goto __pyx_L4;
-  }
-  __pyx_L4:;
-
-  /* "pysam/ctabix.pyx":786
- *         self.infile = fdopen( fd, 'r')
- *         if self.infile == NULL: raise ValueError( "I/O operation on closed file." )
- *         self.parser = parser             # <<<<<<<<<<<<<<
- * 
- *     def __iter__(self):
- */
-  __Pyx_INCREF(((PyObject *)__pyx_v_parser));
-  __Pyx_GIVEREF(((PyObject *)__pyx_v_parser));
-  __Pyx_GOTREF(__pyx_v_self->parser);
-  __Pyx_DECREF(((PyObject *)__pyx_v_self->parser));
-  __pyx_v_self->parser = __pyx_v_parser;
-
-  __pyx_r = 0;
-  goto __pyx_L0;
-  __pyx_L1_error:;
-  __Pyx_XDECREF(__pyx_t_3);
-  __Pyx_AddTraceback("pysam.ctabix.tabix_copy_iterator.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = -1;
-  __pyx_L0:;
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* Python wrapper */
-static PyObject *__pyx_pw_5pysam_6ctabix_19tabix_copy_iterator_3__iter__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_5pysam_6ctabix_19tabix_copy_iterator_3__iter__(PyObject *__pyx_v_self) {
-  PyObject *__pyx_r = 0;
-  __Pyx_RefNannyDeclarations
-  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
-  __pyx_r = __pyx_pf_5pysam_6ctabix_19tabix_copy_iterator_2__iter__(((struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *)__pyx_v_self));
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* "pysam/ctabix.pyx":788
- *         self.parser = parser
- * 
- *     def __iter__(self):             # <<<<<<<<<<<<<<
- *         return self
- * 
- */
-
-static PyObject *__pyx_pf_5pysam_6ctabix_19tabix_copy_iterator_2__iter__(struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *__pyx_v_self) {
-  PyObject *__pyx_r = NULL;
-  __Pyx_RefNannyDeclarations
-  __Pyx_RefNannySetupContext("__iter__", 0);
-
-  /* "pysam/ctabix.pyx":789
- * 
- *     def __iter__(self):
- *         return self             # <<<<<<<<<<<<<<
- * 
- *     cdef __cnext__(self):
- */
-  __Pyx_XDECREF(__pyx_r);
-  __Pyx_INCREF(((PyObject *)__pyx_v_self));
-  __pyx_r = ((PyObject *)__pyx_v_self);
-  goto __pyx_L0;
-
-  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
-  __pyx_L0:;
-  __Pyx_XGIVEREF(__pyx_r);
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* "pysam/ctabix.pyx":791
- *         return self
- * 
- *     cdef __cnext__(self):             # <<<<<<<<<<<<<<
- * 
- *         cdef char * b
- */
-
-static PyObject *__pyx_f_5pysam_6ctabix_19tabix_copy_iterator___cnext__(struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *__pyx_v_self) {
-  char *__pyx_v_b;
-  size_t __pyx_v_nbytes;
-  char *__pyx_v_result;
-  PyObject *__pyx_r = NULL;
-  __Pyx_RefNannyDeclarations
-  int __pyx_t_1;
-  int __pyx_t_2;
-  int __pyx_t_3;
-  int __pyx_t_4;
-  PyObject *__pyx_t_5 = NULL;
-  PyObject *__pyx_t_6 = NULL;
-  PyObject *__pyx_t_7 = NULL;
-  int __pyx_lineno = 0;
-  const char *__pyx_filename = NULL;
-  int __pyx_clineno = 0;
-  __Pyx_RefNannySetupContext("__cnext__", 0);
-
-  /* "pysam/ctabix.pyx":797
- *         cdef int x
- * 
- *         b = NULL             # <<<<<<<<<<<<<<
- * 
- *         while not feof( self.infile ):
- */
-  __pyx_v_b = NULL;
-
-  /* "pysam/ctabix.pyx":799
- *         b = NULL
- * 
- *         while not feof( self.infile ):             # <<<<<<<<<<<<<<
- * 
- *             # getline allocates on demand
- */
-  while (1) {
-    __pyx_t_1 = (!feof(__pyx_v_self->infile));
-    if (!__pyx_t_1) break;
-
-    /* "pysam/ctabix.pyx":803
- *             # getline allocates on demand
- *             # return number of characters read excluding null byte
- *             nbytes = getline( &b, &nbytes, self.infile)             # <<<<<<<<<<<<<<
- *             # stop at first error
- *             if (nbytes == -1): break
- */
-    __pyx_v_nbytes = getline((&__pyx_v_b), (&__pyx_v_nbytes), __pyx_v_self->infile);
-
-    /* "pysam/ctabix.pyx":805
- *             nbytes = getline( &b, &nbytes, self.infile)
- *             # stop at first error
- *             if (nbytes == -1): break             # <<<<<<<<<<<<<<
- *             # skip comments
- *             if (b[0] == '#'): continue
- */
-    __pyx_t_1 = (__pyx_v_nbytes == -1);
-    if (__pyx_t_1) {
-      goto __pyx_L4_break;
-      goto __pyx_L5;
-    }
-    __pyx_L5:;
-
-    /* "pysam/ctabix.pyx":807
- *             if (nbytes == -1): break
- *             # skip comments
- *             if (b[0] == '#'): continue             # <<<<<<<<<<<<<<
- * 
- *             # skip empty lines
- */
-    __pyx_t_1 = ((__pyx_v_b[0]) == '#');
-    if (__pyx_t_1) {
-      goto __pyx_L3_continue;
-      goto __pyx_L6;
-    }
-    __pyx_L6:;
-
-    /* "pysam/ctabix.pyx":810
- * 
- *             # skip empty lines
- *             if b[0] == '\0' or b[0] == '\n' or b[0] == '\r': continue             # <<<<<<<<<<<<<<
- * 
- *             # make sure that entry is complete
- */
-    __pyx_t_1 = ((__pyx_v_b[0]) == '\x00');
-    if (!__pyx_t_1) {
-      __pyx_t_2 = ((__pyx_v_b[0]) == '\n');
-      if (!__pyx_t_2) {
-        __pyx_t_3 = ((__pyx_v_b[0]) == '\r');
-        __pyx_t_4 = __pyx_t_3;
-      } else {
-        __pyx_t_4 = __pyx_t_2;
-      }
-      __pyx_t_2 = __pyx_t_4;
-    } else {
-      __pyx_t_2 = __pyx_t_1;
-    }
-    if (__pyx_t_2) {
-      goto __pyx_L3_continue;
-      goto __pyx_L7;
-    }
-    __pyx_L7:;
-
-    /* "pysam/ctabix.pyx":813
- * 
- *             # make sure that entry is complete
- *             if b[nbytes-1] != '\n' and b[nbytes-1] != '\r':             # <<<<<<<<<<<<<<
- *                 result = b
- *                 free(b)
- */
-    __pyx_t_2 = ((__pyx_v_b[(__pyx_v_nbytes - 1)]) != '\n');
-    if (__pyx_t_2) {
-      __pyx_t_1 = ((__pyx_v_b[(__pyx_v_nbytes - 1)]) != '\r');
-      __pyx_t_4 = __pyx_t_1;
-    } else {
-      __pyx_t_4 = __pyx_t_2;
-    }
-    if (__pyx_t_4) {
-
-      /* "pysam/ctabix.pyx":814
- *             # make sure that entry is complete
- *             if b[nbytes-1] != '\n' and b[nbytes-1] != '\r':
- *                 result = b             # <<<<<<<<<<<<<<
- *                 free(b)
- *                 raise ValueError( "incomplete line at %s" % result )
- */
-      __pyx_v_result = __pyx_v_b;
-
-      /* "pysam/ctabix.pyx":815
- *             if b[nbytes-1] != '\n' and b[nbytes-1] != '\r':
- *                 result = b
- *                 free(b)             # <<<<<<<<<<<<<<
- *                 raise ValueError( "incomplete line at %s" % result )
- * 
- */
-      free(__pyx_v_b);
-
-      /* "pysam/ctabix.pyx":816
- *                 result = b
- *                 free(b)
- *                 raise ValueError( "incomplete line at %s" % result )             # <<<<<<<<<<<<<<
- * 
- *             # make sure that this goes fully through C
- */
-      __pyx_t_5 = PyBytes_FromString(__pyx_v_result); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
-      __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_54), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(((PyObject *)__pyx_t_6));
-      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
-      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_5);
-      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_6));
-      __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
-      __pyx_t_6 = 0;
-      __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_6);
-      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
-      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
-      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      goto __pyx_L8;
-    }
-    __pyx_L8:;
-
-    /* "pysam/ctabix.pyx":823
- *             # the wrong memory is freed
- *             # -1 to remove the new-line character
- *             return self.parser(b, nbytes)             # <<<<<<<<<<<<<<
- * 
- *         free(b)
- */
-    __Pyx_XDECREF(__pyx_r);
-    __pyx_t_6 = PyBytes_FromString(__pyx_v_b); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
-    __pyx_t_5 = __Pyx_PyInt_FromSize_t(__pyx_v_nbytes); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_5);
-    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_7);
-    PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_6));
-    __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
-    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_5);
-    __Pyx_GIVEREF(__pyx_t_5);
-    __pyx_t_6 = 0;
-    __pyx_t_5 = 0;
-    __pyx_t_5 = PyObject_Call(((PyObject *)__pyx_v_self->parser), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_5);
-    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
-    __pyx_r = __pyx_t_5;
-    __pyx_t_5 = 0;
-    goto __pyx_L0;
-    __pyx_L3_continue:;
-  }
-  __pyx_L4_break:;
-
-  /* "pysam/ctabix.pyx":825
- *             return self.parser(b, nbytes)
- * 
- *         free(b)             # <<<<<<<<<<<<<<
- *         raise StopIteration
- * 
- */
-  free(__pyx_v_b);
-
-  /* "pysam/ctabix.pyx":826
- * 
- *         free(b)
- *         raise StopIteration             # <<<<<<<<<<<<<<
- * 
- *     def __next__(self):
- */
-  __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-
-  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
-  goto __pyx_L0;
-  __pyx_L1_error:;
-  __Pyx_XDECREF(__pyx_t_5);
-  __Pyx_XDECREF(__pyx_t_6);
-  __Pyx_XDECREF(__pyx_t_7);
-  __Pyx_AddTraceback("pysam.ctabix.tabix_copy_iterator.__cnext__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = 0;
-  __pyx_L0:;
-  __Pyx_XGIVEREF(__pyx_r);
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* Python wrapper */
-static PyObject *__pyx_pw_5pysam_6ctabix_19tabix_copy_iterator_5__next__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_5pysam_6ctabix_19tabix_copy_iterator_5__next__(PyObject *__pyx_v_self) {
-  PyObject *__pyx_r = 0;
-  __Pyx_RefNannyDeclarations
-  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
-  __pyx_r = __pyx_pf_5pysam_6ctabix_19tabix_copy_iterator_4__next__(((struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *)__pyx_v_self));
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* "pysam/ctabix.pyx":828
- *         raise StopIteration
- * 
- *     def __next__(self):             # <<<<<<<<<<<<<<
- *         return self.__cnext__()
- * 
- */
-
-static PyObject *__pyx_pf_5pysam_6ctabix_19tabix_copy_iterator_4__next__(struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *__pyx_v_self) {
-  PyObject *__pyx_r = NULL;
-  __Pyx_RefNannyDeclarations
-  PyObject *__pyx_t_1 = NULL;
-  int __pyx_lineno = 0;
-  const char *__pyx_filename = NULL;
-  int __pyx_clineno = 0;
-  __Pyx_RefNannySetupContext("__next__", 0);
-
-  /* "pysam/ctabix.pyx":829
- * 
- *     def __next__(self):
- *         return self.__cnext__()             # <<<<<<<<<<<<<<
- * 
- * class tabix_generic_iterator:
- */
-  __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_6ctabix_tabix_copy_iterator *)__pyx_v_self->__pyx_vtab)->__pyx___cnext__(__pyx_v_self); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_1);
-  __pyx_r = __pyx_t_1;
-  __pyx_t_1 = 0;
-  goto __pyx_L0;
-
-  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
-  goto __pyx_L0;
-  __pyx_L1_error:;
-  __Pyx_XDECREF(__pyx_t_1);
-  __Pyx_AddTraceback("pysam.ctabix.tabix_copy_iterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
-  __pyx_L0:;
-  __Pyx_XGIVEREF(__pyx_r);
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* Python wrapper */
-static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_generic_iterator_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_5pysam_6ctabix_22tabix_generic_iterator___init__[] = "tabix_generic_iterator.__init__(self, infile, parser)";
-static PyMethodDef __pyx_mdef_5pysam_6ctabix_22tabix_generic_iterator_1__init__ = {__Pyx_NAMESTR("__init__"), (PyCFunction)__pyx_pw_5pysam_6ctabix_22tabix_generic_iterator_1__init__, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_22tabix_generic_iterator___init__)};
-static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_generic_iterator_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
-  PyObject *__pyx_v_self = 0;
-  PyObject *__pyx_v_infile = 0;
-  PyObject *__pyx_v_parser = 0;
-  PyObject *__pyx_r = 0;
-  __Pyx_RefNannyDeclarations
-  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
-  {
-    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__infile,&__pyx_n_s__parser,0};
-    PyObject* values[3] = {0,0,0};
-    if (unlikely(__pyx_kwds)) {
-      Py_ssize_t kw_args;
-      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
-      switch (pos_args) {
-        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
-        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
-        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
-        case  0: break;
-        default: goto __pyx_L5_argtuple_error;
-      }
-      kw_args = PyDict_Size(__pyx_kwds);
-      switch (pos_args) {
-        case  0:
-        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self)) != 0)) kw_args--;
-        else goto __pyx_L5_argtuple_error;
-        case  1:
-        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__infile)) != 0)) kw_args--;
-        else {
-          __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  2:
         if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__parser)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
       goto __pyx_L5_argtuple_error;
@@ -8439,7 +8116,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_generic_iterator_1__init__(PyOb
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.ctabix.tabix_generic_iterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -8450,7 +8127,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_generic_iterator_1__init__(PyOb
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":836
+/* "pysam/ctabix.pyx":882
  *     Permits the use of file-like objects for example from the gzip module.
  *     '''
  *     def __init__(self, infile, parser ):             # <<<<<<<<<<<<<<
@@ -8469,47 +8146,47 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator___init__(CYTHO
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__init__", 0);
 
-  /* "pysam/ctabix.pyx":838
+  /* "pysam/ctabix.pyx":884
  *     def __init__(self, infile, parser ):
  * 
  *         self.infile = infile             # <<<<<<<<<<<<<<
  *         if self.infile.closed: raise ValueError( "I/O operation on closed file." )
  *         self.parser = parser
  */
-  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__infile, __pyx_v_infile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__infile, __pyx_v_infile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/ctabix.pyx":839
+  /* "pysam/ctabix.pyx":885
  * 
  *         self.infile = infile
  *         if self.infile.closed: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
  *         self.parser = parser
  * 
  */
-  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__infile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__infile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__closed); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__closed); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   if (__pyx_t_3) {
-    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_57), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_55), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 885; __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 = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     goto __pyx_L3;
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":840
+  /* "pysam/ctabix.pyx":886
  *         self.infile = infile
  *         if self.infile.closed: raise ValueError( "I/O operation on closed file." )
  *         self.parser = parser             # <<<<<<<<<<<<<<
  * 
  *     def __iter__(self):
  */
-  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__parser, __pyx_v_parser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__parser, __pyx_v_parser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
   goto __pyx_L0;
@@ -8537,7 +8214,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_generic_iterator_3__iter__(PyOb
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":842
+/* "pysam/ctabix.pyx":888
  *         self.parser = parser
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
@@ -8550,7 +8227,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_2__iter__(CYTH
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__iter__", 0);
 
-  /* "pysam/ctabix.pyx":843
+  /* "pysam/ctabix.pyx":889
  * 
  *     def __iter__(self):
  *         return self             # <<<<<<<<<<<<<<
@@ -8582,7 +8259,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_generic_iterator_5__next__(PyOb
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":846
+/* "pysam/ctabix.pyx":892
  * 
  *     # cython version - required for python 3
  *     def __next__(self):             # <<<<<<<<<<<<<<
@@ -8613,9 +8290,33 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_4__next__(CYTH
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__next__", 0);
 
-  /* "pysam/ctabix.pyx":850
- *         cdef char * b, * cpy
- *         cdef size_t nbytes
+  /* "pysam/ctabix.pyx":899
+ *         # note that GzipFile.close() does not close the file
+ *         # reading is still possible.
+ *         if self.infile.closed: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
+ * 
+ *         while 1:
+ */
+  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__infile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__closed); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (__pyx_t_3) {
+    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_56), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 899; __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 = 899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    goto __pyx_L3;
+  }
+  __pyx_L3:;
+
+  /* "pysam/ctabix.pyx":901
+ *         if self.infile.closed: raise ValueError( "I/O operation on closed file." )
+ * 
  *         while 1:             # <<<<<<<<<<<<<<
  * 
  *             line = self.infile.readline()
@@ -8623,74 +8324,74 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_4__next__(CYTH
   while (1) {
     if (!1) break;
 
-    /* "pysam/ctabix.pyx":852
+    /* "pysam/ctabix.pyx":903
  *         while 1:
  * 
  *             line = self.infile.readline()             # <<<<<<<<<<<<<<
  *             if not line: break
  * 
  */
-    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__infile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__readline); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__infile); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 903; __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_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__readline); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __Pyx_XDECREF(__pyx_v_line);
-    __pyx_v_line = __pyx_t_1;
-    __pyx_t_1 = 0;
+    __pyx_v_line = __pyx_t_2;
+    __pyx_t_2 = 0;
 
-    /* "pysam/ctabix.pyx":853
+    /* "pysam/ctabix.pyx":904
  * 
  *             line = self.infile.readline()
  *             if not line: break             # <<<<<<<<<<<<<<
  * 
  *             s = _force_bytes( line )
  */
-    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_line); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_line); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_t_4 = (!__pyx_t_3);
     if (__pyx_t_4) {
-      goto __pyx_L4_break;
-      goto __pyx_L5;
+      goto __pyx_L5_break;
+      goto __pyx_L6;
     }
-    __pyx_L5:;
+    __pyx_L6:;
 
-    /* "pysam/ctabix.pyx":855
+    /* "pysam/ctabix.pyx":906
  *             if not line: break
  * 
  *             s = _force_bytes( line )             # <<<<<<<<<<<<<<
  *             b = s
  *             nbytes = len( line )
  */
-    __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_6ctabix__force_bytes(__pyx_v_line)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_6ctabix__force_bytes(__pyx_v_line)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_2);
     __Pyx_XDECREF(((PyObject *)__pyx_v_s));
-    __pyx_v_s = ((PyObject*)__pyx_t_1);
-    __pyx_t_1 = 0;
+    __pyx_v_s = ((PyObject*)__pyx_t_2);
+    __pyx_t_2 = 0;
 
-    /* "pysam/ctabix.pyx":856
+    /* "pysam/ctabix.pyx":907
  * 
  *             s = _force_bytes( line )
  *             b = s             # <<<<<<<<<<<<<<
  *             nbytes = len( line )
  *             assert b[nbytes] == '\0'
  */
-    __pyx_t_5 = PyBytes_AsString(((PyObject *)__pyx_v_s)); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = PyBytes_AsString(((PyObject *)__pyx_v_s)); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_v_b = __pyx_t_5;
 
-    /* "pysam/ctabix.pyx":857
+    /* "pysam/ctabix.pyx":908
  *             s = _force_bytes( line )
  *             b = s
  *             nbytes = len( line )             # <<<<<<<<<<<<<<
  *             assert b[nbytes] == '\0'
  * 
  */
-    __pyx_t_6 = PyObject_Length(__pyx_v_line); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = PyObject_Length(__pyx_v_line); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 908; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_v_nbytes = __pyx_t_6;
 
-    /* "pysam/ctabix.pyx":858
+    /* "pysam/ctabix.pyx":909
  *             b = s
  *             nbytes = len( line )
  *             assert b[nbytes] == '\0'             # <<<<<<<<<<<<<<
@@ -8700,11 +8401,11 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_4__next__(CYTH
     #ifndef CYTHON_WITHOUT_ASSERTIONS
     if (unlikely(!((__pyx_v_b[__pyx_v_nbytes]) == '\x00'))) {
       PyErr_SetNone(PyExc_AssertionError);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 909; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     #endif
 
-    /* "pysam/ctabix.pyx":861
+    /* "pysam/ctabix.pyx":912
  * 
  *             # skip comments
  *             if (b[0] == '#'): continue             # <<<<<<<<<<<<<<
@@ -8713,12 +8414,12 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_4__next__(CYTH
  */
     __pyx_t_4 = ((__pyx_v_b[0]) == '#');
     if (__pyx_t_4) {
-      goto __pyx_L3_continue;
-      goto __pyx_L6;
+      goto __pyx_L4_continue;
+      goto __pyx_L7;
     }
-    __pyx_L6:;
+    __pyx_L7:;
 
-    /* "pysam/ctabix.pyx":864
+    /* "pysam/ctabix.pyx":915
  * 
  *             # skip empty lines
  *             if b[0] == '\0' or b[0] == '\n' or b[0] == '\r': continue             # <<<<<<<<<<<<<<
@@ -8739,12 +8440,12 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_4__next__(CYTH
       __pyx_t_3 = __pyx_t_4;
     }
     if (__pyx_t_3) {
-      goto __pyx_L3_continue;
-      goto __pyx_L7;
+      goto __pyx_L4_continue;
+      goto __pyx_L8;
     }
-    __pyx_L7:;
+    __pyx_L8:;
 
-    /* "pysam/ctabix.pyx":867
+    /* "pysam/ctabix.pyx":918
  * 
  *             # make sure that entry is complete
  *             if b[nbytes-1] != '\n' and b[nbytes-1] != '\r':             # <<<<<<<<<<<<<<
@@ -8760,31 +8461,31 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_4__next__(CYTH
     }
     if (__pyx_t_8) {
 
-      /* "pysam/ctabix.pyx":868
+      /* "pysam/ctabix.pyx":919
  *             # make sure that entry is complete
  *             if b[nbytes-1] != '\n' and b[nbytes-1] != '\r':
  *                 raise ValueError( "incomplete line at %s" % line )             # <<<<<<<<<<<<<<
  * 
  *             # create a copy
  */
-      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_54), __pyx_v_line); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
-      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_2);
-      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
-      __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
-      __pyx_t_1 = 0;
-      __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_57), __pyx_v_line); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
-      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
-      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      goto __pyx_L8;
+      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2));
+      __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
+      __pyx_t_2 = 0;
+      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      goto __pyx_L9;
     }
-    __pyx_L8:;
+    __pyx_L9:;
 
-    /* "pysam/ctabix.pyx":871
+    /* "pysam/ctabix.pyx":922
  * 
  *             # create a copy
  *             cpy = <char*>malloc(nbytes+1)             # <<<<<<<<<<<<<<
@@ -8793,7 +8494,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_4__next__(CYTH
  */
     __pyx_v_cpy = ((char *)malloc((__pyx_v_nbytes + 1)));
 
-    /* "pysam/ctabix.pyx":872
+    /* "pysam/ctabix.pyx":923
  *             # create a copy
  *             cpy = <char*>malloc(nbytes+1)
  *             if cpy == NULL: raise MemoryError()             # <<<<<<<<<<<<<<
@@ -8802,12 +8503,12 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_4__next__(CYTH
  */
     __pyx_t_8 = (__pyx_v_cpy == NULL);
     if (__pyx_t_8) {
-      PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      goto __pyx_L9;
+      PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      goto __pyx_L10;
     }
-    __pyx_L9:;
+    __pyx_L10:;
 
-    /* "pysam/ctabix.pyx":873
+    /* "pysam/ctabix.pyx":924
  *             cpy = <char*>malloc(nbytes+1)
  *             if cpy == NULL: raise MemoryError()
  *             memcpy( cpy, b, nbytes+1)             # <<<<<<<<<<<<<<
@@ -8816,7 +8517,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_4__next__(CYTH
  */
     memcpy(__pyx_v_cpy, __pyx_v_b, (__pyx_v_nbytes + 1));
 
-    /* "pysam/ctabix.pyx":875
+    /* "pysam/ctabix.pyx":926
  *             memcpy( cpy, b, nbytes+1)
  * 
  *             return self.parser(cpy, nbytes)             # <<<<<<<<<<<<<<
@@ -8824,32 +8525,32 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_4__next__(CYTH
  *         raise StopIteration
  */
     __Pyx_XDECREF(__pyx_r);
-    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__parser); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyBytes_FromString(__pyx_v_cpy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
-    __pyx_t_9 = __Pyx_PyInt_FromSize_t(__pyx_v_nbytes); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__parser); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_1 = PyBytes_FromString(__pyx_v_cpy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+    __pyx_t_9 = __Pyx_PyInt_FromSize_t(__pyx_v_nbytes); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
-    __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_10);
-    PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_2));
-    __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
+    PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_1));
+    __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
     PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_9);
     __Pyx_GIVEREF(__pyx_t_9);
-    __pyx_t_2 = 0;
+    __pyx_t_1 = 0;
     __pyx_t_9 = 0;
-    __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_9 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_9);
-    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
     __pyx_r = __pyx_t_9;
     __pyx_t_9 = 0;
     goto __pyx_L0;
-    __pyx_L3_continue:;
+    __pyx_L4_continue:;
   }
-  __pyx_L4_break:;
+  __pyx_L5_break:;
 
-  /* "pysam/ctabix.pyx":877
+  /* "pysam/ctabix.pyx":928
  *             return self.parser(cpy, nbytes)
  * 
  *         raise StopIteration             # <<<<<<<<<<<<<<
@@ -8857,7 +8558,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_4__next__(CYTH
  *     # python version - required for python 2.7
  */
   __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
-  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 928; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
   goto __pyx_L0;
@@ -8889,7 +8590,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_22tabix_generic_iterator_7next(PyObject
   return __pyx_r;
 }
 
-/* "pysam/ctabix.pyx":880
+/* "pysam/ctabix.pyx":931
  * 
  *     # python version - required for python 2.7
  *     def next(self):             # <<<<<<<<<<<<<<
@@ -8907,7 +8608,7 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_6next(CYTHON_U
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("next", 0);
 
-  /* "pysam/ctabix.pyx":881
+  /* "pysam/ctabix.pyx":932
  *     # python version - required for python 2.7
  *     def next(self):
  *         return self.__next__()             # <<<<<<<<<<<<<<
@@ -8915,9 +8616,9 @@ static PyObject *__pyx_pf_5pysam_6ctabix_22tabix_generic_iterator_6next(CYTHON_U
  * def tabix_iterator( infile, parser ):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____next__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____next__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __pyx_r = __pyx_t_2;
@@ -8967,11 +8668,11 @@ static PyObject *__pyx_pw_5pysam_6ctabix_5tabix_iterator(PyObject *__pyx_self, P
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__parser)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("tabix_iterator", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 883; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("tabix_iterator", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tabix_iterator") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 883; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tabix_iterator") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
       goto __pyx_L5_argtuple_error;
@@ -8984,7 +8685,7 @@ static PyObject *__pyx_pw_5pysam_6ctabix_5tabix_iterator(PyObject *__pyx_self, P
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("tabix_iterator", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 883; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("tabix_iterator", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("pysam.ctabix.tabix_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -8992,300 +8693,174 @@ static PyObject *__pyx_pw_5pysam_6ctabix_5tabix_iterator(PyObject *__pyx_self, P
   __pyx_L4_argument_unpacking_done:;
   __pyx_r = __pyx_pf_5pysam_6ctabix_4tabix_iterator(__pyx_self, __pyx_v_infile, __pyx_v_parser);
   __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-/* "pysam/ctabix.pyx":883
- *         return self.__next__()
- * 
- * def tabix_iterator( infile, parser ):             # <<<<<<<<<<<<<<
- *     """return an iterator over all entries in a file."""
- *     return tabix_generic_iterator( infile, parser )
- */
-
-static PyObject *__pyx_pf_5pysam_6ctabix_4tabix_iterator(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_infile, PyObject *__pyx_v_parser) {
-  PyObject *__pyx_r = NULL;
-  __Pyx_RefNannyDeclarations
-  PyObject *__pyx_t_1 = NULL;
-  PyObject *__pyx_t_2 = NULL;
-  PyObject *__pyx_t_3 = NULL;
-  int __pyx_lineno = 0;
-  const char *__pyx_filename = NULL;
-  int __pyx_clineno = 0;
-  __Pyx_RefNannySetupContext("tabix_iterator", 0);
-
-  /* "pysam/ctabix.pyx":885
- * def tabix_iterator( infile, parser ):
- *     """return an iterator over all entries in a file."""
- *     return tabix_generic_iterator( infile, parser )             # <<<<<<<<<<<<<<
- *     # file objects can use C stdio
- *     # used to be: isinstance( infile, file):
- */
-  __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s_58); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_2);
-  __Pyx_INCREF(__pyx_v_infile);
-  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_infile);
-  __Pyx_GIVEREF(__pyx_v_infile);
-  __Pyx_INCREF(__pyx_v_parser);
-  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_parser);
-  __Pyx_GIVEREF(__pyx_v_parser);
-  __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 = 885; __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_r = __pyx_t_3;
-  __pyx_t_3 = 0;
-  goto __pyx_L0;
-
-  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
-  goto __pyx_L0;
-  __pyx_L1_error:;
-  __Pyx_XDECREF(__pyx_t_1);
-  __Pyx_XDECREF(__pyx_t_2);
-  __Pyx_XDECREF(__pyx_t_3);
-  __Pyx_AddTraceback("pysam.ctabix.tabix_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
-  __pyx_L0:;
-  __Pyx_XGIVEREF(__pyx_r);
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-static PyObject *__pyx_tp_new_5pysam_6ctabix_Tabixfile(PyTypeObject *t, PyObject *a, PyObject *k) {
-  PyObject *o = (*t->tp_alloc)(t, 0);
-  if (!o) return 0;
-  if (__pyx_pw_5pysam_6ctabix_9Tabixfile_1__cinit__(o, a, k) < 0) {
-    Py_DECREF(o); o = 0;
-  }
-  return o;
-}
-
-static void __pyx_tp_dealloc_5pysam_6ctabix_Tabixfile(PyObject *o) {
-  {
-    PyObject *etype, *eval, *etb;
-    PyErr_Fetch(&etype, &eval, &etb);
-    ++Py_REFCNT(o);
-    __pyx_pw_5pysam_6ctabix_9Tabixfile_13__dealloc__(o);
-    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
-    --Py_REFCNT(o);
-    PyErr_Restore(etype, eval, etb);
-  }
-  (*Py_TYPE(o)->tp_free)(o);
-}
-
-static PyObject *__pyx_getprop_5pysam_6ctabix_9Tabixfile_filename(PyObject *o, CYTHON_UNUSED void *x) {
-  return __pyx_pw_5pysam_6ctabix_9Tabixfile_8filename_1__get__(o);
-}
-
-static PyObject *__pyx_getprop_5pysam_6ctabix_9Tabixfile_header(PyObject *o, CYTHON_UNUSED void *x) {
-  return __pyx_pw_5pysam_6ctabix_9Tabixfile_6header_1__get__(o);
-}
-
-static PyObject *__pyx_getprop_5pysam_6ctabix_9Tabixfile_contigs(PyObject *o, CYTHON_UNUSED void *x) {
-  return __pyx_pw_5pysam_6ctabix_9Tabixfile_7contigs_1__get__(o);
-}
-
-static PyMethodDef __pyx_methods_5pysam_6ctabix_Tabixfile[] = {
-  {__Pyx_NAMESTR("_isOpen"), (PyCFunction)__pyx_pw_5pysam_6ctabix_9Tabixfile_3_isOpen, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_9Tabixfile_2_isOpen)},
-  {__Pyx_NAMESTR("_open"), (PyCFunction)__pyx_pw_5pysam_6ctabix_9Tabixfile_5_open, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_9Tabixfile_4_open)},
-  {__Pyx_NAMESTR("_parseRegion"), (PyCFunction)__pyx_pw_5pysam_6ctabix_9Tabixfile_7_parseRegion, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_9Tabixfile_6_parseRegion)},
-  {__Pyx_NAMESTR("fetch"), (PyCFunction)__pyx_pw_5pysam_6ctabix_9Tabixfile_9fetch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_9Tabixfile_8fetch)},
-  {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pw_5pysam_6ctabix_9Tabixfile_11close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_9Tabixfile_10close)},
-  {0, 0, 0, 0}
-};
-
-static struct PyGetSetDef __pyx_getsets_5pysam_6ctabix_Tabixfile[] = {
-  {(char *)"filename", __pyx_getprop_5pysam_6ctabix_9Tabixfile_filename, 0, __Pyx_DOCSTR(__pyx_k_59), 0},
-  {(char *)"header", __pyx_getprop_5pysam_6ctabix_9Tabixfile_header, 0, __Pyx_DOCSTR(__pyx_k_60), 0},
-  {(char *)"contigs", __pyx_getprop_5pysam_6ctabix_9Tabixfile_contigs, 0, __Pyx_DOCSTR(__pyx_k_61), 0},
-  {0, 0, 0, 0, 0}
-};
-
-static PyNumberMethods __pyx_tp_as_number_Tabixfile = {
-  0, /*nb_add*/
-  0, /*nb_subtract*/
-  0, /*nb_multiply*/
-  #if PY_MAJOR_VERSION < 3
-  0, /*nb_divide*/
-  #endif
-  0, /*nb_remainder*/
-  0, /*nb_divmod*/
-  0, /*nb_power*/
-  0, /*nb_negative*/
-  0, /*nb_positive*/
-  0, /*nb_absolute*/
-  0, /*nb_nonzero*/
-  0, /*nb_invert*/
-  0, /*nb_lshift*/
-  0, /*nb_rshift*/
-  0, /*nb_and*/
-  0, /*nb_xor*/
-  0, /*nb_or*/
-  #if PY_MAJOR_VERSION < 3
-  0, /*nb_coerce*/
-  #endif
-  0, /*nb_int*/
-  #if PY_MAJOR_VERSION < 3
-  0, /*nb_long*/
-  #else
-  0, /*reserved*/
-  #endif
-  0, /*nb_float*/
-  #if PY_MAJOR_VERSION < 3
-  0, /*nb_oct*/
-  #endif
-  #if PY_MAJOR_VERSION < 3
-  0, /*nb_hex*/
-  #endif
-  0, /*nb_inplace_add*/
-  0, /*nb_inplace_subtract*/
-  0, /*nb_inplace_multiply*/
-  #if PY_MAJOR_VERSION < 3
-  0, /*nb_inplace_divide*/
-  #endif
-  0, /*nb_inplace_remainder*/
-  0, /*nb_inplace_power*/
-  0, /*nb_inplace_lshift*/
-  0, /*nb_inplace_rshift*/
-  0, /*nb_inplace_and*/
-  0, /*nb_inplace_xor*/
-  0, /*nb_inplace_or*/
-  0, /*nb_floor_divide*/
-  0, /*nb_true_divide*/
-  0, /*nb_inplace_floor_divide*/
-  0, /*nb_inplace_true_divide*/
-  #if PY_VERSION_HEX >= 0x02050000
-  0, /*nb_index*/
-  #endif
-};
+  return __pyx_r;
+}
 
-static PySequenceMethods __pyx_tp_as_sequence_Tabixfile = {
-  0, /*sq_length*/
-  0, /*sq_concat*/
-  0, /*sq_repeat*/
-  0, /*sq_item*/
-  0, /*sq_slice*/
-  0, /*sq_ass_item*/
-  0, /*sq_ass_slice*/
-  0, /*sq_contains*/
-  0, /*sq_inplace_concat*/
-  0, /*sq_inplace_repeat*/
-};
+/* "pysam/ctabix.pyx":934
+ *         return self.__next__()
+ * 
+ * def tabix_iterator( infile, parser ):             # <<<<<<<<<<<<<<
+ *     """return an iterator over all entries in a file."""
+ *     if PYTHON3:
+ */
 
-static PyMappingMethods __pyx_tp_as_mapping_Tabixfile = {
-  0, /*mp_length*/
-  0, /*mp_subscript*/
-  0, /*mp_ass_subscript*/
-};
+static PyObject *__pyx_pf_5pysam_6ctabix_4tabix_iterator(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_infile, PyObject *__pyx_v_parser) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("tabix_iterator", 0);
 
-static PyBufferProcs __pyx_tp_as_buffer_Tabixfile = {
-  #if PY_MAJOR_VERSION < 3
-  0, /*bf_getreadbuffer*/
-  #endif
-  #if PY_MAJOR_VERSION < 3
-  0, /*bf_getwritebuffer*/
-  #endif
-  #if PY_MAJOR_VERSION < 3
-  0, /*bf_getsegcount*/
-  #endif
-  #if PY_MAJOR_VERSION < 3
-  0, /*bf_getcharbuffer*/
-  #endif
-  #if PY_VERSION_HEX >= 0x02060000
-  0, /*bf_getbuffer*/
-  #endif
-  #if PY_VERSION_HEX >= 0x02060000
-  0, /*bf_releasebuffer*/
-  #endif
-};
+  /* "pysam/ctabix.pyx":936
+ * def tabix_iterator( infile, parser ):
+ *     """return an iterator over all entries in a file."""
+ *     if PYTHON3:             # <<<<<<<<<<<<<<
+ *         return tabix_generic_iterator( infile, parser )
+ *     else:
+ */
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__PYTHON3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (__pyx_t_2) {
 
-static PyTypeObject __pyx_type_5pysam_6ctabix_Tabixfile = {
-  PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.ctabix.Tabixfile"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_6ctabix_Tabixfile), /*tp_basicsize*/
-  0, /*tp_itemsize*/
-  __pyx_tp_dealloc_5pysam_6ctabix_Tabixfile, /*tp_dealloc*/
-  0, /*tp_print*/
-  0, /*tp_getattr*/
-  0, /*tp_setattr*/
-  #if PY_MAJOR_VERSION < 3
-  0, /*tp_compare*/
-  #else
-  0, /*reserved*/
-  #endif
-  0, /*tp_repr*/
-  &__pyx_tp_as_number_Tabixfile, /*tp_as_number*/
-  &__pyx_tp_as_sequence_Tabixfile, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping_Tabixfile, /*tp_as_mapping*/
-  0, /*tp_hash*/
-  0, /*tp_call*/
-  0, /*tp_str*/
-  0, /*tp_getattro*/
-  0, /*tp_setattro*/
-  &__pyx_tp_as_buffer_Tabixfile, /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-  __Pyx_DOCSTR("*(filename, mode='r')*\n\n    opens a :term:`tabix file` for reading. A missing\n    index (*filename* + \".tbi\") will raise an exception.\n    "), /*tp_doc*/
-  0, /*tp_traverse*/
-  0, /*tp_clear*/
-  0, /*tp_richcompare*/
-  0, /*tp_weaklistoffset*/
-  0, /*tp_iter*/
-  0, /*tp_iternext*/
-  __pyx_methods_5pysam_6ctabix_Tabixfile, /*tp_methods*/
-  0, /*tp_members*/
-  __pyx_getsets_5pysam_6ctabix_Tabixfile, /*tp_getset*/
-  0, /*tp_base*/
-  0, /*tp_dict*/
-  0, /*tp_descr_get*/
-  0, /*tp_descr_set*/
-  0, /*tp_dictoffset*/
-  0, /*tp_init*/
-  0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_6ctabix_Tabixfile, /*tp_new*/
-  0, /*tp_free*/
-  0, /*tp_is_gc*/
-  0, /*tp_bases*/
-  0, /*tp_mro*/
-  0, /*tp_cache*/
-  0, /*tp_subclasses*/
-  0, /*tp_weaklist*/
-  0, /*tp_del*/
-  #if PY_VERSION_HEX >= 0x02060000
-  0, /*tp_version_tag*/
-  #endif
-};
+    /* "pysam/ctabix.pyx":937
+ *     """return an iterator over all entries in a file."""
+ *     if PYTHON3:
+ *         return tabix_generic_iterator( infile, parser )             # <<<<<<<<<<<<<<
+ *     else:
+ *         return tabix_file_iterator( infile, parser )
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s_58); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_INCREF(__pyx_v_infile);
+    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_infile);
+    __Pyx_GIVEREF(__pyx_v_infile);
+    __Pyx_INCREF(__pyx_v_parser);
+    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_parser);
+    __Pyx_GIVEREF(__pyx_v_parser);
+    __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+    __pyx_r = __pyx_t_4;
+    __pyx_t_4 = 0;
+    goto __pyx_L0;
+    goto __pyx_L3;
+  }
+  /*else*/ {
 
-static PyObject *__pyx_tp_new_5pysam_6ctabix_TabixIterator(PyTypeObject *t, PyObject *a, PyObject *k) {
+    /* "pysam/ctabix.pyx":939
+ *         return tabix_generic_iterator( infile, parser )
+ *     else:
+ *         return tabix_file_iterator( infile, parser )             # <<<<<<<<<<<<<<
+ * 
+ *     # file objects can use C stdio
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_INCREF(__pyx_v_infile);
+    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_infile);
+    __Pyx_GIVEREF(__pyx_v_infile);
+    __Pyx_INCREF(__pyx_v_parser);
+    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_parser);
+    __Pyx_GIVEREF(__pyx_v_parser);
+    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_6ctabix_tabix_file_iterator)), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
+    __pyx_r = __pyx_t_3;
+    __pyx_t_3 = 0;
+    goto __pyx_L0;
+  }
+  __pyx_L3:;
+
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("pysam.ctabix.tabix_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static struct __pyx_vtabstruct_5pysam_6ctabix_tabix_file_iterator __pyx_vtable_5pysam_6ctabix_tabix_file_iterator;
+
+static PyObject *__pyx_tp_new_5pysam_6ctabix_tabix_file_iterator(PyTypeObject *t, PyObject *a, PyObject *k) {
+  struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *p;
   PyObject *o = (*t->tp_alloc)(t, 0);
   if (!o) return 0;
-  if (__pyx_pw_5pysam_6ctabix_13TabixIterator_1__cinit__(o, a, k) < 0) {
+  p = ((struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *)o);
+  p->__pyx_vtab = __pyx_vtabptr_5pysam_6ctabix_tabix_file_iterator;
+  p->parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)Py_None); Py_INCREF(Py_None);
+  p->infile = Py_None; Py_INCREF(Py_None);
+  if (__pyx_pw_5pysam_6ctabix_19tabix_file_iterator_1__cinit__(o, a, k) < 0) {
     Py_DECREF(o); o = 0;
   }
   return o;
 }
 
-static void __pyx_tp_dealloc_5pysam_6ctabix_TabixIterator(PyObject *o) {
+static void __pyx_tp_dealloc_5pysam_6ctabix_tabix_file_iterator(PyObject *o) {
+  struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *p = (struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *)o;
+  PyObject_GC_UnTrack(o);
   {
     PyObject *etype, *eval, *etb;
     PyErr_Fetch(&etype, &eval, &etb);
     ++Py_REFCNT(o);
-    __pyx_pw_5pysam_6ctabix_13TabixIterator_7__dealloc__(o);
+    __pyx_pw_5pysam_6ctabix_19tabix_file_iterator_5__dealloc__(o);
     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
     --Py_REFCNT(o);
     PyErr_Restore(etype, eval, etb);
   }
+  Py_CLEAR(p->parser);
+  Py_CLEAR(p->infile);
+  PyObject_GC_Track(o);
   (*Py_TYPE(o)->tp_free)(o);
 }
 
-static PyMethodDef __pyx_methods_5pysam_6ctabix_TabixIterator[] = {
-  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_6ctabix_13TabixIterator_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_13TabixIterator_4__next__)},
+static int __pyx_tp_traverse_5pysam_6ctabix_tabix_file_iterator(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *p = (struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *)o;
+  if (p->parser) {
+    e = (*v)(((PyObject*)p->parser), a); if (e) return e;
+  }
+  if (p->infile) {
+    e = (*v)(p->infile, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_5pysam_6ctabix_tabix_file_iterator(PyObject *o) {
+  struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *p = (struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *)o;
+  PyObject* tmp;
+  tmp = ((PyObject*)p->parser);
+  p->parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->infile);
+  p->infile = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyMethodDef __pyx_methods_5pysam_6ctabix_tabix_file_iterator[] = {
+  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_6ctabix_19tabix_file_iterator_7__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)},
+  {__Pyx_NAMESTR("next"), (PyCFunction)__pyx_pw_5pysam_6ctabix_19tabix_file_iterator_9next, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_19tabix_file_iterator_8next)},
   {0, 0, 0, 0}
 };
 
-static PyNumberMethods __pyx_tp_as_number_TabixIterator = {
+static PyNumberMethods __pyx_tp_as_number_tabix_file_iterator = {
   0, /*nb_add*/
   0, /*nb_subtract*/
   0, /*nb_multiply*/
@@ -9343,7 +8918,7 @@ static PyNumberMethods __pyx_tp_as_number_TabixIterator = {
   #endif
 };
 
-static PySequenceMethods __pyx_tp_as_sequence_TabixIterator = {
+static PySequenceMethods __pyx_tp_as_sequence_tabix_file_iterator = {
   0, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
@@ -9356,13 +8931,13 @@ static PySequenceMethods __pyx_tp_as_sequence_TabixIterator = {
   0, /*sq_inplace_repeat*/
 };
 
-static PyMappingMethods __pyx_tp_as_mapping_TabixIterator = {
+static PyMappingMethods __pyx_tp_as_mapping_tabix_file_iterator = {
   0, /*mp_length*/
   0, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
-static PyBufferProcs __pyx_tp_as_buffer_TabixIterator = {
+static PyBufferProcs __pyx_tp_as_buffer_tabix_file_iterator = {
   #if PY_MAJOR_VERSION < 3
   0, /*bf_getreadbuffer*/
   #endif
@@ -9383,12 +8958,12 @@ static PyBufferProcs __pyx_tp_as_buffer_TabixIterator = {
   #endif
 };
 
-static PyTypeObject __pyx_type_5pysam_6ctabix_TabixIterator = {
+static PyTypeObject __pyx_type_5pysam_6ctabix_tabix_file_iterator = {
   PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.ctabix.TabixIterator"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_6ctabix_TabixIterator), /*tp_basicsize*/
+  __Pyx_NAMESTR("pysam.ctabix.tabix_file_iterator"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator), /*tp_basicsize*/
   0, /*tp_itemsize*/
-  __pyx_tp_dealloc_5pysam_6ctabix_TabixIterator, /*tp_dealloc*/
+  __pyx_tp_dealloc_5pysam_6ctabix_tabix_file_iterator, /*tp_dealloc*/
   0, /*tp_print*/
   0, /*tp_getattr*/
   0, /*tp_setattr*/
@@ -9398,24 +8973,24 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_TabixIterator = {
   0, /*reserved*/
   #endif
   0, /*tp_repr*/
-  &__pyx_tp_as_number_TabixIterator, /*tp_as_number*/
-  &__pyx_tp_as_sequence_TabixIterator, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping_TabixIterator, /*tp_as_mapping*/
+  &__pyx_tp_as_number_tabix_file_iterator, /*tp_as_number*/
+  &__pyx_tp_as_sequence_tabix_file_iterator, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_tabix_file_iterator, /*tp_as_mapping*/
   0, /*tp_hash*/
   0, /*tp_call*/
   0, /*tp_str*/
   0, /*tp_getattro*/
   0, /*tp_setattro*/
-  &__pyx_tp_as_buffer_TabixIterator, /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-  __Pyx_DOCSTR("iterates over rows in *tabixfile* in region\n    given by *tid*, *start* and *end*.\n    "), /*tp_doc*/
-  0, /*tp_traverse*/
-  0, /*tp_clear*/
+  &__pyx_tp_as_buffer_tabix_file_iterator, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  __Pyx_DOCSTR("iterate over a compressed or uncompressed ``infile``.\n    "), /*tp_doc*/
+  __pyx_tp_traverse_5pysam_6ctabix_tabix_file_iterator, /*tp_traverse*/
+  __pyx_tp_clear_5pysam_6ctabix_tabix_file_iterator, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
-  __pyx_pw_5pysam_6ctabix_13TabixIterator_3__iter__, /*tp_iter*/
-  __pyx_pw_5pysam_6ctabix_13TabixIterator_5__next__, /*tp_iternext*/
-  __pyx_methods_5pysam_6ctabix_TabixIterator, /*tp_methods*/
+  __pyx_pw_5pysam_6ctabix_19tabix_file_iterator_3__iter__, /*tp_iter*/
+  __pyx_pw_5pysam_6ctabix_19tabix_file_iterator_7__next__, /*tp_iternext*/
+  __pyx_methods_5pysam_6ctabix_tabix_file_iterator, /*tp_methods*/
   0, /*tp_members*/
   0, /*tp_getset*/
   0, /*tp_base*/
@@ -9425,7 +9000,7 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_TabixIterator = {
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_6ctabix_TabixIterator, /*tp_new*/
+  __pyx_tp_new_5pysam_6ctabix_tabix_file_iterator, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -9439,34 +9014,82 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_TabixIterator = {
   #endif
 };
 
-static PyObject *__pyx_tp_new_5pysam_6ctabix_TabixHeaderIterator(PyTypeObject *t, PyObject *a, PyObject *k) {
+static PyObject *__pyx_tp_new_5pysam_6ctabix_Tabixfile(PyTypeObject *t, PyObject *a, PyObject *k) {
+  struct __pyx_obj_5pysam_6ctabix_Tabixfile *p;
   PyObject *o = (*t->tp_alloc)(t, 0);
   if (!o) return 0;
-  if (__pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_1__cinit__(o, a, k) < 0) {
+  p = ((struct __pyx_obj_5pysam_6ctabix_Tabixfile *)o);
+  p->parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)Py_None); Py_INCREF(Py_None);
+  if (__pyx_pw_5pysam_6ctabix_9Tabixfile_1__cinit__(o, a, k) < 0) {
     Py_DECREF(o); o = 0;
   }
   return o;
 }
 
-static void __pyx_tp_dealloc_5pysam_6ctabix_TabixHeaderIterator(PyObject *o) {
+static void __pyx_tp_dealloc_5pysam_6ctabix_Tabixfile(PyObject *o) {
+  struct __pyx_obj_5pysam_6ctabix_Tabixfile *p = (struct __pyx_obj_5pysam_6ctabix_Tabixfile *)o;
+  PyObject_GC_UnTrack(o);
   {
     PyObject *etype, *eval, *etb;
     PyErr_Fetch(&etype, &eval, &etb);
     ++Py_REFCNT(o);
-    __pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_7__dealloc__(o);
+    __pyx_pw_5pysam_6ctabix_9Tabixfile_13__dealloc__(o);
     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
     --Py_REFCNT(o);
     PyErr_Restore(etype, eval, etb);
   }
+  Py_CLEAR(p->parser);
+  PyObject_GC_Track(o);
   (*Py_TYPE(o)->tp_free)(o);
 }
 
-static PyMethodDef __pyx_methods_5pysam_6ctabix_TabixHeaderIterator[] = {
-  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_19TabixHeaderIterator_4__next__)},
+static int __pyx_tp_traverse_5pysam_6ctabix_Tabixfile(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_5pysam_6ctabix_Tabixfile *p = (struct __pyx_obj_5pysam_6ctabix_Tabixfile *)o;
+  if (p->parser) {
+    e = (*v)(((PyObject*)p->parser), a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_5pysam_6ctabix_Tabixfile(PyObject *o) {
+  struct __pyx_obj_5pysam_6ctabix_Tabixfile *p = (struct __pyx_obj_5pysam_6ctabix_Tabixfile *)o;
+  PyObject* tmp;
+  tmp = ((PyObject*)p->parser);
+  p->parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyObject *__pyx_getprop_5pysam_6ctabix_9Tabixfile_filename(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_5pysam_6ctabix_9Tabixfile_8filename_1__get__(o);
+}
+
+static PyObject *__pyx_getprop_5pysam_6ctabix_9Tabixfile_header(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_5pysam_6ctabix_9Tabixfile_6header_1__get__(o);
+}
+
+static PyObject *__pyx_getprop_5pysam_6ctabix_9Tabixfile_contigs(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_5pysam_6ctabix_9Tabixfile_7contigs_1__get__(o);
+}
+
+static PyMethodDef __pyx_methods_5pysam_6ctabix_Tabixfile[] = {
+  {__Pyx_NAMESTR("_isOpen"), (PyCFunction)__pyx_pw_5pysam_6ctabix_9Tabixfile_3_isOpen, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_9Tabixfile_2_isOpen)},
+  {__Pyx_NAMESTR("_open"), (PyCFunction)__pyx_pw_5pysam_6ctabix_9Tabixfile_5_open, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_9Tabixfile_4_open)},
+  {__Pyx_NAMESTR("_parseRegion"), (PyCFunction)__pyx_pw_5pysam_6ctabix_9Tabixfile_7_parseRegion, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_9Tabixfile_6_parseRegion)},
+  {__Pyx_NAMESTR("fetch"), (PyCFunction)__pyx_pw_5pysam_6ctabix_9Tabixfile_9fetch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_9Tabixfile_8fetch)},
+  {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pw_5pysam_6ctabix_9Tabixfile_11close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_9Tabixfile_10close)},
   {0, 0, 0, 0}
 };
 
-static PyNumberMethods __pyx_tp_as_number_TabixHeaderIterator = {
+static struct PyGetSetDef __pyx_getsets_5pysam_6ctabix_Tabixfile[] = {
+  {(char *)"filename", __pyx_getprop_5pysam_6ctabix_9Tabixfile_filename, 0, __Pyx_DOCSTR(__pyx_k_59), 0},
+  {(char *)"header", __pyx_getprop_5pysam_6ctabix_9Tabixfile_header, 0, __Pyx_DOCSTR(__pyx_k_60), 0},
+  {(char *)"contigs", __pyx_getprop_5pysam_6ctabix_9Tabixfile_contigs, 0, __Pyx_DOCSTR(__pyx_k_61), 0},
+  {0, 0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_Tabixfile = {
   0, /*nb_add*/
   0, /*nb_subtract*/
   0, /*nb_multiply*/
@@ -9524,7 +9147,7 @@ static PyNumberMethods __pyx_tp_as_number_TabixHeaderIterator = {
   #endif
 };
 
-static PySequenceMethods __pyx_tp_as_sequence_TabixHeaderIterator = {
+static PySequenceMethods __pyx_tp_as_sequence_Tabixfile = {
   0, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
@@ -9537,13 +9160,13 @@ static PySequenceMethods __pyx_tp_as_sequence_TabixHeaderIterator = {
   0, /*sq_inplace_repeat*/
 };
 
-static PyMappingMethods __pyx_tp_as_mapping_TabixHeaderIterator = {
+static PyMappingMethods __pyx_tp_as_mapping_Tabixfile = {
   0, /*mp_length*/
   0, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
-static PyBufferProcs __pyx_tp_as_buffer_TabixHeaderIterator = {
+static PyBufferProcs __pyx_tp_as_buffer_Tabixfile = {
   #if PY_MAJOR_VERSION < 3
   0, /*bf_getreadbuffer*/
   #endif
@@ -9564,12 +9187,12 @@ static PyBufferProcs __pyx_tp_as_buffer_TabixHeaderIterator = {
   #endif
 };
 
-static PyTypeObject __pyx_type_5pysam_6ctabix_TabixHeaderIterator = {
+static PyTypeObject __pyx_type_5pysam_6ctabix_Tabixfile = {
   PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.ctabix.TabixHeaderIterator"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator), /*tp_basicsize*/
+  __Pyx_NAMESTR("pysam.ctabix.Tabixfile"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_6ctabix_Tabixfile), /*tp_basicsize*/
   0, /*tp_itemsize*/
-  __pyx_tp_dealloc_5pysam_6ctabix_TabixHeaderIterator, /*tp_dealloc*/
+  __pyx_tp_dealloc_5pysam_6ctabix_Tabixfile, /*tp_dealloc*/
   0, /*tp_print*/
   0, /*tp_getattr*/
   0, /*tp_setattr*/
@@ -9579,26 +9202,26 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_TabixHeaderIterator = {
   0, /*reserved*/
   #endif
   0, /*tp_repr*/
-  &__pyx_tp_as_number_TabixHeaderIterator, /*tp_as_number*/
-  &__pyx_tp_as_sequence_TabixHeaderIterator, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping_TabixHeaderIterator, /*tp_as_mapping*/
+  &__pyx_tp_as_number_Tabixfile, /*tp_as_number*/
+  &__pyx_tp_as_sequence_Tabixfile, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_Tabixfile, /*tp_as_mapping*/
   0, /*tp_hash*/
   0, /*tp_call*/
   0, /*tp_str*/
   0, /*tp_getattro*/
   0, /*tp_setattro*/
-  &__pyx_tp_as_buffer_TabixHeaderIterator, /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-  __Pyx_DOCSTR("return header lines.\n    "), /*tp_doc*/
-  0, /*tp_traverse*/
-  0, /*tp_clear*/
+  &__pyx_tp_as_buffer_Tabixfile, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  __Pyx_DOCSTR("*(filename, mode='r', parser = None)*\n\n    opens a :term:`tabix file` for reading. A missing\n    index (*filename* + \".tbi\") will raise an exception.\n\n    *parser* sets the default parser for this tabix file. If *parser*\n    is None, the results are returned as an unparsed string.\n    Otherwise, *parser* is assumed to be a functor that will return\n    parsed data (see for example :meth:`asTuple` and :meth:`asGTF`).\n    "), /*tp_doc*/
+  __pyx_tp_traverse_5pysam_6ctabix_Tabixfile, /*tp_traverse*/
+  __pyx_tp_clear_5pysam_6ctabix_Tabixfile, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
-  __pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_3__iter__, /*tp_iter*/
-  __pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_5__next__, /*tp_iternext*/
-  __pyx_methods_5pysam_6ctabix_TabixHeaderIterator, /*tp_methods*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_5pysam_6ctabix_Tabixfile, /*tp_methods*/
   0, /*tp_members*/
-  0, /*tp_getset*/
+  __pyx_getsets_5pysam_6ctabix_Tabixfile, /*tp_getset*/
   0, /*tp_base*/
   0, /*tp_dict*/
   0, /*tp_descr_get*/
@@ -9606,7 +9229,7 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_TabixHeaderIterator = {
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_6ctabix_TabixHeaderIterator, /*tp_new*/
+  __pyx_tp_new_5pysam_6ctabix_Tabixfile, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -9620,21 +9243,34 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_TabixHeaderIterator = {
   #endif
 };
 
-static PyObject *__pyx_tp_new_5pysam_6ctabix_Parser(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+static PyObject *__pyx_tp_new_5pysam_6ctabix_TabixIterator(PyTypeObject *t, PyObject *a, PyObject *k) {
   PyObject *o = (*t->tp_alloc)(t, 0);
   if (!o) return 0;
+  if (__pyx_pw_5pysam_6ctabix_13TabixIterator_1__cinit__(o, a, k) < 0) {
+    Py_DECREF(o); o = 0;
+  }
   return o;
 }
 
-static void __pyx_tp_dealloc_5pysam_6ctabix_Parser(PyObject *o) {
+static void __pyx_tp_dealloc_5pysam_6ctabix_TabixIterator(PyObject *o) {
+  {
+    PyObject *etype, *eval, *etb;
+    PyErr_Fetch(&etype, &eval, &etb);
+    ++Py_REFCNT(o);
+    __pyx_pw_5pysam_6ctabix_13TabixIterator_7__dealloc__(o);
+    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
+    --Py_REFCNT(o);
+    PyErr_Restore(etype, eval, etb);
+  }
   (*Py_TYPE(o)->tp_free)(o);
 }
 
-static PyMethodDef __pyx_methods_5pysam_6ctabix_Parser[] = {
+static PyMethodDef __pyx_methods_5pysam_6ctabix_TabixIterator[] = {
+  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_6ctabix_13TabixIterator_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_13TabixIterator_4__next__)},
   {0, 0, 0, 0}
 };
 
-static PyNumberMethods __pyx_tp_as_number_Parser = {
+static PyNumberMethods __pyx_tp_as_number_TabixIterator = {
   0, /*nb_add*/
   0, /*nb_subtract*/
   0, /*nb_multiply*/
@@ -9692,7 +9328,7 @@ static PyNumberMethods __pyx_tp_as_number_Parser = {
   #endif
 };
 
-static PySequenceMethods __pyx_tp_as_sequence_Parser = {
+static PySequenceMethods __pyx_tp_as_sequence_TabixIterator = {
   0, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
@@ -9705,13 +9341,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Parser = {
   0, /*sq_inplace_repeat*/
 };
 
-static PyMappingMethods __pyx_tp_as_mapping_Parser = {
+static PyMappingMethods __pyx_tp_as_mapping_TabixIterator = {
   0, /*mp_length*/
   0, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
-static PyBufferProcs __pyx_tp_as_buffer_Parser = {
+static PyBufferProcs __pyx_tp_as_buffer_TabixIterator = {
   #if PY_MAJOR_VERSION < 3
   0, /*bf_getreadbuffer*/
   #endif
@@ -9732,12 +9368,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Parser = {
   #endif
 };
 
-static PyTypeObject __pyx_type_5pysam_6ctabix_Parser = {
+static PyTypeObject __pyx_type_5pysam_6ctabix_TabixIterator = {
   PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.ctabix.Parser"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_6ctabix_Parser), /*tp_basicsize*/
+  __Pyx_NAMESTR("pysam.ctabix.TabixIterator"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_6ctabix_TabixIterator), /*tp_basicsize*/
   0, /*tp_itemsize*/
-  __pyx_tp_dealloc_5pysam_6ctabix_Parser, /*tp_dealloc*/
+  __pyx_tp_dealloc_5pysam_6ctabix_TabixIterator, /*tp_dealloc*/
   0, /*tp_print*/
   0, /*tp_getattr*/
   0, /*tp_setattr*/
@@ -9747,24 +9383,24 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_Parser = {
   0, /*reserved*/
   #endif
   0, /*tp_repr*/
-  &__pyx_tp_as_number_Parser, /*tp_as_number*/
-  &__pyx_tp_as_sequence_Parser, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping_Parser, /*tp_as_mapping*/
+  &__pyx_tp_as_number_TabixIterator, /*tp_as_number*/
+  &__pyx_tp_as_sequence_TabixIterator, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_TabixIterator, /*tp_as_mapping*/
   0, /*tp_hash*/
   0, /*tp_call*/
   0, /*tp_str*/
   0, /*tp_getattro*/
   0, /*tp_setattro*/
-  &__pyx_tp_as_buffer_Parser, /*tp_as_buffer*/
+  &__pyx_tp_as_buffer_TabixIterator, /*tp_as_buffer*/
   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-  0, /*tp_doc*/
+  __Pyx_DOCSTR("iterates over rows in *tabixfile* in region\n    given by *tid*, *start* and *end*.\n    "), /*tp_doc*/
   0, /*tp_traverse*/
   0, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
-  0, /*tp_iter*/
-  0, /*tp_iternext*/
-  __pyx_methods_5pysam_6ctabix_Parser, /*tp_methods*/
+  __pyx_pw_5pysam_6ctabix_13TabixIterator_3__iter__, /*tp_iter*/
+  __pyx_pw_5pysam_6ctabix_13TabixIterator_5__next__, /*tp_iternext*/
+  __pyx_methods_5pysam_6ctabix_TabixIterator, /*tp_methods*/
   0, /*tp_members*/
   0, /*tp_getset*/
   0, /*tp_base*/
@@ -9774,7 +9410,7 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_Parser = {
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_6ctabix_Parser, /*tp_new*/
+  __pyx_tp_new_5pysam_6ctabix_TabixIterator, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -9788,17 +9424,34 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_Parser = {
   #endif
 };
 
-static PyObject *__pyx_tp_new_5pysam_6ctabix_asTuple(PyTypeObject *t, PyObject *a, PyObject *k) {
-  PyObject *o = __pyx_tp_new_5pysam_6ctabix_Parser(t, a, k);
+static PyObject *__pyx_tp_new_5pysam_6ctabix_TabixHeaderIterator(PyTypeObject *t, PyObject *a, PyObject *k) {
+  PyObject *o = (*t->tp_alloc)(t, 0);
   if (!o) return 0;
+  if (__pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_1__cinit__(o, a, k) < 0) {
+    Py_DECREF(o); o = 0;
+  }
   return o;
 }
 
-static PyMethodDef __pyx_methods_5pysam_6ctabix_asTuple[] = {
+static void __pyx_tp_dealloc_5pysam_6ctabix_TabixHeaderIterator(PyObject *o) {
+  {
+    PyObject *etype, *eval, *etb;
+    PyErr_Fetch(&etype, &eval, &etb);
+    ++Py_REFCNT(o);
+    __pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_7__dealloc__(o);
+    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
+    --Py_REFCNT(o);
+    PyErr_Restore(etype, eval, etb);
+  }
+  (*Py_TYPE(o)->tp_free)(o);
+}
+
+static PyMethodDef __pyx_methods_5pysam_6ctabix_TabixHeaderIterator[] = {
+  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_19TabixHeaderIterator_4__next__)},
   {0, 0, 0, 0}
 };
 
-static PyNumberMethods __pyx_tp_as_number_asTuple = {
+static PyNumberMethods __pyx_tp_as_number_TabixHeaderIterator = {
   0, /*nb_add*/
   0, /*nb_subtract*/
   0, /*nb_multiply*/
@@ -9856,7 +9509,7 @@ static PyNumberMethods __pyx_tp_as_number_asTuple = {
   #endif
 };
 
-static PySequenceMethods __pyx_tp_as_sequence_asTuple = {
+static PySequenceMethods __pyx_tp_as_sequence_TabixHeaderIterator = {
   0, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
@@ -9869,13 +9522,13 @@ static PySequenceMethods __pyx_tp_as_sequence_asTuple = {
   0, /*sq_inplace_repeat*/
 };
 
-static PyMappingMethods __pyx_tp_as_mapping_asTuple = {
+static PyMappingMethods __pyx_tp_as_mapping_TabixHeaderIterator = {
   0, /*mp_length*/
   0, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
-static PyBufferProcs __pyx_tp_as_buffer_asTuple = {
+static PyBufferProcs __pyx_tp_as_buffer_TabixHeaderIterator = {
   #if PY_MAJOR_VERSION < 3
   0, /*bf_getreadbuffer*/
   #endif
@@ -9896,12 +9549,12 @@ static PyBufferProcs __pyx_tp_as_buffer_asTuple = {
   #endif
 };
 
-static PyTypeObject __pyx_type_5pysam_6ctabix_asTuple = {
+static PyTypeObject __pyx_type_5pysam_6ctabix_TabixHeaderIterator = {
   PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.ctabix.asTuple"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_6ctabix_asTuple), /*tp_basicsize*/
+  __Pyx_NAMESTR("pysam.ctabix.TabixHeaderIterator"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator), /*tp_basicsize*/
   0, /*tp_itemsize*/
-  __pyx_tp_dealloc_5pysam_6ctabix_Parser, /*tp_dealloc*/
+  __pyx_tp_dealloc_5pysam_6ctabix_TabixHeaderIterator, /*tp_dealloc*/
   0, /*tp_print*/
   0, /*tp_getattr*/
   0, /*tp_setattr*/
@@ -9911,24 +9564,24 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_asTuple = {
   0, /*reserved*/
   #endif
   0, /*tp_repr*/
-  &__pyx_tp_as_number_asTuple, /*tp_as_number*/
-  &__pyx_tp_as_sequence_asTuple, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping_asTuple, /*tp_as_mapping*/
+  &__pyx_tp_as_number_TabixHeaderIterator, /*tp_as_number*/
+  &__pyx_tp_as_sequence_TabixHeaderIterator, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_TabixHeaderIterator, /*tp_as_mapping*/
   0, /*tp_hash*/
-  __pyx_pw_5pysam_6ctabix_7asTuple_1__call__, /*tp_call*/
+  0, /*tp_call*/
   0, /*tp_str*/
   0, /*tp_getattro*/
   0, /*tp_setattro*/
-  &__pyx_tp_as_buffer_asTuple, /*tp_as_buffer*/
+  &__pyx_tp_as_buffer_TabixHeaderIterator, /*tp_as_buffer*/
   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-  __Pyx_DOCSTR("converts a :term:`tabix row` into a python tuple.\n\n    Access is by numeric index.\n    "), /*tp_doc*/
+  __Pyx_DOCSTR("return header lines.\n    "), /*tp_doc*/
   0, /*tp_traverse*/
   0, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
-  0, /*tp_iter*/
-  0, /*tp_iternext*/
-  __pyx_methods_5pysam_6ctabix_asTuple, /*tp_methods*/
+  __pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_3__iter__, /*tp_iter*/
+  __pyx_pw_5pysam_6ctabix_19TabixHeaderIterator_5__next__, /*tp_iternext*/
+  __pyx_methods_5pysam_6ctabix_TabixHeaderIterator, /*tp_methods*/
   0, /*tp_members*/
   0, /*tp_getset*/
   0, /*tp_base*/
@@ -9938,7 +9591,7 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_asTuple = {
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_6ctabix_asTuple, /*tp_new*/
+  __pyx_tp_new_5pysam_6ctabix_TabixHeaderIterator, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -9951,18 +9604,26 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_asTuple = {
   0, /*tp_version_tag*/
   #endif
 };
+static struct __pyx_vtabstruct_5pysam_6ctabix_Parser __pyx_vtable_5pysam_6ctabix_Parser;
 
-static PyObject *__pyx_tp_new_5pysam_6ctabix_asGTF(PyTypeObject *t, PyObject *a, PyObject *k) {
-  PyObject *o = __pyx_tp_new_5pysam_6ctabix_Parser(t, a, k);
+static PyObject *__pyx_tp_new_5pysam_6ctabix_Parser(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  struct __pyx_obj_5pysam_6ctabix_Parser *p;
+  PyObject *o = (*t->tp_alloc)(t, 0);
   if (!o) return 0;
+  p = ((struct __pyx_obj_5pysam_6ctabix_Parser *)o);
+  p->__pyx_vtab = __pyx_vtabptr_5pysam_6ctabix_Parser;
   return o;
 }
 
-static PyMethodDef __pyx_methods_5pysam_6ctabix_asGTF[] = {
+static void __pyx_tp_dealloc_5pysam_6ctabix_Parser(PyObject *o) {
+  (*Py_TYPE(o)->tp_free)(o);
+}
+
+static PyMethodDef __pyx_methods_5pysam_6ctabix_Parser[] = {
   {0, 0, 0, 0}
 };
 
-static PyNumberMethods __pyx_tp_as_number_asGTF = {
+static PyNumberMethods __pyx_tp_as_number_Parser = {
   0, /*nb_add*/
   0, /*nb_subtract*/
   0, /*nb_multiply*/
@@ -10020,7 +9681,7 @@ static PyNumberMethods __pyx_tp_as_number_asGTF = {
   #endif
 };
 
-static PySequenceMethods __pyx_tp_as_sequence_asGTF = {
+static PySequenceMethods __pyx_tp_as_sequence_Parser = {
   0, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
@@ -10033,13 +9694,13 @@ static PySequenceMethods __pyx_tp_as_sequence_asGTF = {
   0, /*sq_inplace_repeat*/
 };
 
-static PyMappingMethods __pyx_tp_as_mapping_asGTF = {
+static PyMappingMethods __pyx_tp_as_mapping_Parser = {
   0, /*mp_length*/
   0, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
-static PyBufferProcs __pyx_tp_as_buffer_asGTF = {
+static PyBufferProcs __pyx_tp_as_buffer_Parser = {
   #if PY_MAJOR_VERSION < 3
   0, /*bf_getreadbuffer*/
   #endif
@@ -10060,10 +9721,10 @@ static PyBufferProcs __pyx_tp_as_buffer_asGTF = {
   #endif
 };
 
-static PyTypeObject __pyx_type_5pysam_6ctabix_asGTF = {
+static PyTypeObject __pyx_type_5pysam_6ctabix_Parser = {
   PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.ctabix.asGTF"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_6ctabix_asGTF), /*tp_basicsize*/
+  __Pyx_NAMESTR("pysam.ctabix.Parser"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_6ctabix_Parser), /*tp_basicsize*/
   0, /*tp_itemsize*/
   __pyx_tp_dealloc_5pysam_6ctabix_Parser, /*tp_dealloc*/
   0, /*tp_print*/
@@ -10075,24 +9736,24 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_asGTF = {
   0, /*reserved*/
   #endif
   0, /*tp_repr*/
-  &__pyx_tp_as_number_asGTF, /*tp_as_number*/
-  &__pyx_tp_as_sequence_asGTF, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping_asGTF, /*tp_as_mapping*/
+  &__pyx_tp_as_number_Parser, /*tp_as_number*/
+  &__pyx_tp_as_sequence_Parser, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_Parser, /*tp_as_mapping*/
   0, /*tp_hash*/
-  __pyx_pw_5pysam_6ctabix_5asGTF_1__call__, /*tp_call*/
+  __pyx_pw_5pysam_6ctabix_6Parser_1__call__, /*tp_call*/
   0, /*tp_str*/
   0, /*tp_getattro*/
   0, /*tp_setattro*/
-  &__pyx_tp_as_buffer_asGTF, /*tp_as_buffer*/
+  &__pyx_tp_as_buffer_Parser, /*tp_as_buffer*/
   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-  __Pyx_DOCSTR("converts a :term:`tabix row` into a GTF record with the following \n    fields:\n\n    contig\n       contig\n    feature\n       feature\n    source\n       source\n    start\n       genomic start coordinate (0-based)\n    end\n       genomic end coordinate plus one (0-based)\n    score\n       feature score\n    strand\n       strand\n    frame\n       frame\n    attributes\n       attribute string.\n\n    GTF formatted entries also defined the attributes:\n\n    gene_i [...]
+  0, /*tp_doc*/
   0, /*tp_traverse*/
   0, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
   0, /*tp_iter*/
   0, /*tp_iternext*/
-  __pyx_methods_5pysam_6ctabix_asGTF, /*tp_methods*/
+  __pyx_methods_5pysam_6ctabix_Parser, /*tp_methods*/
   0, /*tp_members*/
   0, /*tp_getset*/
   0, /*tp_base*/
@@ -10102,7 +9763,7 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_asGTF = {
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_6ctabix_asGTF, /*tp_new*/
+  __pyx_tp_new_5pysam_6ctabix_Parser, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -10115,18 +9776,22 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_asGTF = {
   0, /*tp_version_tag*/
   #endif
 };
+static struct __pyx_vtabstruct_5pysam_6ctabix_asTuple __pyx_vtable_5pysam_6ctabix_asTuple;
 
-static PyObject *__pyx_tp_new_5pysam_6ctabix_asBed(PyTypeObject *t, PyObject *a, PyObject *k) {
+static PyObject *__pyx_tp_new_5pysam_6ctabix_asTuple(PyTypeObject *t, PyObject *a, PyObject *k) {
+  struct __pyx_obj_5pysam_6ctabix_asTuple *p;
   PyObject *o = __pyx_tp_new_5pysam_6ctabix_Parser(t, a, k);
   if (!o) return 0;
+  p = ((struct __pyx_obj_5pysam_6ctabix_asTuple *)o);
+  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_6ctabix_Parser*)__pyx_vtabptr_5pysam_6ctabix_asTuple;
   return o;
 }
 
-static PyMethodDef __pyx_methods_5pysam_6ctabix_asBed[] = {
+static PyMethodDef __pyx_methods_5pysam_6ctabix_asTuple[] = {
   {0, 0, 0, 0}
 };
 
-static PyNumberMethods __pyx_tp_as_number_asBed = {
+static PyNumberMethods __pyx_tp_as_number_asTuple = {
   0, /*nb_add*/
   0, /*nb_subtract*/
   0, /*nb_multiply*/
@@ -10184,7 +9849,7 @@ static PyNumberMethods __pyx_tp_as_number_asBed = {
   #endif
 };
 
-static PySequenceMethods __pyx_tp_as_sequence_asBed = {
+static PySequenceMethods __pyx_tp_as_sequence_asTuple = {
   0, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
@@ -10197,13 +9862,13 @@ static PySequenceMethods __pyx_tp_as_sequence_asBed = {
   0, /*sq_inplace_repeat*/
 };
 
-static PyMappingMethods __pyx_tp_as_mapping_asBed = {
+static PyMappingMethods __pyx_tp_as_mapping_asTuple = {
   0, /*mp_length*/
   0, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
-static PyBufferProcs __pyx_tp_as_buffer_asBed = {
+static PyBufferProcs __pyx_tp_as_buffer_asTuple = {
   #if PY_MAJOR_VERSION < 3
   0, /*bf_getreadbuffer*/
   #endif
@@ -10224,10 +9889,10 @@ static PyBufferProcs __pyx_tp_as_buffer_asBed = {
   #endif
 };
 
-static PyTypeObject __pyx_type_5pysam_6ctabix_asBed = {
+static PyTypeObject __pyx_type_5pysam_6ctabix_asTuple = {
   PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.ctabix.asBed"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_6ctabix_asBed), /*tp_basicsize*/
+  __Pyx_NAMESTR("pysam.ctabix.asTuple"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_6ctabix_asTuple), /*tp_basicsize*/
   0, /*tp_itemsize*/
   __pyx_tp_dealloc_5pysam_6ctabix_Parser, /*tp_dealloc*/
   0, /*tp_print*/
@@ -10239,24 +9904,28 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_asBed = {
   0, /*reserved*/
   #endif
   0, /*tp_repr*/
-  &__pyx_tp_as_number_asBed, /*tp_as_number*/
-  &__pyx_tp_as_sequence_asBed, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping_asBed, /*tp_as_mapping*/
+  &__pyx_tp_as_number_asTuple, /*tp_as_number*/
+  &__pyx_tp_as_sequence_asTuple, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_asTuple, /*tp_as_mapping*/
   0, /*tp_hash*/
-  __pyx_pw_5pysam_6ctabix_5asBed_1__call__, /*tp_call*/
+  #if CYTHON_COMPILING_IN_PYPY
+  __pyx_pw_5pysam_6ctabix_6Parser_1__call__, /*tp_call*/
+  #else
+  0, /*tp_call*/
+  #endif
   0, /*tp_str*/
   0, /*tp_getattro*/
   0, /*tp_setattro*/
-  &__pyx_tp_as_buffer_asBed, /*tp_as_buffer*/
+  &__pyx_tp_as_buffer_asTuple, /*tp_as_buffer*/
   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-  __Pyx_DOCSTR("converts a :term:`tabix row` into a bed record\n    with the following fields:\n\n    contig\n       contig\n    start\n       genomic start coordinate (zero-based)\n    end\n       genomic end coordinate plus one (zero-based)\n    name\n       name of feature.\n    score\n       score of feature\n    strand\n       strand of feature\n    thickStart\n       thickStart\n    thickEnd\n       thickEnd\n    itemRGB\n       itemRGB\n    blockCount\n       number of bocks\n     [...]
+  __Pyx_DOCSTR("converts a :term:`tabix row` into a python tuple.\n\n    Access is by numeric index.\n    "), /*tp_doc*/
   0, /*tp_traverse*/
   0, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
   0, /*tp_iter*/
   0, /*tp_iternext*/
-  __pyx_methods_5pysam_6ctabix_asBed, /*tp_methods*/
+  __pyx_methods_5pysam_6ctabix_asTuple, /*tp_methods*/
   0, /*tp_members*/
   0, /*tp_getset*/
   0, /*tp_base*/
@@ -10266,7 +9935,7 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_asBed = {
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_6ctabix_asBed, /*tp_new*/
+  __pyx_tp_new_5pysam_6ctabix_asTuple, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -10279,18 +9948,22 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_asBed = {
   0, /*tp_version_tag*/
   #endif
 };
+static struct __pyx_vtabstruct_5pysam_6ctabix_asGTF __pyx_vtable_5pysam_6ctabix_asGTF;
 
-static PyObject *__pyx_tp_new_5pysam_6ctabix_asVCF(PyTypeObject *t, PyObject *a, PyObject *k) {
+static PyObject *__pyx_tp_new_5pysam_6ctabix_asGTF(PyTypeObject *t, PyObject *a, PyObject *k) {
+  struct __pyx_obj_5pysam_6ctabix_asGTF *p;
   PyObject *o = __pyx_tp_new_5pysam_6ctabix_Parser(t, a, k);
   if (!o) return 0;
+  p = ((struct __pyx_obj_5pysam_6ctabix_asGTF *)o);
+  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_6ctabix_Parser*)__pyx_vtabptr_5pysam_6ctabix_asGTF;
   return o;
 }
 
-static PyMethodDef __pyx_methods_5pysam_6ctabix_asVCF[] = {
+static PyMethodDef __pyx_methods_5pysam_6ctabix_asGTF[] = {
   {0, 0, 0, 0}
 };
 
-static PyNumberMethods __pyx_tp_as_number_asVCF = {
+static PyNumberMethods __pyx_tp_as_number_asGTF = {
   0, /*nb_add*/
   0, /*nb_subtract*/
   0, /*nb_multiply*/
@@ -10348,7 +10021,7 @@ static PyNumberMethods __pyx_tp_as_number_asVCF = {
   #endif
 };
 
-static PySequenceMethods __pyx_tp_as_sequence_asVCF = {
+static PySequenceMethods __pyx_tp_as_sequence_asGTF = {
   0, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
@@ -10361,13 +10034,13 @@ static PySequenceMethods __pyx_tp_as_sequence_asVCF = {
   0, /*sq_inplace_repeat*/
 };
 
-static PyMappingMethods __pyx_tp_as_mapping_asVCF = {
+static PyMappingMethods __pyx_tp_as_mapping_asGTF = {
   0, /*mp_length*/
   0, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
-static PyBufferProcs __pyx_tp_as_buffer_asVCF = {
+static PyBufferProcs __pyx_tp_as_buffer_asGTF = {
   #if PY_MAJOR_VERSION < 3
   0, /*bf_getreadbuffer*/
   #endif
@@ -10388,10 +10061,10 @@ static PyBufferProcs __pyx_tp_as_buffer_asVCF = {
   #endif
 };
 
-static PyTypeObject __pyx_type_5pysam_6ctabix_asVCF = {
+static PyTypeObject __pyx_type_5pysam_6ctabix_asGTF = {
   PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.ctabix.asVCF"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_6ctabix_asVCF), /*tp_basicsize*/
+  __Pyx_NAMESTR("pysam.ctabix.asGTF"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_6ctabix_asGTF), /*tp_basicsize*/
   0, /*tp_itemsize*/
   __pyx_tp_dealloc_5pysam_6ctabix_Parser, /*tp_dealloc*/
   0, /*tp_print*/
@@ -10403,24 +10076,28 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_asVCF = {
   0, /*reserved*/
   #endif
   0, /*tp_repr*/
-  &__pyx_tp_as_number_asVCF, /*tp_as_number*/
-  &__pyx_tp_as_sequence_asVCF, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping_asVCF, /*tp_as_mapping*/
+  &__pyx_tp_as_number_asGTF, /*tp_as_number*/
+  &__pyx_tp_as_sequence_asGTF, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_asGTF, /*tp_as_mapping*/
   0, /*tp_hash*/
-  __pyx_pw_5pysam_6ctabix_5asVCF_1__call__, /*tp_call*/
+  #if CYTHON_COMPILING_IN_PYPY
+  __pyx_pw_5pysam_6ctabix_6Parser_1__call__, /*tp_call*/
+  #else
+  0, /*tp_call*/
+  #endif
   0, /*tp_str*/
   0, /*tp_getattro*/
   0, /*tp_setattro*/
-  &__pyx_tp_as_buffer_asVCF, /*tp_as_buffer*/
+  &__pyx_tp_as_buffer_asGTF, /*tp_as_buffer*/
   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-  __Pyx_DOCSTR("converts a :term:`tabix row` into a VCF record with\n    the following fields:\n    \n    contig\n       contig\n    pos\n       chromosomal position, zero-based\n    id \n       id\n    ref\n       reference\n    alt\n       alt\n    qual\n       qual\n    filter\n       filter\n    info\n       info\n    format\n       format specifier.\n\n    Access to genotypes is via index::\n\n        contig = vcf.contig\n        first_sample_genotype = vcf[0]\n        second_sample [...]
+  __Pyx_DOCSTR("converts a :term:`tabix row` into a GTF record with the following \n    fields:\n\n    contig\n       contig\n    feature\n       feature\n    source\n       source\n    start\n       genomic start coordinate (0-based)\n    end\n       genomic end coordinate plus one (0-based)\n    score\n       feature score\n    strand\n       strand\n    frame\n       frame\n    attributes\n       attribute string.\n\n    GTF formatted entries also defined the attributes:\n\n    gene_i [...]
   0, /*tp_traverse*/
   0, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
   0, /*tp_iter*/
   0, /*tp_iternext*/
-  __pyx_methods_5pysam_6ctabix_asVCF, /*tp_methods*/
+  __pyx_methods_5pysam_6ctabix_asGTF, /*tp_methods*/
   0, /*tp_members*/
   0, /*tp_getset*/
   0, /*tp_base*/
@@ -10430,7 +10107,7 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_asVCF = {
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_6ctabix_asVCF, /*tp_new*/
+  __pyx_tp_new_5pysam_6ctabix_asGTF, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -10443,60 +10120,22 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_asVCF = {
   0, /*tp_version_tag*/
   #endif
 };
+static struct __pyx_vtabstruct_5pysam_6ctabix_asBed __pyx_vtable_5pysam_6ctabix_asBed;
 
-static PyObject *__pyx_tp_new_5pysam_6ctabix_TabixIteratorParsed(PyTypeObject *t, PyObject *a, PyObject *k) {
-  struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *p;
-  PyObject *o = (*t->tp_alloc)(t, 0);
+static PyObject *__pyx_tp_new_5pysam_6ctabix_asBed(PyTypeObject *t, PyObject *a, PyObject *k) {
+  struct __pyx_obj_5pysam_6ctabix_asBed *p;
+  PyObject *o = __pyx_tp_new_5pysam_6ctabix_Parser(t, a, k);
   if (!o) return 0;
-  p = ((struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *)o);
-  p->parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)Py_None); Py_INCREF(Py_None);
-  if (__pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_1__cinit__(o, a, k) < 0) {
-    Py_DECREF(o); o = 0;
-  }
+  p = ((struct __pyx_obj_5pysam_6ctabix_asBed *)o);
+  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_6ctabix_Parser*)__pyx_vtabptr_5pysam_6ctabix_asBed;
   return o;
 }
 
-static void __pyx_tp_dealloc_5pysam_6ctabix_TabixIteratorParsed(PyObject *o) {
-  struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *p = (struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *)o;
-  PyObject_GC_UnTrack(o);
-  {
-    PyObject *etype, *eval, *etb;
-    PyErr_Fetch(&etype, &eval, &etb);
-    ++Py_REFCNT(o);
-    __pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_7__dealloc__(o);
-    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
-    --Py_REFCNT(o);
-    PyErr_Restore(etype, eval, etb);
-  }
-  Py_CLEAR(p->parser);
-  PyObject_GC_Track(o);
-  (*Py_TYPE(o)->tp_free)(o);
-}
-
-static int __pyx_tp_traverse_5pysam_6ctabix_TabixIteratorParsed(PyObject *o, visitproc v, void *a) {
-  int e;
-  struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *p = (struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *)o;
-  if (p->parser) {
-    e = (*v)(((PyObject*)p->parser), a); if (e) return e;
-  }
-  return 0;
-}
-
-static int __pyx_tp_clear_5pysam_6ctabix_TabixIteratorParsed(PyObject *o) {
-  struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *p = (struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *)o;
-  PyObject* tmp;
-  tmp = ((PyObject*)p->parser);
-  p->parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)Py_None); Py_INCREF(Py_None);
-  Py_XDECREF(tmp);
-  return 0;
-}
-
-static PyMethodDef __pyx_methods_5pysam_6ctabix_TabixIteratorParsed[] = {
-  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_19TabixIteratorParsed_4__next__)},
+static PyMethodDef __pyx_methods_5pysam_6ctabix_asBed[] = {
   {0, 0, 0, 0}
 };
 
-static PyNumberMethods __pyx_tp_as_number_TabixIteratorParsed = {
+static PyNumberMethods __pyx_tp_as_number_asBed = {
   0, /*nb_add*/
   0, /*nb_subtract*/
   0, /*nb_multiply*/
@@ -10554,7 +10193,7 @@ static PyNumberMethods __pyx_tp_as_number_TabixIteratorParsed = {
   #endif
 };
 
-static PySequenceMethods __pyx_tp_as_sequence_TabixIteratorParsed = {
+static PySequenceMethods __pyx_tp_as_sequence_asBed = {
   0, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
@@ -10567,13 +10206,13 @@ static PySequenceMethods __pyx_tp_as_sequence_TabixIteratorParsed = {
   0, /*sq_inplace_repeat*/
 };
 
-static PyMappingMethods __pyx_tp_as_mapping_TabixIteratorParsed = {
+static PyMappingMethods __pyx_tp_as_mapping_asBed = {
   0, /*mp_length*/
   0, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
-static PyBufferProcs __pyx_tp_as_buffer_TabixIteratorParsed = {
+static PyBufferProcs __pyx_tp_as_buffer_asBed = {
   #if PY_MAJOR_VERSION < 3
   0, /*bf_getreadbuffer*/
   #endif
@@ -10594,12 +10233,12 @@ static PyBufferProcs __pyx_tp_as_buffer_TabixIteratorParsed = {
   #endif
 };
 
-static PyTypeObject __pyx_type_5pysam_6ctabix_TabixIteratorParsed = {
+static PyTypeObject __pyx_type_5pysam_6ctabix_asBed = {
   PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.ctabix.TabixIteratorParsed"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed), /*tp_basicsize*/
+  __Pyx_NAMESTR("pysam.ctabix.asBed"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_6ctabix_asBed), /*tp_basicsize*/
   0, /*tp_itemsize*/
-  __pyx_tp_dealloc_5pysam_6ctabix_TabixIteratorParsed, /*tp_dealloc*/
+  __pyx_tp_dealloc_5pysam_6ctabix_Parser, /*tp_dealloc*/
   0, /*tp_print*/
   0, /*tp_getattr*/
   0, /*tp_setattr*/
@@ -10609,24 +10248,28 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_TabixIteratorParsed = {
   0, /*reserved*/
   #endif
   0, /*tp_repr*/
-  &__pyx_tp_as_number_TabixIteratorParsed, /*tp_as_number*/
-  &__pyx_tp_as_sequence_TabixIteratorParsed, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping_TabixIteratorParsed, /*tp_as_mapping*/
+  &__pyx_tp_as_number_asBed, /*tp_as_number*/
+  &__pyx_tp_as_sequence_asBed, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_asBed, /*tp_as_mapping*/
   0, /*tp_hash*/
+  #if CYTHON_COMPILING_IN_PYPY
+  __pyx_pw_5pysam_6ctabix_6Parser_1__call__, /*tp_call*/
+  #else
   0, /*tp_call*/
+  #endif
   0, /*tp_str*/
   0, /*tp_getattro*/
   0, /*tp_setattro*/
-  &__pyx_tp_as_buffer_TabixIteratorParsed, /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
-  __Pyx_DOCSTR("iterates over mapped reads in a region.\n\n    Returns parsed data.\n    "), /*tp_doc*/
-  __pyx_tp_traverse_5pysam_6ctabix_TabixIteratorParsed, /*tp_traverse*/
-  __pyx_tp_clear_5pysam_6ctabix_TabixIteratorParsed, /*tp_clear*/
+  &__pyx_tp_as_buffer_asBed, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+  __Pyx_DOCSTR("converts a :term:`tabix row` into a bed record\n    with the following fields:\n\n    contig\n       contig\n    start\n       genomic start coordinate (zero-based)\n    end\n       genomic end coordinate plus one (zero-based)\n    name\n       name of feature.\n    score\n       score of feature\n    strand\n       strand of feature\n    thickStart\n       thickStart\n    thickEnd\n       thickEnd\n    itemRGB\n       itemRGB\n    blockCount\n       number of bocks\n     [...]
+  0, /*tp_traverse*/
+  0, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
-  __pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_3__iter__, /*tp_iter*/
-  __pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_5__next__, /*tp_iternext*/
-  __pyx_methods_5pysam_6ctabix_TabixIteratorParsed, /*tp_methods*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_5pysam_6ctabix_asBed, /*tp_methods*/
   0, /*tp_members*/
   0, /*tp_getset*/
   0, /*tp_base*/
@@ -10636,7 +10279,7 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_TabixIteratorParsed = {
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_6ctabix_TabixIteratorParsed, /*tp_new*/
+  __pyx_tp_new_5pysam_6ctabix_asBed, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -10649,62 +10292,22 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_TabixIteratorParsed = {
   0, /*tp_version_tag*/
   #endif
 };
-static struct __pyx_vtabstruct_5pysam_6ctabix_tabix_inplace_iterator __pyx_vtable_5pysam_6ctabix_tabix_inplace_iterator;
+static struct __pyx_vtabstruct_5pysam_6ctabix_asVCF __pyx_vtable_5pysam_6ctabix_asVCF;
 
-static PyObject *__pyx_tp_new_5pysam_6ctabix_tabix_inplace_iterator(PyTypeObject *t, PyObject *a, PyObject *k) {
-  struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *p;
-  PyObject *o = (*t->tp_alloc)(t, 0);
+static PyObject *__pyx_tp_new_5pysam_6ctabix_asVCF(PyTypeObject *t, PyObject *a, PyObject *k) {
+  struct __pyx_obj_5pysam_6ctabix_asVCF *p;
+  PyObject *o = __pyx_tp_new_5pysam_6ctabix_Parser(t, a, k);
   if (!o) return 0;
-  p = ((struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *)o);
-  p->__pyx_vtab = __pyx_vtabptr_5pysam_6ctabix_tabix_inplace_iterator;
-  p->parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)Py_None); Py_INCREF(Py_None);
-  if (__pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_1__cinit__(o, a, k) < 0) {
-    Py_DECREF(o); o = 0;
-  }
+  p = ((struct __pyx_obj_5pysam_6ctabix_asVCF *)o);
+  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_6ctabix_Parser*)__pyx_vtabptr_5pysam_6ctabix_asVCF;
   return o;
 }
 
-static void __pyx_tp_dealloc_5pysam_6ctabix_tabix_inplace_iterator(PyObject *o) {
-  struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *p = (struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *)o;
-  PyObject_GC_UnTrack(o);
-  {
-    PyObject *etype, *eval, *etb;
-    PyErr_Fetch(&etype, &eval, &etb);
-    ++Py_REFCNT(o);
-    __pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_5__dealloc__(o);
-    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
-    --Py_REFCNT(o);
-    PyErr_Restore(etype, eval, etb);
-  }
-  Py_CLEAR(p->parser);
-  PyObject_GC_Track(o);
-  (*Py_TYPE(o)->tp_free)(o);
-}
-
-static int __pyx_tp_traverse_5pysam_6ctabix_tabix_inplace_iterator(PyObject *o, visitproc v, void *a) {
-  int e;
-  struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *p = (struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *)o;
-  if (p->parser) {
-    e = (*v)(((PyObject*)p->parser), a); if (e) return e;
-  }
-  return 0;
-}
-
-static int __pyx_tp_clear_5pysam_6ctabix_tabix_inplace_iterator(PyObject *o) {
-  struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *p = (struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *)o;
-  PyObject* tmp;
-  tmp = ((PyObject*)p->parser);
-  p->parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)Py_None); Py_INCREF(Py_None);
-  Py_XDECREF(tmp);
-  return 0;
-}
-
-static PyMethodDef __pyx_methods_5pysam_6ctabix_tabix_inplace_iterator[] = {
-  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_7__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)},
+static PyMethodDef __pyx_methods_5pysam_6ctabix_asVCF[] = {
   {0, 0, 0, 0}
 };
 
-static PyNumberMethods __pyx_tp_as_number_tabix_inplace_iterator = {
+static PyNumberMethods __pyx_tp_as_number_asVCF = {
   0, /*nb_add*/
   0, /*nb_subtract*/
   0, /*nb_multiply*/
@@ -10762,7 +10365,7 @@ static PyNumberMethods __pyx_tp_as_number_tabix_inplace_iterator = {
   #endif
 };
 
-static PySequenceMethods __pyx_tp_as_sequence_tabix_inplace_iterator = {
+static PySequenceMethods __pyx_tp_as_sequence_asVCF = {
   0, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
@@ -10775,13 +10378,13 @@ static PySequenceMethods __pyx_tp_as_sequence_tabix_inplace_iterator = {
   0, /*sq_inplace_repeat*/
 };
 
-static PyMappingMethods __pyx_tp_as_mapping_tabix_inplace_iterator = {
+static PyMappingMethods __pyx_tp_as_mapping_asVCF = {
   0, /*mp_length*/
   0, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
-static PyBufferProcs __pyx_tp_as_buffer_tabix_inplace_iterator = {
+static PyBufferProcs __pyx_tp_as_buffer_asVCF = {
   #if PY_MAJOR_VERSION < 3
   0, /*bf_getreadbuffer*/
   #endif
@@ -10802,12 +10405,12 @@ static PyBufferProcs __pyx_tp_as_buffer_tabix_inplace_iterator = {
   #endif
 };
 
-static PyTypeObject __pyx_type_5pysam_6ctabix_tabix_inplace_iterator = {
+static PyTypeObject __pyx_type_5pysam_6ctabix_asVCF = {
   PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.ctabix.tabix_inplace_iterator"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator), /*tp_basicsize*/
+  __Pyx_NAMESTR("pysam.ctabix.asVCF"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_6ctabix_asVCF), /*tp_basicsize*/
   0, /*tp_itemsize*/
-  __pyx_tp_dealloc_5pysam_6ctabix_tabix_inplace_iterator, /*tp_dealloc*/
+  __pyx_tp_dealloc_5pysam_6ctabix_Parser, /*tp_dealloc*/
   0, /*tp_print*/
   0, /*tp_getattr*/
   0, /*tp_setattr*/
@@ -10817,24 +10420,28 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_tabix_inplace_iterator = {
   0, /*reserved*/
   #endif
   0, /*tp_repr*/
-  &__pyx_tp_as_number_tabix_inplace_iterator, /*tp_as_number*/
-  &__pyx_tp_as_sequence_tabix_inplace_iterator, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping_tabix_inplace_iterator, /*tp_as_mapping*/
+  &__pyx_tp_as_number_asVCF, /*tp_as_number*/
+  &__pyx_tp_as_sequence_asVCF, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_asVCF, /*tp_as_mapping*/
   0, /*tp_hash*/
+  #if CYTHON_COMPILING_IN_PYPY
+  __pyx_pw_5pysam_6ctabix_6Parser_1__call__, /*tp_call*/
+  #else
   0, /*tp_call*/
+  #endif
   0, /*tp_str*/
   0, /*tp_getattro*/
   0, /*tp_setattro*/
-  &__pyx_tp_as_buffer_tabix_inplace_iterator, /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
-  __Pyx_DOCSTR("iterate over ``infile``.\n\n    This iterator is not safe. If the :meth:`__next__()` method is called \n    after ``infile`` is closed, the result is undefined (see ``fclose()``).\n\n    The iterator might either raise a StopIteration or segfault.\n    "), /*tp_doc*/
-  __pyx_tp_traverse_5pysam_6ctabix_tabix_inplace_iterator, /*tp_traverse*/
-  __pyx_tp_clear_5pysam_6ctabix_tabix_inplace_iterator, /*tp_clear*/
+  &__pyx_tp_as_buffer_asVCF, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+  __Pyx_DOCSTR("converts a :term:`tabix row` into a VCF record with\n    the following fields:\n    \n    contig\n       contig\n    pos\n       chromosomal position, zero-based\n    id \n       id\n    ref\n       reference\n    alt\n       alt\n    qual\n       qual\n    filter\n       filter\n    info\n       info\n    format\n       format specifier.\n\n    Access to genotypes is via index::\n\n        contig = vcf.contig\n        first_sample_genotype = vcf[0]\n        second_sample [...]
+  0, /*tp_traverse*/
+  0, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
-  __pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_3__iter__, /*tp_iter*/
-  __pyx_pw_5pysam_6ctabix_22tabix_inplace_iterator_7__next__, /*tp_iternext*/
-  __pyx_methods_5pysam_6ctabix_tabix_inplace_iterator, /*tp_methods*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_5pysam_6ctabix_asVCF, /*tp_methods*/
   0, /*tp_members*/
   0, /*tp_getset*/
   0, /*tp_base*/
@@ -10844,7 +10451,7 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_tabix_inplace_iterator = {
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_6ctabix_tabix_inplace_iterator, /*tp_new*/
+  __pyx_tp_new_5pysam_6ctabix_asVCF, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -10857,40 +10464,47 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_tabix_inplace_iterator = {
   0, /*tp_version_tag*/
   #endif
 };
-static struct __pyx_vtabstruct_5pysam_6ctabix_tabix_copy_iterator __pyx_vtable_5pysam_6ctabix_tabix_copy_iterator;
 
-static PyObject *__pyx_tp_new_5pysam_6ctabix_tabix_copy_iterator(PyTypeObject *t, PyObject *a, PyObject *k) {
-  struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *p;
+static PyObject *__pyx_tp_new_5pysam_6ctabix_TabixIteratorParsed(PyTypeObject *t, PyObject *a, PyObject *k) {
+  struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *p;
   PyObject *o = (*t->tp_alloc)(t, 0);
   if (!o) return 0;
-  p = ((struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *)o);
-  p->__pyx_vtab = __pyx_vtabptr_5pysam_6ctabix_tabix_copy_iterator;
+  p = ((struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *)o);
   p->parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)Py_None); Py_INCREF(Py_None);
-  if (__pyx_pw_5pysam_6ctabix_19tabix_copy_iterator_1__cinit__(o, a, k) < 0) {
+  if (__pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_1__cinit__(o, a, k) < 0) {
     Py_DECREF(o); o = 0;
   }
   return o;
 }
 
-static void __pyx_tp_dealloc_5pysam_6ctabix_tabix_copy_iterator(PyObject *o) {
-  struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *p = (struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *)o;
+static void __pyx_tp_dealloc_5pysam_6ctabix_TabixIteratorParsed(PyObject *o) {
+  struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *p = (struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *)o;
   PyObject_GC_UnTrack(o);
+  {
+    PyObject *etype, *eval, *etb;
+    PyErr_Fetch(&etype, &eval, &etb);
+    ++Py_REFCNT(o);
+    __pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_7__dealloc__(o);
+    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
+    --Py_REFCNT(o);
+    PyErr_Restore(etype, eval, etb);
+  }
   Py_CLEAR(p->parser);
   PyObject_GC_Track(o);
   (*Py_TYPE(o)->tp_free)(o);
 }
 
-static int __pyx_tp_traverse_5pysam_6ctabix_tabix_copy_iterator(PyObject *o, visitproc v, void *a) {
+static int __pyx_tp_traverse_5pysam_6ctabix_TabixIteratorParsed(PyObject *o, visitproc v, void *a) {
   int e;
-  struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *p = (struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *)o;
+  struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *p = (struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *)o;
   if (p->parser) {
     e = (*v)(((PyObject*)p->parser), a); if (e) return e;
   }
   return 0;
 }
 
-static int __pyx_tp_clear_5pysam_6ctabix_tabix_copy_iterator(PyObject *o) {
-  struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *p = (struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *)o;
+static int __pyx_tp_clear_5pysam_6ctabix_TabixIteratorParsed(PyObject *o) {
+  struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *p = (struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed *)o;
   PyObject* tmp;
   tmp = ((PyObject*)p->parser);
   p->parser = ((struct __pyx_obj_5pysam_6ctabix_Parser *)Py_None); Py_INCREF(Py_None);
@@ -10898,12 +10512,12 @@ static int __pyx_tp_clear_5pysam_6ctabix_tabix_copy_iterator(PyObject *o) {
   return 0;
 }
 
-static PyMethodDef __pyx_methods_5pysam_6ctabix_tabix_copy_iterator[] = {
-  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_6ctabix_19tabix_copy_iterator_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)},
+static PyMethodDef __pyx_methods_5pysam_6ctabix_TabixIteratorParsed[] = {
+  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_6ctabix_19TabixIteratorParsed_4__next__)},
   {0, 0, 0, 0}
 };
 
-static PyNumberMethods __pyx_tp_as_number_tabix_copy_iterator = {
+static PyNumberMethods __pyx_tp_as_number_TabixIteratorParsed = {
   0, /*nb_add*/
   0, /*nb_subtract*/
   0, /*nb_multiply*/
@@ -10961,7 +10575,7 @@ static PyNumberMethods __pyx_tp_as_number_tabix_copy_iterator = {
   #endif
 };
 
-static PySequenceMethods __pyx_tp_as_sequence_tabix_copy_iterator = {
+static PySequenceMethods __pyx_tp_as_sequence_TabixIteratorParsed = {
   0, /*sq_length*/
   0, /*sq_concat*/
   0, /*sq_repeat*/
@@ -10974,13 +10588,13 @@ static PySequenceMethods __pyx_tp_as_sequence_tabix_copy_iterator = {
   0, /*sq_inplace_repeat*/
 };
 
-static PyMappingMethods __pyx_tp_as_mapping_tabix_copy_iterator = {
+static PyMappingMethods __pyx_tp_as_mapping_TabixIteratorParsed = {
   0, /*mp_length*/
   0, /*mp_subscript*/
   0, /*mp_ass_subscript*/
 };
 
-static PyBufferProcs __pyx_tp_as_buffer_tabix_copy_iterator = {
+static PyBufferProcs __pyx_tp_as_buffer_TabixIteratorParsed = {
   #if PY_MAJOR_VERSION < 3
   0, /*bf_getreadbuffer*/
   #endif
@@ -11001,12 +10615,12 @@ static PyBufferProcs __pyx_tp_as_buffer_tabix_copy_iterator = {
   #endif
 };
 
-static PyTypeObject __pyx_type_5pysam_6ctabix_tabix_copy_iterator = {
+static PyTypeObject __pyx_type_5pysam_6ctabix_TabixIteratorParsed = {
   PyVarObject_HEAD_INIT(0, 0)
-  __Pyx_NAMESTR("pysam.ctabix.tabix_copy_iterator"), /*tp_name*/
-  sizeof(struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator), /*tp_basicsize*/
+  __Pyx_NAMESTR("pysam.ctabix.TabixIteratorParsed"), /*tp_name*/
+  sizeof(struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed), /*tp_basicsize*/
   0, /*tp_itemsize*/
-  __pyx_tp_dealloc_5pysam_6ctabix_tabix_copy_iterator, /*tp_dealloc*/
+  __pyx_tp_dealloc_5pysam_6ctabix_TabixIteratorParsed, /*tp_dealloc*/
   0, /*tp_print*/
   0, /*tp_getattr*/
   0, /*tp_setattr*/
@@ -11016,24 +10630,24 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_tabix_copy_iterator = {
   0, /*reserved*/
   #endif
   0, /*tp_repr*/
-  &__pyx_tp_as_number_tabix_copy_iterator, /*tp_as_number*/
-  &__pyx_tp_as_sequence_tabix_copy_iterator, /*tp_as_sequence*/
-  &__pyx_tp_as_mapping_tabix_copy_iterator, /*tp_as_mapping*/
+  &__pyx_tp_as_number_TabixIteratorParsed, /*tp_as_number*/
+  &__pyx_tp_as_sequence_TabixIteratorParsed, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_TabixIteratorParsed, /*tp_as_mapping*/
   0, /*tp_hash*/
   0, /*tp_call*/
   0, /*tp_str*/
   0, /*tp_getattro*/
   0, /*tp_setattro*/
-  &__pyx_tp_as_buffer_tabix_copy_iterator, /*tp_as_buffer*/
+  &__pyx_tp_as_buffer_TabixIteratorParsed, /*tp_as_buffer*/
   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
-  __Pyx_DOCSTR("iterate over ``infile``.\n\n    This iterator is not save. If the :meth:`__next__()` method is called \n    after ``infile`` is closed, the result is undefined (see ``fclose()``).\n\n    The iterator might either raise a StopIteration or segfault.\n    "), /*tp_doc*/
-  __pyx_tp_traverse_5pysam_6ctabix_tabix_copy_iterator, /*tp_traverse*/
-  __pyx_tp_clear_5pysam_6ctabix_tabix_copy_iterator, /*tp_clear*/
+  __Pyx_DOCSTR("iterates over mapped reads in a region.\n\n    Returns parsed data.\n    "), /*tp_doc*/
+  __pyx_tp_traverse_5pysam_6ctabix_TabixIteratorParsed, /*tp_traverse*/
+  __pyx_tp_clear_5pysam_6ctabix_TabixIteratorParsed, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
-  __pyx_pw_5pysam_6ctabix_19tabix_copy_iterator_3__iter__, /*tp_iter*/
-  __pyx_pw_5pysam_6ctabix_19tabix_copy_iterator_5__next__, /*tp_iternext*/
-  __pyx_methods_5pysam_6ctabix_tabix_copy_iterator, /*tp_methods*/
+  __pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_3__iter__, /*tp_iter*/
+  __pyx_pw_5pysam_6ctabix_19TabixIteratorParsed_5__next__, /*tp_iternext*/
+  __pyx_methods_5pysam_6ctabix_TabixIteratorParsed, /*tp_methods*/
   0, /*tp_members*/
   0, /*tp_getset*/
   0, /*tp_base*/
@@ -11043,7 +10657,7 @@ static PyTypeObject __pyx_type_5pysam_6ctabix_tabix_copy_iterator = {
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_5pysam_6ctabix_tabix_copy_iterator, /*tp_new*/
+  __pyx_tp_new_5pysam_6ctabix_TabixIteratorParsed, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -11090,24 +10704,25 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0},
   {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0},
   {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0},
-  {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0},
-  {&__pyx_kp_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 0},
-  {&__pyx_kp_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 0},
+  {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0},
+  {&__pyx_kp_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 0},
   {&__pyx_kp_u_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 1, 0, 0},
+  {&__pyx_kp_s_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 0, 1, 0},
   {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0},
-  {&__pyx_kp_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 0},
-  {&__pyx_kp_s_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 1, 0},
-  {&__pyx_kp_s_36, __pyx_k_36, sizeof(__pyx_k_36), 0, 0, 1, 0},
-  {&__pyx_kp_s_40, __pyx_k_40, sizeof(__pyx_k_40), 0, 0, 1, 0},
+  {&__pyx_kp_s_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 0, 1, 0},
+  {&__pyx_kp_s_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 1, 0},
+  {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0},
+  {&__pyx_kp_s_41, __pyx_k_41, sizeof(__pyx_k_41), 0, 0, 1, 0},
   {&__pyx_kp_s_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 0, 1, 0},
-  {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0},
-  {&__pyx_kp_s_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 1, 0},
-  {&__pyx_kp_s_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 1, 0},
+  {&__pyx_kp_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 0},
+  {&__pyx_kp_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 0},
+  {&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 0},
   {&__pyx_kp_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 0},
   {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0},
   {&__pyx_kp_s_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 0},
   {&__pyx_kp_s_51, __pyx_k_51, sizeof(__pyx_k_51), 0, 0, 1, 0},
   {&__pyx_kp_s_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 1, 0},
+  {&__pyx_kp_s_57, __pyx_k_57, sizeof(__pyx_k_57), 0, 0, 1, 0},
   {&__pyx_n_s_58, __pyx_k_58, sizeof(__pyx_k_58), 0, 0, 1, 1},
   {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0},
   {&__pyx_n_s_62, __pyx_k_62, sizeof(__pyx_k_62), 0, 0, 1, 1},
@@ -11119,16 +10734,15 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s_77, __pyx_k_77, sizeof(__pyx_k_77), 0, 0, 1, 1},
   {&__pyx_n_s_80, __pyx_k_80, sizeof(__pyx_k_80), 0, 0, 1, 1},
   {&__pyx_kp_s_81, __pyx_k_81, sizeof(__pyx_k_81), 0, 0, 1, 0},
-  {&__pyx_n_s_84, __pyx_k_84, sizeof(__pyx_k_84), 0, 0, 1, 1},
   {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
   {&__pyx_n_s__IOError, __pyx_k__IOError, sizeof(__pyx_k__IOError), 0, 0, 1, 1},
+  {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1},
   {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1},
   {&__pyx_n_s__MemoryError, __pyx_k__MemoryError, sizeof(__pyx_k__MemoryError), 0, 0, 1, 1},
   {&__pyx_n_s__NotImplementedError, __pyx_k__NotImplementedError, sizeof(__pyx_k__NotImplementedError), 0, 0, 1, 1},
   {&__pyx_n_s__OSError, __pyx_k__OSError, sizeof(__pyx_k__OSError), 0, 0, 1, 1},
   {&__pyx_n_s__O_RDONLY, __pyx_k__O_RDONLY, sizeof(__pyx_k__O_RDONLY), 0, 0, 1, 1},
   {&__pyx_n_s__PYTHON3, __pyx_k__PYTHON3, sizeof(__pyx_k__PYTHON3), 0, 0, 1, 1},
-  {&__pyx_n_s__Parser, __pyx_k__Parser, sizeof(__pyx_k__Parser), 0, 0, 1, 1},
   {&__pyx_n_s__StopIteration, __pyx_k__StopIteration, sizeof(__pyx_k__StopIteration), 0, 0, 1, 1},
   {&__pyx_n_s__Tabixfile, __pyx_k__Tabixfile, sizeof(__pyx_k__Tabixfile), 0, 0, 1, 1},
   {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1},
@@ -11179,7 +10793,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s__io, __pyx_k__io, sizeof(__pyx_k__io), 0, 0, 1, 1},
   {&__pyx_n_s__itertools, __pyx_k__itertools, sizeof(__pyx_k__itertools), 0, 0, 1, 1},
   {&__pyx_n_s__join, __pyx_k__join, sizeof(__pyx_k__join), 0, 0, 1, 1},
-  {&__pyx_n_s__len, __pyx_k__len, sizeof(__pyx_k__len), 0, 0, 1, 1},
+  {&__pyx_n_s__length, __pyx_k__length, sizeof(__pyx_k__length), 0, 0, 1, 1},
   {&__pyx_n_s__line, __pyx_k__line, sizeof(__pyx_k__line), 0, 0, 1, 1},
   {&__pyx_n_s__meta_char, __pyx_k__meta_char, sizeof(__pyx_k__meta_char), 0, 0, 1, 1},
   {&__pyx_n_s__mode, __pyx_k__mode, sizeof(__pyx_k__mode), 0, 0, 1, 1},
@@ -11190,7 +10804,6 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s__parser, __pyx_k__parser, sizeof(__pyx_k__parser), 0, 0, 1, 1},
   {&__pyx_n_s__path, __pyx_k__path, sizeof(__pyx_k__path), 0, 0, 1, 1},
   {&__pyx_n_s__pileup, __pyx_k__pileup, sizeof(__pyx_k__pileup), 0, 0, 1, 1},
-  {&__pyx_n_s__present, __pyx_k__present, sizeof(__pyx_k__present), 0, 0, 1, 1},
   {&__pyx_n_s__preset, __pyx_k__preset, sizeof(__pyx_k__preset), 0, 0, 1, 1},
   {&__pyx_n_s__preset2conf, __pyx_k__preset2conf, sizeof(__pyx_k__preset2conf), 0, 0, 1, 1},
   {&__pyx_n_s__psltbl, __pyx_k__psltbl, sizeof(__pyx_k__psltbl), 0, 0, 1, 1},
@@ -11208,6 +10821,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s__struct, __pyx_k__struct, sizeof(__pyx_k__struct), 0, 0, 1, 1},
   {&__pyx_n_s__sys, __pyx_k__sys, sizeof(__pyx_k__sys), 0, 0, 1, 1},
   {&__pyx_n_s__tabix_compress, __pyx_k__tabix_compress, sizeof(__pyx_k__tabix_compress), 0, 0, 1, 1},
+  {&__pyx_n_s__tabix_file_iterator, __pyx_k__tabix_file_iterator, sizeof(__pyx_k__tabix_file_iterator), 0, 0, 1, 1},
   {&__pyx_n_s__tabix_index, __pyx_k__tabix_index, sizeof(__pyx_k__tabix_index), 0, 0, 1, 1},
   {&__pyx_n_s__tabix_iterator, __pyx_k__tabix_iterator, sizeof(__pyx_k__tabix_iterator), 0, 0, 1, 1},
   {&__pyx_n_s__tabixfile, __pyx_k__tabixfile, sizeof(__pyx_k__tabixfile), 0, 0, 1, 1},
@@ -11221,15 +10835,16 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {0, 0, 0, 0, 0, 0, 0}
 };
 static int __Pyx_InitCachedBuiltins(void) {
-  __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_NotImplementedError = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplementedError); if (!__pyx_builtin_NotImplementedError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_IOError = __Pyx_GetName(__pyx_b, __pyx_n_s__IOError); if (!__pyx_builtin_IOError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_OSError = __Pyx_GetName(__pyx_b, __pyx_n_s__OSError); if (!__pyx_builtin_OSError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_ord = __Pyx_GetName(__pyx_b, __pyx_n_s__ord); if (!__pyx_builtin_ord) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 670; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_NotImplementedError = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplementedError); if (!__pyx_builtin_NotImplementedError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_IOError = __Pyx_GetName(__pyx_b, __pyx_n_s__IOError); if (!__pyx_builtin_IOError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_OSError = __Pyx_GetName(__pyx_b, __pyx_n_s__OSError); if (!__pyx_builtin_OSError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_ord = __Pyx_GetName(__pyx_b, __pyx_n_s__ord); if (!__pyx_builtin_ord) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   return 0;
   __pyx_L1_error:;
   return -1;
@@ -11239,334 +10854,323 @@ static int __Pyx_InitCachedConstants(void) {
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
 
-  /* "pysam/ctabix.pyx":58
+  /* "pysam/ctabix.pyx":63
  *         return s
  *     elif PyUnicode_Check(s):
  *         return s.encode('ascii')             # <<<<<<<<<<<<<<
  *     else:
  *         raise TypeError, u"Argument must be string, bytes or unicode."
  */
-  __pyx_k_tuple_2 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_2 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_2);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));
 
-  /* "pysam/ctabix.pyx":78
+  /* "pysam/ctabix.pyx":83
  *         return s
  *     elif PyBytes_Check(s):
  *         return s.decode('ascii')             # <<<<<<<<<<<<<<
  *     else:
  *         # assume unicode
  */
-  __pyx_k_tuple_4 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_4 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_4);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));
 
-  /* "pysam/ctabix.pyx":112
+  /* "pysam/ctabix.pyx":124
  * 
  *         filename_index = filename + ".tbi"
  *         self.isremote = filename.startswith( "http:") or filename.startswith( "ftp:" )             # <<<<<<<<<<<<<<
  * 
  *         # encode all the strings
  */
-  __pyx_k_tuple_8 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_7)); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_8 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_7)); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_8);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8));
-  __pyx_k_tuple_10 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_9)); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_10 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_9)); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_10);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10));
 
-  /* "pysam/ctabix.pyx":117
+  /* "pysam/ctabix.pyx":129
  *         filename = _my_encodeFilename(filename)
  *         filename_index = _my_encodeFilename(filename_index)
  *         cdef bytes bmode = mode.encode('ascii')             # <<<<<<<<<<<<<<
  * 
  *         if self._filename != NULL: free(self._filename )
  */
-  __pyx_k_tuple_11 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_11 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__ascii)); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_11);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_11));
 
-  /* "pysam/ctabix.pyx":125
+  /* "pysam/ctabix.pyx":137
  *         if mode[0] == 'w':
  *             # open file for writing
  *             raise NotImplementedError("writing to tabix files not implemented" )             # <<<<<<<<<<<<<<
  * 
  *         elif mode[0] == "r":
  */
-  __pyx_k_tuple_13 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_12)); if (unlikely(!__pyx_k_tuple_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_13 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_12)); if (unlikely(!__pyx_k_tuple_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_13);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_13));
 
-  /* "pysam/ctabix.pyx":212
+  /* "pysam/ctabix.pyx":222
  * 
  *         if not self._isOpen():
  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  * 
- *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
+ *         # the following will raise errors for invalid regions
  */
-  __pyx_k_tuple_23 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_22)); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_23);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23));
+  __pyx_k_tuple_22 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_21)); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_22);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22));
 
-  /* "pysam/ctabix.pyx":235
+  /* "pysam/ctabix.pyx":250
  *         '''filename associated with this object.'''
  *         def __get__(self):
  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
  *             return self._filename
  * 
  */
-  __pyx_k_tuple_24 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_22)); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_24);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24));
+  __pyx_k_tuple_23 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_21)); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_23);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23));
 
-  /* "pysam/ctabix.pyx":302
+  /* "pysam/ctabix.pyx":317
  * 
  *         if <void*>self.iterator == NULL:
  *             raise ValueError("malformatted query or wrong sequence name.\n")             # <<<<<<<<<<<<<<
  * 
  *     def __iter__(self):
  */
-  __pyx_k_tuple_26 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_25)); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_26);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26));
+  __pyx_k_tuple_25 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_24)); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_25);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25));
 
-  /* "pysam/ctabix.pyx":347
+  /* "pysam/ctabix.pyx":361
  * 
  *         if <void*>self.iterator == NULL:
  *             raise ValueError("can't open header.\n")             # <<<<<<<<<<<<<<
  * 
  *     def __iter__(self):
  */
-  __pyx_k_tuple_28 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_27)); if (unlikely(!__pyx_k_tuple_28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_28);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_28));
+  __pyx_k_tuple_27 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_26)); if (unlikely(!__pyx_k_tuple_27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_27);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_27));
 
-  /* "pysam/ctabix.pyx":539
+  /* "pysam/ctabix.pyx":558
  * 
  *         if <void*>self.iterator == NULL:
  *             raise ValueError("malformatted query or wrong sequence name.\n")             # <<<<<<<<<<<<<<
  * 
  *     def __iter__(self):
  */
-  __pyx_k_tuple_29 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_25)); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_29);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29));
+  __pyx_k_tuple_28 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_24)); if (unlikely(!__pyx_k_tuple_28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_28);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_28));
 
-  /* "pysam/ctabix.pyx":590
+  /* "pysam/ctabix.pyx":608
  *     fp = bgzf_open( fn, "w")
  *     if fp == NULL:
  *         raise IOError( "could not open '%s' for writing" )             # <<<<<<<<<<<<<<
  * 
  *     fn = _force_bytes(filename_in)
  */
-  __pyx_k_tuple_33 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_32)); if (unlikely(!__pyx_k_tuple_33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_33);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_33));
+  __pyx_k_tuple_32 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_31)); if (unlikely(!__pyx_k_tuple_32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_32);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_32));
 
-  /* "pysam/ctabix.pyx":595
+  /* "pysam/ctabix.pyx":613
  *     fd_src = open(fn, O_RDONLY)
  *     if fd_src == 0:
  *         raise IOError( "could not open '%s' for reading" )             # <<<<<<<<<<<<<<
  * 
  *     buffer = malloc(WINDOW_SIZE)
  */
-  __pyx_k_tuple_35 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_34)); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 595; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_35);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35));
+  __pyx_k_tuple_34 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_33)); if (unlikely(!__pyx_k_tuple_34)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_34);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_34));
 
-  /* "pysam/ctabix.pyx":605
+  /* "pysam/ctabix.pyx":623
  *         if r < 0:
  *             free( buffer )
  *             raise OSError("writing failed")             # <<<<<<<<<<<<<<
  * 
  *     free( buffer )
  */
-  __pyx_k_tuple_37 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_36)); if (unlikely(!__pyx_k_tuple_37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_37);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_37));
+  __pyx_k_tuple_36 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_35)); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_36);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36));
 
-  /* "pysam/ctabix.pyx":609
+  /* "pysam/ctabix.pyx":627
  *     free( buffer )
  *     r = bgzf_close(fp)
  *     if r < 0: raise OSError("writing failed")             # <<<<<<<<<<<<<<
  * 
  * def tabix_index( filename,
  */
-  __pyx_k_tuple_38 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_36)); if (unlikely(!__pyx_k_tuple_38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_38);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_38));
+  __pyx_k_tuple_37 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_35)); if (unlikely(!__pyx_k_tuple_37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_37);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_37));
 
-  /* "pysam/ctabix.pyx":656
+  /* "pysam/ctabix.pyx":674
  * 
  *     if preset == None and (seq_col == None or start_col == None or end_col == None):
  *         raise ValueError("neither preset nor seq_col,start_col and end_col given" )             # <<<<<<<<<<<<<<
  * 
  *     if not filename.endswith(".gz"):
  */
-  __pyx_k_tuple_44 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_43)); if (unlikely(!__pyx_k_tuple_44)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_44);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_44));
+  __pyx_k_tuple_43 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_42)); if (unlikely(!__pyx_k_tuple_43)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_43);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_43));
 
-  /* "pysam/ctabix.pyx":658
+  /* "pysam/ctabix.pyx":676
  *         raise ValueError("neither preset nor seq_col,start_col and end_col given" )
  * 
  *     if not filename.endswith(".gz"):             # <<<<<<<<<<<<<<
  *         tabix_compress( filename, filename + ".gz", force = force )
  *         os.unlink( filename )
  */
-  __pyx_k_tuple_46 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_k_tuple_46)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 658; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_46);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_46));
+  __pyx_k_tuple_45 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_44)); if (unlikely(!__pyx_k_tuple_45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_45);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_45));
 
-  /* "pysam/ctabix.pyx":664
+  /* "pysam/ctabix.pyx":682
  * 
  *     if not force and os.path.exists(filename + ".tbi" ):
  *         raise IOError( "Filename '%s.tbi' already exists, use *force* to overwrite" )             # <<<<<<<<<<<<<<
  * 
  *     # columns (1-based)
  */
-  __pyx_k_tuple_48 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_47)); if (unlikely(!__pyx_k_tuple_48)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_48);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_48));
+  __pyx_k_tuple_47 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_46)); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_k_tuple_47);
+  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47));
 
-  /* "pysam/ctabix.pyx":722
+  /* "pysam/ctabix.pyx":812
  * 
- *         cdef int fd = PyObject_AsFileDescriptor( infile )
- *         if fd == -1: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
- *         self.infile = fdopen( fd, 'r')
+ *         if infile.closed:
+ *             raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
  * 
+ *         self.infile = infile
  */
-  __pyx_k_tuple_52 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_51)); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 722; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_52 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_51)); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_52);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52));
 
-  /* "pysam/ctabix.pyx":725
- *         self.infile = fdopen( fd, 'r')
+  /* "pysam/ctabix.pyx":817
  * 
- *         if self.infile == NULL: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
+ *         cdef int fd = PyObject_AsFileDescriptor( infile )
+ *         if fd == -1: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
  * 
- *         self.buffer = <char*>malloc( buffer_size )
+ *         # From the manual:
  */
-  __pyx_k_tuple_53 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_51)); if (unlikely(!__pyx_k_tuple_53)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_53 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_51)); if (unlikely(!__pyx_k_tuple_53)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_53);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_53));
 
-  /* "pysam/ctabix.pyx":783
+  /* "pysam/ctabix.pyx":885
+ * 
+ *         self.infile = infile
+ *         if self.infile.closed: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
+ *         self.parser = parser
  * 
- *         cdef int fd = PyObject_AsFileDescriptor( infile )
- *         if fd == -1: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
- *         self.infile = fdopen( fd, 'r')
- *         if self.infile == NULL: raise ValueError( "I/O operation on closed file." )
  */
-  __pyx_k_tuple_55 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_51)); if (unlikely(!__pyx_k_tuple_55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_55 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_51)); if (unlikely(!__pyx_k_tuple_55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_55);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_55));
 
-  /* "pysam/ctabix.pyx":785
- *         if fd == -1: raise ValueError( "I/O operation on closed file." )
- *         self.infile = fdopen( fd, 'r')
- *         if self.infile == NULL: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
- *         self.parser = parser
+  /* "pysam/ctabix.pyx":899
+ *         # note that GzipFile.close() does not close the file
+ *         # reading is still possible.
+ *         if self.infile.closed: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
  * 
+ *         while 1:
  */
-  __pyx_k_tuple_56 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_51)); if (unlikely(!__pyx_k_tuple_56)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_56 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_51)); if (unlikely(!__pyx_k_tuple_56)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_56);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_56));
 
-  /* "pysam/ctabix.pyx":839
- * 
- *         self.infile = infile
- *         if self.infile.closed: raise ValueError( "I/O operation on closed file." )             # <<<<<<<<<<<<<<
- *         self.parser = parser
- * 
- */
-  __pyx_k_tuple_57 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_51)); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_k_tuple_57);
-  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_57));
-
-  /* "pysam/ctabix.pyx":564
+  /* "pysam/ctabix.pyx":582
  *             ti_iter_destroy(self.iterator)
  * 
  * def tabix_compress( filename_in,             # <<<<<<<<<<<<<<
  *                     filename_out,
  *                     force = False ):
  */
-  __pyx_k_tuple_63 = PyTuple_Pack(11, ((PyObject *)__pyx_n_s__filename_in), ((PyObject *)__pyx_n_s__filename_out), ((PyObject *)__pyx_n_s__force), ((PyObject *)__pyx_n_s__WINDOW_SIZE), ((PyObject *)__pyx_n_s__c), ((PyObject *)__pyx_n_s__r), ((PyObject *)__pyx_n_s__buffer), ((PyObject *)__pyx_n_s__fp), ((PyObject *)__pyx_n_s__fd_src), ((PyObject *)__pyx_n_s__O_RDONLY), ((PyObject *)__pyx_n_s__fn)); if (unlikely(!__pyx_k_tuple_63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_cl [...]
+  __pyx_k_tuple_63 = PyTuple_Pack(11, ((PyObject *)__pyx_n_s__filename_in), ((PyObject *)__pyx_n_s__filename_out), ((PyObject *)__pyx_n_s__force), ((PyObject *)__pyx_n_s__WINDOW_SIZE), ((PyObject *)__pyx_n_s__c), ((PyObject *)__pyx_n_s__r), ((PyObject *)__pyx_n_s__buffer), ((PyObject *)__pyx_n_s__fp), ((PyObject *)__pyx_n_s__fd_src), ((PyObject *)__pyx_n_s__O_RDONLY), ((PyObject *)__pyx_n_s__fn)); if (unlikely(!__pyx_k_tuple_63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_cl [...]
   __Pyx_GOTREF(__pyx_k_tuple_63);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_63));
-  __pyx_k_codeobj_64 = (PyObject*)__Pyx_PyCode_New(3, 0, 11, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_63, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s__tabix_compress, 564, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_64)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_64 = (PyObject*)__Pyx_PyCode_New(3, 0, 11, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_63, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s__tabix_compress, 582, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_64)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/ctabix.pyx":611
+  /* "pysam/ctabix.pyx":629
  *     if r < 0: raise OSError("writing failed")
  * 
  * def tabix_index( filename,             # <<<<<<<<<<<<<<
  *                  force = False,
  *                  seq_col = None,
  */
-  __pyx_k_tuple_67 = PyTuple_Pack(12, ((PyObject *)__pyx_n_s__filename), ((PyObject *)__pyx_n_s__force), ((PyObject *)__pyx_n_s__seq_col), ((PyObject *)__pyx_n_s__start_col), ((PyObject *)__pyx_n_s__end_col), ((PyObject *)__pyx_n_s__preset), ((PyObject *)__pyx_n_s__meta_char), ((PyObject *)__pyx_n_s__zerobased), ((PyObject *)__pyx_n_s__preset2conf), ((PyObject *)__pyx_n_s__conf_data), ((PyObject *)__pyx_n_s__conf), ((PyObject *)__pyx_n_s__fn)); if (unlikely(!__pyx_k_tuple_67)) {__pyx_fil [...]
+  __pyx_k_tuple_67 = PyTuple_Pack(12, ((PyObject *)__pyx_n_s__filename), ((PyObject *)__pyx_n_s__force), ((PyObject *)__pyx_n_s__seq_col), ((PyObject *)__pyx_n_s__start_col), ((PyObject *)__pyx_n_s__end_col), ((PyObject *)__pyx_n_s__preset), ((PyObject *)__pyx_n_s__meta_char), ((PyObject *)__pyx_n_s__zerobased), ((PyObject *)__pyx_n_s__preset2conf), ((PyObject *)__pyx_n_s__conf_data), ((PyObject *)__pyx_n_s__conf), ((PyObject *)__pyx_n_s__fn)); if (unlikely(!__pyx_k_tuple_67)) {__pyx_fil [...]
   __Pyx_GOTREF(__pyx_k_tuple_67);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_67));
-  __pyx_k_codeobj_68 = (PyObject*)__Pyx_PyCode_New(8, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_67, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s__tabix_index, 611, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_68)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_68 = (PyObject*)__Pyx_PyCode_New(8, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_67, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s__tabix_index, 629, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_68)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/ctabix.pyx":836
+  /* "pysam/ctabix.pyx":882
  *     Permits the use of file-like objects for example from the gzip module.
  *     '''
  *     def __init__(self, infile, parser ):             # <<<<<<<<<<<<<<
  * 
  *         self.infile = infile
  */
-  __pyx_k_tuple_69 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_n_s__infile), ((PyObject *)__pyx_n_s__parser)); if (unlikely(!__pyx_k_tuple_69)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_69 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_n_s__infile), ((PyObject *)__pyx_n_s__parser)); if (unlikely(!__pyx_k_tuple_69)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_69);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_69));
-  __pyx_k_codeobj_70 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_69, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s____init__, 836, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_70)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_70 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_69, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s____init__, 882, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_70)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/ctabix.pyx":842
+  /* "pysam/ctabix.pyx":888
  *         self.parser = parser
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
  *         return self
  * 
  */
-  __pyx_k_tuple_72 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_72)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_72 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_72)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_72);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_72));
-  __pyx_k_codeobj_73 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_72, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s____iter__, 842, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_73)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_73 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_72, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s____iter__, 888, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_73)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/ctabix.pyx":846
+  /* "pysam/ctabix.pyx":892
  * 
  *     # cython version - required for python 3
  *     def __next__(self):             # <<<<<<<<<<<<<<
  * 
  *         cdef char * b, * cpy
  */
-  __pyx_k_tuple_75 = PyTuple_Pack(6, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_n_s__b), ((PyObject *)__pyx_n_s__cpy), ((PyObject *)__pyx_n_s__nbytes), ((PyObject *)__pyx_n_s__line), ((PyObject *)__pyx_n_s__s)); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_75 = PyTuple_Pack(6, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_n_s__b), ((PyObject *)__pyx_n_s__cpy), ((PyObject *)__pyx_n_s__nbytes), ((PyObject *)__pyx_n_s__line), ((PyObject *)__pyx_n_s__s)); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_75);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_75));
-  __pyx_k_codeobj_76 = (PyObject*)__Pyx_PyCode_New(1, 0, 6, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_75, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s____next__, 846, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_76)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_76 = (PyObject*)__Pyx_PyCode_New(1, 0, 6, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_75, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s____next__, 892, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_76)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/ctabix.pyx":880
+  /* "pysam/ctabix.pyx":931
  * 
  *     # python version - required for python 2.7
  *     def next(self):             # <<<<<<<<<<<<<<
  *         return self.__next__()
  * 
  */
-  __pyx_k_tuple_78 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_78)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_78 = PyTuple_Pack(1, ((PyObject *)__pyx_n_s__self)); if (unlikely(!__pyx_k_tuple_78)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_78);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_78));
-  __pyx_k_codeobj_79 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_78, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s__next, 880, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_79)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_79 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_78, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s__next, 931, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_79)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "pysam/ctabix.pyx":883
+  /* "pysam/ctabix.pyx":934
  *         return self.__next__()
  * 
  * def tabix_iterator( infile, parser ):             # <<<<<<<<<<<<<<
  *     """return an iterator over all entries in a file."""
- *     return tabix_generic_iterator( infile, parser )
+ *     if PYTHON3:
  */
-  __pyx_k_tuple_82 = PyTuple_Pack(2, ((PyObject *)__pyx_n_s__infile), ((PyObject *)__pyx_n_s__parser)); if (unlikely(!__pyx_k_tuple_82)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_tuple_82 = PyTuple_Pack(2, ((PyObject *)__pyx_n_s__infile), ((PyObject *)__pyx_n_s__parser)); if (unlikely(!__pyx_k_tuple_82)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_k_tuple_82);
   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_82));
-  __pyx_k_codeobj_83 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_82, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s__tabix_iterator, 883, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_83)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_k_codeobj_83 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_82, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_65, __pyx_n_s__tabix_iterator, 934, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_83)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_RefNannyFinishContext();
   return 0;
   __pyx_L1_error:;
@@ -11587,6 +11191,7 @@ static int __Pyx_InitGlobals(void) {
   __pyx_int_17 = PyInt_FromLong(17); if (unlikely(!__pyx_int_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
   __pyx_int_18 = PyInt_FromLong(18); if (unlikely(!__pyx_int_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
   __pyx_int_35 = PyInt_FromLong(35); if (unlikely(!__pyx_int_35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+  __pyx_int_64 = PyInt_FromLong(64); if (unlikely(!__pyx_int_64)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
   __pyx_int_65536 = PyInt_FromLong(65536); if (unlikely(!__pyx_int_65536)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
   return 0;
   __pyx_L1_error:;
@@ -11668,13 +11273,19 @@ PyMODINIT_FUNC PyInit_ctabix(void)
   /*--- Variable export code ---*/
   /*--- Function export code ---*/
   /*--- Type init code ---*/
-  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_Tabixfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "Tabixfile", (PyObject *)&__pyx_type_5pysam_6ctabix_Tabixfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_vtabptr_5pysam_6ctabix_tabix_file_iterator = &__pyx_vtable_5pysam_6ctabix_tabix_file_iterator;
+  __pyx_vtable_5pysam_6ctabix_tabix_file_iterator.__pyx___cnext__ = (PyObject *(*)(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *))__pyx_f_5pysam_6ctabix_19tabix_file_iterator___cnext__;
+  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_tabix_file_iterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_6ctabix_tabix_file_iterator.tp_dict, __pyx_vtabptr_5pysam_6ctabix_tabix_file_iterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "tabix_file_iterator", (PyObject *)&__pyx_type_5pysam_6ctabix_tabix_file_iterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_6ctabix_tabix_file_iterator = &__pyx_type_5pysam_6ctabix_tabix_file_iterator;
+  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_Tabixfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "Tabixfile", (PyObject *)&__pyx_type_5pysam_6ctabix_Tabixfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_6ctabix_Tabixfile = &__pyx_type_5pysam_6ctabix_Tabixfile;
-  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_TabixIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_TabixIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_CPYTHON
   {
-    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_6ctabix_TabixIterator, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_6ctabix_TabixIterator, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
       __pyx_wrapperbase_5pysam_6ctabix_13TabixIterator_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
       __pyx_wrapperbase_5pysam_6ctabix_13TabixIterator_4__next__.doc = __pyx_doc_5pysam_6ctabix_13TabixIterator_4__next__;
@@ -11682,12 +11293,12 @@ PyMODINIT_FUNC PyInit_ctabix(void)
     }
   }
   #endif
-  if (__Pyx_SetAttrString(__pyx_m, "TabixIterator", (PyObject *)&__pyx_type_5pysam_6ctabix_TabixIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "TabixIterator", (PyObject *)&__pyx_type_5pysam_6ctabix_TabixIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_6ctabix_TabixIterator = &__pyx_type_5pysam_6ctabix_TabixIterator;
-  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_TabixHeaderIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_TabixHeaderIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_CPYTHON
   {
-    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_6ctabix_TabixHeaderIterator, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_6ctabix_TabixHeaderIterator, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
       __pyx_wrapperbase_5pysam_6ctabix_19TabixHeaderIterator_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
       __pyx_wrapperbase_5pysam_6ctabix_19TabixHeaderIterator_4__next__.doc = __pyx_doc_5pysam_6ctabix_19TabixHeaderIterator_4__next__;
@@ -11695,31 +11306,50 @@ PyMODINIT_FUNC PyInit_ctabix(void)
     }
   }
   #endif
-  if (__Pyx_SetAttrString(__pyx_m, "TabixHeaderIterator", (PyObject *)&__pyx_type_5pysam_6ctabix_TabixHeaderIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "TabixHeaderIterator", (PyObject *)&__pyx_type_5pysam_6ctabix_TabixHeaderIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_6ctabix_TabixHeaderIterator = &__pyx_type_5pysam_6ctabix_TabixHeaderIterator;
-  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_Parser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "Parser", (PyObject *)&__pyx_type_5pysam_6ctabix_Parser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_vtabptr_5pysam_6ctabix_Parser = &__pyx_vtable_5pysam_6ctabix_Parser;
+  __pyx_vtable_5pysam_6ctabix_Parser.parse = (PyObject *(*)(struct __pyx_obj_5pysam_6ctabix_Parser *, char *, int))__pyx_f_5pysam_6ctabix_6Parser_parse;
+  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_Parser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_6ctabix_Parser.tp_dict, __pyx_vtabptr_5pysam_6ctabix_Parser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "Parser", (PyObject *)&__pyx_type_5pysam_6ctabix_Parser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_6ctabix_Parser = &__pyx_type_5pysam_6ctabix_Parser;
+  __pyx_vtabptr_5pysam_6ctabix_asTuple = &__pyx_vtable_5pysam_6ctabix_asTuple;
+  __pyx_vtable_5pysam_6ctabix_asTuple.__pyx_base = *__pyx_vtabptr_5pysam_6ctabix_Parser;
+  __pyx_vtable_5pysam_6ctabix_asTuple.__pyx_base.parse = (PyObject *(*)(struct __pyx_obj_5pysam_6ctabix_Parser *, char *, int))__pyx_f_5pysam_6ctabix_7asTuple_parse;
   __pyx_type_5pysam_6ctabix_asTuple.tp_base = __pyx_ptype_5pysam_6ctabix_Parser;
-  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_asTuple) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "asTuple", (PyObject *)&__pyx_type_5pysam_6ctabix_asTuple) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_asTuple) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_6ctabix_asTuple.tp_dict, __pyx_vtabptr_5pysam_6ctabix_asTuple) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "asTuple", (PyObject *)&__pyx_type_5pysam_6ctabix_asTuple) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_6ctabix_asTuple = &__pyx_type_5pysam_6ctabix_asTuple;
+  __pyx_vtabptr_5pysam_6ctabix_asGTF = &__pyx_vtable_5pysam_6ctabix_asGTF;
+  __pyx_vtable_5pysam_6ctabix_asGTF.__pyx_base = *__pyx_vtabptr_5pysam_6ctabix_Parser;
+  __pyx_vtable_5pysam_6ctabix_asGTF.__pyx_base.parse = (PyObject *(*)(struct __pyx_obj_5pysam_6ctabix_Parser *, char *, int))__pyx_f_5pysam_6ctabix_5asGTF_parse;
   __pyx_type_5pysam_6ctabix_asGTF.tp_base = __pyx_ptype_5pysam_6ctabix_Parser;
-  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_asGTF) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "asGTF", (PyObject *)&__pyx_type_5pysam_6ctabix_asGTF) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_asGTF) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_6ctabix_asGTF.tp_dict, __pyx_vtabptr_5pysam_6ctabix_asGTF) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "asGTF", (PyObject *)&__pyx_type_5pysam_6ctabix_asGTF) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_6ctabix_asGTF = &__pyx_type_5pysam_6ctabix_asGTF;
+  __pyx_vtabptr_5pysam_6ctabix_asBed = &__pyx_vtable_5pysam_6ctabix_asBed;
+  __pyx_vtable_5pysam_6ctabix_asBed.__pyx_base = *__pyx_vtabptr_5pysam_6ctabix_Parser;
+  __pyx_vtable_5pysam_6ctabix_asBed.__pyx_base.parse = (PyObject *(*)(struct __pyx_obj_5pysam_6ctabix_Parser *, char *, int))__pyx_f_5pysam_6ctabix_5asBed_parse;
   __pyx_type_5pysam_6ctabix_asBed.tp_base = __pyx_ptype_5pysam_6ctabix_Parser;
-  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_asBed) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "asBed", (PyObject *)&__pyx_type_5pysam_6ctabix_asBed) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_asBed) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_6ctabix_asBed.tp_dict, __pyx_vtabptr_5pysam_6ctabix_asBed) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "asBed", (PyObject *)&__pyx_type_5pysam_6ctabix_asBed) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_6ctabix_asBed = &__pyx_type_5pysam_6ctabix_asBed;
+  __pyx_vtabptr_5pysam_6ctabix_asVCF = &__pyx_vtable_5pysam_6ctabix_asVCF;
+  __pyx_vtable_5pysam_6ctabix_asVCF.__pyx_base = *__pyx_vtabptr_5pysam_6ctabix_Parser;
+  __pyx_vtable_5pysam_6ctabix_asVCF.__pyx_base.parse = (PyObject *(*)(struct __pyx_obj_5pysam_6ctabix_Parser *, char *, int))__pyx_f_5pysam_6ctabix_5asVCF_parse;
   __pyx_type_5pysam_6ctabix_asVCF.tp_base = __pyx_ptype_5pysam_6ctabix_Parser;
-  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_asVCF) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "asVCF", (PyObject *)&__pyx_type_5pysam_6ctabix_asVCF) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_asVCF) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_6ctabix_asVCF.tp_dict, __pyx_vtabptr_5pysam_6ctabix_asVCF) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "asVCF", (PyObject *)&__pyx_type_5pysam_6ctabix_asVCF) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_6ctabix_asVCF = &__pyx_type_5pysam_6ctabix_asVCF;
-  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_TabixIteratorParsed) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_TabixIteratorParsed) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_CPYTHON
   {
-    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_6ctabix_TabixIteratorParsed, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_6ctabix_TabixIteratorParsed, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
       __pyx_wrapperbase_5pysam_6ctabix_19TabixIteratorParsed_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
       __pyx_wrapperbase_5pysam_6ctabix_19TabixIteratorParsed_4__next__.doc = __pyx_doc_5pysam_6ctabix_19TabixIteratorParsed_4__next__;
@@ -11727,20 +11357,8 @@ PyMODINIT_FUNC PyInit_ctabix(void)
     }
   }
   #endif
-  if (__Pyx_SetAttrString(__pyx_m, "TabixIteratorParsed", (PyObject *)&__pyx_type_5pysam_6ctabix_TabixIteratorParsed) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetAttrString(__pyx_m, "TabixIteratorParsed", (PyObject *)&__pyx_type_5pysam_6ctabix_TabixIteratorParsed) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_6ctabix_TabixIteratorParsed = &__pyx_type_5pysam_6ctabix_TabixIteratorParsed;
-  __pyx_vtabptr_5pysam_6ctabix_tabix_inplace_iterator = &__pyx_vtable_5pysam_6ctabix_tabix_inplace_iterator;
-  __pyx_vtable_5pysam_6ctabix_tabix_inplace_iterator.__pyx___cnext__ = (PyObject *(*)(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *))__pyx_f_5pysam_6ctabix_22tabix_inplace_iterator___cnext__;
-  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_tabix_inplace_iterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetVtable(__pyx_type_5pysam_6ctabix_tabix_inplace_iterator.tp_dict, __pyx_vtabptr_5pysam_6ctabix_tabix_inplace_iterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "tabix_inplace_iterator", (PyObject *)&__pyx_type_5pysam_6ctabix_tabix_inplace_iterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_ptype_5pysam_6ctabix_tabix_inplace_iterator = &__pyx_type_5pysam_6ctabix_tabix_inplace_iterator;
-  __pyx_vtabptr_5pysam_6ctabix_tabix_copy_iterator = &__pyx_vtable_5pysam_6ctabix_tabix_copy_iterator;
-  __pyx_vtable_5pysam_6ctabix_tabix_copy_iterator.__pyx___cnext__ = (PyObject *(*)(struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *))__pyx_f_5pysam_6ctabix_19tabix_copy_iterator___cnext__;
-  if (PyType_Ready(&__pyx_type_5pysam_6ctabix_tabix_copy_iterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetVtable(__pyx_type_5pysam_6ctabix_tabix_copy_iterator.tp_dict, __pyx_vtabptr_5pysam_6ctabix_tabix_copy_iterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (__Pyx_SetAttrString(__pyx_m, "tabix_copy_iterator", (PyObject *)&__pyx_type_5pysam_6ctabix_tabix_copy_iterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_ptype_5pysam_6ctabix_tabix_copy_iterator = &__pyx_type_5pysam_6ctabix_tabix_copy_iterator;
   /*--- Type import code ---*/
   __pyx_ptype_5pysam_10TabProxies_TupleProxy = __Pyx_ImportType("pysam.TabProxies", "TupleProxy", sizeof(struct __pyx_obj_5pysam_10TabProxies_TupleProxy), 1); if (unlikely(!__pyx_ptype_5pysam_10TabProxies_TupleProxy)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_vtabptr_5pysam_10TabProxies_TupleProxy = (struct __pyx_vtabstruct_5pysam_10TabProxies_TupleProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_10TabProxies_TupleProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10TabProxies_TupleProxy)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
@@ -11817,41 +11435,41 @@ PyMODINIT_FUNC PyInit_ctabix(void)
   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__io, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":14
- *     PyObject_AsFileDescriptor
+  /* "pysam/ctabix.pyx":19
+ * from libc.stdint cimport int64_t
  * 
  * PYTHON3 = PY_MAJOR_VERSION >= 3             # <<<<<<<<<<<<<<
  * 
  * # from cpython cimport PyString_FromStringAndSize, PyString_AS_STRING
  */
-  __pyx_t_1 = __Pyx_PyBool_FromLong((PY_MAJOR_VERSION >= 3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyBool_FromLong((PY_MAJOR_VERSION >= 3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__PYTHON3, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__PYTHON3, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":27
+  /* "pysam/ctabix.pyx":32
  * # filename encoding (copied from lxml.etree.pyx)
  * cdef str _FILENAME_ENCODING
  * _FILENAME_ENCODING = sys.getfilesystemencoding()             # <<<<<<<<<<<<<<
  * if _FILENAME_ENCODING is None:
  *     _FILENAME_ENCODING = sys.getdefaultencoding()
  */
-  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s_62); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s_62); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __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_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_XGOTREF(((PyObject *)__pyx_v_5pysam_6ctabix__FILENAME_ENCODING));
   __Pyx_DECREF(((PyObject *)__pyx_v_5pysam_6ctabix__FILENAME_ENCODING));
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_v_5pysam_6ctabix__FILENAME_ENCODING = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":28
+  /* "pysam/ctabix.pyx":33
  * cdef str _FILENAME_ENCODING
  * _FILENAME_ENCODING = sys.getfilesystemencoding()
  * if _FILENAME_ENCODING is None:             # <<<<<<<<<<<<<<
@@ -11861,22 +11479,22 @@ PyMODINIT_FUNC PyInit_ctabix(void)
   __pyx_t_3 = (__pyx_v_5pysam_6ctabix__FILENAME_ENCODING == ((PyObject*)Py_None));
   if (__pyx_t_3) {
 
-    /* "pysam/ctabix.pyx":29
+    /* "pysam/ctabix.pyx":34
  * _FILENAME_ENCODING = sys.getfilesystemencoding()
  * if _FILENAME_ENCODING is None:
  *     _FILENAME_ENCODING = sys.getdefaultencoding()             # <<<<<<<<<<<<<<
  * if _FILENAME_ENCODING is None:
  *     _FILENAME_ENCODING = 'ascii'
  */
-    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__getdefaultencoding); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__getdefaultencoding); 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_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_XGOTREF(((PyObject *)__pyx_v_5pysam_6ctabix__FILENAME_ENCODING));
     __Pyx_DECREF(((PyObject *)__pyx_v_5pysam_6ctabix__FILENAME_ENCODING));
     __Pyx_GIVEREF(__pyx_t_1);
@@ -11886,7 +11504,7 @@ PyMODINIT_FUNC PyInit_ctabix(void)
   }
   __pyx_L2:;
 
-  /* "pysam/ctabix.pyx":30
+  /* "pysam/ctabix.pyx":35
  * if _FILENAME_ENCODING is None:
  *     _FILENAME_ENCODING = sys.getdefaultencoding()
  * if _FILENAME_ENCODING is None:             # <<<<<<<<<<<<<<
@@ -11896,7 +11514,7 @@ PyMODINIT_FUNC PyInit_ctabix(void)
   __pyx_t_3 = (__pyx_v_5pysam_6ctabix__FILENAME_ENCODING == ((PyObject*)Py_None));
   if (__pyx_t_3) {
 
-    /* "pysam/ctabix.pyx":31
+    /* "pysam/ctabix.pyx":36
  *     _FILENAME_ENCODING = sys.getdefaultencoding()
  * if _FILENAME_ENCODING is None:
  *     _FILENAME_ENCODING = 'ascii'             # <<<<<<<<<<<<<<
@@ -11912,161 +11530,161 @@ PyMODINIT_FUNC PyInit_ctabix(void)
   }
   __pyx_L3:;
 
-  /* "pysam/ctabix.pyx":566
+  /* "pysam/ctabix.pyx":584
  * def tabix_compress( filename_in,
  *                     filename_out,
  *                     force = False ):             # <<<<<<<<<<<<<<
  *     '''
  *     compress *filename_in* writing the output to *filename_out*.
  */
-  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_k_30 = __pyx_t_1;
+  __pyx_k_29 = __pyx_t_1;
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":564
+  /* "pysam/ctabix.pyx":582
  *             ti_iter_destroy(self.iterator)
  * 
  * def tabix_compress( filename_in,             # <<<<<<<<<<<<<<
  *                     filename_out,
  *                     force = False ):
  */
-  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_1tabix_compress, NULL, __pyx_n_s_66); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_1tabix_compress, NULL, __pyx_n_s_66); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__tabix_compress, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__tabix_compress, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":612
+  /* "pysam/ctabix.pyx":630
  * 
  * def tabix_index( filename,
  *                  force = False,             # <<<<<<<<<<<<<<
  *                  seq_col = None,
  *                  start_col = None,
  */
-  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_k_39 = __pyx_t_1;
+  __pyx_k_38 = __pyx_t_1;
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":618
+  /* "pysam/ctabix.pyx":636
  *                  preset = None,
  *                  meta_char = "#",
  *                  zerobased = False,             # <<<<<<<<<<<<<<
  *                 ):
  *     '''
  */
-  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 618; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_k_41 = __pyx_t_1;
+  __pyx_k_40 = __pyx_t_1;
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":611
+  /* "pysam/ctabix.pyx":629
  *     if r < 0: raise OSError("writing failed")
  * 
  * def tabix_index( filename,             # <<<<<<<<<<<<<<
  *                  force = False,
  *                  seq_col = None,
  */
-  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_3tabix_index, NULL, __pyx_n_s_66); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_3tabix_index, NULL, __pyx_n_s_66); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__tabix_index, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__tabix_index, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":831
+  /* "pysam/ctabix.pyx":877
  *         return self.__cnext__()
  * 
  * class tabix_generic_iterator:             # <<<<<<<<<<<<<<
  *     '''iterate over ``infile``.
  * 
  */
-  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
 
-  /* "pysam/ctabix.pyx":836
+  /* "pysam/ctabix.pyx":882
  *     Permits the use of file-like objects for example from the gzip module.
  *     '''
  *     def __init__(self, infile, parser ):             # <<<<<<<<<<<<<<
  * 
  *         self.infile = infile
  */
-  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_22tabix_generic_iterator_1__init__, 0, __pyx_n_s_71, NULL, __pyx_n_s_66, ((PyObject *)__pyx_k_codeobj_70)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_22tabix_generic_iterator_1__init__, 0, __pyx_n_s_71, NULL, __pyx_n_s_66, ((PyObject *)__pyx_k_codeobj_70)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____init__, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____init__, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/ctabix.pyx":842
+  /* "pysam/ctabix.pyx":888
  *         self.parser = parser
  * 
  *     def __iter__(self):             # <<<<<<<<<<<<<<
  *         return self
  * 
  */
-  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_22tabix_generic_iterator_3__iter__, 0, __pyx_n_s_74, NULL, __pyx_n_s_66, ((PyObject *)__pyx_k_codeobj_73)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_22tabix_generic_iterator_3__iter__, 0, __pyx_n_s_74, NULL, __pyx_n_s_66, ((PyObject *)__pyx_k_codeobj_73)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____iter__, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____iter__, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/ctabix.pyx":846
+  /* "pysam/ctabix.pyx":892
  * 
  *     # cython version - required for python 3
  *     def __next__(self):             # <<<<<<<<<<<<<<
  * 
  *         cdef char * b, * cpy
  */
-  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_22tabix_generic_iterator_5__next__, 0, __pyx_n_s_77, NULL, __pyx_n_s_66, ((PyObject *)__pyx_k_codeobj_76)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_22tabix_generic_iterator_5__next__, 0, __pyx_n_s_77, NULL, __pyx_n_s_66, ((PyObject *)__pyx_k_codeobj_76)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____next__, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____next__, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/ctabix.pyx":880
+  /* "pysam/ctabix.pyx":931
  * 
  *     # python version - required for python 2.7
  *     def next(self):             # <<<<<<<<<<<<<<
  *         return self.__next__()
  * 
  */
-  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_22tabix_generic_iterator_7next, 0, __pyx_n_s_80, NULL, __pyx_n_s_66, ((PyObject *)__pyx_k_codeobj_79)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_22tabix_generic_iterator_7next, 0, __pyx_n_s_80, NULL, __pyx_n_s_66, ((PyObject *)__pyx_k_codeobj_79)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__next, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__next, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "pysam/ctabix.pyx":831
+  /* "pysam/ctabix.pyx":877
  *         return self.__cnext__()
  * 
  * class tabix_generic_iterator:             # <<<<<<<<<<<<<<
  *     '''iterate over ``infile``.
  * 
  */
-  if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_81)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_t_2 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s_58, __pyx_n_s_58, __pyx_n_s_66); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_81)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s_58, __pyx_n_s_58, __pyx_n_s_66); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_58, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_58, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":883
+  /* "pysam/ctabix.pyx":934
  *         return self.__next__()
  * 
  * def tabix_iterator( infile, parser ):             # <<<<<<<<<<<<<<
  *     """return an iterator over all entries in a file."""
- *     return tabix_generic_iterator( infile, parser )
+ *     if PYTHON3:
  */
-  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_5tabix_iterator, NULL, __pyx_n_s_66); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_6ctabix_5tabix_iterator, NULL, __pyx_n_s_66); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__tabix_iterator, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__tabix_iterator, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "pysam/ctabix.pyx":899
+  /* "pysam/ctabix.pyx":954
  * #            return tabix_generic_iterator( infile, parser )
  * 
  * __all__ = ["tabix_index",             # <<<<<<<<<<<<<<
  *            "tabix_compress",
  *            "Tabixfile",
  */
-  __pyx_t_1 = PyList_New(9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyList_New(10); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(((PyObject *)__pyx_n_s__tabix_index));
   PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__tabix_index));
@@ -12092,10 +11710,13 @@ PyMODINIT_FUNC PyInit_ctabix(void)
   __Pyx_INCREF(((PyObject *)__pyx_n_s__tabix_iterator));
   PyList_SET_ITEM(__pyx_t_1, 7, ((PyObject *)__pyx_n_s__tabix_iterator));
   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tabix_iterator));
-  __Pyx_INCREF(((PyObject *)__pyx_n_s_84));
-  PyList_SET_ITEM(__pyx_t_1, 8, ((PyObject *)__pyx_n_s_84));
-  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_84));
-  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_INCREF(((PyObject *)__pyx_n_s_58));
+  PyList_SET_ITEM(__pyx_t_1, 8, ((PyObject *)__pyx_n_s_58));
+  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_58));
+  __Pyx_INCREF(((PyObject *)__pyx_n_s__tabix_file_iterator));
+  PyList_SET_ITEM(__pyx_t_1, 9, ((PyObject *)__pyx_n_s__tabix_file_iterator));
+  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tabix_file_iterator));
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
   /* "pysam/ctabix.pyx":1
@@ -12504,6 +12125,18 @@ static void __Pyx_RaiseArgtupleInvalid(
                  (num_expected == 1) ? "" : "s", num_found);
 }
 
+static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
+    if (unlikely(!type)) {
+        PyErr_Format(PyExc_SystemError, "Missing type object");
+        return 0;
+    }
+    if (likely(PyObject_TypeCheck(obj, type)))
+        return 1;
+    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
+                 Py_TYPE(obj)->tp_name, type->tp_name);
+    return 0;
+}
+
 static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
     PyErr_Format(PyExc_ValueError,
                  "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
diff --git a/pysam/ctabix.pxd b/pysam/ctabix.pxd
index c10dc43..1631f43 100644
--- a/pysam/ctabix.pxd
+++ b/pysam/ctabix.pxd
@@ -74,6 +74,19 @@ cdef extern from "stdint.h":
   ctypedef int uint8_t
   ctypedef int uint64_t
 
+cdef extern from "zlib.h":
+  ctypedef void * gzFile
+  ctypedef int64_t z_off_t
+
+  int gzclose(gzFile fp)
+  int gzread(gzFile fp, void *buf, unsigned int n)
+  char *gzerror(gzFile fp, int *errnum)
+
+  gzFile gzopen( char *path, char *mode)
+  gzFile gzdopen (int fd, char *mode)
+  char * gzgets(gzFile file, char *buf, int len)
+  int gzeof( gzFile file )
+
 cdef extern from "Python.h":
     ctypedef struct FILE
     char *fgets(char *str, int size, FILE *ifile)
@@ -169,6 +182,33 @@ cdef extern from "tabix.h":
   #  /* Get the data line pointed by the iterator and iterate to the next record. */
   # char *ti_iter_read(BGZF *fp, ti_iter_t iter, int *len)
 
+cdef extern from "tabix_util.h":
+
+    ctypedef struct kstring_t:
+        size_t l
+        size_t m
+        char * s
+
+    ctypedef struct kstream_t:
+        pass
+
+    kstream_t * ks_init( gzFile )
+
+    int ks_read( kstream_t * )
+    void ks_destroy( kstream_t * )
+    int ks_getuntil( kstream_t *, int, kstring_t *, int * ) 
+
+cdef class tabix_file_iterator:
+    cdef gzFile fh
+    cdef kstream_t * ks
+    cdef kstring_t buffer
+    cdef size_t size
+    cdef Parser parser
+    cdef int fd
+    cdef infile
+
+    cdef __cnext__(self)
+
 cdef class Tabixfile:
 
     # pointer to tabixfile
@@ -179,6 +219,8 @@ cdef class Tabixfile:
 
     cdef char * _filename
 
+    cdef Parser parser
+    
 cdef class TabixIterator:
     cdef ti_iter_t iterator
     cdef tabix_t * tabixfile
@@ -188,10 +230,11 @@ cdef class TabixHeaderIterator:
     cdef tabix_t * tabixfile
 
 cdef class Parser:
-     pass
+     cdef parse( self, char * buffer, int len )
 
 cdef class asTuple(Parser):
-     pass
+     cdef parse( self, char * buffer, int len )
+
 
 cdef class asGTF(Parser):
      pass
@@ -206,19 +249,3 @@ cdef class TabixIteratorParsed:
     cdef ti_iter_t iterator
     cdef tabix_t * tabixfile
     cdef Parser parser
-
-cdef class tabix_inplace_iterator:
-    cdef FILE * infile
-    cdef char * buffer
-    cdef size_t size
-    cdef Parser parser
-
-    cdef __cnext__(self)
-
-cdef class tabix_copy_iterator:
-    cdef FILE * infile  
-    cdef Parser parser
-    cdef __cnext__(self)
-
-cdef extern from "tabix_util.h":
-     pass
diff --git a/pysam/ctabix.pyx b/pysam/ctabix.pyx
index 6a19541..c9cf419 100644
--- a/pysam/ctabix.pyx
+++ b/pysam/ctabix.pyx
@@ -11,6 +11,11 @@ from cpython cimport PyErr_SetString, PyBytes_Check, \
     PyUnicode_Check, PyBytes_FromStringAndSize, \
     PyObject_AsFileDescriptor
 
+from libc.stdio cimport printf, fprintf, stderr
+from libc.string cimport strerror
+from libc.errno cimport errno
+from libc.stdint cimport int64_t
+
 PYTHON3 = PY_MAJOR_VERSION >= 3
 
 # from cpython cimport PyString_FromStringAndSize, PyString_AS_STRING
@@ -82,13 +87,20 @@ cdef _force_str(object s):
 
 
 cdef class Tabixfile:
-    '''*(filename, mode='r')*
+    '''*(filename, mode='r', parser = None)*
 
     opens a :term:`tabix file` for reading. A missing
     index (*filename* + ".tbi") will raise an exception.
+
+    *parser* sets the default parser for this tabix file. If *parser*
+    is None, the results are returned as an unparsed string.
+    Otherwise, *parser* is assumed to be a functor that will return
+    parsed data (see for example :meth:`asTuple` and :meth:`asGTF`).
     '''
-    def __cinit__(self, filename, mode = 'r', *args, **kwargs ):
+    def __cinit__(self, filename, mode = 'r', 
+                  parser = None, *args, **kwargs ):
         self.tabixfile = NULL
+        self.parser = parser
         self._open( filename, mode, *args, **kwargs )
 
     def _isOpen( self ):
@@ -180,10 +192,10 @@ cdef class Tabixfile:
             region = _force_bytes(region)
             ti_parse_region( self.tabixfile.idx, region, 
                              &rtid, &rstart, &rend)        
-            if rtid < 0: raise ValueError( "invalid region `%s`" % region )
+            if rtid < 0: raise KeyError( reference )
             if rstart > rend: raise ValueError( 'invalid region: start (%i) > end (%i)' % (rstart, rend) )
-            if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
-            if not 0 <= rend < max_pos: raise ValueError( 'end out of range (%i)' % rend )
+            if not 0 <= rstart < max_pos: raise IndexError( 'start out of range (%i)' % rstart )
+            if not 0 <= rend < max_pos: raise IndexError( 'end out of range (%i)' % rend )
 
         return region, rtid, rstart, rend
 
@@ -202,25 +214,28 @@ cdef class Tabixfile:
         
         If only *reference* is set, all reads matching on *reference* will be fetched.
 
-        If *parser* is None, the results are returned as an unparsed string.
-        Otherwise, *parser* is assumed to be a functor that will return parsed 
-        data (see for example :meth:`asTuple` and :meth:`asGTF`).
+        If *parser* is None, the default parser will be used for parsing.
         '''
         ti_lazy_index_load( self.tabixfile )
 
         if not self._isOpen():
             raise ValueError( "I/O operation on closed file" )
 
+        # the following will raise errors for invalid regions
         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
 
-        if parser == None:
+        # use default parser if no parser is specified
+        if parser == None: parser = self.parser
+
+        if parser == None: 
             if region:
                 return TabixIterator( self, rtid, rstart, rend )
             else:
                 return TabixIterator( self, -1, 0, 0 )
         else:
             if region:
-                return TabixIteratorParsed( self, rtid, rstart, rend, parser )
+                return TabixIteratorParsed( self, rtid, rstart, 
+                                            rend, parser )
             else:
                 return TabixIteratorParsed( self, -1, 0, 0, parser )
 
@@ -315,7 +330,6 @@ cdef class TabixIterator:
         # metachar filtering does not work within tabix 
         # though it should. Getting the metachar is a pain
         # as ti_index_t is incomplete type.
-
         # simply use '#' for now.
         while 1:
             s = ti_read(self.tabixfile, self.iterator, &len)
@@ -376,14 +390,19 @@ cdef class TabixHeaderIterator:
 #########################################################
 #########################################################
 cdef class Parser:
-    pass
+
+    cdef parse(self, char * buffer, int length):
+        raise NotImplementedError
+
+    def __call__(self, char * buffer, int length):
+        return self.parse( buffer, length )
 
 cdef class asTuple(Parser):
     '''converts a :term:`tabix row` into a python tuple.
 
     Access is by numeric index.
     ''' 
-    def __call__(self, char * buffer, int len):
+    cdef parse(self, char * buffer, int len):
         cdef TabProxies.TupleProxy r
         r = TabProxies.TupleProxy()
         # need to copy - there were some
@@ -422,7 +441,7 @@ cdef class asGTF(Parser):
        the transcript identifier
     
     ''' 
-    def __call__(self, char * buffer, int len):
+    cdef parse(self, char * buffer, int len):
         cdef TabProxies.GTFProxy r
         r = TabProxies.GTFProxy()
         r.copy( buffer, len )
@@ -462,7 +481,7 @@ cdef class asBed( Parser ):
     need to be defined as well.
 
     ''' 
-    def __call__(self, char * buffer, int len):
+    cdef parse(self, char * buffer, int len):
         cdef TabProxies.BedProxy r
         r = TabProxies.BedProxy()
         r.copy( buffer, len )
@@ -498,7 +517,7 @@ cdef class asVCF( Parser ):
         second_sample_genotype = vcf[1]
 
     '''
-    def __call__(self, char * buffer, int len ):
+    cdef parse(self, char * buffer, int len ):
         cdef TabProxies.VCFProxy r
         r = TabProxies.VCFProxy()
         r.copy( buffer, len )
@@ -552,10 +571,9 @@ cdef class TabixIteratorParsed:
         while 1:
             s = ti_read(self.tabixfile, self.iterator, &len)
             if s == NULL: raise StopIteration
-            # todo: read metachar from configuration
             if s[0] != '#': break
             
-        return self.parser(s, len)
+        return self.parser.parse(s, len)
 
     def __dealloc__(self):
         if <void*>self.iterator != NULL:
@@ -670,7 +688,7 @@ def tabix_index( filename,
         'gff' : ( 0, 1, 4, 5, ord('#'), 0 ),
         'bed' : ( 0x10000, 1, 2, 3, ord('#'), 0 ),
         'psltbl' : ( 0x10000, 15, 17, 18, ord('#'), 0 ),
-        'sam' : ( 1, 3, 4, 0, ord('#'), 0 ),
+        'sam' : ( 1, 3, 4, 0, ord('@'), 0 ),
         'vcf' : ( 2, 1, 2, 0, ord('#'), 0 ),
         'pileup': (3, 1, 2, 0, ord('#'), 0 ),
         }
@@ -701,88 +719,119 @@ def tabix_index( filename,
     
     return filename
 
-#########################################################
-#########################################################
-#########################################################
-## Iterators for parsing through unindexed files.
-#########################################################
-ctypedef class tabix_inplace_iterator:
-    '''iterate over ``infile``.
+# #########################################################
+# #########################################################
+# #########################################################
+# ## Iterators for parsing through unindexed files.
+# #########################################################
+# cdef class tabix_file_iterator_old:
+#     '''iterate over ``infile``.
 
-    This iterator is not safe. If the :meth:`__next__()` method is called 
-    after ``infile`` is closed, the result is undefined (see ``fclose()``).
+#     This iterator is not safe. If the :meth:`__next__()` method is called 
+#     after ``infile`` is closed, the result is undefined (see ``fclose()``).
 
-    The iterator might either raise a StopIteration or segfault.
-    '''
+#     The iterator might either raise a StopIteration or segfault.
+#     '''
 
 
-    def __cinit__(self, infile, int buffer_size = 65536 ):
+#     def __cinit__(self, 
+#                   infile, 
+#                   Parser parser,
+#                   int buffer_size = 65536 ):
 
-        cdef int fd = PyObject_AsFileDescriptor( infile )
-        if fd == -1: raise ValueError( "I/O operation on closed file." )
-        self.infile = fdopen( fd, 'r')
+#         cdef int fd = PyObject_AsFileDescriptor( infile )
+#         if fd == -1: raise ValueError( "I/O operation on closed file." )
+#         self.infile = fdopen( fd, 'r')
 
-        if self.infile == NULL: raise ValueError( "I/O operation on closed file." )
+#         if self.infile == NULL: raise ValueError( "I/O operation on closed file." )
 
-        self.buffer = <char*>malloc( buffer_size )        
-        self.size = buffer_size
+#         self.buffer = <char*>malloc( buffer_size )        
+#         self.size = buffer_size
+#         self.parser = parser
 
-    def __iter__(self):
-        return self
+#     def __iter__(self):
+#         return self
 
-    cdef __cnext__(self):
+#     cdef __cnext__(self):
 
-        cdef char * b
-        cdef size_t nbytes
-        b = self.buffer
-        r = self.Parser()
+#         cdef char * b
+#         cdef size_t nbytes
+#         b = self.buffer
 
-        while not feof( self.infile ):
-            nbytes = getline( &b, &self.size, self.infile)
+#         while not feof( self.infile ):
+#             nbytes = getline( &b, &self.size, self.infile)
 
-            # stop at first error or eof
-            if (nbytes == -1): break
-            # skip comments
-            if (b[0] == '#'): continue
+#             # stop at first error or eof
+#             if (nbytes == -1): break
+#             # skip comments
+#             if (b[0] == '#'): continue
 
-            # skip empty lines
-            if b[0] == '\0' or b[0] == '\n' or b[0] == '\r': continue
+#             # skip empty lines
+#             if b[0] == '\0' or b[0] == '\n' or b[0] == '\r': continue
 
-            # make sure that entry is complete
-            if b[nbytes-1] != '\n' and b[nbytes-1] != '\r':
-                result = b
-                raise ValueError( "incomplete line at %s" % result )
+#             # make sure that entry is complete
+#             if b[nbytes-1] != '\n' and b[nbytes-1] != '\r':
+#                 result = b
+#                 raise ValueError( "incomplete line at %s" % result )
 
-            # make sure that this goes fully through C
-            # otherwise buffer is copied to/from a
-            # Python object causing segfaults as
-            # the wrong memory is freed
-            r.present( b, nbytes )
-            return r 
+#             # make sure that this goes fully through C
+#             # otherwise buffer is copied to/from a
+#             # Python object causing segfaults as
+#             # the wrong memory is freed
+#             return self.parser.parse( b, nbytes )
 
-        raise StopIteration
+#         raise StopIteration
 
-    def __dealloc__(self):
-        free(self.buffer)
+#     def __dealloc__(self):
+#         free(self.buffer)
 
-    def __next__(self):
-        return self.__cnext__()
+#     def __next__(self):
+#         return self.__cnext__()
 
-ctypedef class tabix_copy_iterator:
-    '''iterate over ``infile``.
+#########################################################
+#########################################################
+#########################################################
+## Iterators for parsing through unindexed files.
+#########################################################
+cdef buildGzipError(void *gzfp):
+    cdef int errnum = 0
+    cdef const char *s = gzerror(gzfp, &errnum)
+    return "error (%d): %s (%d: %s)" % (errno, strerror(errno), errnum, s)
 
-    This iterator is not save. If the :meth:`__next__()` method is called 
-    after ``infile`` is closed, the result is undefined (see ``fclose()``).
 
-    The iterator might either raise a StopIteration or segfault.
+cdef class tabix_file_iterator:
+    '''iterate over a compressed or uncompressed ``infile``.
     '''
 
-    def __cinit__(self, infile, Parser parser ):
+    def __cinit__(self, 
+                  infile, 
+                  Parser parser,
+                  int buffer_size = 65536 ):
+
+        if infile.closed:
+            raise ValueError( "I/O operation on closed file." )
+
+        self.infile = infile
 
         cdef int fd = PyObject_AsFileDescriptor( infile )
         if fd == -1: raise ValueError( "I/O operation on closed file." )
-        self.infile = fdopen( fd, 'r')
-        if self.infile == NULL: raise ValueError( "I/O operation on closed file." )
+
+        # From the manual:
+        # gzopen can be used to read a file which is not in gzip format; 
+        # in this case gzread will directly read from the file without decompression. 
+        # When reading, this will be detected automatically by looking 
+        # for the magic two-byte gzip header. 
+        self.fh = gzdopen( fd, 'r')
+
+        if self.fh == NULL: 
+            raise IOError('%s' % strerror(errno))
+
+        self.ks = ks_init( self.fh) 
+        
+        self.buffer.s = <char*>malloc( buffer_size )
+        #if self.buffer == NULL:
+        #    raise MemoryError( "tabix_file_iterator: could not allocate %i bytes" % buffer_size)
+        #self.size = buffer_size
         self.parser = parser
 
     def __iter__(self):
@@ -791,42 +840,39 @@ ctypedef class tabix_copy_iterator:
     cdef __cnext__(self):
 
         cdef char * b
-        cdef size_t nbytes
-        cdef int x
-
-        b = NULL        
-
-        while not feof( self.infile ):
+        cdef int dret = 0
+        cdef int retval = 0
+        while 1:
+            
+            retval = ks_getuntil(self.ks, '\n', &self.buffer, &dret)
+            
+            if retval < 0: 
+                break
+                #raise IOError('gzip error: %s' % buildGzipError( self.fh ))
 
-            # getline allocates on demand
-            # return number of characters read excluding null byte
-            nbytes = getline( &b, &nbytes, self.infile)
-            # stop at first error
-            if (nbytes == -1): break
+            b = self.buffer.s
+            
             # skip comments
             if (b[0] == '#'): continue
 
             # skip empty lines
             if b[0] == '\0' or b[0] == '\n' or b[0] == '\r': continue
 
-            # make sure that entry is complete
-            if b[nbytes-1] != '\n' and b[nbytes-1] != '\r':
-                result = b
-                free(b)
-                raise ValueError( "incomplete line at %s" % result )
-
-            # make sure that this goes fully through C
-            # otherwise buffer is copied to/from a
-            # Python object causing segfaults as
-            # the wrong memory is freed
-            # -1 to remove the new-line character
-            return self.parser(b, nbytes)
-
-        free(b)
+            # gzgets terminates at \n, no need to test
+
+            # parser creates a copy
+            return self.parser.parse( b, self.buffer.l )
+
         raise StopIteration
 
+    def __dealloc__(self):
+        free(self.buffer.s)
+        
     def __next__(self):
         return self.__cnext__()
+
+    def next(self):
+        return self.__cnext__()
     
 class tabix_generic_iterator:
     '''iterate over ``infile``.
@@ -847,6 +893,11 @@ class tabix_generic_iterator:
         
         cdef char * b, * cpy
         cdef size_t nbytes
+
+        # note that GzipFile.close() does not close the file
+        # reading is still possible.
+        if self.infile.closed: raise ValueError( "I/O operation on closed file." )
+
         while 1:
 
             line = self.infile.readline()
@@ -879,10 +930,14 @@ class tabix_generic_iterator:
     # python version - required for python 2.7
     def next(self):
         return self.__next__()
-    
+
 def tabix_iterator( infile, parser ):
     """return an iterator over all entries in a file."""
-    return tabix_generic_iterator( infile, parser )
+    if PYTHON3:
+        return tabix_generic_iterator( infile, parser )
+    else:
+        return tabix_file_iterator( infile, parser )
+        
     # file objects can use C stdio
     # used to be: isinstance( infile, file):
     # if PYTHON3:
@@ -904,5 +959,6 @@ __all__ = ["tabix_index",
            "asVCF",
            "asBed",
            "tabix_iterator", 
-           "tabix_inplace_iterator"
+           "tabix_generic_iterator", 
+           "tabix_file_iterator", 
            ]
diff --git a/pysam/cvcf.c b/pysam/cvcf.c
index 51f2cf0..dcb83b4 100644
--- a/pysam/cvcf.c
+++ b/pysam/cvcf.c
@@ -1,4 +1,4 @@
-/* Generated by Cython 0.18 on Fri Sep 20 00:20:26 2013 */
+/* Generated by Cython 0.18 on Sat Nov 16 01:37:33 2013 */
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
@@ -260,6 +260,7 @@
 #include "sys/stat.h"
 #include "fcntl.h"
 #include "unistd.h"
+#include "zlib.h"
 #include "bgzf.h"
 #include "tabix.h"
 #include "tabix_util.h"
@@ -345,27 +346,26 @@ static const char *__pyx_f[] = {
 };
 
 /*--- Type declarations ---*/
-struct __pyx_obj_5pysam_6ctabix_Parser;
-struct __pyx_obj_5pysam_6ctabix_asBed;
-struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed;
 struct __pyx_obj_5pysam_4cvcf___pyx_scope_struct_2__parse;
+struct __pyx_obj_5pysam_6ctabix_Parser;
 struct __pyx_obj_5pysam_10TabProxies_TupleProxy;
-struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy;
-struct __pyx_obj_5pysam_10TabProxies_VCFProxy;
 struct __pyx_obj_5pysam_4cvcf_VCFRecord;
-struct __pyx_obj_5pysam_4cvcf_asVCFRecord;
-struct __pyx_obj_5pysam_6ctabix_asVCF;
-struct __pyx_obj_5pysam_4cvcf___pyx_scope_struct__parse_data;
-struct __pyx_obj_5pysam_10TabProxies_GTFProxy;
-struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator;
 struct __pyx_obj_5pysam_6ctabix_asGTF;
+struct __pyx_obj_5pysam_10TabProxies_GTFProxy;
+struct __pyx_obj_5pysam_6ctabix_asTuple;
+struct __pyx_obj_5pysam_6ctabix_asBed;
+struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator;
+struct __pyx_obj_5pysam_4cvcf___pyx_scope_struct__parse_data;
+struct __pyx_obj_5pysam_4cvcf_asVCFRecord;
 struct __pyx_obj_5pysam_6ctabix_Tabixfile;
-struct __pyx_obj_5pysam_6ctabix_TabixIterator;
-struct __pyx_obj_5pysam_4cvcf___pyx_scope_struct_1_genexpr;
-struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator;
+struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy;
 struct __pyx_obj_5pysam_10TabProxies_BedProxy;
-struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator;
-struct __pyx_obj_5pysam_6ctabix_asTuple;
+struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed;
+struct __pyx_obj_5pysam_4cvcf___pyx_scope_struct_1_genexpr;
+struct __pyx_obj_5pysam_6ctabix_asVCF;
+struct __pyx_obj_5pysam_6ctabix_TabixIterator;
+struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator;
+struct __pyx_obj_5pysam_10TabProxies_VCFProxy;
 struct __pyx_defaults;
 typedef struct __pyx_defaults __pyx_defaults;
 struct __pyx_defaults1;
@@ -393,45 +393,6 @@ struct __pyx_defaults4 {
   PyObject *__pyx_arg_lineparse;
 };
 
-/* "ctabix.pxd":190
- *     cdef tabix_t * tabixfile
- * 
- * cdef class Parser:             # <<<<<<<<<<<<<<
- *      pass
- * 
- */
-struct __pyx_obj_5pysam_6ctabix_Parser {
-  PyObject_HEAD
-};
-
-
-/* "ctabix.pxd":199
- *      pass
- * 
- * cdef class asBed(Parser):             # <<<<<<<<<<<<<<
- *      pass
- * 
- */
-struct __pyx_obj_5pysam_6ctabix_asBed {
-  struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
-};
-
-
-/* "ctabix.pxd":205
- *      pass
- * 
- * cdef class TabixIteratorParsed:             # <<<<<<<<<<<<<<
- *     cdef ti_iter_t iterator
- *     cdef tabix_t * tabixfile
- */
-struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed {
-  PyObject_HEAD
-  ti_iter_t iterator;
-  tabix_t *tabixfile;
-  struct __pyx_obj_5pysam_6ctabix_Parser *parser;
-};
-
-
 /* "pysam/cvcf.pyx":902
  *         return line
  * 
@@ -451,6 +412,19 @@ struct __pyx_obj_5pysam_4cvcf___pyx_scope_struct_2__parse {
 };
 
 
+/* "ctabix.pxd":232
+ *     cdef tabix_t * tabixfile
+ * 
+ * cdef class Parser:             # <<<<<<<<<<<<<<
+ *      cdef parse( self, char * buffer, int len )
+ * 
+ */
+struct __pyx_obj_5pysam_6ctabix_Parser {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_5pysam_6ctabix_Parser *__pyx_vtab;
+};
+
+
 /* "TabProxies.pxd":41
  *   ctypedef int uint64_t
  * 
@@ -471,72 +445,91 @@ struct __pyx_obj_5pysam_10TabProxies_TupleProxy {
 };
 
 
-/* "TabProxies.pxd":69
- *     cdef char * getAttributes( self )
+/* "pysam/cvcf.pyx":95
+ * ###########################################################################################################
  * 
- * cdef class NamedTupleProxy( TupleProxy) :             # <<<<<<<<<<<<<<
- *     pass
+ * cdef class VCFRecord( TabProxies.TupleProxy):             # <<<<<<<<<<<<<<
+ *     '''vcf record.
  * 
  */
-struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy {
+struct __pyx_obj_5pysam_4cvcf_VCFRecord {
   struct __pyx_obj_5pysam_10TabProxies_TupleProxy __pyx_base;
+  PyObject *vcf;
+  char *contig;
+  uint32_t pos;
 };
 
 
-/* "TabProxies.pxd":83
- *     cdef update( self, char * buffer, size_t nbytes )
+/* "ctabix.pxd":239
  * 
- * cdef class VCFProxy( NamedTupleProxy) :             # <<<<<<<<<<<<<<
  * 
- *     cdef:
+ * cdef class asGTF(Parser):             # <<<<<<<<<<<<<<
+ *      pass
+ * 
  */
-struct __pyx_obj_5pysam_10TabProxies_VCFProxy {
-  struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy __pyx_base;
-  char *contig;
-  uint32_t pos;
+struct __pyx_obj_5pysam_6ctabix_asGTF {
+  struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
 };
 
 
-/* "pysam/cvcf.pyx":95
- * ###########################################################################################################
+/* "TabProxies.pxd":60
+ *     cdef update( self, char * buffer, size_t nbytes )
  * 
- * cdef class VCFRecord( TabProxies.TupleProxy):             # <<<<<<<<<<<<<<
- *     '''vcf record.
+ * cdef class GTFProxy( TupleProxy) :             # <<<<<<<<<<<<<<
  * 
+ *     cdef:
  */
-struct __pyx_obj_5pysam_4cvcf_VCFRecord {
+struct __pyx_obj_5pysam_10TabProxies_GTFProxy {
   struct __pyx_obj_5pysam_10TabProxies_TupleProxy __pyx_base;
-  PyObject *vcf;
-  char *contig;
-  uint32_t pos;
+  char *_attributes;
+  int hasOwnAttributes;
 };
 
 
-/* "pysam/cvcf.pyx":229
+/* "ctabix.pxd":235
+ *      cdef parse( self, char * buffer, int len )
  * 
+ * cdef class asTuple(Parser):             # <<<<<<<<<<<<<<
+ *      cdef parse( self, char * buffer, int len )
  * 
- * cdef class asVCFRecord( ctabix.Parser ):             # <<<<<<<<<<<<<<
- *     '''converts a :term:`tabix row` into a VCF record.'''
- *     cdef vcffile
  */
-struct __pyx_obj_5pysam_4cvcf_asVCFRecord {
+struct __pyx_obj_5pysam_6ctabix_asTuple {
   struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
-  PyObject *vcffile;
 };
 
 
-/* "ctabix.pxd":202
+/* "ctabix.pxd":242
  *      pass
  * 
- * cdef class asVCF(Parser):             # <<<<<<<<<<<<<<
+ * cdef class asBed(Parser):             # <<<<<<<<<<<<<<
  *      pass
  * 
  */
-struct __pyx_obj_5pysam_6ctabix_asVCF {
+struct __pyx_obj_5pysam_6ctabix_asBed {
   struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
 };
 
 
+/* "ctabix.pxd":201
+ *     int ks_getuntil( kstream_t *, int, kstring_t *, int * )
+ * 
+ * cdef class tabix_file_iterator:             # <<<<<<<<<<<<<<
+ *     cdef gzFile fh
+ *     cdef kstream_t * ks
+ */
+struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_5pysam_6ctabix_tabix_file_iterator *__pyx_vtab;
+  gzFile fh;
+  kstream_t *ks;
+  kstring_t buffer;
+  size_t size;
+  struct __pyx_obj_5pysam_6ctabix_Parser *parser;
+  int fd;
+  PyObject *infile;
+};
+
+
 /* "pysam/cvcf.pyx":650
  *         return False
  * 
@@ -550,72 +543,75 @@ struct __pyx_obj_5pysam_4cvcf___pyx_scope_struct__parse_data {
 };
 
 
-/* "TabProxies.pxd":60
- *     cdef update( self, char * buffer, size_t nbytes )
+/* "pysam/cvcf.pyx":229
  * 
- * cdef class GTFProxy( TupleProxy) :             # <<<<<<<<<<<<<<
  * 
- *     cdef:
+ * cdef class asVCFRecord( ctabix.Parser ):             # <<<<<<<<<<<<<<
+ *     '''converts a :term:`tabix row` into a VCF record.'''
+ *     cdef vcffile
  */
-struct __pyx_obj_5pysam_10TabProxies_GTFProxy {
-  struct __pyx_obj_5pysam_10TabProxies_TupleProxy __pyx_base;
-  char *_attributes;
-  int hasOwnAttributes;
+struct __pyx_obj_5pysam_4cvcf_asVCFRecord {
+  struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
+  PyObject *vcffile;
 };
 
 
-/* "ctabix.pxd":186
- *     cdef tabix_t * tabixfile
+/* "ctabix.pxd":212
+ *     cdef __cnext__(self)
  * 
- * cdef class TabixHeaderIterator:             # <<<<<<<<<<<<<<
- *     cdef ti_iter_t iterator
- *     cdef tabix_t * tabixfile
+ * cdef class Tabixfile:             # <<<<<<<<<<<<<<
+ * 
+ *     # pointer to tabixfile
  */
-struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator {
+struct __pyx_obj_5pysam_6ctabix_Tabixfile {
   PyObject_HEAD
-  ti_iter_t iterator;
   tabix_t *tabixfile;
+  int isremote;
+  char *_filename;
+  struct __pyx_obj_5pysam_6ctabix_Parser *parser;
 };
 
 
-/* "ctabix.pxd":196
- *      pass
+/* "TabProxies.pxd":69
+ *     cdef char * getAttributes( self )
  * 
- * cdef class asGTF(Parser):             # <<<<<<<<<<<<<<
- *      pass
+ * cdef class NamedTupleProxy( TupleProxy) :             # <<<<<<<<<<<<<<
+ *     pass
  * 
  */
-struct __pyx_obj_5pysam_6ctabix_asGTF {
-  struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
+struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy {
+  struct __pyx_obj_5pysam_10TabProxies_TupleProxy __pyx_base;
 };
 
 
-/* "ctabix.pxd":172
- *   # char *ti_iter_read(BGZF *fp, ti_iter_t iter, int *len)
+/* "TabProxies.pxd":72
+ *     pass
  * 
- * cdef class Tabixfile:             # <<<<<<<<<<<<<<
+ * cdef class BedProxy( NamedTupleProxy) :             # <<<<<<<<<<<<<<
  * 
- *     # pointer to tabixfile
+ *     cdef:
  */
-struct __pyx_obj_5pysam_6ctabix_Tabixfile {
-  PyObject_HEAD
-  tabix_t *tabixfile;
-  int isremote;
-  char *_filename;
+struct __pyx_obj_5pysam_10TabProxies_BedProxy {
+  struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy __pyx_base;
+  char *contig;
+  uint32_t start;
+  uint32_t end;
+  int bedfields;
 };
 
 
-/* "ctabix.pxd":182
- *     cdef char * _filename
+/* "ctabix.pxd":248
+ *      pass
  * 
- * cdef class TabixIterator:             # <<<<<<<<<<<<<<
+ * cdef class TabixIteratorParsed:             # <<<<<<<<<<<<<<
  *     cdef ti_iter_t iterator
  *     cdef tabix_t * tabixfile
  */
-struct __pyx_obj_5pysam_6ctabix_TabixIterator {
+struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed {
   PyObject_HEAD
   ti_iter_t iterator;
   tabix_t *tabixfile;
+  struct __pyx_obj_5pysam_6ctabix_Parser *parser;
 };
 
 
@@ -636,63 +632,57 @@ struct __pyx_obj_5pysam_4cvcf___pyx_scope_struct_1_genexpr {
 };
 
 
-/* "ctabix.pxd":210
- *     cdef Parser parser
+/* "ctabix.pxd":245
+ *      pass
+ * 
+ * cdef class asVCF(Parser):             # <<<<<<<<<<<<<<
+ *      pass
  * 
- * cdef class tabix_inplace_iterator:             # <<<<<<<<<<<<<<
- *     cdef FILE * infile
- *     cdef char * buffer
  */
-struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator {
-  PyObject_HEAD
-  struct __pyx_vtabstruct_5pysam_6ctabix_tabix_inplace_iterator *__pyx_vtab;
-  FILE *infile;
-  char *buffer;
-  size_t size;
-  struct __pyx_obj_5pysam_6ctabix_Parser *parser;
+struct __pyx_obj_5pysam_6ctabix_asVCF {
+  struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
 };
 
 
-/* "TabProxies.pxd":72
- *     pass
- * 
- * cdef class BedProxy( NamedTupleProxy) :             # <<<<<<<<<<<<<<
+/* "ctabix.pxd":224
+ *     cdef Parser parser
  * 
- *     cdef:
+ * cdef class TabixIterator:             # <<<<<<<<<<<<<<
+ *     cdef ti_iter_t iterator
+ *     cdef tabix_t * tabixfile
  */
-struct __pyx_obj_5pysam_10TabProxies_BedProxy {
-  struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy __pyx_base;
-  char *contig;
-  uint32_t start;
-  uint32_t end;
-  int bedfields;
+struct __pyx_obj_5pysam_6ctabix_TabixIterator {
+  PyObject_HEAD
+  ti_iter_t iterator;
+  tabix_t *tabixfile;
 };
 
 
-/* "ctabix.pxd":218
- *     cdef __cnext__(self)
+/* "ctabix.pxd":228
+ *     cdef tabix_t * tabixfile
  * 
- * cdef class tabix_copy_iterator:             # <<<<<<<<<<<<<<
- *     cdef FILE * infile
- *     cdef Parser parser
+ * cdef class TabixHeaderIterator:             # <<<<<<<<<<<<<<
+ *     cdef ti_iter_t iterator
+ *     cdef tabix_t * tabixfile
  */
-struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator {
+struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator {
   PyObject_HEAD
-  struct __pyx_vtabstruct_5pysam_6ctabix_tabix_copy_iterator *__pyx_vtab;
-  FILE *infile;
-  struct __pyx_obj_5pysam_6ctabix_Parser *parser;
+  ti_iter_t iterator;
+  tabix_t *tabixfile;
 };
 
 
-/* "ctabix.pxd":193
- *      pass
+/* "TabProxies.pxd":83
+ *     cdef update( self, char * buffer, size_t nbytes )
  * 
- * cdef class asTuple(Parser):             # <<<<<<<<<<<<<<
- *      pass
+ * cdef class VCFProxy( NamedTupleProxy) :             # <<<<<<<<<<<<<<
  * 
+ *     cdef:
  */
-struct __pyx_obj_5pysam_6ctabix_asTuple {
-  struct __pyx_obj_5pysam_6ctabix_Parser __pyx_base;
+struct __pyx_obj_5pysam_10TabProxies_VCFProxy {
+  struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy __pyx_base;
+  char *contig;
+  uint32_t pos;
 };
 
 
@@ -715,6 +705,20 @@ struct __pyx_vtabstruct_5pysam_10TabProxies_TupleProxy {
 static struct __pyx_vtabstruct_5pysam_10TabProxies_TupleProxy *__pyx_vtabptr_5pysam_10TabProxies_TupleProxy;
 
 
+/* "pysam/cvcf.pyx":95
+ * ###########################################################################################################
+ * 
+ * cdef class VCFRecord( TabProxies.TupleProxy):             # <<<<<<<<<<<<<<
+ *     '''vcf record.
+ * 
+ */
+
+struct __pyx_vtabstruct_5pysam_4cvcf_VCFRecord {
+  struct __pyx_vtabstruct_5pysam_10TabProxies_TupleProxy __pyx_base;
+};
+static struct __pyx_vtabstruct_5pysam_4cvcf_VCFRecord *__pyx_vtabptr_5pysam_4cvcf_VCFRecord;
+
+
 /* "TabProxies.pxd":69
  *     cdef char * getAttributes( self )
  * 
@@ -743,32 +747,60 @@ struct __pyx_vtabstruct_5pysam_10TabProxies_VCFProxy {
 static struct __pyx_vtabstruct_5pysam_10TabProxies_VCFProxy *__pyx_vtabptr_5pysam_10TabProxies_VCFProxy;
 
 
-/* "pysam/cvcf.pyx":95
- * ###########################################################################################################
+/* "ctabix.pxd":232
+ *     cdef tabix_t * tabixfile
  * 
- * cdef class VCFRecord( TabProxies.TupleProxy):             # <<<<<<<<<<<<<<
- *     '''vcf record.
+ * cdef class Parser:             # <<<<<<<<<<<<<<
+ *      cdef parse( self, char * buffer, int len )
  * 
  */
 
-struct __pyx_vtabstruct_5pysam_4cvcf_VCFRecord {
-  struct __pyx_vtabstruct_5pysam_10TabProxies_TupleProxy __pyx_base;
+struct __pyx_vtabstruct_5pysam_6ctabix_Parser {
+  PyObject *(*parse)(struct __pyx_obj_5pysam_6ctabix_Parser *, char *, int);
 };
-static struct __pyx_vtabstruct_5pysam_4cvcf_VCFRecord *__pyx_vtabptr_5pysam_4cvcf_VCFRecord;
+static struct __pyx_vtabstruct_5pysam_6ctabix_Parser *__pyx_vtabptr_5pysam_6ctabix_Parser;
 
 
-/* "ctabix.pxd":210
- *     cdef Parser parser
+/* "ctabix.pxd":242
+ *      pass
+ * 
+ * cdef class asBed(Parser):             # <<<<<<<<<<<<<<
+ *      pass
  * 
- * cdef class tabix_inplace_iterator:             # <<<<<<<<<<<<<<
- *     cdef FILE * infile
- *     cdef char * buffer
  */
 
-struct __pyx_vtabstruct_5pysam_6ctabix_tabix_inplace_iterator {
-  PyObject *(*__pyx___cnext__)(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator *);
+struct __pyx_vtabstruct_5pysam_6ctabix_asBed {
+  struct __pyx_vtabstruct_5pysam_6ctabix_Parser __pyx_base;
 };
-static struct __pyx_vtabstruct_5pysam_6ctabix_tabix_inplace_iterator *__pyx_vtabptr_5pysam_6ctabix_tabix_inplace_iterator;
+static struct __pyx_vtabstruct_5pysam_6ctabix_asBed *__pyx_vtabptr_5pysam_6ctabix_asBed;
+
+
+/* "ctabix.pxd":201
+ *     int ks_getuntil( kstream_t *, int, kstring_t *, int * )
+ * 
+ * cdef class tabix_file_iterator:             # <<<<<<<<<<<<<<
+ *     cdef gzFile fh
+ *     cdef kstream_t * ks
+ */
+
+struct __pyx_vtabstruct_5pysam_6ctabix_tabix_file_iterator {
+  PyObject *(*__pyx___cnext__)(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator *);
+};
+static struct __pyx_vtabstruct_5pysam_6ctabix_tabix_file_iterator *__pyx_vtabptr_5pysam_6ctabix_tabix_file_iterator;
+
+
+/* "ctabix.pxd":245
+ *      pass
+ * 
+ * cdef class asVCF(Parser):             # <<<<<<<<<<<<<<
+ *      pass
+ * 
+ */
+
+struct __pyx_vtabstruct_5pysam_6ctabix_asVCF {
+  struct __pyx_vtabstruct_5pysam_6ctabix_Parser __pyx_base;
+};
+static struct __pyx_vtabstruct_5pysam_6ctabix_asVCF *__pyx_vtabptr_5pysam_6ctabix_asVCF;
 
 
 /* "TabProxies.pxd":72
@@ -785,18 +817,32 @@ struct __pyx_vtabstruct_5pysam_10TabProxies_BedProxy {
 static struct __pyx_vtabstruct_5pysam_10TabProxies_BedProxy *__pyx_vtabptr_5pysam_10TabProxies_BedProxy;
 
 
-/* "ctabix.pxd":218
- *     cdef __cnext__(self)
+/* "pysam/cvcf.pyx":229
  * 
- * cdef class tabix_copy_iterator:             # <<<<<<<<<<<<<<
- *     cdef FILE * infile
- *     cdef Parser parser
+ * 
+ * cdef class asVCFRecord( ctabix.Parser ):             # <<<<<<<<<<<<<<
+ *     '''converts a :term:`tabix row` into a VCF record.'''
+ *     cdef vcffile
  */
 
-struct __pyx_vtabstruct_5pysam_6ctabix_tabix_copy_iterator {
-  PyObject *(*__pyx___cnext__)(struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator *);
+struct __pyx_vtabstruct_5pysam_4cvcf_asVCFRecord {
+  struct __pyx_vtabstruct_5pysam_6ctabix_Parser __pyx_base;
 };
-static struct __pyx_vtabstruct_5pysam_6ctabix_tabix_copy_iterator *__pyx_vtabptr_5pysam_6ctabix_tabix_copy_iterator;
+static struct __pyx_vtabstruct_5pysam_4cvcf_asVCFRecord *__pyx_vtabptr_5pysam_4cvcf_asVCFRecord;
+
+
+/* "ctabix.pxd":239
+ * 
+ * 
+ * cdef class asGTF(Parser):             # <<<<<<<<<<<<<<
+ *      pass
+ * 
+ */
+
+struct __pyx_vtabstruct_5pysam_6ctabix_asGTF {
+  struct __pyx_vtabstruct_5pysam_6ctabix_Parser __pyx_base;
+};
+static struct __pyx_vtabstruct_5pysam_6ctabix_asGTF *__pyx_vtabptr_5pysam_6ctabix_asGTF;
 
 
 /* "TabProxies.pxd":60
@@ -812,6 +858,20 @@ struct __pyx_vtabstruct_5pysam_10TabProxies_GTFProxy {
   char *(*getAttributes)(struct __pyx_obj_5pysam_10TabProxies_GTFProxy *);
 };
 static struct __pyx_vtabstruct_5pysam_10TabProxies_GTFProxy *__pyx_vtabptr_5pysam_10TabProxies_GTFProxy;
+
+
+/* "ctabix.pxd":235
+ *      cdef parse( self, char * buffer, int len )
+ * 
+ * cdef class asTuple(Parser):             # <<<<<<<<<<<<<<
+ *      cdef parse( self, char * buffer, int len )
+ * 
+ */
+
+struct __pyx_vtabstruct_5pysam_6ctabix_asTuple {
+  struct __pyx_vtabstruct_5pysam_6ctabix_Parser __pyx_base;
+};
+static struct __pyx_vtabstruct_5pysam_6ctabix_asTuple *__pyx_vtabptr_5pysam_6ctabix_asTuple;
 #ifndef CYTHON_REFNANNY
   #define CYTHON_REFNANNY 0
 #endif
@@ -1305,6 +1365,7 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
 
 
 /* Module declarations from 'pysam.ctabix' */
+static PyTypeObject *__pyx_ptype_5pysam_6ctabix_tabix_file_iterator = 0;
 static PyTypeObject *__pyx_ptype_5pysam_6ctabix_Tabixfile = 0;
 static PyTypeObject *__pyx_ptype_5pysam_6ctabix_TabixIterator = 0;
 static PyTypeObject *__pyx_ptype_5pysam_6ctabix_TabixHeaderIterator = 0;
@@ -1314,8 +1375,6 @@ static PyTypeObject *__pyx_ptype_5pysam_6ctabix_asGTF = 0;
 static PyTypeObject *__pyx_ptype_5pysam_6ctabix_asBed = 0;
 static PyTypeObject *__pyx_ptype_5pysam_6ctabix_asVCF = 0;
 static PyTypeObject *__pyx_ptype_5pysam_6ctabix_TabixIteratorParsed = 0;
-static PyTypeObject *__pyx_ptype_5pysam_6ctabix_tabix_inplace_iterator = 0;
-static PyTypeObject *__pyx_ptype_5pysam_6ctabix_tabix_copy_iterator = 0;
 
 /* Module declarations from 'pysam.TabProxies' */
 static PyTypeObject *__pyx_ptype_5pysam_10TabProxies_TupleProxy = 0;
@@ -23555,12 +23614,14 @@ static PyTypeObject __pyx_type_5pysam_4cvcf_VCFRecord = {
   0, /*tp_version_tag*/
   #endif
 };
+static struct __pyx_vtabstruct_5pysam_4cvcf_asVCFRecord __pyx_vtable_5pysam_4cvcf_asVCFRecord;
 
 static PyObject *__pyx_tp_new_5pysam_4cvcf_asVCFRecord(PyTypeObject *t, PyObject *a, PyObject *k) {
   struct __pyx_obj_5pysam_4cvcf_asVCFRecord *p;
   PyObject *o = __pyx_ptype_5pysam_6ctabix_Parser->tp_new(t, a, k);
   if (!o) return 0;
   p = ((struct __pyx_obj_5pysam_4cvcf_asVCFRecord *)o);
+  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_6ctabix_Parser*)__pyx_vtabptr_5pysam_4cvcf_asVCFRecord;
   p->vcffile = Py_None; Py_INCREF(Py_None);
   return o;
 }
@@ -26080,8 +26141,12 @@ PyMODINIT_FUNC PyInit_cvcf(void)
   if (__Pyx_SetAttrString(__pyx_m, "VCFRecord", (PyObject *)&__pyx_type_5pysam_4cvcf_VCFRecord) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_4cvcf_VCFRecord = &__pyx_type_5pysam_4cvcf_VCFRecord;
   __pyx_ptype_5pysam_6ctabix_Parser = __Pyx_ImportType("pysam.ctabix", "Parser", sizeof(struct __pyx_obj_5pysam_6ctabix_Parser), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_Parser)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_vtabptr_5pysam_6ctabix_Parser = (struct __pyx_vtabstruct_5pysam_6ctabix_Parser*)__Pyx_GetVtable(__pyx_ptype_5pysam_6ctabix_Parser->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6ctabix_Parser)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_vtabptr_5pysam_4cvcf_asVCFRecord = &__pyx_vtable_5pysam_4cvcf_asVCFRecord;
+  __pyx_vtable_5pysam_4cvcf_asVCFRecord.__pyx_base = *__pyx_vtabptr_5pysam_6ctabix_Parser;
   __pyx_type_5pysam_4cvcf_asVCFRecord.tp_base = __pyx_ptype_5pysam_6ctabix_Parser;
   if (PyType_Ready(&__pyx_type_5pysam_4cvcf_asVCFRecord) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_SetVtable(__pyx_type_5pysam_4cvcf_asVCFRecord.tp_dict, __pyx_vtabptr_5pysam_4cvcf_asVCFRecord) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__Pyx_SetAttrString(__pyx_m, "asVCFRecord", (PyObject *)&__pyx_type_5pysam_4cvcf_asVCFRecord) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_4cvcf_asVCFRecord = &__pyx_type_5pysam_4cvcf_asVCFRecord;
   if (PyType_Ready(&__pyx_type_5pysam_4cvcf___pyx_scope_struct__parse_data) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
@@ -26091,18 +26156,20 @@ PyMODINIT_FUNC PyInit_cvcf(void)
   if (PyType_Ready(&__pyx_type_5pysam_4cvcf___pyx_scope_struct_2__parse) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_4cvcf___pyx_scope_struct_2__parse = &__pyx_type_5pysam_4cvcf___pyx_scope_struct_2__parse;
   /*--- Type import code ---*/
-  __pyx_ptype_5pysam_6ctabix_Tabixfile = __Pyx_ImportType("pysam.ctabix", "Tabixfile", sizeof(struct __pyx_obj_5pysam_6ctabix_Tabixfile), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_Tabixfile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_ptype_5pysam_6ctabix_TabixIterator = __Pyx_ImportType("pysam.ctabix", "TabixIterator", sizeof(struct __pyx_obj_5pysam_6ctabix_TabixIterator), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_TabixIterator)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_ptype_5pysam_6ctabix_TabixHeaderIterator = __Pyx_ImportType("pysam.ctabix", "TabixHeaderIterator", sizeof(struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_TabixHeaderIterator)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_ptype_5pysam_6ctabix_asTuple = __Pyx_ImportType("pysam.ctabix", "asTuple", sizeof(struct __pyx_obj_5pysam_6ctabix_asTuple), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_asTuple)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_ptype_5pysam_6ctabix_asGTF = __Pyx_ImportType("pysam.ctabix", "asGTF", sizeof(struct __pyx_obj_5pysam_6ctabix_asGTF), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_asGTF)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_ptype_5pysam_6ctabix_asBed = __Pyx_ImportType("pysam.ctabix", "asBed", sizeof(struct __pyx_obj_5pysam_6ctabix_asBed), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_asBed)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_ptype_5pysam_6ctabix_asVCF = __Pyx_ImportType("pysam.ctabix", "asVCF", sizeof(struct __pyx_obj_5pysam_6ctabix_asVCF), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_asVCF)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_ptype_5pysam_6ctabix_TabixIteratorParsed = __Pyx_ImportType("pysam.ctabix", "TabixIteratorParsed", sizeof(struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_TabixIteratorParsed)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_ptype_5pysam_6ctabix_tabix_inplace_iterator = __Pyx_ImportType("pysam.ctabix", "tabix_inplace_iterator", sizeof(struct __pyx_obj_5pysam_6ctabix_tabix_inplace_iterator), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_tabix_inplace_iterator)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_vtabptr_5pysam_6ctabix_tabix_inplace_iterator = (struct __pyx_vtabstruct_5pysam_6ctabix_tabix_inplace_iterator*)__Pyx_GetVtable(__pyx_ptype_5pysam_6ctabix_tabix_inplace_iterator->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6ctabix_tabix_inplace_iterator)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_ptype_5pysam_6ctabix_tabix_copy_iterator = __Pyx_ImportType("pysam.ctabix", "tabix_copy_iterator", sizeof(struct __pyx_obj_5pysam_6ctabix_tabix_copy_iterator), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_tabix_copy_iterator)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_vtabptr_5pysam_6ctabix_tabix_copy_iterator = (struct __pyx_vtabstruct_5pysam_6ctabix_tabix_copy_iterator*)__Pyx_GetVtable(__pyx_ptype_5pysam_6ctabix_tabix_copy_iterator->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6ctabix_tabix_copy_iterator)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_6ctabix_tabix_file_iterator = __Pyx_ImportType("pysam.ctabix", "tabix_file_iterator", sizeof(struct __pyx_obj_5pysam_6ctabix_tabix_file_iterator), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_tabix_file_iterator)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_vtabptr_5pysam_6ctabix_tabix_file_iterator = (struct __pyx_vtabstruct_5pysam_6ctabix_tabix_file_iterator*)__Pyx_GetVtable(__pyx_ptype_5pysam_6ctabix_tabix_file_iterator->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6ctabix_tabix_file_iterator)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_6ctabix_Tabixfile = __Pyx_ImportType("pysam.ctabix", "Tabixfile", sizeof(struct __pyx_obj_5pysam_6ctabix_Tabixfile), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_Tabixfile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_6ctabix_TabixIterator = __Pyx_ImportType("pysam.ctabix", "TabixIterator", sizeof(struct __pyx_obj_5pysam_6ctabix_TabixIterator), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_TabixIterator)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_6ctabix_TabixHeaderIterator = __Pyx_ImportType("pysam.ctabix", "TabixHeaderIterator", sizeof(struct __pyx_obj_5pysam_6ctabix_TabixHeaderIterator), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_TabixHeaderIterator)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_6ctabix_asTuple = __Pyx_ImportType("pysam.ctabix", "asTuple", sizeof(struct __pyx_obj_5pysam_6ctabix_asTuple), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_asTuple)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_vtabptr_5pysam_6ctabix_asTuple = (struct __pyx_vtabstruct_5pysam_6ctabix_asTuple*)__Pyx_GetVtable(__pyx_ptype_5pysam_6ctabix_asTuple->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6ctabix_asTuple)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_6ctabix_asGTF = __Pyx_ImportType("pysam.ctabix", "asGTF", sizeof(struct __pyx_obj_5pysam_6ctabix_asGTF), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_asGTF)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_vtabptr_5pysam_6ctabix_asGTF = (struct __pyx_vtabstruct_5pysam_6ctabix_asGTF*)__Pyx_GetVtable(__pyx_ptype_5pysam_6ctabix_asGTF->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6ctabix_asGTF)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_6ctabix_asBed = __Pyx_ImportType("pysam.ctabix", "asBed", sizeof(struct __pyx_obj_5pysam_6ctabix_asBed), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_asBed)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_vtabptr_5pysam_6ctabix_asBed = (struct __pyx_vtabstruct_5pysam_6ctabix_asBed*)__Pyx_GetVtable(__pyx_ptype_5pysam_6ctabix_asBed->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6ctabix_asBed)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_6ctabix_asVCF = __Pyx_ImportType("pysam.ctabix", "asVCF", sizeof(struct __pyx_obj_5pysam_6ctabix_asVCF), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_asVCF)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_vtabptr_5pysam_6ctabix_asVCF = (struct __pyx_vtabstruct_5pysam_6ctabix_asVCF*)__Pyx_GetVtable(__pyx_ptype_5pysam_6ctabix_asVCF->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6ctabix_asVCF)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_ptype_5pysam_6ctabix_TabixIteratorParsed = __Pyx_ImportType("pysam.ctabix", "TabixIteratorParsed", sizeof(struct __pyx_obj_5pysam_6ctabix_TabixIteratorParsed), 1); if (unlikely(!__pyx_ptype_5pysam_6ctabix_TabixIteratorParsed)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_10TabProxies_GTFProxy = __Pyx_ImportType("pysam.TabProxies", "GTFProxy", sizeof(struct __pyx_obj_5pysam_10TabProxies_GTFProxy), 1); if (unlikely(!__pyx_ptype_5pysam_10TabProxies_GTFProxy)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_vtabptr_5pysam_10TabProxies_GTFProxy = (struct __pyx_vtabstruct_5pysam_10TabProxies_GTFProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_10TabProxies_GTFProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10TabProxies_GTFProxy)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_5pysam_10TabProxies_NamedTupleProxy = __Pyx_ImportType("pysam.TabProxies", "NamedTupleProxy", sizeof(struct __pyx_obj_5pysam_10TabProxies_NamedTupleProxy), 1); if (unlikely(!__pyx_ptype_5pysam_10TabProxies_NamedTupleProxy)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
diff --git a/pysam/tabix_util.c b/pysam/tabix_util.c
index 0305de1..89ffc23 100644
--- a/pysam/tabix_util.c
+++ b/pysam/tabix_util.c
@@ -1,5 +1,6 @@
 // Definition of pysamerr
 #include "stdio.h"
+#include "unistd.h"
 FILE * pysamerr = NULL;
 
 #if !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
@@ -24,3 +25,4 @@ getline(char **line, size_t *linelen, FILE *fp)
 
 }
 #endif
+
diff --git a/pysam/tabix_util.h b/pysam/tabix_util.h
index 6a7db92..e3e38d1 100644
--- a/pysam/tabix_util.h
+++ b/pysam/tabix_util.h
@@ -1,6 +1,13 @@
 /* See issue 122
    On some MACOSX systems getline is not defined.
  */
+#include <zlib.h>
+#include "kseq.h"
+
 #if !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
+#include "unistd.h"
 ssize_t getline(char **line, size_t *linelen, FILE *fp);
 #endif
+
+KSTREAM_INIT( gzFile, gzread, 16384)
+
diff --git a/pysam/version.py b/pysam/version.py
index 0dfb2cf..c3375ad 100644
--- a/pysam/version.py
+++ b/pysam/version.py
@@ -1,6 +1,6 @@
 # pysam versioning information
 
-__version__ = "0.7.6"
+__version__ = "0.7.7"
 
 __samtools_version__ = "0.1.19"
 
diff --git a/tests/Makefile b/tests/Makefile
index 05963e5..e985e61 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -13,6 +13,7 @@ all: ex1.pileup.gz ex1.bam.bai \
 	example_user_header.bam \
 	example_btag.bam \
 	example_bai.bam \
+	softclip.bam
 
 ex2.sam.gz: ex1.bam ex1.bam.bai
 		samtools view -h ex1.bam | gzip > ex2.sam.gz
@@ -42,8 +43,8 @@ example_bai.bam: ex1.bam
 	samtools index $@
 	mv $@.bai example_bai.bai
 
-
-
+softclip.bam: softclip.sam
+	samtools view -bS $< > $@
 
 clean:
 	rm -fr *.bam *.bai *.fai *.pileup* \
diff --git a/tests/pysam_test.py b/tests/pysam_test.py
index 67f205f..3cb49bd 100755
--- a/tests/pysam_test.py
+++ b/tests/pysam_test.py
@@ -667,6 +667,40 @@ class TestTagParsing( unittest.TestCase ):
         
         self.assertEqual( tags, r.tags )
 
+class TestClipping(unittest.TestCase):
+    
+    def testClipping( self ):
+        
+        self.samfile = pysam.Samfile("softclip.bam", "rb" )
+        for read in self.samfile:
+
+            if read.qname == "r001":
+                self.assertEqual( read.seq, b'AAAAGATAAGGATA' )
+                self.assertEqual( read.query, b'AGATAAGGATA' )
+                self.assertEqual( read.qual, None )
+                self.assertEqual( read.qqual, None )
+                
+            elif read.qname == "r002":
+                
+                self.assertEqual( read.seq, b'GCCTAAGCTAA' )
+                self.assertEqual( read.query, b'AGCTAA' )
+                self.assertEqual( read.qual, b'01234567890' )
+                self.assertEqual( read.qqual, b'567890' )
+            
+            elif read.qname == "r003":
+                
+                self.assertEqual( read.seq, b'GCCTAAGCTAA' )
+                self.assertEqual( read.query, b'GCCTAA' )
+                self.assertEqual( read.qual, b'01234567890' )
+                self.assertEqual( read.qqual, b'012345' )
+
+            elif read.qname == "r004":
+                
+                self.assertEqual( read.seq, b'TAGGC' )
+                self.assertEqual( read.query, b'TAGGC' )
+                self.assertEqual( read.qual, b'01234' )
+                self.assertEqual( read.qqual, b'01234' )
+                
 class TestIteratorRow(unittest.TestCase):
 
     def setUp(self):
@@ -980,7 +1014,24 @@ class TestHeaderBam(TestHeaderSam):
     def setUp(self):
         self.samfile=pysam.Samfile( "ex3.bam","rb" )
 
+class TestHeaderFromRefs( unittest.TestCase ):
+    '''see issue 144
+
+    reference names need to be converted to string for python 3
+    '''
 
+    def testHeader( self ):
+        refs = ['chr1', 'chr2']
+        tmpfile = "tmp_%i" % id(self)
+        s = pysam.Samfile(tmpfile, 'wb', 
+                          referencenames=refs, 
+                          referencelengths=[100]*len(refs))
+        s.close()
+        
+        self.assertTrue( checkBinaryEqual( 'issue144.bam', tmpfile ),
+                         'bam files differ')
+        os.unlink( tmpfile )
+        
 class TestHeader1000Genomes( unittest.TestCase ):
 
     # bamfile = "http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/phase2b_alignment/data/NA07048/exome_alignment/NA07048.unmapped.ILLUMINA.bwa.CEU.exome.20120522_p2b.bam"
@@ -1150,6 +1201,7 @@ class TestFastaFile(unittest.TestCase):
 
         
         # unknown sequence returns ""
+        # change: should be an IndexError
         self.assertEqual( b"", self.file.fetch("chr12") )
 
     def testOutOfRangeAccess( self ):
@@ -1162,12 +1214,19 @@ class TestFastaFile(unittest.TestCase):
 
     def testFetchErrors( self ):
         self.assertRaises( ValueError, self.file.fetch )
-        self.assertRaises( ValueError, self.file.fetch, "chr1", -1, 10 )
+        self.assertRaises( IndexError, self.file.fetch, "chr1", -1, 10 )
         self.assertRaises( ValueError, self.file.fetch, "chr1", 20, 10 )
+        
+        # does not work yet
+        # self.assertRaises( KeyError, self.file.fetch, "chrX" )
 
     def testLength( self ):
         self.assertEqual( len(self.file), 2 )
         
+    def testSequenceLengths( self ):
+        self.assertEqual( 1575, self.file.getReferenceLength( "chr1" ) )
+        self.assertEqual( 1584, self.file.getReferenceLength( "chr2" ) )
+
     def tearDown(self):
         self.file.close()
 
diff --git a/tests/tabix_test.py b/tests/tabix_test.py
index 3477340..90c2340 100644
--- a/tests/tabix_test.py
+++ b/tests/tabix_test.py
@@ -28,22 +28,32 @@ def myzip_open( infile, mode = "r" ):
     else:
         return gzip.open( mode )
 
-def loadAndConvert( infile ):
-    '''load and convert all fields to bytes'''
+def loadAndConvert( infile, encode = True ):
+    '''load data from infile and convert all fields to bytes.
+
+    infile can be either plain or compressed (ending in .gz).
+    '''
     data = []
     if infile.endswith(".gz"):
         for line in gzip.open( infile ):
             line = line.decode("ascii")
             if line.startswith("#"): continue
             d = line.strip().split("\t")
-            data.append( [x.encode("ascii") for x in d ] )
+            if encode:
+                data.append( [x.encode("ascii") for x in d ] )
+            else:
+                data.append( d )
+
     else:
         with open(infile) as f:
             for line in f:
                 if line.startswith("#"): continue
                 d = line.strip().split("\t")
-                data.append( [x.encode("ascii") for x in d ] )
-
+                if encode:
+                    data.append( [x.encode("ascii") for x in d ] )
+                else:
+                    data.append( d )
+                
     return data
 
 def splitToBytes( s ):
@@ -91,32 +101,62 @@ class TestIndexing(unittest.TestCase):
 class TestCompression(unittest.TestCase):
     filename = "example.gtf.gz" 
     filename_idx = "example.gtf.gz.tbi" 
+    preset = "gff"
 
     def setUp( self ):
         
-        self.tmpfilename = "tmp_%i.gtf" % id(self)
+        self.tmpfilename = "tmp_%i" % id(self)
         infile = gzip.open( self.filename, "rb")
         outfile = open( self.tmpfilename, "wb" )
         outfile.write( infile.read() )
         outfile.close()
         infile.close()
 
-    def testIndexPreset( self ):
+    def testCompression( self ):
+        '''see also issue 106'''
+        pysam.tabix_compress( self.tmpfilename, self.tmpfilename + ".gz" )
+        checkBinaryEqual( self.tmpfilename, self.tmpfilename + ".gz" )
+
+    def testIndexPresetUncompressed( self ):
         '''test indexing via preset.'''
         
-        pysam.tabix_index( self.tmpfilename, preset = "gff" )
+        pysam.tabix_index( self.tmpfilename, preset = self.preset )
+        # check if uncompressed file has been removed
+        self.assertEqual( os.path.exists( self.tmpfilename ), False )
         checkBinaryEqual( self.tmpfilename + ".gz", self.filename )
         checkBinaryEqual( self.tmpfilename + ".gz.tbi", self.filename_idx )
 
-    def testCompression( self ):
-        '''see also issue 106'''
+    def testIndexPresetCompressed( self ):
+        '''test indexing via preset.'''
+
         pysam.tabix_compress( self.tmpfilename, self.tmpfilename + ".gz" )
-        checkBinaryEqual( self.tmpfilename, self.tmpfilename + ".gz" )
+        pysam.tabix_index( self.tmpfilename + ".gz", preset = self.preset )
+        checkBinaryEqual( self.tmpfilename + ".gz", self.filename )
+        checkBinaryEqual( self.tmpfilename + ".gz.tbi", self.filename_idx )
         
     def tearDown( self ):
-        os.unlink( self.tmpfilename + ".gz" )
-        if os.path.exists( self.tmpfilename + ".gz.tbi" ):
+
+        try: 
+            os.unlink( self.tmpfilename )
+            os.unlink( self.tmpfilename + ".gz" )
             os.unlink( self.tmpfilename + ".gz.tbi" )
+        except OSError:
+            pass
+
+class TestCompressionSam( TestCompression ):
+    filename = "example.sam.gz"
+    filename_index = "example.sam.gz.tbi"
+    preset = "sam"
+
+class TestCompressionBed( TestCompression ):
+    filename = "example.bed.gz"
+    filename_index = "example.bed.gz.tbi"
+    preset = "bed"
+
+class TestCompressionVCF( TestCompression ):
+    filename = "example.vcf.gz"
+    filename_index = "example.vcf.gz.tbi"
+    preset = "vcf"
 
 class TestIteration( unittest.TestCase ):
 
@@ -231,11 +271,23 @@ class TestIteration( unittest.TestCase ):
 
     def testInvalidIntervals( self ):
         
+        # invalid intervals (start > end)
         self.assertRaises( ValueError, self.tabix.fetch, "chr1", 0, -10)
-        self.assertRaises( ValueError, self.tabix.fetch, "chr1", -10, 200)
         self.assertRaises( ValueError, self.tabix.fetch, "chr1", 200, 0)
-        self.assertRaises( ValueError, self.tabix.fetch, "chr1", -10, -20)
-        self.assertRaises( ValueError, self.tabix.fetch, "chrUn" )
+
+        # out of range intervals
+        self.assertRaises( IndexError, self.tabix.fetch, "chr1", -10, 200)
+        self.assertRaises( IndexError, self.tabix.fetch, "chr1", -10, -20)
+
+        # unknown chromosome
+        self.assertRaises( KeyError, self.tabix.fetch, "chrUn" )
+
+        # out of range access
+        # to be implemented
+        # self.assertRaises( IndexError, self.tabix.fetch, "chr1", 1000000, 2000000 )
+
+        # raise no error for invalid intervals
+        self.tabix.fetch( "chr1", 100,100)
 
     def testGetContigs( self ):
         self.assertEqual( sorted(self.tabix.contigs), [b"chr1", b"chr2"] )
@@ -360,6 +412,85 @@ class TestParser( unittest.TestCase ):
 
         os.unlink( tmpfilename )
 
+class TestIterators( unittest.TestCase ):
+
+    filename = "example.gtf.gz" 
+
+    iterator = pysam.tabix_generic_iterator
+    parser = pysam.asTuple
+    is_compressed = False
+
+    def setUp( self ):
+
+        self.tabix = pysam.Tabixfile( self.filename )
+        self.compare = loadAndConvert( self.filename )
+        self.tmpfilename_uncompressed = 'tmp_TestIterators'
+        infile = gzip.open( self.filename, "rb")
+        outfile = open( self.tmpfilename_uncompressed, "wb" )
+        outfile.write( infile.read() )
+        outfile.close()
+        infile.close()
+
+    def open( self ):
+
+        if self.is_compressed:
+            infile = gzip.open( self.filename )
+        else:
+            infile = open( self.tmpfilename_uncompressed ) 
+        return infile
+
+    def testIteration( self ):
+
+        infile = self.open()
+
+        for x, r in enumerate(self.iterator( infile, self.parser())):
+            self.assertEqual( self.compare[x], list(r) )
+            self.assertEqual( len(self.compare[x]), len(r) )
+
+            # test indexing
+            for c in range(0,len(r)):
+                self.assertEqual( self.compare[x][c], r[c] )
+
+            # test slicing access
+            for c in range(0, len(r)-1):
+                for cc in range(c+1, len(r)):
+                    self.assertEqual( self.compare[x][c:cc],
+                                      r[c:cc] )
+
+    def testClosedFile( self ):
+        '''test for error when iterating from closed file.'''
+        infile = self.open()
+        infile.close()
+
+        # iterating from a closed file should raise a value error
+        self.assertRaises( ValueError, self.iterator, infile, self.parser())
+
+    def testClosedFileIteration( self ):
+        '''test for error when iterating from file that has been closed'''
+        
+        infile = self.open()
+
+        i = self.iterator( infile, self.parser())
+        x = i.next()
+        infile.close()
+        # Not implemented
+        #self.assertRaises( ValueError, i.next )
+
+    def tearUp( self ):
+        os.unlink( self.tmpfilename_uncompressed )
+
+class TestIteratorsGenericCompressed( TestIterators ):
+    is_compressed = True
+
+class TestIteratorsFileCompressed( TestIterators ):
+    iterator = pysam.tabix_file_iterator
+    is_compressed = True
+
+class TestIteratorsFileUncompressed( TestIterators ):
+    iterator = pysam.tabix_file_iterator
+    is_compressed = False
+                      
+
 class TestGTF( TestParser ):
 
     def testRead( self ):
@@ -527,7 +658,7 @@ class TestVCFFromVCF( TestVCF ):
         TestVCF.setUp( self )
 
         self.vcf = pysam.VCF()
-        self.compare = loadAndConvert( self.filename )
+        self.compare = loadAndConvert( self.filename, encode = False )
 
     def testParsing( self ):
 
@@ -612,7 +743,7 @@ class TestVCFFromVCF( TestVCF ):
                         else:
                             self.assertEqual( c[y], val, 
                                               "mismatch in field %s: expected %s, got %s" %\
-                                                  ( field,c[y], val ) )
+                                                  ( field, c[y], val ) )
 
 ############################################################################ 
 # create a test class for each example vcf file.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-pysam.git



More information about the debian-med-commit mailing list